(Const64 <typ.UInt64> [63])))
// Unsigned mod by power of 2 constant.
-(Mod8u <t> n (Const8 [c])) && isPowerOfTwo(c) => (And8 n (Const8 <t> [c-1]))
-(Mod16u <t> n (Const16 [c])) && isPowerOfTwo(c) => (And16 n (Const16 <t> [c-1]))
-(Mod32u <t> n (Const32 [c])) && isPowerOfTwo(c) => (And32 n (Const32 <t> [c-1]))
-(Mod64u <t> n (Const64 [c])) && isPowerOfTwo(c) => (And64 n (Const64 <t> [c-1]))
-(Mod64u <t> n (Const64 [-1<<63])) => (And64 n (Const64 <t> [1<<63-1]))
+(Mod8u <t> n (Const8 [c])) && isUnsignedPowerOfTwo(uint8(c)) => (And8 n (Const8 <t> [c-1]))
+(Mod16u <t> n (Const16 [c])) && isUnsignedPowerOfTwo(uint16(c)) => (And16 n (Const16 <t> [c-1]))
+(Mod32u <t> n (Const32 [c])) && isUnsignedPowerOfTwo(uint32(c)) => (And32 n (Const32 <t> [c-1]))
+(Mod64u <t> n (Const64 [c])) && isUnsignedPowerOfTwo(uint64(c)) => (And64 n (Const64 <t> [c-1]))
// Signed non-negative mod by power of 2 constant.
(Mod8 <t> n (Const8 [c])) && isNonNegative(n) && isPowerOfTwo(c) => (And8 n (Const8 <t> [c-1]))
return true
}
// match: (Mod16u <t> n (Const16 [c]))
- // cond: isPowerOfTwo(c)
+ // cond: isUnsignedPowerOfTwo(uint16(c))
// result: (And16 n (Const16 <t> [c-1]))
for {
t := v.Type
break
}
c := auxIntToInt16(v_1.AuxInt)
- if !(isPowerOfTwo(c)) {
+ if !(isUnsignedPowerOfTwo(uint16(c))) {
break
}
v.reset(OpAnd16)
return true
}
// match: (Mod32u <t> n (Const32 [c]))
- // cond: isPowerOfTwo(c)
+ // cond: isUnsignedPowerOfTwo(uint32(c))
// result: (And32 n (Const32 <t> [c-1]))
for {
t := v.Type
break
}
c := auxIntToInt32(v_1.AuxInt)
- if !(isPowerOfTwo(c)) {
+ if !(isUnsignedPowerOfTwo(uint32(c))) {
break
}
v.reset(OpAnd32)
return true
}
// match: (Mod64u <t> n (Const64 [c]))
- // cond: isPowerOfTwo(c)
+ // cond: isUnsignedPowerOfTwo(uint64(c))
// result: (And64 n (Const64 <t> [c-1]))
for {
t := v.Type
break
}
c := auxIntToInt64(v_1.AuxInt)
- if !(isPowerOfTwo(c)) {
+ if !(isUnsignedPowerOfTwo(uint64(c))) {
break
}
v.reset(OpAnd64)
v.AddArg2(n, v0)
return true
}
- // match: (Mod64u <t> n (Const64 [-1<<63]))
- // result: (And64 n (Const64 <t> [1<<63-1]))
- for {
- t := v.Type
- n := v_0
- if v_1.Op != OpConst64 || auxIntToInt64(v_1.AuxInt) != -1<<63 {
- break
- }
- v.reset(OpAnd64)
- v0 := b.NewValue0(v.Pos, OpConst64, t)
- v0.AuxInt = int64ToAuxInt(1<<63 - 1)
- v.AddArg2(n, v0)
- return true
- }
// match: (Mod64u <t> x (Const64 [c]))
// cond: x.Op != OpConst64 && c > 0 && umagicOK64(c)
// result: (Sub64 x (Mul64 <t> (Div64u <t> x (Const64 <t> [c])) (Const64 <t> [c])))
return true
}
// match: (Mod8u <t> n (Const8 [c]))
- // cond: isPowerOfTwo(c)
+ // cond: isUnsignedPowerOfTwo(uint8(c))
// result: (And8 n (Const8 <t> [c-1]))
for {
t := v.Type
break
}
c := auxIntToInt8(v_1.AuxInt)
- if !(isPowerOfTwo(c)) {
+ if !(isUnsignedPowerOfTwo(uint8(c))) {
break
}
v.reset(OpAnd8)
// amd64:"SHRB [$]7, AL"
return b / 128
}
+
+func modUint64(b uint64) uint64 {
+ // amd64:"BTRQ [$]63, AX"
+ return b % 9223372036854775808
+}
+
+func modUint32(b uint32) uint32 {
+ // amd64:"ANDL [$]2147483647, AX"
+ return b % 2147483648
+}
+
+func modUint16(b uint16) uint16 {
+ // amd64:"ANDL [$]32767, AX"
+ return b % 32768
+}
+
+func modUint8(b uint8) uint8 {
+ // amd64:"ANDL [$]127, AX"
+ return b % 128
+}