Skip to content

Commit 4ce1c8e

Browse files
sophie-zhaogopherbot
authored andcommitted
cmd/compile: add rules about ORN and ANDN
Reduce the number of go toolchain instructions on loong64 as follows. file before after Δ % addr2line 279880 279776 -104 -0.0372% asm 556638 556410 -228 -0.0410% buildid 272272 272072 -200 -0.0735% cgo 481522 481318 -204 -0.0424% compile 2457788 2457580 -208 -0.0085% covdata 323384 323280 -104 -0.0322% cover 518450 518234 -216 -0.0417% dist 340790 340686 -104 -0.0305% distpack 282456 282252 -204 -0.0722% doc 789932 789688 -244 -0.0309% fix 324332 324228 -104 -0.0321% link 704622 704390 -232 -0.0329% nm 277132 277028 -104 -0.0375% objdump 507862 507758 -104 -0.0205% pack 221774 221674 -100 -0.0451% pprof 1469816 1469552 -264 -0.0180% test2json 254836 254732 -104 -0.0408% trace 1100002 1099738 -264 -0.0240% vet 781078 780874 -204 -0.0261% go 1529116 1528848 -268 -0.0175% gofmt 318556 318448 -108 -0.0339% total 13792238 13788566 -3672 -0.0266% Change-Id: I23fb3ebd41309252c7075e57ea7094e79f8c4fef Reviewed-on: https://go-review.googlesource.com/c/go/+/674335 Reviewed-by: abner chenc <chenguoqi@loongson.cn> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: abner chenc <chenguoqi@loongson.cn> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Meidan Li <limeidan@loongson.cn>
1 parent 0810fd2 commit 4ce1c8e

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed

src/cmd/compile/internal/loong64/ssa.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
165165
ssa.OpLOONG64OR,
166166
ssa.OpLOONG64XOR,
167167
ssa.OpLOONG64NOR,
168+
ssa.OpLOONG64ANDN,
169+
ssa.OpLOONG64ORN,
168170
ssa.OpLOONG64SLL,
169171
ssa.OpLOONG64SLLV,
170172
ssa.OpLOONG64SRL,

src/cmd/compile/internal/ssa/_gen/LOONG64.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@
782782
(AND x x) => x
783783
(OR x x) => x
784784
(XOR x x) => (MOVVconst [0])
785+
(ORN x (MOVVconst [-1])) => x
786+
(AND x (NORconst [0] y)) => (ANDN x y)
787+
(OR x (NORconst [0] y)) => (ORN x y)
785788

786789
// Fold negation into subtraction.
787790
(NEGV (SUBV x y)) => (SUBV y x)

src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ func init() {
221221
{name: "XORconst", argLength: 1, reg: gp11, asm: "XOR", aux: "Int64", typ: "UInt64"}, // arg0 ^ auxInt
222222
{name: "NOR", argLength: 2, reg: gp21, asm: "NOR", commutative: true}, // ^(arg0 | arg1)
223223
{name: "NORconst", argLength: 1, reg: gp11, asm: "NOR", aux: "Int64"}, // ^(arg0 | auxInt)
224+
{name: "ANDN", argLength: 2, reg: gp21, asm: "ANDN"}, // arg0 & ^arg1
225+
{name: "ORN", argLength: 2, reg: gp21, asm: "ORN"}, // arg0 | ^arg1
224226

225227
{name: "FMADDF", argLength: 3, reg: fp31, asm: "FMADDF", commutative: true, typ: "Float32"}, // (arg0 * arg1) + arg2
226228
{name: "FMADDD", argLength: 3, reg: fp31, asm: "FMADDD", commutative: true, typ: "Float64"}, // (arg0 * arg1) + arg2

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssa/rewriteLOONG64.go

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/bits.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func op_eon(x, y, z uint32, a []uint32, n, m uint64) uint64 {
332332

333333
func op_orn(x, y uint32) uint32 {
334334
// arm64:`ORN\t`,-`ORR`
335+
// loong64:"ORN"\t,-"OR\t"
335336
return x | ^y
336337
}
337338

@@ -344,6 +345,11 @@ func op_nor(x int64, a []int64) {
344345
a[2] = ^(0x12 | 0x34)
345346
}
346347

348+
func op_andn(x, y uint32) uint32 {
349+
// loong64:"ANDN\t",-"AND\t"
350+
return x &^ y
351+
}
352+
347353
// check bitsets
348354
func bitSetPowerOf2Test(x int) bool {
349355
// amd64:"BTL\t[$]3"

0 commit comments

Comments
 (0)