diff options
author | Alberto Donizetti <alb.donizetti@gmail.com> | 2018-03-15 10:06:37 +0100 |
---|---|---|
committer | Alberto Donizetti <alb.donizetti@gmail.com> | 2018-03-15 13:34:01 +0000 |
commit | ded9a1b3723e2c16f2ac0373ef4593f09e65f54d (patch) | |
tree | 98442afe8e9a029dcbcfd1e1ce305bd5f5003135 /test/codegen/arithmetic.go | |
parent | 107325627b584968b9408565e8ff50ef11b229e2 (diff) | |
download | go-git-ded9a1b3723e2c16f2ac0373ef4593f09e65f54d.tar.gz |
test/codegen: port len/cap pow2 div tests to codegen
And delete them from asm_test.
Change-Id: I29c8d098a8893e6b669b6272a2f508985ac9d618
Reviewed-on: https://go-review.googlesource.com/100876
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/codegen/arithmetic.go')
-rw-r--r-- | test/codegen/arithmetic.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index 20adc84bee..16517cfac4 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -118,3 +118,42 @@ func ConstMods(n1 uint, n2 int) (uint, int) { return a, b } + +// Check that len() and cap() calls divided by powers of two are +// optimized into shifts and ands + +func LenDiv1(a []int) int { + // 386:"SHRL\t[$]10" + // amd64:"SHRQ\t[$]10" + return len(a) / 1024 +} + +func LenDiv2(s string) int { + // 386:"SHRL\t[$]11" + // amd64:"SHRQ\t[$]11" + return len(s) / (4097 >> 1) +} + +func LenMod1(a []int) int { + // 386:"ANDL\t[$]1023" + // amd64:"ANDQ\t[$]1023" + return len(a) % 1024 +} + +func LenMod2(s string) int { + // 386:"ANDL\t[$]2047" + // amd64:"ANDQ\t[$]2047" + return len(s) % (4097 >> 1) +} + +func CapDiv(a []int) int { + // 386:"SHRL\t[$]12" + // amd64:"SHRQ\t[$]12" + return cap(a) / ((1 << 11) + 2048) +} + +func CapMod(a []int) int { + // 386:"ANDL\t[$]4095" + // amd64:"ANDQ\t[$]4095" + return cap(a) % ((1 << 11) + 2048) +} |