Created
August 9, 2023 05:00
-
-
Save layou233/edb68fbcf5a6139909a264b628828e54 to your computer and use it in GitHub Desktop.
SSE accelerated uint128 left shift in Go
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
| package main | |
| import "fmt" | |
| func main() { | |
| var x, y uint64 = 0x123456789abcdef0, 0xfedcba9876543213 | |
| fmt.Printf("Before shift: %016x%016x\n", x, y) | |
| //y <<= 8 | |
| //x = x<<8 | y>>(64-8) | |
| y, x = shiftLeft128ASM(y, x) | |
| fmt.Printf("After shift: %016x%016x\n", x, y) | |
| } | |
| //go:noescape | |
| func shiftLeft128ASM(lo, hi uint64) (uint64, uint64) |
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
| //go:build i386 || amd64 | |
| #include "textflag.h" | |
| TEXT ·shiftLeft128ASM(SB), NOSPLIT, $0-32 | |
| MOVOA x+0(FP), X0 | |
| PSLLDQ $1, X0 | |
| MOVOA X0, x+16(FP) | |
| RET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment