Skip to content

Instantly share code, notes, and snippets.

@layou233
Created August 9, 2023 05:00
Show Gist options
  • Select an option

  • Save layou233/edb68fbcf5a6139909a264b628828e54 to your computer and use it in GitHub Desktop.

Select an option

Save layou233/edb68fbcf5a6139909a264b628828e54 to your computer and use it in GitHub Desktop.
SSE accelerated uint128 left shift in Go
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)
//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