-
Notifications
You must be signed in to change notification settings - Fork 260
Accelerate dense bitmap decoding in ToArray #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
perfloop-agent
wants to merge
2
commits into
RoaringBitmap:master
from
perfloop:perfloop-pr-open-kcdwa7sdmg
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| //go:build amd64 && !appengine | ||
| // +build amd64,!appengine | ||
|
|
||
| package roaring | ||
|
|
||
| //go:noescape | ||
| func fillLeastSignificant16bitsAVX512(bitmap []uint64, x []uint32, pos int, mask uint32) int | ||
|
|
||
| //go:noescape | ||
| func _hasAVX512() bool | ||
|
|
||
| // AVX-512 is used only when the operating system saves the ZMM state and the | ||
| // CPU exposes AVX-512 Foundation. The scalar implementation remains available | ||
| // for CPUs without that feature and for appengine builds. | ||
| var useAVX512 = _hasAVX512() | ||
This file contains hidden or 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,127 @@ | ||
| //go:build amd64 && !appengine | ||
| // +build amd64,!appengine | ||
|
|
||
| #include "textflag.h" | ||
|
|
||
| // The vector contains the 16 possible bit positions in one 16-bit input | ||
| // block. VPCOMPRESSD writes only the lanes selected by the input mask, so its | ||
| // store is exactly the variable-sized output for that block. | ||
| DATA fillLeastSignificant16bitsOffsets<>+0(SB)/4, $0 | ||
| DATA fillLeastSignificant16bitsOffsets<>+4(SB)/4, $1 | ||
| DATA fillLeastSignificant16bitsOffsets<>+8(SB)/4, $2 | ||
| DATA fillLeastSignificant16bitsOffsets<>+12(SB)/4, $3 | ||
| DATA fillLeastSignificant16bitsOffsets<>+16(SB)/4, $4 | ||
| DATA fillLeastSignificant16bitsOffsets<>+20(SB)/4, $5 | ||
| DATA fillLeastSignificant16bitsOffsets<>+24(SB)/4, $6 | ||
| DATA fillLeastSignificant16bitsOffsets<>+28(SB)/4, $7 | ||
| DATA fillLeastSignificant16bitsOffsets<>+32(SB)/4, $8 | ||
| DATA fillLeastSignificant16bitsOffsets<>+36(SB)/4, $9 | ||
| DATA fillLeastSignificant16bitsOffsets<>+40(SB)/4, $10 | ||
| DATA fillLeastSignificant16bitsOffsets<>+44(SB)/4, $11 | ||
| DATA fillLeastSignificant16bitsOffsets<>+48(SB)/4, $12 | ||
| DATA fillLeastSignificant16bitsOffsets<>+52(SB)/4, $13 | ||
| DATA fillLeastSignificant16bitsOffsets<>+56(SB)/4, $14 | ||
| DATA fillLeastSignificant16bitsOffsets<>+60(SB)/4, $15 | ||
| GLOBL fillLeastSignificant16bitsOffsets<>(SB), RODATA|NOPTR, $64 | ||
|
|
||
| // func fillLeastSignificant16bitsAVX512(bitmap []uint64, x []uint32, pos int, mask uint32) int | ||
| TEXT ·fillLeastSignificant16bitsAVX512(SB), NOSPLIT, $0-72 | ||
| MOVQ bitmap_base+0(FP), SI | ||
| MOVQ bitmap_len+8(FP), CX | ||
| MOVQ x_base+24(FP), DI | ||
| MOVQ pos+48(FP), R8 | ||
| LEAQ (DI)(R8*4), DI | ||
| MOVL mask+56(FP), R9 | ||
| VMOVDQU64 fillLeastSignificant16bitsOffsets<>(SB), Z0 | ||
|
|
||
| TESTQ CX, CX | ||
| JZ fillLeastSignificant16bitsAVX512Done | ||
| fillLeastSignificant16bitsAVX512Loop: | ||
| MOVQ (SI), AX | ||
|
|
||
| MOVWQZX AX, R11 | ||
| KMOVW R11, K1 | ||
| VPBROADCASTD R9, Z1 | ||
| VPADDD Z1, Z0, Z2 | ||
| VPCOMPRESSD Z2, K1, (DI) | ||
| POPCNTQ R11, R11 | ||
| ADDQ R11, R8 | ||
| SHLQ $2, R11 | ||
| ADDQ R11, DI | ||
| ADDQ $16, R9 | ||
| SHRQ $16, AX | ||
|
|
||
| MOVWQZX AX, R11 | ||
| KMOVW R11, K1 | ||
| VPBROADCASTD R9, Z1 | ||
| VPADDD Z1, Z0, Z2 | ||
| VPCOMPRESSD Z2, K1, (DI) | ||
| POPCNTQ R11, R11 | ||
| ADDQ R11, R8 | ||
| SHLQ $2, R11 | ||
| ADDQ R11, DI | ||
| ADDQ $16, R9 | ||
| SHRQ $16, AX | ||
|
|
||
| MOVWQZX AX, R11 | ||
| KMOVW R11, K1 | ||
| VPBROADCASTD R9, Z1 | ||
| VPADDD Z1, Z0, Z2 | ||
| VPCOMPRESSD Z2, K1, (DI) | ||
| POPCNTQ R11, R11 | ||
| ADDQ R11, R8 | ||
| SHLQ $2, R11 | ||
| ADDQ R11, DI | ||
| ADDQ $16, R9 | ||
| SHRQ $16, AX | ||
|
|
||
| MOVWQZX AX, R11 | ||
| KMOVW R11, K1 | ||
| VPBROADCASTD R9, Z1 | ||
| VPADDD Z1, Z0, Z2 | ||
| VPCOMPRESSD Z2, K1, (DI) | ||
| POPCNTQ R11, R11 | ||
| ADDQ R11, R8 | ||
| SHLQ $2, R11 | ||
| ADDQ R11, DI | ||
| ADDQ $16, R9 | ||
|
|
||
| ADDQ $8, SI | ||
| DECQ CX | ||
| JNZ fillLeastSignificant16bitsAVX512Loop | ||
| fillLeastSignificant16bitsAVX512Done: | ||
| VZEROUPPER | ||
| MOVQ R8, ret+64(FP) | ||
| RET | ||
|
|
||
| // func _hasAVX512() bool | ||
| // Reports whether AVX-512 Foundation is available and the OS has enabled the | ||
| // complete state needed by ZMM and opmask registers. The check is done once at | ||
| // package initialization, so unsupported machines never execute the vector | ||
| // decoder. | ||
| TEXT ·_hasAVX512(SB), NOSPLIT, $0-1 | ||
| // CPUID leaf 1: require OSXSAVE (ECX bit 27) and AVX (ECX bit 28). | ||
| MOVL $1, AX | ||
| XORL CX, CX | ||
| CPUID | ||
| NOTL CX | ||
| TESTL $0x18000000, CX | ||
| JNE noavx512 | ||
|
|
||
| // XCR0: bits 1, 2, 5, 6, and 7 enable the SSE, YMM, opmask, ZMM_hi256, | ||
| // and Hi16_ZMM state that AVX-512 instructions use. | ||
| XORL CX, CX | ||
| XGETBV | ||
| NOTL AX | ||
| TESTL $0xe6, AX | ||
| JNE noavx512 | ||
|
|
||
| // CPUID leaf 7, sub-leaf 0: AVX-512 Foundation is EBX bit 16. | ||
| MOVL $7, AX | ||
| XORL CX, CX | ||
| CPUID | ||
| NOTL BX | ||
| TESTL $0x10000, BX | ||
| noavx512: | ||
| SETEQ ret+0(FP) | ||
| RET |
This file contains hidden or 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,10 @@ | ||
| //go:build !amd64 || appengine | ||
| // +build !amd64 appengine | ||
|
|
||
| package roaring | ||
|
|
||
| const useAVX512 = false | ||
|
|
||
| func fillLeastSignificant16bitsAVX512(bitmap []uint64, x []uint32, pos int, mask uint32) int { | ||
| return fillLeastSignificant16bitsScalar(bitmap, x, pos, mask) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. This will be a problem, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in
74b708afddae. Response to this feedback.The repaired source retains the OS and CPU feature gate before executing AVX-512 instructions, and keeps the ordered
ToArraycursor and existing allocation path unchanged. This limits the new path to supported dense inputs.