Source file src/simd/archsimd/internal/simd_test/clmul_test.go
1 // Copyright 2026 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build goexperiment.simdstable && (amd64 || arm64) 6 7 package simd_test 8 9 // clmul64 returns the 128-bit carryless product of a and b. 10 func clmul64(a, b uint64) (lo, hi uint64) { 11 for i := range 64 { 12 if b>>i&1 != 0 { 13 lo ^= a << i 14 if i > 0 { 15 hi ^= a >> (64 - i) 16 } 17 } 18 } 19 return lo, hi 20 } 21 22 // clmulSlice returns a slice simulation of the CarrylessMul method that, 23 // for each pair of elements, multiplies element i of the pair of x by element 24 // j of the pair of y. 25 func clmulSlice(i, j int) func(x, y []uint64) []uint64 { 26 return func(x, y []uint64) []uint64 { 27 z := make([]uint64, len(x)) 28 for k := 0; k < len(x); k += 2 { 29 z[k], z[k+1] = clmul64(x[k+i], y[k+j]) 30 } 31 return z 32 } 33 } 34