[go] test/codegen: codify bit related code generation for riscv64

3 views
Skip to first unread message

Joel Sing (Gerrit)

unread,
Dec 23, 2025, 5:09:22 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: codify bit related code generation for riscv64
Change-Id: Iba4d3ded15d578e97a978780069e70a51a5e944b

Change diff

diff --git a/test/codegen/bits.go b/test/codegen/bits.go
index 39969dc..191cfc5 100644
--- a/test/codegen/bits.go
+++ b/test/codegen/bits.go
@@ -14,14 +14,17 @@

func bitcheck64_constleft(a uint64) (n int) {
// amd64:"BTQ [$]63"
+ // riscv64:"MOV [$]" "AND" "BNEZ"
if a&(1<<63) != 0 {
return 1
}
// amd64:"BTQ [$]60"
+ // riscv64:"MOV [$]" "AND" "BNEZ"
if a&(1<<60) != 0 {
return 1
}
// amd64:"BTL [$]0"
+ // riscv64:"ANDI" "BEQZ"
if a&(1<<0) != 0 {
return 1
}
@@ -30,30 +33,37 @@

func bitcheck64_constright(a [8]uint64) (n int) {
// amd64:"BTQ [$]63"
+ // riscv64:"SRLI" "ANDI" "BNEZ"
if (a[0]>>63)&1 != 0 {
return 1
}
// amd64:"BTQ [$]63"
+ // riscv64:"SRLI" "BNEZ"
if a[1]>>63 != 0 {
return 1
}
// amd64:"BTQ [$]63"
+ // riscv64:"SRLI" "BEQZ"
if a[2]>>63 == 0 {
return 1
}
// amd64:"BTQ [$]60"
+ // riscv64:"SRLI", "ANDI" "BEQZ"
if (a[3]>>60)&1 == 0 {
return 1
}
// amd64:"BTL [$]1"
+ // riscv64:"SRLI" "ANDI" "BEQZ"
if (a[4]>>1)&1 == 0 {
return 1
}
// amd64:"BTL [$]0"
+ // riscv64:"ANDI" "BEQZ" -"SRLI"
if (a[5]>>0)&1 == 0 {
return 1
}
// amd64:"BTL [$]7"
+ // riscv64:"SRLI" "ANDI" "BNEZ"
if (a[6]>>5)&4 == 0 {
return 1
}
@@ -62,10 +72,12 @@

func bitcheck64_var(a, b uint64) (n int) {
// amd64:"BTQ"
+ // riscv64:"ANDI [$]63," "SLL " "AND "
if a&(1<<(b&63)) != 0 {
return 1
}
// amd64:"BTQ" -"BT. [$]0"
+ // riscv64:"ANDI [$]63," "SRL " "ANDI [$]1,"
if (b>>(a&63))&1 != 0 {
return 1
}
@@ -74,14 +86,17 @@

func bitcheck64_mask(a uint64) (n int) {
// amd64:"BTQ [$]63"
+ // riscv64:"MOV [$]" "AND" "BNEZ"
if a&0x8000000000000000 != 0 {
return 1
}
// amd64:"BTQ [$]59"
+ // riscv64:"MOV [$]" "AND" "BNEZ"
if a&0x800000000000000 != 0 {
return 1
}
// amd64:"BTL [$]0"
+ // riscv64:"ANDI" "BEQZ"
if a&0x1 != 0 {
return 1
}
@@ -90,15 +105,19 @@

func biton64(a, b uint64) (n uint64) {
// amd64:"BTSQ"
+ // riscv64:"ANDI" "SLL" "OR"
n += b | (1 << (a & 63))

// amd64:"BTSQ [$]63"
+ // riscv64:"MOV [$]" "OR "
n += a | (1 << 63)

// amd64:"BTSQ [$]60"
+ // riscv64:"MOV [$]" "OR "
n += a | (1 << 60)

// amd64:"ORQ [$]1"
+ // riscv64:"ORI"
n += a | (1 << 0)

return n
@@ -106,15 +125,19 @@

func bitoff64(a, b uint64) (n uint64) {
// amd64:"BTRQ"
+ // riscv64:"ANDI" "SLL" "ANDN"
n += b &^ (1 << (a & 63))

// amd64:"BTRQ [$]63"
+ // riscv64:"MOV [$]" "AND "
n += a &^ (1 << 63)

// amd64:"BTRQ [$]60"
+ // riscv64:"MOV [$]" "AND "
n += a &^ (1 << 60)

// amd64:"ANDQ [$]-2"
+ // riscv64:"ANDI [$]-2"
n += a &^ (1 << 0)

return n
@@ -122,9 +145,11 @@

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

// amd64:"ANDL [$]-2"
+ // riscv64:"ANDI [$]-2"
b := (y >> 1) << 1

return a, b
@@ -132,15 +157,19 @@

func bitcompl64(a, b uint64) (n uint64) {
// amd64:"BTCQ"
+ // riscv64:"ANDI" "SLL" "XOR "
n += b ^ (1 << (a & 63))

// amd64:"BTCQ [$]63"
+ // riscv64:"MOV [$]" "XOR "
n += a ^ (1 << 63)

// amd64:"BTCQ [$]60"
+ // riscv64:"MOV [$]" "XOR "
n += a ^ (1 << 60)

// amd64:"XORQ [$]1"
+ // riscv64:"XORI [$]1"
n += a ^ (1 << 0)

return n
@@ -152,14 +181,17 @@

func bitcheck32_constleft(a uint32) (n int) {
// amd64:"BTL [$]31"
+ // riscv64:"MOV [$]" "AND" "BNEZ"
if a&(1<<31) != 0 {
return 1
}
// amd64:"BTL [$]28"
+ // riscv64:"ANDI" "BNEZ"
if a&(1<<28) != 0 {
return 1
}
// amd64:"BTL [$]0"
+ // riscv64:"ANDI" "BEQZ"
if a&(1<<0) != 0 {
return 1
}
@@ -168,30 +200,37 @@

func bitcheck32_constright(a [8]uint32) (n int) {
// amd64:"BTL [$]31"
+ // riscv64:"SRLI" "ANDI" "BNEZ"
if (a[0]>>31)&1 != 0 {
return 1
}
// amd64:"BTL [$]31"
+ // riscv64:"SRLI" "BNEZ"
if a[1]>>31 != 0 {
return 1
}
// amd64:"BTL [$]31"
+ // riscv64:"SRLI" "BEQZ"
if a[2]>>31 == 0 {
return 1
}
// amd64:"BTL [$]28"
+ // riscv64:"SRLI" "ANDI" "BEQZ"
if (a[3]>>28)&1 == 0 {
return 1
}
// amd64:"BTL [$]1"
+ // riscv64:"SRLI" "ANDI" "BEQZ"
if (a[4]>>1)&1 == 0 {
return 1
}
// amd64:"BTL [$]0"
+ // riscv64:"ANDI" "BEQZ" -"SRLI"
if (a[5]>>0)&1 == 0 {
return 1
}
// amd64:"BTL [$]7"
+ // riscv64:"SRLI" "ANDI" "BNEZ"
if (a[6]>>5)&4 == 0 {
return 1
}
@@ -200,10 +239,12 @@

func bitcheck32_var(a, b uint32) (n int) {
// amd64:"BTL"
+ // riscv64:"ANDI [$]31," "SLL " "AND "
if a&(1<<(b&31)) != 0 {
return 1
}
// amd64:"BTL" -"BT. [$]0"
+ // riscv64:"ANDI [$]31," "SRLW " "ANDI [$]1,"
if (b>>(a&31))&1 != 0 {
return 1
}
@@ -212,14 +253,17 @@

func bitcheck32_mask(a uint32) (n int) {
// amd64:"BTL [$]31"
+ // riscv64:"MOV [$]" "AND" "BNEZ"
if a&0x80000000 != 0 {
return 1
}
// amd64:"BTL [$]27"
+ // riscv64:"ANDI" "BNEZ"
if a&0x8000000 != 0 {
return 1
}
// amd64:"BTL [$]0"
+ // riscv64:"ANDI" "BEQZ"
if a&0x1 != 0 {
return 1
}
@@ -228,15 +272,19 @@

func biton32(a, b uint32) (n uint32) {
// amd64:"BTSL"
+ // riscv64:"ANDI" "SLL" "OR"
n += b | (1 << (a & 31))

// amd64:"ORL [$]-2147483648"
+ // riscv64:"ORI [$]-2147483648"
n += a | (1 << 31)

// amd64:"ORL [$]268435456"
+ // riscv64:"ORI [$]268435456"
n += a | (1 << 28)

// amd64:"ORL [$]1"
+ // riscv64:"ORI [$]1"
n += a | (1 << 0)

return n
@@ -244,15 +292,19 @@

func bitoff32(a, b uint32) (n uint32) {
// amd64:"BTRL"
+ // riscv64:"ANDI" "SLL" "ANDN"
n += b &^ (1 << (a & 31))

// amd64:"ANDL [$]2147483647"
+ // riscv64:"ANDI [$]2147483647"
n += a &^ (1 << 31)

// amd64:"ANDL [$]-268435457"
+ // riscv64:"ANDI [$]-268435457"
n += a &^ (1 << 28)

// amd64:"ANDL [$]-2"
+ // riscv64:"ANDI [$]-2"
n += a &^ (1 << 0)

return n
@@ -260,15 +312,19 @@

func bitcompl32(a, b uint32) (n uint32) {
// amd64:"BTCL"
+ // riscv64:"ANDI" "SLL" "XOR "
n += b ^ (1 << (a & 31))

// amd64:"XORL [$]-2147483648"
+ // riscv64:"XORI [$]-2147483648"
n += a ^ (1 << 31)

// amd64:"XORL [$]268435456"
+ // riscv64:"XORI [$]268435456"
n += a ^ (1 << 28)

// amd64:"XORL [$]1"
+ // riscv64:"XORI [$]1"
n += a ^ (1 << 0)

return n
@@ -286,6 +342,7 @@

func bitcheckMostNegative(b uint8) bool {
// amd64:"TESTB"
+ // riscv64:"ANDI [$]128," "SNEZ" -"ADDI"
return b&0x80 == 0x80
}

@@ -318,21 +375,26 @@

func op_eon(x, y, z uint32, a []uint32, n, m uint64) uint64 {
// arm64:`EON `,-`EOR`,-`MVN`
+ // riscv64:"XNOR " -"MOV [$]" -"XOR"
a[0] = x ^ (y ^ 0xffffffff)

// arm64:`EON `,-`EOR`,-`MVN`
+ // riscv64:"XNOR" -"XOR"
a[1] = ^(y ^ z)

// arm64:`EON `,-`XOR`
+ // riscv64:"XNOR" -"XOR" -"NOT"
a[2] = x ^ ^z

// arm64:`EON `,-`EOR`,-`MVN`
+ // riscv64:"XNOR" -"MOV [$]" -"XOR"
return n ^ (m ^ 0xffffffffffffffff)
}

func op_orn(x, y uint32) uint32 {
- // arm64:`ORN `,-`ORR`
- // loong64:"ORN" ,-"OR "
+ // arm64:"ORN " -"ORR"
+ // loong64:"ORN" -"OR "
+ // riscv64:"ORN" -"OR "
return x | ^y
}

@@ -347,18 +409,21 @@

func op_andn(x, y uint32) uint32 {
// loong64:"ANDN " -"AND "
+ // riscv64:"ANDN" -"AND "
return x &^ y
}

// check bitsets
func bitSetPowerOf2Test(x int) bool {
// amd64:"BTL [$]3"
+ // riscv64:"ANDI [$]8," "SNEZ" -"ADDI"
return x&8 == 8
}

func bitSetTest(x int) bool {
// amd64:"ANDL [$]9, AX"
// amd64:"CMPQ AX, [$]9"
+ // riscv64:"ANDI [$]9," "ADDI [$]-9," "SEQZ"
return x&9 == 9
}

Change information

Files:
  • M test/codegen/bits.go
Change size: M
Delta: 1 file changed, 67 insertions(+), 2 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: Iba4d3ded15d578e97a978780069e70a51a5e944b
Gerrit-Change-Number: 732180
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
unsatisfied_requirement
satisfied_requirement
open
diffy

Joel Sing (Gerrit)

unread,
Dec 23, 2025, 5:10:23 AM (yesterday) Dec 23
to goph...@pubsubhelper.golang.org, Mark Ryan, Meng Zhuo, golang-co...@googlegroups.com
Attention needed from Mark Ryan and Meng Zhuo

Joel Sing voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Mark Ryan
  • Meng Zhuo
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: Iba4d3ded15d578e97a978780069e70a51a5e944b
Gerrit-Change-Number: 732180
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Mark Ryan <mark...@rivosinc.com>
Gerrit-Reviewer: Meng Zhuo <mengzh...@gmail.com>
Gerrit-Attention: Meng Zhuo <mengzh...@gmail.com>
Gerrit-Attention: Mark Ryan <mark...@rivosinc.com>
Gerrit-Comment-Date: Tue, 23 Dec 2025 10:10:15 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Joel Sing (Gerrit)

unread,
Dec 23, 2025, 5:37:48 AM (yesterday) Dec 23
to goph...@pubsubhelper.golang.org, Mark Ryan, Meng Zhuo, golang-co...@googlegroups.com
Attention needed from Mark Ryan and Meng Zhuo

Joel Sing voted

Auto-Submit+1
Code-Review+0
Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Mark Ryan
  • Meng Zhuo
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: Iba4d3ded15d578e97a978780069e70a51a5e944b
Gerrit-Change-Number: 732180
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Mark Ryan <mark...@rivosinc.com>
Gerrit-Reviewer: Meng Zhuo <mengzh...@gmail.com>
Gerrit-Attention: Meng Zhuo <mengzh...@gmail.com>
Gerrit-Attention: Mark Ryan <mark...@rivosinc.com>
Gerrit-Comment-Date: Tue, 23 Dec 2025 10:37:41 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Meng Zhuo (Gerrit)

unread,
Dec 23, 2025, 6:10:17 AM (yesterday) Dec 23
to Joel Sing, goph...@pubsubhelper.golang.org, Meng Zhuo, Go LUCI, Mark Ryan, golang-co...@googlegroups.com
Attention needed from Joel Sing and Mark Ryan

Meng Zhuo voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Joel Sing
  • Mark Ryan
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: Iba4d3ded15d578e97a978780069e70a51a5e944b
Gerrit-Change-Number: 732180
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Mark Ryan <mark...@rivosinc.com>
Gerrit-Reviewer: Meng Zhuo <mengzh...@gmail.com>
Gerrit-Attention: Joel Sing <jo...@sing.id.au>
Gerrit-Attention: Mark Ryan <mark...@rivosinc.com>
Gerrit-Comment-Date: Tue, 23 Dec 2025 11:10:09 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Michael Knyszek (Gerrit)

unread,
Dec 23, 2025, 1:44:58 PM (yesterday) Dec 23
to Joel Sing, goph...@pubsubhelper.golang.org, Meng Zhuo, Go LUCI, Mark Ryan, golang-co...@googlegroups.com
Attention needed from Joel Sing and Mark Ryan

Michael Knyszek voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Joel Sing
  • Mark Ryan
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: Iba4d3ded15d578e97a978780069e70a51a5e944b
Gerrit-Change-Number: 732180
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
Gerrit-Reviewer: Mark Ryan <mark...@rivosinc.com>
Gerrit-Reviewer: Meng Zhuo <mengzh...@gmail.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Attention: Joel Sing <jo...@sing.id.au>
Gerrit-Attention: Mark Ryan <mark...@rivosinc.com>
Gerrit-Comment-Date: Tue, 23 Dec 2025 18:44:54 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Nicholas Husin (Gerrit)

unread,
Dec 23, 2025, 1:50:46 PM (yesterday) Dec 23
to Joel Sing, goph...@pubsubhelper.golang.org, Meng Zhuo, Go LUCI, Mark Ryan, golang-co...@googlegroups.com
Attention needed from Joel Sing and Mark Ryan

Nicholas Husin voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Joel Sing
  • Mark Ryan
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: Iba4d3ded15d578e97a978780069e70a51a5e944b
    Gerrit-Change-Number: 732180
    Gerrit-PatchSet: 1
    Gerrit-Owner: Joel Sing <jo...@sing.id.au>
    Gerrit-Reviewer: Joel Sing <jo...@sing.id.au>
    Gerrit-Reviewer: Mark Ryan <mark...@rivosinc.com>
    Gerrit-Reviewer: Meng Zhuo <mengzh...@gmail.com>
    Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
    Gerrit-Reviewer: Nicholas Husin <hu...@google.com>
    Gerrit-Attention: Joel Sing <jo...@sing.id.au>
    Gerrit-Attention: Mark Ryan <mark...@rivosinc.com>
    Gerrit-Comment-Date: Tue, 23 Dec 2025 18:50:43 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Dec 23, 2025, 1:51:37 PM (yesterday) Dec 23
    to Joel Sing, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Nicholas Husin, Michael Knyszek, Meng Zhuo, Go LUCI, Mark Ryan, golang-co...@googlegroups.com

    Gopher Robot submitted the change

    Change information

    Commit message:
    test/codegen: codify bit related code generation for riscv64
    Change-Id: Iba4d3ded15d578e97a978780069e70a51a5e944b
    Reviewed-by: Nicholas Husin <hu...@google.com>
    Reviewed-by: Meng Zhuo <mengzh...@gmail.com>
    Reviewed-by: Michael Knyszek <mkny...@google.com>
    Auto-Submit: Joel Sing <jo...@sing.id.au>
    Files:
    • M test/codegen/bits.go
    Change size: M
    Delta: 1 file changed, 67 insertions(+), 2 deletions(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +2 by Meng Zhuo, +1 by Michael Knyszek, +1 by Nicholas Husin, +0 by Joel Sing
    • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Iba4d3ded15d578e97a978780069e70a51a5e944b
    Gerrit-Change-Number: 732180
    Gerrit-PatchSet: 2
    Gerrit-Owner: Joel Sing <jo...@sing.id.au>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages