]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix the implementation of NORconst on loong64
authorXiaolin Zhao <zhaoxiaolin@loongson.cn>
Mon, 19 May 2025 09:02:48 +0000 (17:02 +0800)
committerabner chenc <chenguoqi@loongson.cn>
Wed, 21 May 2025 03:24:09 +0000 (20:24 -0700)
In the loong64 instruction set, there is no NORI instruction,
so the immediate value in NORconst need to be stored in register
and then use the three-register NOR instruction.

Change-Id: I5ef697450619317218cb3ef47fc07e238bdc2139
Reviewed-on: https://go-review.googlesource.com/c/go/+/673836
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/loong64/ssa.go
test/codegen/bits.go

index d60aef165cc31e98122b6bdb003de846e940ad0a..03d7a1082a3671b7049eac9b2c5a6b6c1553f999 100644 (file)
@@ -276,7 +276,6 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
                ssa.OpLOONG64ANDconst,
                ssa.OpLOONG64ORconst,
                ssa.OpLOONG64XORconst,
-               ssa.OpLOONG64NORconst,
                ssa.OpLOONG64SLLconst,
                ssa.OpLOONG64SLLVconst,
                ssa.OpLOONG64SRLconst,
@@ -293,6 +292,23 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
                p.Reg = v.Args[0].Reg()
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
+
+       case ssa.OpLOONG64NORconst:
+               // MOVV $const, Rtmp
+               // NOR  Rtmp, Rarg0, Rout
+               p := s.Prog(loong64.AMOVV)
+               p.From.Type = obj.TYPE_CONST
+               p.From.Offset = v.AuxInt
+               p.To.Type = obj.TYPE_REG
+               p.To.Reg = loong64.REGTMP
+
+               p2 := s.Prog(v.Op.Asm())
+               p2.From.Type = obj.TYPE_REG
+               p2.From.Reg = loong64.REGTMP
+               p2.Reg = v.Args[0].Reg()
+               p2.To.Type = obj.TYPE_REG
+               p2.To.Reg = v.Reg()
+
        case ssa.OpLOONG64MOVVconst:
                r := v.Reg()
                p := s.Prog(v.Op.Asm())
index c20e4d67333f6399998372d8ca3e200f93bb831d..95e0ed85e46b71024a4ec81380d1984e9dc3e09b 100644 (file)
@@ -335,6 +335,15 @@ func op_orn(x, y uint32) uint32 {
        return x | ^y
 }
 
+func op_nor(x int64, a []int64) {
+       // loong64: "MOVV\t[$]0","NOR\tR"
+       a[0] = ^(0x1234 | x)
+       // loong64:"NOR",-"XOR"
+       a[1] = (-1) ^ x
+       // loong64: "MOVV\t[$]-55",-"OR",-"NOR"
+       a[2] = ^(0x12 | 0x34)
+}
+
 // check bitsets
 func bitSetPowerOf2Test(x int) bool {
        // amd64:"BTL\t[$]3"