]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add intrinsic for MulUintptr on arm64
authorruinan <ruinan.sun@arm.com>
Thu, 21 Jul 2022 05:16:11 +0000 (05:16 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 19 Aug 2022 16:08:24 +0000 (16:08 +0000)
This CL adds intrinsic for runtime/internal/math.MulUintptr on arm64

Benchmark         master     ThisCL(ns/op)   delta
MulUintptr/small  0.95ns     0.79ns          -16%
MulUintptr/large  1.31ns     0.95ns          -27.6%

Change-Id: Ic7b453ad502826beffe93ce5531b8ba752312a1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/419556
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Eric Fang <eric.fang@arm.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/rewriteARM64.go
src/cmd/compile/internal/ssagen/ssa.go

index e3d77be0b47fd8980c449082587060bb6cab3f47..fbf853e40e92091fc9aad07907b74fca3a7f36e1 100644 (file)
        => (Move [sz] dst src mem)
 
 ((REV|REVW) ((REV|REVW) p)) => p
+
+// runtime/internal/math.MulUintptr intrinsics
+
+(Select0 (Mul64uover x y)) => (MUL x y)
+(Select1 (Mul64uover x y)) => (NotEqual (CMPconst (UMULH <typ.UInt64> x y) [0]))
\ No newline at end of file
index 7845e9cf1d65f9f696a19d7afc225525c5a3daf5..f6e3cfc9993e87d5e6d0e5fb74e7caf88f741f82 100644 (file)
@@ -27362,6 +27362,18 @@ func rewriteValueARM64_OpSelect0(v *Value) bool {
                v.AddArg(v0)
                return true
        }
+       // match: (Select0 (Mul64uover x y))
+       // result: (MUL x y)
+       for {
+               if v_0.Op != OpMul64uover {
+                       break
+               }
+               y := v_0.Args[1]
+               x := v_0.Args[0]
+               v.reset(OpARM64MUL)
+               v.AddArg2(x, y)
+               return true
+       }
        return false
 }
 func rewriteValueARM64_OpSelect1(v *Value) bool {
@@ -27415,6 +27427,23 @@ func rewriteValueARM64_OpSelect1(v *Value) bool {
                v.AddArg(v0)
                return true
        }
+       // match: (Select1 (Mul64uover x y))
+       // result: (NotEqual (CMPconst (UMULH <typ.UInt64> x y) [0]))
+       for {
+               if v_0.Op != OpMul64uover {
+                       break
+               }
+               y := v_0.Args[1]
+               x := v_0.Args[0]
+               v.reset(OpARM64NotEqual)
+               v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags)
+               v0.AuxInt = int64ToAuxInt(0)
+               v1 := b.NewValue0(v.Pos, OpARM64UMULH, typ.UInt64)
+               v1.AddArg2(x, y)
+               v0.AddArg(v1)
+               v.AddArg(v0)
+               return true
+       }
        return false
 }
 func rewriteValueARM64_OpSelectN(v *Value) bool {
index 0c30cfecab8a030fb38b05fb9b97fd9de3a535bb..7cb1da32058de7a3da139cdc44e541825718428b 100644 (file)
@@ -3908,7 +3908,7 @@ func InitTables() {
                        }
                        return s.newValue2(ssa.OpMul64uover, types.NewTuple(types.Types[types.TUINT], types.Types[types.TUINT]), args[0], args[1])
                },
-               sys.AMD64, sys.I386, sys.Loong64, sys.MIPS64, sys.RISCV64)
+               sys.AMD64, sys.I386, sys.Loong64, sys.MIPS64, sys.RISCV64, sys.ARM64)
        alias("runtime", "mulUintptr", "runtime/internal/math", "MulUintptr", all...)
        add("runtime", "KeepAlive",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {