]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: enforce strongly typed rules for ARM (GOARM)
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sat, 29 Aug 2020 09:10:50 +0000 (11:10 +0200)
committerGiovanni Bajo <rasky@develer.com>
Thu, 24 Sep 2020 09:15:20 +0000 (09:15 +0000)
Toolstash-check successful for remaining rules using GOARM value.

Change-Id: I254f80d17839ef4957c1b7afbdb4db363a3b9367
Reviewed-on: https://go-review.googlesource.com/c/go/+/240997
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Giovanni Bajo <rasky@develer.com>

src/cmd/compile/internal/ssa/gen/ARM.rules
src/cmd/compile/internal/ssa/rewriteARM.go

index 2be347d98b396fd13eb39d20df564762f0b8d6d0..840b93bb5365f68b97e99e83de531904bb8d2d9e 100644 (file)
 
 // count trailing zero for ARMv5 and ARMv6
 // 32 - CLZ(x&-x - 1)
-(Ctz32 <t> x) && objabi.GOARM<=6 ->
+(Ctz32 <t> x) && objabi.GOARM<=6 =>
        (RSBconst [32] (CLZ <t> (SUBconst <t> (AND <t> x (RSBconst <t> [0] x)) [1])))
-(Ctz16 <t> x) && objabi.GOARM<=6 ->
+(Ctz16 <t> x) && objabi.GOARM<=6 =>
        (RSBconst [32] (CLZ <t> (SUBconst <typ.UInt32> (AND <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x) (RSBconst <typ.UInt32> [0] (ORconst <typ.UInt32> [0x10000] x))) [1])))
-(Ctz8 <t> x) && objabi.GOARM<=6 ->
+(Ctz8 <t> x) && objabi.GOARM<=6 =>
        (RSBconst [32] (CLZ <t> (SUBconst <typ.UInt32> (AND <typ.UInt32> (ORconst <typ.UInt32> [0x100] x) (RSBconst <typ.UInt32> [0] (ORconst <typ.UInt32> [0x100] x))) [1])))
 
 // count trailing zero for ARMv7
-(Ctz32 <t> x) && objabi.GOARM==7 -> (CLZ <t> (RBIT <t> x))
-(Ctz16 <t> x) && objabi.GOARM==7 -> (CLZ <t> (RBIT <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x)))
-(Ctz8 <t> x) && objabi.GOARM==7 -> (CLZ <t> (RBIT <typ.UInt32> (ORconst <typ.UInt32> [0x100] x)))
+(Ctz32 <t> x) && objabi.GOARM==7 => (CLZ <t> (RBIT <t> x))
+(Ctz16 <t> x) && objabi.GOARM==7 => (CLZ <t> (RBIT <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x)))
+(Ctz8 <t> x) && objabi.GOARM==7 => (CLZ <t> (RBIT <typ.UInt32> (ORconst <typ.UInt32> [0x100] x)))
 
 // bit length
 (BitLen32 <t> x) => (RSBconst [32] (CLZ <t> x))
 // t5 = x right rotate 8 bits  -- (d,   a,   b,   c  )
 // result = t4 ^ t5            -- (d,   c,   b,   a  )
 // using shifted ops this can be done in 4 instructions.
-(Bswap32 <t> x) && objabi.GOARM==5 ->
+(Bswap32 <t> x) && objabi.GOARM==5 =>
        (XOR <t>
                (SRLconst <t> (BICconst <t> (XOR <t> x (SRRconst <t> [16] x)) [0xff0000]) [8])
                (SRRconst <t> x [8]))
 
 // byte swap for ARMv6 and above
-(Bswap32 x) && objabi.GOARM>=6 -> (REV x)
+(Bswap32 x) && objabi.GOARM>=6 => (REV x)
 
 // boolean ops -- booleans are represented with 0=false, 1=true
 (AndB ...) => (AND ...)
 // UBFX instruction is supported by ARMv6T2, ARMv7 and above versions, REV16 is supported by
 // ARMv6 and above versions. So for ARMv6, we need to match SLLconst, SRLconst and ORshiftLL.
 ((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (BFXU <typ.UInt16> [int32(armBFAuxInt(8, 8))] x) x) => (REV16 x)
-((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (SRLconst <typ.UInt16> [24] (SLLconst [16] x)) x) && objabi.GOARM>=6 -> (REV16 x)
+((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (SRLconst <typ.UInt16> [24] (SLLconst [16] x)) x) && objabi.GOARM>=6 => (REV16 x)
 
 // use indexed loads and stores
 (MOVWload [0] {sym} (ADD ptr idx) mem) && sym == nil => (MOVWloadidx ptr idx mem)
 (BIC x x) => (MOVWconst [0])
 
 (ADD (MUL x y) a) => (MULA x y a)
-(SUB a (MUL x y)) && objabi.GOARM == 7 -> (MULS x y a)
-(RSB (MUL x y) a) && objabi.GOARM == 7 -> (MULS x y a)
+(SUB a (MUL x y)) && objabi.GOARM == 7 => (MULS x y a)
+(RSB (MUL x y) a) && objabi.GOARM == 7 => (MULS x y a)
 
-(NEGF (MULF x y)) && objabi.GOARM >= 6 -> (NMULF x y)
-(NEGD (MULD x y)) && objabi.GOARM >= 6 -> (NMULD x y)
-(MULF (NEGF x) y) && objabi.GOARM >= 6 -> (NMULF x y)
-(MULD (NEGD x) y) && objabi.GOARM >= 6 -> (NMULD x y)
+(NEGF (MULF x y)) && objabi.GOARM >= 6 => (NMULF x y)
+(NEGD (MULD x y)) && objabi.GOARM >= 6 => (NMULD x y)
+(MULF (NEGF x) y) && objabi.GOARM >= 6 => (NMULF x y)
+(MULD (NEGD x) y) && objabi.GOARM >= 6 => (NMULD x y)
 (NMULF (NEGF x) y) => (MULF x y)
 (NMULD (NEGD x) y) => (MULD x y)
 
 // the result will overwrite the addend, since they are in the same register
-(ADDF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAF a x y)
-(ADDF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSF a x y)
-(ADDD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAD a x y)
-(ADDD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSD a x y)
-(SUBF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSF a x y)
-(SUBF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAF a x y)
-(SUBD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSD a x y)
-(SUBD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAD a x y)
+(ADDF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAF a x y)
+(ADDF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSF a x y)
+(ADDD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAD a x y)
+(ADDD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSD a x y)
+(SUBF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSF a x y)
+(SUBF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAF a x y)
+(SUBD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSD a x y)
+(SUBD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAD a x y)
 
 (AND x (MVN y)) => (BIC x y)
 
 (CMPD x (MOVDconst [0])) => (CMPD0 x)
 
 // bit extraction
-(SRAconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 -> (BFX [(d-c)|(32-d)<<8] x)
-(SRLconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 -> (BFXU [(d-c)|(32-d)<<8] x)
+(SRAconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 => (BFX [(d-c)|(32-d)<<8] x)
+(SRLconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 => (BFXU [(d-c)|(32-d)<<8] x)
 
 // comparison simplification
 (CMP x (RSBconst [0] y)) => (CMN x y)
index 594d7427c475b88229fe03e71246132d69d6a5ea..b790d28cacfbf7c1084c8c2dc78dd1c32c4e7537 100644 (file)
@@ -2087,11 +2087,11 @@ func rewriteValueARM_OpARMADDshiftLL(v *Value) bool {
        // cond: objabi.GOARM>=6
        // result: (REV16 x)
        for {
-               if v.Type != typ.UInt16 || v.AuxInt != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || v_0.AuxInt != 24 {
+               if v.Type != typ.UInt16 || auxIntToInt32(v.AuxInt) != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || auxIntToInt32(v_0.AuxInt) != 24 {
                        break
                }
                v_0_0 := v_0.Args[0]
-               if v_0_0.Op != OpARMSLLconst || v_0_0.AuxInt != 16 {
+               if v_0_0.Op != OpARMSLLconst || auxIntToInt32(v_0_0.AuxInt) != 16 {
                        break
                }
                x := v_0_0.Args[0]
@@ -8555,11 +8555,11 @@ func rewriteValueARM_OpARMORshiftLL(v *Value) bool {
        // cond: objabi.GOARM>=6
        // result: (REV16 x)
        for {
-               if v.Type != typ.UInt16 || v.AuxInt != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || v_0.AuxInt != 24 {
+               if v.Type != typ.UInt16 || auxIntToInt32(v.AuxInt) != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || auxIntToInt32(v_0.AuxInt) != 24 {
                        break
                }
                v_0_0 := v_0.Args[0]
-               if v_0_0.Op != OpARMSLLconst || v_0_0.AuxInt != 16 {
+               if v_0_0.Op != OpARMSLLconst || auxIntToInt32(v_0_0.AuxInt) != 16 {
                        break
                }
                x := v_0_0.Args[0]
@@ -10466,17 +10466,17 @@ func rewriteValueARM_OpARMSRAconst(v *Value) bool {
        // cond: objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31
        // result: (BFX [(d-c)|(32-d)<<8] x)
        for {
-               d := v.AuxInt
+               d := auxIntToInt32(v.AuxInt)
                if v_0.Op != OpARMSLLconst {
                        break
                }
-               c := v_0.AuxInt
+               c := auxIntToInt32(v_0.AuxInt)
                x := v_0.Args[0]
                if !(objabi.GOARM == 7 && uint64(d) >= uint64(c) && uint64(d) <= 31) {
                        break
                }
                v.reset(OpARMBFX)
-               v.AuxInt = (d - c) | (32-d)<<8
+               v.AuxInt = int32ToAuxInt((d - c) | (32-d)<<8)
                v.AddArg(x)
                return true
        }
@@ -10518,17 +10518,17 @@ func rewriteValueARM_OpARMSRLconst(v *Value) bool {
        // cond: objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31
        // result: (BFXU [(d-c)|(32-d)<<8] x)
        for {
-               d := v.AuxInt
+               d := auxIntToInt32(v.AuxInt)
                if v_0.Op != OpARMSLLconst {
                        break
                }
-               c := v_0.AuxInt
+               c := auxIntToInt32(v_0.AuxInt)
                x := v_0.Args[0]
                if !(objabi.GOARM == 7 && uint64(d) >= uint64(c) && uint64(d) <= 31) {
                        break
                }
                v.reset(OpARMBFXU)
-               v.AuxInt = (d - c) | (32-d)<<8
+               v.AuxInt = int32ToAuxInt((d - c) | (32-d)<<8)
                v.AddArg(x)
                return true
        }
@@ -12594,11 +12594,11 @@ func rewriteValueARM_OpARMXORshiftLL(v *Value) bool {
        // cond: objabi.GOARM>=6
        // result: (REV16 x)
        for {
-               if v.Type != typ.UInt16 || v.AuxInt != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || v_0.AuxInt != 24 {
+               if v.Type != typ.UInt16 || auxIntToInt32(v.AuxInt) != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || auxIntToInt32(v_0.AuxInt) != 24 {
                        break
                }
                v_0_0 := v_0.Args[0]
-               if v_0_0.Op != OpARMSLLconst || v_0_0.AuxInt != 16 {
+               if v_0_0.Op != OpARMSLLconst || auxIntToInt32(v_0_0.AuxInt) != 16 {
                        break
                }
                x := v_0_0.Args[0]
@@ -12951,18 +12951,18 @@ func rewriteValueARM_OpBswap32(v *Value) bool {
                v.reset(OpARMXOR)
                v.Type = t
                v0 := b.NewValue0(v.Pos, OpARMSRLconst, t)
-               v0.AuxInt = 8
+               v0.AuxInt = int32ToAuxInt(8)
                v1 := b.NewValue0(v.Pos, OpARMBICconst, t)
-               v1.AuxInt = 0xff0000
+               v1.AuxInt = int32ToAuxInt(0xff0000)
                v2 := b.NewValue0(v.Pos, OpARMXOR, t)
                v3 := b.NewValue0(v.Pos, OpARMSRRconst, t)
-               v3.AuxInt = 16
+               v3.AuxInt = int32ToAuxInt(16)
                v3.AddArg(x)
                v2.AddArg2(x, v3)
                v1.AddArg(v2)
                v0.AddArg(v1)
                v4 := b.NewValue0(v.Pos, OpARMSRRconst, t)
-               v4.AuxInt = 8
+               v4.AuxInt = int32ToAuxInt(8)
                v4.AddArg(x)
                v.AddArg2(v0, v4)
                return true
@@ -13004,16 +13004,16 @@ func rewriteValueARM_OpCtz16(v *Value) bool {
                        break
                }
                v.reset(OpARMRSBconst)
-               v.AuxInt = 32
+               v.AuxInt = int32ToAuxInt(32)
                v0 := b.NewValue0(v.Pos, OpARMCLZ, t)
                v1 := b.NewValue0(v.Pos, OpARMSUBconst, typ.UInt32)
-               v1.AuxInt = 1
+               v1.AuxInt = int32ToAuxInt(1)
                v2 := b.NewValue0(v.Pos, OpARMAND, typ.UInt32)
                v3 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32)
-               v3.AuxInt = 0x10000
+               v3.AuxInt = int32ToAuxInt(0x10000)
                v3.AddArg(x)
                v4 := b.NewValue0(v.Pos, OpARMRSBconst, typ.UInt32)
-               v4.AuxInt = 0
+               v4.AuxInt = int32ToAuxInt(0)
                v4.AddArg(v3)
                v2.AddArg2(v3, v4)
                v1.AddArg(v2)
@@ -13034,7 +13034,7 @@ func rewriteValueARM_OpCtz16(v *Value) bool {
                v.Type = t
                v0 := b.NewValue0(v.Pos, OpARMRBIT, typ.UInt32)
                v1 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32)
-               v1.AuxInt = 0x10000
+               v1.AuxInt = int32ToAuxInt(0x10000)
                v1.AddArg(x)
                v0.AddArg(v1)
                v.AddArg(v0)
@@ -13055,13 +13055,13 @@ func rewriteValueARM_OpCtz32(v *Value) bool {
                        break
                }
                v.reset(OpARMRSBconst)
-               v.AuxInt = 32
+               v.AuxInt = int32ToAuxInt(32)
                v0 := b.NewValue0(v.Pos, OpARMCLZ, t)
                v1 := b.NewValue0(v.Pos, OpARMSUBconst, t)
-               v1.AuxInt = 1
+               v1.AuxInt = int32ToAuxInt(1)
                v2 := b.NewValue0(v.Pos, OpARMAND, t)
                v3 := b.NewValue0(v.Pos, OpARMRSBconst, t)
-               v3.AuxInt = 0
+               v3.AuxInt = int32ToAuxInt(0)
                v3.AddArg(x)
                v2.AddArg2(x, v3)
                v1.AddArg(v2)
@@ -13101,16 +13101,16 @@ func rewriteValueARM_OpCtz8(v *Value) bool {
                        break
                }
                v.reset(OpARMRSBconst)
-               v.AuxInt = 32
+               v.AuxInt = int32ToAuxInt(32)
                v0 := b.NewValue0(v.Pos, OpARMCLZ, t)
                v1 := b.NewValue0(v.Pos, OpARMSUBconst, typ.UInt32)
-               v1.AuxInt = 1
+               v1.AuxInt = int32ToAuxInt(1)
                v2 := b.NewValue0(v.Pos, OpARMAND, typ.UInt32)
                v3 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32)
-               v3.AuxInt = 0x100
+               v3.AuxInt = int32ToAuxInt(0x100)
                v3.AddArg(x)
                v4 := b.NewValue0(v.Pos, OpARMRSBconst, typ.UInt32)
-               v4.AuxInt = 0
+               v4.AuxInt = int32ToAuxInt(0)
                v4.AddArg(v3)
                v2.AddArg2(v3, v4)
                v1.AddArg(v2)
@@ -13131,7 +13131,7 @@ func rewriteValueARM_OpCtz8(v *Value) bool {
                v.Type = t
                v0 := b.NewValue0(v.Pos, OpARMRBIT, typ.UInt32)
                v1 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32)
-               v1.AuxInt = 0x100
+               v1.AuxInt = int32ToAuxInt(0x100)
                v1.AddArg(x)
                v0.AddArg(v1)
                v.AddArg(v0)