[go] test/codegen: tidy tests for bits

7 views
Skip to first unread message

Joel Sing (Gerrit)

unread,
Dec 23, 2025, 7:52:13 AM (yesterday) Dec 23
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Joel Sing has uploaded the change for review

Commit message

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

Change diff

diff --git a/test/codegen/bits.go b/test/codegen/bits.go
index 39969dc..560c5e7 100644
--- a/test/codegen/bits.go
+++ b/test/codegen/bits.go
@@ -8,11 +8,11 @@

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"
if a&(1<<63) != 0 {
return 1
@@ -28,7 +28,7 @@
return 0
}

-func bitcheck64_constright(a [8]uint64) (n int) {
+func bitsCheckConstRightShiftU64(a [8]uint64) (n int) {
// amd64:"BTQ [$]63"
if (a[0]>>63)&1 != 0 {
return 1
@@ -60,7 +60,7 @@
return 0
}

-func bitcheck64_var(a, b uint64) (n int) {
+func bitsCheckVarU64(a, b uint64) (n int) {
// amd64:"BTQ"
if a&(1<<(b&63)) != 0 {
return 1
@@ -72,7 +72,7 @@
return 0
}

-func bitcheck64_mask(a uint64) (n int) {
+func bitsCheckMaskU64(a uint64) (n int) {
// amd64:"BTQ [$]63"
if a&0x8000000000000000 != 0 {
return 1
@@ -88,7 +88,7 @@
return 0
}

-func biton64(a, b uint64) (n uint64) {
+func bitsSetU64(a, b uint64) (n uint64) {
// amd64:"BTSQ"
n += b | (1 << (a & 63))

@@ -104,7 +104,7 @@
return n
}

-func bitoff64(a, b uint64) (n uint64) {
+func bitsClearU64(a, b uint64) (n uint64) {
// amd64:"BTRQ"
n += b &^ (1 << (a & 63))

@@ -120,7 +120,7 @@
return n
}

-func clearLastBit(x int64, y int32) (int64, int32) {
+func bitsClearLowest(x int64, y int32) (int64, int32) {
// amd64:"ANDQ [$]-2"
a := (x >> 1) << 1

@@ -130,7 +130,7 @@
return a, b
}

-func bitcompl64(a, b uint64) (n uint64) {
+func bitsFlipU64(a, b uint64) (n uint64) {
// amd64:"BTCQ"
n += b ^ (1 << (a & 63))

@@ -146,11 +146,11 @@
return n
}

-/************************************
- * 32-bit instructions
- ************************************/
+//
+// 32 bit instructions
+//

-func bitcheck32_constleft(a uint32) (n int) {
+func bitsCheckConstShiftLeftU32(a uint32) (n int) {
// amd64:"BTL [$]31"
if a&(1<<31) != 0 {
return 1
@@ -166,7 +166,7 @@
return 0
}

-func bitcheck32_constright(a [8]uint32) (n int) {
+func bitsCheckConstRightShiftU32(a [8]uint32) (n int) {
// amd64:"BTL [$]31"
if (a[0]>>31)&1 != 0 {
return 1
@@ -198,7 +198,7 @@
return 0
}

-func bitcheck32_var(a, b uint32) (n int) {
+func bitsCheckVarU32(a, b uint32) (n int) {
// amd64:"BTL"
if a&(1<<(b&31)) != 0 {
return 1
@@ -210,7 +210,7 @@
return 0
}

-func bitcheck32_mask(a uint32) (n int) {
+func bitsCheckMaskU32(a uint32) (n int) {
// amd64:"BTL [$]31"
if a&0x80000000 != 0 {
return 1
@@ -226,7 +226,7 @@
return 0
}

-func biton32(a, b uint32) (n uint32) {
+func bitsSetU32(a, b uint32) (n uint32) {
// amd64:"BTSL"
n += b | (1 << (a & 31))

@@ -242,7 +242,7 @@
return n
}

-func bitoff32(a, b uint32) (n uint32) {
+func bitsClearU32(a, b uint32) (n uint32) {
// amd64:"BTRL"
n += b &^ (1 << (a & 31))

@@ -258,7 +258,7 @@
return n
}

-func bitcompl32(a, b uint32) (n uint32) {
+func bitsFlipU32(a, b uint32) (n uint32) {
// amd64:"BTCL"
n += b ^ (1 << (a & 31))

@@ -274,8 +274,9 @@
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]+\)`
@@ -284,24 +285,22 @@
a[2] ^= 240
}

-func bitcheckMostNegative(b uint8) bool {
+func bitsCheckMostNegative(b uint8) bool {
// amd64:"TESTB"
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`
@@ -309,14 +308,13 @@
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 "
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`
a[0] = x ^ (y ^ 0xffffffff)

@@ -330,13 +328,13 @@
return n ^ (m ^ 0xffffffffffffffff)
}

-func op_orn(x, y uint32) uint32 {
+func bitsOrNot(x, y uint32) uint32 {
// arm64:`ORN `,-`ORR`
// loong64:"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"
@@ -345,64 +343,58 @@
a[2] = ^(0x12 | 0x34)
}

-func op_andn(x, y uint32) uint32 {
- // loong64:"ANDN " -"AND "
- return x &^ y
-}
-
-// check bitsets
-func bitSetPowerOf2Test(x int) bool {
+func bitsSetPowerOf2Test(x int) bool {
// amd64:"BTL [$]3"
return x&8 == 8
}

-func bitSetTest(x int) bool {
+func bitsSetTest(x int) bool {
// amd64:"ANDL [$]9, AX"
// amd64:"CMPQ AX, [$]9"
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,"
@@ -410,8 +402,9 @@
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"
@@ -419,8 +412,9 @@
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"

Change information

Files:
  • M test/codegen/bits.go
Change size: M
Delta: 1 file changed, 52 insertions(+), 58 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I996e9efd7497821edef94c1997d4a310d9d79a71
Gerrit-Change-Number: 732200
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
unsatisfied_requirement
satisfied_requirement
open
diffy

Joel Sing (Gerrit)

unread,
Dec 23, 2025, 8:01:19 AM (yesterday) Dec 23
to goph...@pubsubhelper.golang.org, Cherry Mui, golang-co...@googlegroups.com
Attention needed from Cherry Mui

Joel Sing voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Cherry Mui
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I996e9efd7497821edef94c1997d4a310d9d79a71
Gerrit-Change-Number: 732200
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
Gerrit-Attention: Cherry Mui <cher...@google.com>
Gerrit-Comment-Date: Tue, 23 Dec 2025 13:01:10 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Cherry Mui (Gerrit)

unread,
Dec 23, 2025, 11:23:41 AM (yesterday) Dec 23
to Joel Sing, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Joel Sing

Cherry Mui voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Joel Sing
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I996e9efd7497821edef94c1997d4a310d9d79a71
Gerrit-Change-Number: 732200
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Cherry Mui <cher...@google.com>
Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
Gerrit-Attention: Joel Sing <jo...@sing.id.au>
Gerrit-Comment-Date: Tue, 23 Dec 2025 16:23:38 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Knyszek (Gerrit)

unread,
Dec 23, 2025, 1:45:12 PM (yesterday) Dec 23
to Joel Sing, goph...@pubsubhelper.golang.org, Cherry Mui, Go LUCI, golang-co...@googlegroups.com
Attention needed from Joel Sing

Michael Knyszek voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Joel Sing
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I996e9efd7497821edef94c1997d4a310d9d79a71
    Gerrit-Change-Number: 732200
    Gerrit-PatchSet: 1
    Gerrit-Owner: Joel Sing <jo...@sing.id.au>
    Gerrit-Reviewer: Cherry Mui <cher...@google.com>
    Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Attention: Joel Sing <jo...@sing.id.au>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 18:45:09 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Joel Sing (Gerrit)

    unread,
    8:44 AM (13 hours ago) 8:44 AM
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Joel Sing

    Joel Sing uploaded new patchset

    Joel Sing uploaded patch set #2 to this change.
    Following approvals got outdated and were removed:
    • TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Joel Sing
    Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: newpatchset
      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I996e9efd7497821edef94c1997d4a310d9d79a71
      Gerrit-Change-Number: 732200
      Gerrit-PatchSet: 2
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages