mirror of
https://github.com/golang/go.git
synced 2026-01-29 07:02:05 +03:00
test/codegen: tidy tests for bits
Use Go idiomatic function names, use a common prefix, attempt to maintain some consistency, avoid naming functions based upon machine specific instructions and combine a duplicate test that likely exists due to this confusion. Change-Id: I996e9efd7497821edef94c1997d4a310d9d79a71 Reviewed-on: https://go-review.googlesource.com/c/go/+/732200 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Joel Sing <joel@sing.id.au> Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
@@ -8,11 +8,11 @@ package codegen
|
||||
|
||||
import "math/bits"
|
||||
|
||||
/************************************
|
||||
* 64-bit instructions
|
||||
************************************/
|
||||
//
|
||||
// 64 bit instructions
|
||||
//
|
||||
|
||||
func bitcheck64_constleft(a uint64) (n int) {
|
||||
func bitsCheckConstLeftShiftU64(a uint64) (n int) {
|
||||
// amd64:"BTQ [$]63"
|
||||
// riscv64:"MOV [$]" "AND" "BNEZ"
|
||||
if a&(1<<63) != 0 {
|
||||
@@ -31,7 +31,7 @@ func bitcheck64_constleft(a uint64) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func bitcheck64_constright(a [8]uint64) (n int) {
|
||||
func bitsCheckConstRightShiftU64(a [8]uint64) (n int) {
|
||||
// amd64:"BTQ [$]63"
|
||||
// riscv64:"SRLI" "ANDI" "BNEZ"
|
||||
if (a[0]>>63)&1 != 0 {
|
||||
@@ -70,7 +70,7 @@ func bitcheck64_constright(a [8]uint64) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func bitcheck64_var(a, b uint64) (n int) {
|
||||
func bitsCheckVarU64(a, b uint64) (n int) {
|
||||
// amd64:"BTQ"
|
||||
// riscv64:"ANDI [$]63," "SLL " "AND "
|
||||
if a&(1<<(b&63)) != 0 {
|
||||
@@ -84,7 +84,7 @@ func bitcheck64_var(a, b uint64) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func bitcheck64_mask(a uint64) (n int) {
|
||||
func bitsCheckMaskU64(a uint64) (n int) {
|
||||
// amd64:"BTQ [$]63"
|
||||
// riscv64:"MOV [$]" "AND" "BNEZ"
|
||||
if a&0x8000000000000000 != 0 {
|
||||
@@ -103,7 +103,7 @@ func bitcheck64_mask(a uint64) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func biton64(a, b uint64) (n uint64) {
|
||||
func bitsSetU64(a, b uint64) (n uint64) {
|
||||
// amd64:"BTSQ"
|
||||
// riscv64:"ANDI" "SLL" "OR"
|
||||
n += b | (1 << (a & 63))
|
||||
@@ -123,7 +123,7 @@ func biton64(a, b uint64) (n uint64) {
|
||||
return n
|
||||
}
|
||||
|
||||
func bitoff64(a, b uint64) (n uint64) {
|
||||
func bitsClearU64(a, b uint64) (n uint64) {
|
||||
// amd64:"BTRQ"
|
||||
// riscv64:"ANDI" "SLL" "ANDN"
|
||||
n += b &^ (1 << (a & 63))
|
||||
@@ -143,7 +143,7 @@ func bitoff64(a, b uint64) (n uint64) {
|
||||
return n
|
||||
}
|
||||
|
||||
func clearLastBit(x int64, y int32) (int64, int32) {
|
||||
func bitsClearLowest(x int64, y int32) (int64, int32) {
|
||||
// amd64:"ANDQ [$]-2"
|
||||
// riscv64:"ANDI [$]-2"
|
||||
a := (x >> 1) << 1
|
||||
@@ -155,7 +155,7 @@ func clearLastBit(x int64, y int32) (int64, int32) {
|
||||
return a, b
|
||||
}
|
||||
|
||||
func bitcompl64(a, b uint64) (n uint64) {
|
||||
func bitsFlipU64(a, b uint64) (n uint64) {
|
||||
// amd64:"BTCQ"
|
||||
// riscv64:"ANDI" "SLL" "XOR "
|
||||
n += b ^ (1 << (a & 63))
|
||||
@@ -175,11 +175,11 @@ func bitcompl64(a, b uint64) (n uint64) {
|
||||
return n
|
||||
}
|
||||
|
||||
/************************************
|
||||
* 32-bit instructions
|
||||
************************************/
|
||||
//
|
||||
// 32 bit instructions
|
||||
//
|
||||
|
||||
func bitcheck32_constleft(a uint32) (n int) {
|
||||
func bitsCheckConstShiftLeftU32(a uint32) (n int) {
|
||||
// amd64:"BTL [$]31"
|
||||
// riscv64:"MOV [$]" "AND" "BNEZ"
|
||||
if a&(1<<31) != 0 {
|
||||
@@ -198,7 +198,7 @@ func bitcheck32_constleft(a uint32) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func bitcheck32_constright(a [8]uint32) (n int) {
|
||||
func bitsCheckConstRightShiftU32(a [8]uint32) (n int) {
|
||||
// amd64:"BTL [$]31"
|
||||
// riscv64:"SRLI" "ANDI" "BNEZ"
|
||||
if (a[0]>>31)&1 != 0 {
|
||||
@@ -237,7 +237,7 @@ func bitcheck32_constright(a [8]uint32) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func bitcheck32_var(a, b uint32) (n int) {
|
||||
func bitsCheckVarU32(a, b uint32) (n int) {
|
||||
// amd64:"BTL"
|
||||
// riscv64:"ANDI [$]31," "SLL " "AND "
|
||||
if a&(1<<(b&31)) != 0 {
|
||||
@@ -251,7 +251,7 @@ func bitcheck32_var(a, b uint32) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func bitcheck32_mask(a uint32) (n int) {
|
||||
func bitsCheckMaskU32(a uint32) (n int) {
|
||||
// amd64:"BTL [$]31"
|
||||
// riscv64:"MOV [$]" "AND" "BNEZ"
|
||||
if a&0x80000000 != 0 {
|
||||
@@ -270,7 +270,7 @@ func bitcheck32_mask(a uint32) (n int) {
|
||||
return 0
|
||||
}
|
||||
|
||||
func biton32(a, b uint32) (n uint32) {
|
||||
func bitsSetU32(a, b uint32) (n uint32) {
|
||||
// amd64:"BTSL"
|
||||
// riscv64:"ANDI" "SLL" "OR"
|
||||
n += b | (1 << (a & 31))
|
||||
@@ -290,7 +290,7 @@ func biton32(a, b uint32) (n uint32) {
|
||||
return n
|
||||
}
|
||||
|
||||
func bitoff32(a, b uint32) (n uint32) {
|
||||
func bitsClearU32(a, b uint32) (n uint32) {
|
||||
// amd64:"BTRL"
|
||||
// riscv64:"ANDI" "SLL" "ANDN"
|
||||
n += b &^ (1 << (a & 31))
|
||||
@@ -310,7 +310,7 @@ func bitoff32(a, b uint32) (n uint32) {
|
||||
return n
|
||||
}
|
||||
|
||||
func bitcompl32(a, b uint32) (n uint32) {
|
||||
func bitsFlipU32(a, b uint32) (n uint32) {
|
||||
// amd64:"BTCL"
|
||||
// riscv64:"ANDI" "SLL" "XOR "
|
||||
n += b ^ (1 << (a & 31))
|
||||
@@ -330,8 +330,9 @@ func bitcompl32(a, b uint32) (n uint32) {
|
||||
return n
|
||||
}
|
||||
|
||||
// check direct operation on memory with constant and shifted constant sources
|
||||
func bitOpOnMem(a []uint32, b, c, d uint32) {
|
||||
func bitsOpOnMem(a []uint32, b, c, d uint32) {
|
||||
// check direct operation on memory with constant
|
||||
|
||||
// amd64:`ANDL\s[$]200,\s\([A-Z][A-Z0-9]+\)`
|
||||
a[0] &= 200
|
||||
// amd64:`ORL\s[$]220,\s4\([A-Z][A-Z0-9]+\)`
|
||||
@@ -340,25 +341,23 @@ func bitOpOnMem(a []uint32, b, c, d uint32) {
|
||||
a[2] ^= 240
|
||||
}
|
||||
|
||||
func bitcheckMostNegative(b uint8) bool {
|
||||
func bitsCheckMostNegative(b uint8) bool {
|
||||
// amd64:"TESTB"
|
||||
// riscv64:"ANDI [$]128," "SNEZ" -"ADDI"
|
||||
return b&0x80 == 0x80
|
||||
}
|
||||
|
||||
// Check AND masking on arm64 (Issue #19857)
|
||||
|
||||
func and_mask_1(a uint64) uint64 {
|
||||
func bitsIssue19857a(a uint64) uint64 {
|
||||
// arm64:`AND `
|
||||
return a & ((1 << 63) - 1)
|
||||
}
|
||||
|
||||
func and_mask_2(a uint64) uint64 {
|
||||
func bitsIssue19857b(a uint64) uint64 {
|
||||
// arm64:`AND `
|
||||
return a & (1 << 63)
|
||||
}
|
||||
|
||||
func and_mask_3(a, b uint32) (uint32, uint32) {
|
||||
func bitsIssue19857c(a, b uint32) (uint32, uint32) {
|
||||
// arm/7:`BIC`,-`AND`
|
||||
a &= 0xffffaaaa
|
||||
// arm/7:`BFC`,-`AND`,-`BIC`
|
||||
@@ -366,14 +365,14 @@ func and_mask_3(a, b uint32) (uint32, uint32) {
|
||||
return a, b
|
||||
}
|
||||
|
||||
// Check generation of arm64 BIC/EON/ORN instructions
|
||||
|
||||
func op_bic(x, y uint32) uint32 {
|
||||
func bitsAndNot(x, y uint32) uint32 {
|
||||
// arm64:`BIC `,-`AND`
|
||||
// loong64:"ANDN " -"AND "
|
||||
// riscv64:"ANDN" -"AND "
|
||||
return x &^ y
|
||||
}
|
||||
|
||||
func op_eon(x, y, z uint32, a []uint32, n, m uint64) uint64 {
|
||||
func bitsXorNot(x, y, z uint32, a []uint32, n, m uint64) uint64 {
|
||||
// arm64:`EON `,-`EOR`,-`MVN`
|
||||
// riscv64:"XNOR " -"MOV [$]" -"XOR"
|
||||
a[0] = x ^ (y ^ 0xffffffff)
|
||||
@@ -391,14 +390,14 @@ func op_eon(x, y, z uint32, a []uint32, n, m uint64) uint64 {
|
||||
return n ^ (m ^ 0xffffffffffffffff)
|
||||
}
|
||||
|
||||
func op_orn(x, y uint32) uint32 {
|
||||
func bitsOrNot(x, y uint32) uint32 {
|
||||
// arm64:"ORN " -"ORR"
|
||||
// loong64:"ORN" -"OR "
|
||||
// riscv64:"ORN" -"OR "
|
||||
return x | ^y
|
||||
}
|
||||
|
||||
func op_nor(x int64, a []int64) {
|
||||
func bitsNotOr(x int64, a []int64) {
|
||||
// loong64: "MOVV [$]0" "NOR R"
|
||||
a[0] = ^(0x1234 | x)
|
||||
// loong64:"NOR" -"XOR"
|
||||
@@ -407,67 +406,60 @@ func op_nor(x int64, a []int64) {
|
||||
a[2] = ^(0x12 | 0x34)
|
||||
}
|
||||
|
||||
func op_andn(x, y uint32) uint32 {
|
||||
// loong64:"ANDN " -"AND "
|
||||
// riscv64:"ANDN" -"AND "
|
||||
return x &^ y
|
||||
}
|
||||
|
||||
// check bitsets
|
||||
func bitSetPowerOf2Test(x int) bool {
|
||||
func bitsSetPowerOf2Test(x int) bool {
|
||||
// amd64:"BTL [$]3"
|
||||
// riscv64:"ANDI [$]8," "SNEZ" -"ADDI"
|
||||
return x&8 == 8
|
||||
}
|
||||
|
||||
func bitSetTest(x int) bool {
|
||||
func bitsSetTest(x int) bool {
|
||||
// amd64:"ANDL [$]9, AX"
|
||||
// amd64:"CMPQ AX, [$]9"
|
||||
// riscv64:"ANDI [$]9," "ADDI [$]-9," "SEQZ"
|
||||
return x&9 == 9
|
||||
}
|
||||
|
||||
// mask contiguous one bits
|
||||
func cont1Mask64U(x uint64) uint64 {
|
||||
func bitsMaskContiguousOnes64U(x uint64) uint64 {
|
||||
// s390x:"RISBGZ [$]16, [$]47, [$]0,"
|
||||
return x & 0x0000ffffffff0000
|
||||
}
|
||||
|
||||
// mask contiguous zero bits
|
||||
func cont0Mask64U(x uint64) uint64 {
|
||||
func bitsMaskContiguousZeroes64U(x uint64) uint64 {
|
||||
// s390x:"RISBGZ [$]48, [$]15, [$]0,"
|
||||
return x & 0xffff00000000ffff
|
||||
}
|
||||
|
||||
func issue44228a(a []int64, i int) bool {
|
||||
func bitsIssue44228a(a []int64, i int) bool {
|
||||
// amd64: "BTQ", -"SHL"
|
||||
return a[i>>6]&(1<<(i&63)) != 0
|
||||
}
|
||||
func issue44228b(a []int32, i int) bool {
|
||||
|
||||
func bitsIssue44228b(a []int32, i int) bool {
|
||||
// amd64: "BTL", -"SHL"
|
||||
return a[i>>5]&(1<<(i&31)) != 0
|
||||
}
|
||||
|
||||
func issue48467(x, y uint64) uint64 {
|
||||
func bitsIssue48467(x, y uint64) uint64 {
|
||||
// arm64: -"NEG"
|
||||
d, borrow := bits.Sub64(x, y, 0)
|
||||
return x - d&(-borrow)
|
||||
}
|
||||
|
||||
func foldConst(x, y uint64) uint64 {
|
||||
func bitsFoldConst(x, y uint64) uint64 {
|
||||
// arm64: "ADDS [$]7" -"MOVD [$]7"
|
||||
// ppc64x: "ADDC [$]7,"
|
||||
d, b := bits.Add64(x, 7, 0)
|
||||
return b & d
|
||||
}
|
||||
|
||||
func foldConstOutOfRange(a uint64) uint64 {
|
||||
func bitsFoldConstOutOfRange(a uint64) uint64 {
|
||||
// arm64: "MOVD [$]19088744" -"ADD [$]19088744"
|
||||
return a + 0x1234568
|
||||
}
|
||||
|
||||
// Verify sign-extended values are not zero-extended under a bit mask (#61297)
|
||||
func signextendAndMask8to64(a int8) (s, z uint64) {
|
||||
func bitsSignExtendAndMask8to64U(a int8) (s, z uint64) {
|
||||
// Verify sign-extended values are not zero-extended under a bit mask (#61297)
|
||||
|
||||
// ppc64x: "MOVB", "ANDCC [$]1015,"
|
||||
s = uint64(a) & 0x3F7
|
||||
// ppc64x: -"MOVB", "ANDCC [$]247,"
|
||||
@@ -475,8 +467,9 @@ func signextendAndMask8to64(a int8) (s, z uint64) {
|
||||
return
|
||||
}
|
||||
|
||||
// Verify zero-extended values are not sign-extended under a bit mask (#61297)
|
||||
func zeroextendAndMask8to64(a int8, b int16) (x, y uint64) {
|
||||
func bitsZeroExtendAndMask8toU64(a int8, b int16) (x, y uint64) {
|
||||
// Verify zero-extended values are not sign-extended under a bit mask (#61297)
|
||||
|
||||
// ppc64x: -"MOVB ", -"ANDCC", "MOVBZ"
|
||||
x = uint64(a) & 0xFF
|
||||
// ppc64x: -"MOVH ", -"ANDCC", "MOVHZ"
|
||||
@@ -484,8 +477,9 @@ func zeroextendAndMask8to64(a int8, b int16) (x, y uint64) {
|
||||
return
|
||||
}
|
||||
|
||||
// Verify rotate and mask instructions, and further simplified instructions for small types
|
||||
func bitRotateAndMask(io64 [8]uint64, io32 [4]uint32, io16 [4]uint16, io8 [4]uint8) {
|
||||
func bitsRotateAndMask(io64 [8]uint64, io32 [4]uint32, io16 [4]uint16, io8 [4]uint8) {
|
||||
// Verify rotate and mask instructions, and further simplified instructions for small types
|
||||
|
||||
// ppc64x: "RLDICR [$]0, R[0-9]*, [$]47, R"
|
||||
io64[0] = io64[0] & 0xFFFFFFFFFFFF0000
|
||||
// ppc64x: "RLDICL [$]0, R[0-9]*, [$]16, R"
|
||||
|
||||
Reference in New Issue
Block a user