cmd/compile: fix the implementation of NORconst on loong64

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>
This commit is contained in:
Xiaolin Zhao 2025-05-19 17:02:48 +08:00 committed by abner chenc
parent 74304cda29
commit d37a1bdd48
2 changed files with 26 additions and 1 deletions

View 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())

View 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"