From 44343c777ca8c02262d1d381a2cc24866b3c5414 Mon Sep 17 00:00:00 2001 From: Brian Kessler Date: Tue, 23 Apr 2019 22:04:38 -0600 Subject: cmd/compile: add signed divisibility by power of 2 rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For powers of two (c=1< TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- test/codegen/arithmetic.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'test/codegen/arithmetic.go') diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index b5976be9d2..a937be7fe5 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -176,15 +176,28 @@ func Pow2Mods(n1 uint, n2 int) (uint, int) { // ppc64le:"ANDCC\t[$]31" a := n1 % 32 // unsigned - // 386:-"IDIVL" - // amd64:-"IDIVQ" - // arm:-".*udiv" - // arm64:-"REM" + // 386:"SHRL",-"IDIVL" + // amd64:"SHRQ",-"IDIVQ" + // arm:"SRA",-".*udiv" + // arm64:"ASR",-"REM" + // ppc64:"SRAD" + // ppc64le:"SRAD" b := n2 % 64 // signed return a, b } +// Check that signed divisibility checks get converted to AND on low bits +func Pow2DivisibleSigned(n int) bool { + // 386:"TESTL\t[$]63",-"DIVL",-"SHRL" + // amd64:"TESTQ\t[$]63",-"DIVQ",-"SHRQ" + // arm:"AND\t[$]63",-".*udiv",-"SRA" + // arm64:"AND\t[$]63",-"UDIV",-"ASR" + // ppc64:"ANDCC\t[$]63",-"SRAD" + // ppc64le:"ANDCC\t[$]63",-"SRAD" + return n%64 == 0 // signed +} + // Check that constant modulo divs get turned into MULs func ConstMods(n1 uint, n2 int) (uint, int) { // amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ" -- cgit v1.2.1