| |
|
|
| |
| |
| |
|
|
| package codegen |
|
|
| func andn64(x, y int64) int64 { |
| |
| return x &^ y |
| } |
|
|
| func andn32(x, y int32) int32 { |
| |
| return x &^ y |
| } |
|
|
| func blsi64(x int64) int64 { |
| |
| return x & -x |
| } |
|
|
| func blsi32(x int32) int32 { |
| |
| return x & -x |
| } |
|
|
| func blsmsk64(x int64) int64 { |
| |
| return x ^ (x - 1) |
| } |
|
|
| func blsmsk32(x int32) int32 { |
| |
| return x ^ (x - 1) |
| } |
|
|
| func blsr64(x int64) int64 { |
| |
| return x & (x - 1) |
| } |
|
|
| func blsr32(x int32) int32 { |
| |
| return x & (x - 1) |
| } |
|
|
| func isPowerOfTwo64(x int64) bool { |
| |
| return blsr64(x) == 0 |
| } |
|
|
| func isPowerOfTwo32(x int32) bool { |
| |
| return blsr32(x) == 0 |
| } |
|
|
| func isPowerOfTwoSelect64(x, a, b int64) int64 { |
| var r int64 |
| |
| if isPowerOfTwo64(x) { |
| r = a |
| } else { |
| r = b |
| } |
| |
| return r * 2 |
| } |
|
|
| func isPowerOfTwoSelect32(x, a, b int32) int32 { |
| var r int32 |
| |
| if isPowerOfTwo32(x) { |
| r = a |
| } else { |
| r = b |
| } |
| |
| return r * 2 |
| } |
|
|
| func isPowerOfTwoBranch64(x int64, a func(bool), b func(string)) { |
| |
| if isPowerOfTwo64(x) { |
| a(true) |
| } else { |
| b("false") |
| } |
| } |
|
|
| func isPowerOfTwoBranch32(x int32, a func(bool), b func(string)) { |
| |
| if isPowerOfTwo32(x) { |
| a(true) |
| } else { |
| b("false") |
| } |
| } |
|
|
| func isNotPowerOfTwo64(x int64) bool { |
| |
| return blsr64(x) != 0 |
| } |
|
|
| func isNotPowerOfTwo32(x int32) bool { |
| |
| return blsr32(x) != 0 |
| } |
|
|
| func isNotPowerOfTwoSelect64(x, a, b int64) int64 { |
| var r int64 |
| |
| if isNotPowerOfTwo64(x) { |
| r = a |
| } else { |
| r = b |
| } |
| |
| return r * 2 |
| } |
|
|
| func isNotPowerOfTwoSelect32(x, a, b int32) int32 { |
| var r int32 |
| |
| if isNotPowerOfTwo32(x) { |
| r = a |
| } else { |
| r = b |
| } |
| |
| return r * 2 |
| } |
|
|
| func isNotPowerOfTwoBranch64(x int64, a func(bool), b func(string)) { |
| |
| if isNotPowerOfTwo64(x) { |
| a(true) |
| } else { |
| b("false") |
| } |
| } |
|
|
| func isNotPowerOfTwoBranch32(x int32, a func(bool), b func(string)) { |
| |
| if isNotPowerOfTwo32(x) { |
| a(true) |
| } else { |
| b("false") |
| } |
| } |
|
|
| func sarx64(x, y int64) int64 { |
| |
| return x >> y |
| } |
|
|
| func sarx32(x, y int32) int32 { |
| |
| return x >> y |
| } |
|
|
| func sarx64_load(x []int64, i int) int64 { |
| |
| s := x[i] >> (i & 63) |
| |
| s = x[i+1] >> (s & 63) |
| return s |
| } |
|
|
| func sarx32_load(x []int32, i int) int32 { |
| |
| s := x[i] >> (i & 63) |
| |
| s = x[i+1] >> (s & 63) |
| return s |
| } |
|
|
| func shlrx64(x, y uint64) uint64 { |
| |
| s := x >> y |
| |
| s = s << y |
| return s |
| } |
|
|
| func shlrx32(x, y uint32) uint32 { |
| |
| s := x >> y |
| |
| s = s << y |
| return s |
| } |
|
|
| func shlrx64_load(x []uint64, i int, s uint64) uint64 { |
| |
| s = x[i] >> i |
| |
| s = x[i+1] << s |
| return s |
| } |
|
|
| func shlrx32_load(x []uint32, i int, s uint32) uint32 { |
| |
| s = x[i] >> i |
| |
| s = x[i+1] << s |
| return s |
| } |
|
|