forked from RoaringBitmap/roaring
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 12c3e01.
- Loading branch information
Showing
5 changed files
with
244 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// +build amd64,!appengine | ||
|
||
TEXT ·hasAsm(SB),4,$0-1 | ||
MOVQ $1, AX | ||
CPUID | ||
SHRQ $23, CX | ||
ANDQ $1, CX | ||
MOVB CX, ret+0(FP) | ||
RET | ||
|
||
#define POPCNTQ_DX_DX BYTE $0xf3; BYTE $0x48; BYTE $0x0f; BYTE $0xb8; BYTE $0xd2 | ||
|
||
TEXT ·popcntSliceAsm(SB),4,$0-32 | ||
XORQ AX, AX | ||
MOVQ s+0(FP), SI | ||
MOVQ s_len+8(FP), CX | ||
TESTQ CX, CX | ||
JZ popcntSliceEnd | ||
popcntSliceLoop: | ||
BYTE $0xf3; BYTE $0x48; BYTE $0x0f; BYTE $0xb8; BYTE $0x16 // POPCNTQ (SI), DX | ||
ADDQ DX, AX | ||
ADDQ $8, SI | ||
LOOP popcntSliceLoop | ||
popcntSliceEnd: | ||
MOVQ AX, ret+24(FP) | ||
RET | ||
|
||
TEXT ·popcntMaskSliceAsm(SB),4,$0-56 | ||
XORQ AX, AX | ||
MOVQ s+0(FP), SI | ||
MOVQ s_len+8(FP), CX | ||
TESTQ CX, CX | ||
JZ popcntMaskSliceEnd | ||
MOVQ m+24(FP), DI | ||
popcntMaskSliceLoop: | ||
MOVQ (DI), DX | ||
NOTQ DX | ||
ANDQ (SI), DX | ||
POPCNTQ_DX_DX | ||
ADDQ DX, AX | ||
ADDQ $8, SI | ||
ADDQ $8, DI | ||
LOOP popcntMaskSliceLoop | ||
popcntMaskSliceEnd: | ||
MOVQ AX, ret+48(FP) | ||
RET | ||
|
||
TEXT ·popcntAndSliceAsm(SB),4,$0-56 | ||
XORQ AX, AX | ||
MOVQ s+0(FP), SI | ||
MOVQ s_len+8(FP), CX | ||
TESTQ CX, CX | ||
JZ popcntAndSliceEnd | ||
MOVQ m+24(FP), DI | ||
popcntAndSliceLoop: | ||
MOVQ (DI), DX | ||
ANDQ (SI), DX | ||
POPCNTQ_DX_DX | ||
ADDQ DX, AX | ||
ADDQ $8, SI | ||
ADDQ $8, DI | ||
LOOP popcntAndSliceLoop | ||
popcntAndSliceEnd: | ||
MOVQ AX, ret+48(FP) | ||
RET | ||
|
||
TEXT ·popcntOrSliceAsm(SB),4,$0-56 | ||
XORQ AX, AX | ||
MOVQ s+0(FP), SI | ||
MOVQ s_len+8(FP), CX | ||
TESTQ CX, CX | ||
JZ popcntOrSliceEnd | ||
MOVQ m+24(FP), DI | ||
popcntOrSliceLoop: | ||
MOVQ (DI), DX | ||
ORQ (SI), DX | ||
POPCNTQ_DX_DX | ||
ADDQ DX, AX | ||
ADDQ $8, SI | ||
ADDQ $8, DI | ||
LOOP popcntOrSliceLoop | ||
popcntOrSliceEnd: | ||
MOVQ AX, ret+48(FP) | ||
RET | ||
|
||
TEXT ·popcntXorSliceAsm(SB),4,$0-56 | ||
XORQ AX, AX | ||
MOVQ s+0(FP), SI | ||
MOVQ s_len+8(FP), CX | ||
TESTQ CX, CX | ||
JZ popcntXorSliceEnd | ||
MOVQ m+24(FP), DI | ||
popcntXorSliceLoop: | ||
MOVQ (DI), DX | ||
XORQ (SI), DX | ||
POPCNTQ_DX_DX | ||
ADDQ DX, AX | ||
ADDQ $8, SI | ||
ADDQ $8, DI | ||
LOOP popcntXorSliceLoop | ||
popcntXorSliceEnd: | ||
MOVQ AX, ret+48(FP) | ||
RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// +build amd64,!appengine | ||
|
||
package roaring | ||
|
||
// *** the following functions are defined in popcnt_amd64.s | ||
|
||
//go:noescape | ||
|
||
func hasAsm() bool | ||
|
||
// useAsm is a flag used to select the GO or ASM implementation of the popcnt function | ||
var useAsm = hasAsm() | ||
|
||
//go:noescape | ||
|
||
func popcntSliceAsm(s []uint64) uint64 | ||
|
||
//go:noescape | ||
|
||
func popcntMaskSliceAsm(s, m []uint64) uint64 | ||
|
||
//go:noescape | ||
|
||
func popcntAndSliceAsm(s, m []uint64) uint64 | ||
|
||
//go:noescape | ||
|
||
func popcntOrSliceAsm(s, m []uint64) uint64 | ||
|
||
//go:noescape | ||
|
||
func popcntXorSliceAsm(s, m []uint64) uint64 | ||
|
||
func popcntSlice(s []uint64) uint64 { | ||
if useAsm { | ||
return popcntSliceAsm(s) | ||
} | ||
return popcntSliceGo(s) | ||
} | ||
|
||
func popcntMaskSlice(s, m []uint64) uint64 { | ||
if useAsm { | ||
return popcntMaskSliceAsm(s, m) | ||
} | ||
return popcntMaskSliceGo(s, m) | ||
} | ||
|
||
func popcntAndSlice(s, m []uint64) uint64 { | ||
if useAsm { | ||
return popcntAndSliceAsm(s, m) | ||
} | ||
return popcntAndSliceGo(s, m) | ||
} | ||
|
||
func popcntOrSlice(s, m []uint64) uint64 { | ||
if useAsm { | ||
return popcntOrSliceAsm(s, m) | ||
} | ||
return popcntOrSliceGo(s, m) | ||
} | ||
|
||
func popcntXorSlice(s, m []uint64) uint64 { | ||
if useAsm { | ||
return popcntXorSliceAsm(s, m) | ||
} | ||
return popcntXorSliceGo(s, m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// +build !amd64 appengine | ||
|
||
package roaring | ||
|
||
func popcntSlice(s []uint64) uint64 { | ||
return popcntSliceGo(s) | ||
} | ||
|
||
func popcntMaskSlice(s, m []uint64) uint64 { | ||
return popcntMaskSliceGo(s, m) | ||
} | ||
|
||
func popcntAndSlice(s, m []uint64) uint64 { | ||
return popcntAndSliceGo(s, m) | ||
} | ||
|
||
func popcntOrSlice(s, m []uint64) uint64 { | ||
return popcntOrSliceGo(s, m) | ||
} | ||
|
||
func popcntXorSlice(s, m []uint64) uint64 { | ||
return popcntXorSliceGo(s, m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters