1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Tests arithmetic expressions
27 func lshNop1(x uint64) uint64 {
28 // two outer shifts should be removed
29 return (((x << 5) >> 2) << 2)
33 func lshNop2(x uint64) uint64 {
34 return (((x << 5) >> 2) << 3)
38 func lshNop3(x uint64) uint64 {
39 return (((x << 5) >> 2) << 6)
43 func lshNotNop(x uint64) uint64 {
44 // outer shift can't be removed
45 return (((x << 5) >> 2) << 1)
49 func rshNop1(x uint64) uint64 {
50 return (((x >> 5) << 2) >> 2)
54 func rshNop2(x uint64) uint64 {
55 return (((x >> 5) << 2) >> 3)
59 func rshNop3(x uint64) uint64 {
60 return (((x >> 5) << 2) >> 6)
64 func rshNotNop(x uint64) uint64 {
65 return (((x >> 5) << 2) >> 1)
68 func testShiftRemoval(t *testing.T) {
70 if want, got := uint64(0x7ffffffffffffff), rshNop1(allSet); want != got {
71 t.Errorf("testShiftRemoval rshNop1 failed, wanted %d got %d", want, got)
73 if want, got := uint64(0x3ffffffffffffff), rshNop2(allSet); want != got {
74 t.Errorf("testShiftRemoval rshNop2 failed, wanted %d got %d", want, got)
76 if want, got := uint64(0x7fffffffffffff), rshNop3(allSet); want != got {
77 t.Errorf("testShiftRemoval rshNop3 failed, wanted %d got %d", want, got)
79 if want, got := uint64(0xffffffffffffffe), rshNotNop(allSet); want != got {
80 t.Errorf("testShiftRemoval rshNotNop failed, wanted %d got %d", want, got)
82 if want, got := uint64(0xffffffffffffffe0), lshNop1(allSet); want != got {
83 t.Errorf("testShiftRemoval lshNop1 failed, wanted %d got %d", want, got)
85 if want, got := uint64(0xffffffffffffffc0), lshNop2(allSet); want != got {
86 t.Errorf("testShiftRemoval lshNop2 failed, wanted %d got %d", want, got)
88 if want, got := uint64(0xfffffffffffffe00), lshNop3(allSet); want != got {
89 t.Errorf("testShiftRemoval lshNop3 failed, wanted %d got %d", want, got)
91 if want, got := uint64(0x7ffffffffffffff0), lshNotNop(allSet); want != got {
92 t.Errorf("testShiftRemoval lshNotNop failed, wanted %d got %d", want, got)
97 func parseLE64(b []byte) uint64 {
98 // skip the first two bytes, and parse the remaining 8 as a uint64
99 return uint64(b[2]) | uint64(b[3])<<8 | uint64(b[4])<<16 | uint64(b[5])<<24 |
100 uint64(b[6])<<32 | uint64(b[7])<<40 | uint64(b[8])<<48 | uint64(b[9])<<56
104 func parseLE32(b []byte) uint32 {
105 return uint32(b[2]) | uint32(b[3])<<8 | uint32(b[4])<<16 | uint32(b[5])<<24
109 func parseLE16(b []byte) uint16 {
110 return uint16(b[2]) | uint16(b[3])<<8
113 // testLoadCombine tests for issue #14694 where load combining didn't respect the pointer offset.
114 func testLoadCombine(t *testing.T) {
115 testData := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}
116 if want, got := uint64(0x0908070605040302), parseLE64(testData); want != got {
117 t.Errorf("testLoadCombine failed, wanted %d got %d", want, got)
119 if want, got := uint32(0x05040302), parseLE32(testData); want != got {
120 t.Errorf("testLoadCombine failed, wanted %d got %d", want, got)
122 if want, got := uint16(0x0302), parseLE16(testData); want != got {
123 t.Errorf("testLoadCombine failed, wanted %d got %d", want, got)
127 var loadSymData = [...]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}
129 func testLoadSymCombine(t *testing.T) {
131 g2 := uint16(loadSymData[0]) | uint16(loadSymData[1])<<8
133 t.Errorf("testLoadSymCombine failed, wanted %d got %d", w2, g2)
135 w4 := uint32(0x04030201)
136 g4 := uint32(loadSymData[0]) | uint32(loadSymData[1])<<8 |
137 uint32(loadSymData[2])<<16 | uint32(loadSymData[3])<<24
139 t.Errorf("testLoadSymCombine failed, wanted %d got %d", w4, g4)
141 w8 := uint64(0x0807060504030201)
142 g8 := uint64(loadSymData[0]) | uint64(loadSymData[1])<<8 |
143 uint64(loadSymData[2])<<16 | uint64(loadSymData[3])<<24 |
144 uint64(loadSymData[4])<<32 | uint64(loadSymData[5])<<40 |
145 uint64(loadSymData[6])<<48 | uint64(loadSymData[7])<<56
147 t.Errorf("testLoadSymCombine failed, wanted %d got %d", w8, g8)
152 func invalidAdd_ssa(x uint32) uint32 {
153 return x + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y
157 func invalidSub_ssa(x uint32) uint32 {
158 return x - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y
162 func invalidMul_ssa(x uint32) uint32 {
163 return x * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y
166 // testLargeConst tests a situation where larger than 32 bit consts were passed to ADDL
167 // causing an invalid instruction error.
168 func testLargeConst(t *testing.T) {
169 if want, got := uint32(268435440), invalidAdd_ssa(1); want != got {
170 t.Errorf("testLargeConst add failed, wanted %d got %d", want, got)
172 if want, got := uint32(4026531858), invalidSub_ssa(1); want != got {
173 t.Errorf("testLargeConst sub failed, wanted %d got %d", want, got)
175 if want, got := uint32(268435455), invalidMul_ssa(1); want != got {
176 t.Errorf("testLargeConst mul failed, wanted %d got %d", want, got)
180 // testArithRshConst ensures that "const >> const" right shifts correctly perform
181 // sign extension on the lhs constant
182 func testArithRshConst(t *testing.T) {
183 wantu := uint64(0x4000000000000000)
184 if got := arithRshuConst_ssa(); got != wantu {
185 t.Errorf("arithRshuConst failed, wanted %d got %d", wantu, got)
188 wants := int64(-0x4000000000000000)
189 if got := arithRshConst_ssa(); got != wants {
190 t.Errorf("arithRshConst failed, wanted %d got %d", wants, got)
195 func arithRshuConst_ssa() uint64 {
196 y := uint64(0x8000000000000001)
198 return uint64(y >> z)
202 func arithRshConst_ssa() int64 {
203 y := int64(-0x8000000000000000)
209 func arithConstShift_ssa(x int64) int64 {
213 // testArithConstShift tests that right shift by large constants preserve
214 // the sign of the input.
215 func testArithConstShift(t *testing.T) {
217 if got := arithConstShift_ssa(-1); want != got {
218 t.Errorf("arithConstShift_ssa(-1) failed, wanted %d got %d", want, got)
221 if got := arithConstShift_ssa(1); want != got {
222 t.Errorf("arithConstShift_ssa(1) failed, wanted %d got %d", want, got)
226 // overflowConstShift_ssa verifies that constant folding for shift
227 // doesn't wrap (i.e. x << MAX_INT << 1 doesn't get folded to x << 0).
230 func overflowConstShift64_ssa(x int64) int64 {
231 return x << uint64(0xffffffffffffffff) << uint64(1)
235 func overflowConstShift32_ssa(x int64) int32 {
236 return int32(x) << uint32(0xffffffff) << uint32(1)
240 func overflowConstShift16_ssa(x int64) int16 {
241 return int16(x) << uint16(0xffff) << uint16(1)
245 func overflowConstShift8_ssa(x int64) int8 {
246 return int8(x) << uint8(0xff) << uint8(1)
249 func testOverflowConstShift(t *testing.T) {
251 for x := int64(-127); x < int64(127); x++ {
252 got := overflowConstShift64_ssa(x)
254 t.Errorf("overflowShift64 failed, wanted %d got %d", want, got)
256 got = int64(overflowConstShift32_ssa(x))
258 t.Errorf("overflowShift32 failed, wanted %d got %d", want, got)
260 got = int64(overflowConstShift16_ssa(x))
262 t.Errorf("overflowShift16 failed, wanted %d got %d", want, got)
264 got = int64(overflowConstShift8_ssa(x))
266 t.Errorf("overflowShift8 failed, wanted %d got %d", want, got)
271 // test64BitConstMult tests that rewrite rules don't fold 64 bit constants
272 // into multiply instructions.
273 func test64BitConstMult(t *testing.T) {
274 want := int64(103079215109)
275 if got := test64BitConstMult_ssa(1, 2); want != got {
276 t.Errorf("test64BitConstMult failed, wanted %d got %d", want, got)
281 func test64BitConstMult_ssa(a, b int64) int64 {
282 return 34359738369*a + b*34359738370
285 // test64BitConstAdd tests that rewrite rules don't fold 64 bit constants
286 // into add instructions.
287 func test64BitConstAdd(t *testing.T) {
288 want := int64(3567671782835376650)
289 if got := test64BitConstAdd_ssa(1, 2); want != got {
290 t.Errorf("test64BitConstAdd failed, wanted %d got %d", want, got)
295 func test64BitConstAdd_ssa(a, b int64) int64 {
296 return a + 575815584948629622 + b + 2991856197886747025
299 // testRegallocCVSpill tests that regalloc spills a value whose last use is the
301 func testRegallocCVSpill(t *testing.T) {
303 if got := testRegallocCVSpill_ssa(1, 2, 3, 4); want != got {
304 t.Errorf("testRegallocCVSpill failed, wanted %d got %d", want, got)
309 func testRegallocCVSpill_ssa(a, b, c, d int8) int8 {
310 return a + -32 + b + 63*c*-87*d
313 func testBitwiseLogic(t *testing.T) {
314 a, b := uint32(57623283), uint32(1314713839)
315 if want, got := uint32(38551779), testBitwiseAnd_ssa(a, b); want != got {
316 t.Errorf("testBitwiseAnd failed, wanted %d got %d", want, got)
318 if want, got := uint32(1333785343), testBitwiseOr_ssa(a, b); want != got {
319 t.Errorf("testBitwiseOr failed, wanted %d got %d", want, got)
321 if want, got := uint32(1295233564), testBitwiseXor_ssa(a, b); want != got {
322 t.Errorf("testBitwiseXor failed, wanted %d got %d", want, got)
324 if want, got := int32(832), testBitwiseLsh_ssa(13, 4, 2); want != got {
325 t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got)
327 if want, got := int32(0), testBitwiseLsh_ssa(13, 25, 15); want != got {
328 t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got)
330 if want, got := int32(0), testBitwiseLsh_ssa(-13, 25, 15); want != got {
331 t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got)
333 if want, got := int32(-13), testBitwiseRsh_ssa(-832, 4, 2); want != got {
334 t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got)
336 if want, got := int32(0), testBitwiseRsh_ssa(13, 25, 15); want != got {
337 t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got)
339 if want, got := int32(-1), testBitwiseRsh_ssa(-13, 25, 15); want != got {
340 t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got)
342 if want, got := uint32(0x3ffffff), testBitwiseRshU_ssa(0xffffffff, 4, 2); want != got {
343 t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got)
345 if want, got := uint32(0), testBitwiseRshU_ssa(13, 25, 15); want != got {
346 t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got)
348 if want, got := uint32(0), testBitwiseRshU_ssa(0x8aaaaaaa, 25, 15); want != got {
349 t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got)
354 func testBitwiseAnd_ssa(a, b uint32) uint32 {
359 func testBitwiseOr_ssa(a, b uint32) uint32 {
364 func testBitwiseXor_ssa(a, b uint32) uint32 {
369 func testBitwiseLsh_ssa(a int32, b, c uint32) int32 {
374 func testBitwiseRsh_ssa(a int32, b, c uint32) int32 {
379 func testBitwiseRshU_ssa(a uint32, b, c uint32) uint32 {
384 func testShiftCX_ssa() int {
386 v4 := (v1 * v1) ^ v1 | v1 - v1 - v1&v1 ^ uint8(3+2) + v1*1>>0 - v1 | 1 | v1<<(2*3|0-0*0^1)
387 v5 := v4>>(3-0-uint(3)) | v1 | v1 + v1 ^ v4<<(0+1|3&1)<<(uint64(1)<<0*2*0<<0) ^ v1
388 v6 := v5 ^ (v1+v1)*v1 | v1 | v1*v1>>(v1&v1)>>(uint(1)<<0*uint(3)>>1)*v1<<2*v1<<v1 - v1>>2 | (v4 - v1) ^ v1 + v1 ^ v1>>1 | v1 + v1 - v1 ^ v1
391 v11 := 2&1 ^ 0 + 3 | int(0^0)<<1>>(1*0*3) ^ 0*0 ^ 3&0*3&3 ^ 3*3 ^ 1 ^ int(2)<<(2*3) + 2 | 2 | 2 ^ 2 + 1 | 3 | 0 ^ int(1)>>1 ^ 2 // int
393 return int(uint64(2*1)<<(3-2)<<uint(3>>v7)-2)&v11 | v11 - int(2)<<0>>(2-1)*(v11*0&v11<<1<<(uint8(2)+v4))
396 func testShiftCX(t *testing.T) {
398 if got := testShiftCX_ssa(); want != got {
399 t.Errorf("testShiftCX failed, wanted %d got %d", want, got)
403 // testSubqToNegq ensures that the SUBQ -> NEGQ translation works correctly.
404 func testSubqToNegq(t *testing.T) {
405 want := int64(-318294940372190156)
406 if got := testSubqToNegq_ssa(1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2); want != got {
407 t.Errorf("testSubqToNegq failed, wanted %d got %d", want, got)
412 func testSubqToNegq_ssa(a, b, c, d, e, f, g, h, i, j, k int64) int64 {
413 return a + 8207351403619448057 - b - 1779494519303207690 + c*8810076340510052032*d - 4465874067674546219 - e*4361839741470334295 - f + 8688847565426072650*g*8065564729145417479
416 func testOcom(t *testing.T) {
417 want1, want2 := int32(0x55555555), int32(-0x55555556)
418 if got1, got2 := testOcom_ssa(0x55555555, 0x55555555); want1 != got1 || want2 != got2 {
419 t.Errorf("testOcom failed, wanted %d and %d got %d and %d", want1, want2, got1, got2)
424 func testOcom_ssa(a, b int32) (int32, int32) {
428 func lrot1_ssa(w uint8, x uint16, y uint32, z uint64) (a uint8, b uint16, c uint32, d uint64) {
429 a = (w << 5) | (w >> 3)
430 b = (x << 13) | (x >> 3)
431 c = (y << 29) | (y >> 3)
432 d = (z << 61) | (z >> 3)
437 func lrot2_ssa(w, n uint32) uint32 {
438 // Want to be sure that a "rotate by 32" which
439 // is really 0 | (w >> 0) == w
440 // is correctly compiled.
441 return (w << n) | (w >> (32 - n))
445 func lrot3_ssa(w uint32) uint32 {
446 // Want to be sure that a "rotate by 32" which
447 // is really 0 | (w >> 0) == w
448 // is correctly compiled.
449 return (w << 32) | (w >> (32 - 32))
452 func testLrot(t *testing.T) {
453 wantA, wantB, wantC, wantD := uint8(0xe1), uint16(0xe001),
454 uint32(0xe0000001), uint64(0xe000000000000001)
455 a, b, c, d := lrot1_ssa(0xf, 0xf, 0xf, 0xf)
456 if a != wantA || b != wantB || c != wantC || d != wantD {
457 t.Errorf("lrot1_ssa(0xf, 0xf, 0xf, 0xf)=%d %d %d %d, got %d %d %d %d", wantA, wantB, wantC, wantD, a, b, c, d)
459 x := lrot2_ssa(0xb0000001, 32)
460 wantX := uint32(0xb0000001)
462 t.Errorf("lrot2_ssa(0xb0000001, 32)=%d, got %d", wantX, x)
464 x = lrot3_ssa(0xb0000001)
466 t.Errorf("lrot3_ssa(0xb0000001)=%d, got %d", wantX, x)
472 func sub1_ssa() uint64 {
473 v1 := uint64(3) // uint64
474 return v1*v1 - (v1&v1)&v1
478 func sub2_ssa() uint8 {
480 v3 := v1 + v1 + v1 ^ v1 | 3 + v1 ^ v1 | v1 ^ v1
481 v1-- // dev.ssa doesn't see this one
482 return v1 ^ v1*v1 - v3
485 func testSubConst(t *testing.T) {
489 t.Errorf("sub1_ssa()=%d, got %d", want1, x1)
494 t.Errorf("sub2_ssa()=%d, got %d", want2, x2)
499 func orPhi_ssa(a bool, x int) int {
509 func testOrPhi(t *testing.T) {
510 if want, got := -1, orPhi_ssa(true, 4); got != want {
511 t.Errorf("orPhi_ssa(true, 4)=%d, want %d", got, want)
513 if want, got := -1, orPhi_ssa(false, 0); got != want {
514 t.Errorf("orPhi_ssa(false, 0)=%d, want %d", got, want)
519 func addshiftLL_ssa(a, b uint32) uint32 {
524 func subshiftLL_ssa(a, b uint32) uint32 {
529 func rsbshiftLL_ssa(a, b uint32) uint32 {
534 func andshiftLL_ssa(a, b uint32) uint32 {
539 func orshiftLL_ssa(a, b uint32) uint32 {
544 func xorshiftLL_ssa(a, b uint32) uint32 {
549 func bicshiftLL_ssa(a, b uint32) uint32 {
554 func notshiftLL_ssa(a uint32) uint32 {
559 func addshiftRL_ssa(a, b uint32) uint32 {
564 func subshiftRL_ssa(a, b uint32) uint32 {
569 func rsbshiftRL_ssa(a, b uint32) uint32 {
574 func andshiftRL_ssa(a, b uint32) uint32 {
579 func orshiftRL_ssa(a, b uint32) uint32 {
584 func xorshiftRL_ssa(a, b uint32) uint32 {
589 func bicshiftRL_ssa(a, b uint32) uint32 {
594 func notshiftRL_ssa(a uint32) uint32 {
599 func addshiftRA_ssa(a, b int32) int32 {
604 func subshiftRA_ssa(a, b int32) int32 {
609 func rsbshiftRA_ssa(a, b int32) int32 {
614 func andshiftRA_ssa(a, b int32) int32 {
619 func orshiftRA_ssa(a, b int32) int32 {
624 func xorshiftRA_ssa(a, b int32) int32 {
629 func bicshiftRA_ssa(a, b int32) int32 {
634 func notshiftRA_ssa(a int32) int32 {
639 func addshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
644 func subshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
649 func rsbshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
654 func andshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
659 func orshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
664 func xorshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
669 func bicshiftLLreg_ssa(a, b uint32, s uint8) uint32 {
674 func notshiftLLreg_ssa(a uint32, s uint8) uint32 {
679 func addshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
684 func subshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
689 func rsbshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
694 func andshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
699 func orshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
704 func xorshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
709 func bicshiftRLreg_ssa(a, b uint32, s uint8) uint32 {
714 func notshiftRLreg_ssa(a uint32, s uint8) uint32 {
719 func addshiftRAreg_ssa(a, b int32, s uint8) int32 {
724 func subshiftRAreg_ssa(a, b int32, s uint8) int32 {
729 func rsbshiftRAreg_ssa(a, b int32, s uint8) int32 {
734 func andshiftRAreg_ssa(a, b int32, s uint8) int32 {
739 func orshiftRAreg_ssa(a, b int32, s uint8) int32 {
744 func xorshiftRAreg_ssa(a, b int32, s uint8) int32 {
749 func bicshiftRAreg_ssa(a, b int32, s uint8) int32 {
754 func notshiftRAreg_ssa(a int32, s uint8) int32 {
758 // test ARM shifted ops
759 func testShiftedOps(t *testing.T) {
760 a, b := uint32(10), uint32(42)
761 if want, got := a+b<<3, addshiftLL_ssa(a, b); got != want {
762 t.Errorf("addshiftLL_ssa(10, 42) = %d want %d", got, want)
764 if want, got := a-b<<3, subshiftLL_ssa(a, b); got != want {
765 t.Errorf("subshiftLL_ssa(10, 42) = %d want %d", got, want)
767 if want, got := a<<3-b, rsbshiftLL_ssa(a, b); got != want {
768 t.Errorf("rsbshiftLL_ssa(10, 42) = %d want %d", got, want)
770 if want, got := a&(b<<3), andshiftLL_ssa(a, b); got != want {
771 t.Errorf("andshiftLL_ssa(10, 42) = %d want %d", got, want)
773 if want, got := a|b<<3, orshiftLL_ssa(a, b); got != want {
774 t.Errorf("orshiftLL_ssa(10, 42) = %d want %d", got, want)
776 if want, got := a^b<<3, xorshiftLL_ssa(a, b); got != want {
777 t.Errorf("xorshiftLL_ssa(10, 42) = %d want %d", got, want)
779 if want, got := a&^(b<<3), bicshiftLL_ssa(a, b); got != want {
780 t.Errorf("bicshiftLL_ssa(10, 42) = %d want %d", got, want)
782 if want, got := ^(a << 3), notshiftLL_ssa(a); got != want {
783 t.Errorf("notshiftLL_ssa(10) = %d want %d", got, want)
785 if want, got := a+b>>3, addshiftRL_ssa(a, b); got != want {
786 t.Errorf("addshiftRL_ssa(10, 42) = %d want %d", got, want)
788 if want, got := a-b>>3, subshiftRL_ssa(a, b); got != want {
789 t.Errorf("subshiftRL_ssa(10, 42) = %d want %d", got, want)
791 if want, got := a>>3-b, rsbshiftRL_ssa(a, b); got != want {
792 t.Errorf("rsbshiftRL_ssa(10, 42) = %d want %d", got, want)
794 if want, got := a&(b>>3), andshiftRL_ssa(a, b); got != want {
795 t.Errorf("andshiftRL_ssa(10, 42) = %d want %d", got, want)
797 if want, got := a|b>>3, orshiftRL_ssa(a, b); got != want {
798 t.Errorf("orshiftRL_ssa(10, 42) = %d want %d", got, want)
800 if want, got := a^b>>3, xorshiftRL_ssa(a, b); got != want {
801 t.Errorf("xorshiftRL_ssa(10, 42) = %d want %d", got, want)
803 if want, got := a&^(b>>3), bicshiftRL_ssa(a, b); got != want {
804 t.Errorf("bicshiftRL_ssa(10, 42) = %d want %d", got, want)
806 if want, got := ^(a >> 3), notshiftRL_ssa(a); got != want {
807 t.Errorf("notshiftRL_ssa(10) = %d want %d", got, want)
809 c, d := int32(10), int32(-42)
810 if want, got := c+d>>3, addshiftRA_ssa(c, d); got != want {
811 t.Errorf("addshiftRA_ssa(10, -42) = %d want %d", got, want)
813 if want, got := c-d>>3, subshiftRA_ssa(c, d); got != want {
814 t.Errorf("subshiftRA_ssa(10, -42) = %d want %d", got, want)
816 if want, got := c>>3-d, rsbshiftRA_ssa(c, d); got != want {
817 t.Errorf("rsbshiftRA_ssa(10, -42) = %d want %d", got, want)
819 if want, got := c&(d>>3), andshiftRA_ssa(c, d); got != want {
820 t.Errorf("andshiftRA_ssa(10, -42) = %d want %d", got, want)
822 if want, got := c|d>>3, orshiftRA_ssa(c, d); got != want {
823 t.Errorf("orshiftRA_ssa(10, -42) = %d want %d", got, want)
825 if want, got := c^d>>3, xorshiftRA_ssa(c, d); got != want {
826 t.Errorf("xorshiftRA_ssa(10, -42) = %d want %d", got, want)
828 if want, got := c&^(d>>3), bicshiftRA_ssa(c, d); got != want {
829 t.Errorf("bicshiftRA_ssa(10, -42) = %d want %d", got, want)
831 if want, got := ^(d >> 3), notshiftRA_ssa(d); got != want {
832 t.Errorf("notshiftRA_ssa(-42) = %d want %d", got, want)
835 if want, got := a+b<<s, addshiftLLreg_ssa(a, b, s); got != want {
836 t.Errorf("addshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
838 if want, got := a-b<<s, subshiftLLreg_ssa(a, b, s); got != want {
839 t.Errorf("subshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
841 if want, got := a<<s-b, rsbshiftLLreg_ssa(a, b, s); got != want {
842 t.Errorf("rsbshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
844 if want, got := a&(b<<s), andshiftLLreg_ssa(a, b, s); got != want {
845 t.Errorf("andshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
847 if want, got := a|b<<s, orshiftLLreg_ssa(a, b, s); got != want {
848 t.Errorf("orshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
850 if want, got := a^b<<s, xorshiftLLreg_ssa(a, b, s); got != want {
851 t.Errorf("xorshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
853 if want, got := a&^(b<<s), bicshiftLLreg_ssa(a, b, s); got != want {
854 t.Errorf("bicshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)
856 if want, got := ^(a << s), notshiftLLreg_ssa(a, s); got != want {
857 t.Errorf("notshiftLLreg_ssa(10) = %d want %d", got, want)
859 if want, got := a+b>>s, addshiftRLreg_ssa(a, b, s); got != want {
860 t.Errorf("addshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
862 if want, got := a-b>>s, subshiftRLreg_ssa(a, b, s); got != want {
863 t.Errorf("subshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
865 if want, got := a>>s-b, rsbshiftRLreg_ssa(a, b, s); got != want {
866 t.Errorf("rsbshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
868 if want, got := a&(b>>s), andshiftRLreg_ssa(a, b, s); got != want {
869 t.Errorf("andshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
871 if want, got := a|b>>s, orshiftRLreg_ssa(a, b, s); got != want {
872 t.Errorf("orshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
874 if want, got := a^b>>s, xorshiftRLreg_ssa(a, b, s); got != want {
875 t.Errorf("xorshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
877 if want, got := a&^(b>>s), bicshiftRLreg_ssa(a, b, s); got != want {
878 t.Errorf("bicshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)
880 if want, got := ^(a >> s), notshiftRLreg_ssa(a, s); got != want {
881 t.Errorf("notshiftRLreg_ssa(10) = %d want %d", got, want)
883 if want, got := c+d>>s, addshiftRAreg_ssa(c, d, s); got != want {
884 t.Errorf("addshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
886 if want, got := c-d>>s, subshiftRAreg_ssa(c, d, s); got != want {
887 t.Errorf("subshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
889 if want, got := c>>s-d, rsbshiftRAreg_ssa(c, d, s); got != want {
890 t.Errorf("rsbshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
892 if want, got := c&(d>>s), andshiftRAreg_ssa(c, d, s); got != want {
893 t.Errorf("andshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
895 if want, got := c|d>>s, orshiftRAreg_ssa(c, d, s); got != want {
896 t.Errorf("orshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
898 if want, got := c^d>>s, xorshiftRAreg_ssa(c, d, s); got != want {
899 t.Errorf("xorshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
901 if want, got := c&^(d>>s), bicshiftRAreg_ssa(c, d, s); got != want {
902 t.Errorf("bicshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)
904 if want, got := ^(d >> s), notshiftRAreg_ssa(d, s); got != want {
905 t.Errorf("notshiftRAreg_ssa(-42, 3) = %d want %d", got, want)
909 // TestArithmetic tests that both backends have the same result for arithmetic expressions.
910 func TestArithmetic(t *testing.T) {
911 test64BitConstMult(t)
913 testRegallocCVSpill(t)
920 testOverflowConstShift(t)
921 testArithConstShift(t)
925 testLoadSymCombine(t)
929 testDivisibleSignedPow2(t)
933 // testDivFixUp ensures that signed division fix-ups are being generated.
934 func testDivFixUp(t *testing.T) {
936 if r := recover(); r != nil {
937 t.Error("testDivFixUp failed")
938 if e, ok := r.(runtime.Error); ok {
939 t.Logf("%v\n", e.Error())
945 var y int32 = -2147483648
946 var z int64 = -9223372036854775808
948 for i := -5; i < 0; i++ {
961 func divisible_int8_2to1(x int8) bool {
966 func divisible_int8_2to2(x int8) bool {
971 func divisible_int8_2to3(x int8) bool {
976 func divisible_int8_2to4(x int8) bool {
981 func divisible_int8_2to5(x int8) bool {
986 func divisible_int8_2to6(x int8) bool {
991 func divisible_int16_2to1(x int16) bool {
996 func divisible_int16_2to2(x int16) bool {
1001 func divisible_int16_2to3(x int16) bool {
1002 return x%(1<<3) == 0
1006 func divisible_int16_2to4(x int16) bool {
1007 return x%(1<<4) == 0
1011 func divisible_int16_2to5(x int16) bool {
1012 return x%(1<<5) == 0
1016 func divisible_int16_2to6(x int16) bool {
1017 return x%(1<<6) == 0
1021 func divisible_int16_2to7(x int16) bool {
1022 return x%(1<<7) == 0
1026 func divisible_int16_2to8(x int16) bool {
1027 return x%(1<<8) == 0
1031 func divisible_int16_2to9(x int16) bool {
1032 return x%(1<<9) == 0
1036 func divisible_int16_2to10(x int16) bool {
1037 return x%(1<<10) == 0
1041 func divisible_int16_2to11(x int16) bool {
1042 return x%(1<<11) == 0
1046 func divisible_int16_2to12(x int16) bool {
1047 return x%(1<<12) == 0
1051 func divisible_int16_2to13(x int16) bool {
1052 return x%(1<<13) == 0
1056 func divisible_int16_2to14(x int16) bool {
1057 return x%(1<<14) == 0
1061 func divisible_int32_2to4(x int32) bool {
1062 return x%(1<<4) == 0
1066 func divisible_int32_2to15(x int32) bool {
1067 return x%(1<<15) == 0
1071 func divisible_int32_2to26(x int32) bool {
1072 return x%(1<<26) == 0
1076 func divisible_int64_2to4(x int64) bool {
1077 return x%(1<<4) == 0
1081 func divisible_int64_2to15(x int64) bool {
1082 return x%(1<<15) == 0
1086 func divisible_int64_2to26(x int64) bool {
1087 return x%(1<<26) == 0
1091 func divisible_int64_2to34(x int64) bool {
1092 return x%(1<<34) == 0
1096 func divisible_int64_2to48(x int64) bool {
1097 return x%(1<<48) == 0
1101 func divisible_int64_2to57(x int64) bool {
1102 return x%(1<<57) == 0
1105 // testDivisibleSignedPow2 confirms that x%(1<<k)==0 is rewritten correctly
1106 func testDivisibleSignedPow2(t *testing.T) {
1125 // exhaustive test for int8
1126 for i = math.MinInt8; i <= math.MaxInt8; i++ {
1127 if want, got := int8(i)%int8(pow2[1]) == 0, divisible_int8_2to1(int8(i)); got != want {
1128 t.Errorf("divisible_int8_2to1(%d) = %v want %v", i, got, want)
1130 if want, got := int8(i)%int8(pow2[2]) == 0, divisible_int8_2to2(int8(i)); got != want {
1131 t.Errorf("divisible_int8_2to2(%d) = %v want %v", i, got, want)
1133 if want, got := int8(i)%int8(pow2[3]) == 0, divisible_int8_2to3(int8(i)); got != want {
1134 t.Errorf("divisible_int8_2to3(%d) = %v want %v", i, got, want)
1136 if want, got := int8(i)%int8(pow2[4]) == 0, divisible_int8_2to4(int8(i)); got != want {
1137 t.Errorf("divisible_int8_2to4(%d) = %v want %v", i, got, want)
1139 if want, got := int8(i)%int8(pow2[5]) == 0, divisible_int8_2to5(int8(i)); got != want {
1140 t.Errorf("divisible_int8_2to5(%d) = %v want %v", i, got, want)
1142 if want, got := int8(i)%int8(pow2[6]) == 0, divisible_int8_2to6(int8(i)); got != want {
1143 t.Errorf("divisible_int8_2to6(%d) = %v want %v", i, got, want)
1146 // exhaustive test for int16
1147 for i = math.MinInt16; i <= math.MaxInt16; i++ {
1148 if want, got := int16(i)%int16(pow2[1]) == 0, divisible_int16_2to1(int16(i)); got != want {
1149 t.Errorf("divisible_int16_2to1(%d) = %v want %v", i, got, want)
1151 if want, got := int16(i)%int16(pow2[2]) == 0, divisible_int16_2to2(int16(i)); got != want {
1152 t.Errorf("divisible_int16_2to2(%d) = %v want %v", i, got, want)
1154 if want, got := int16(i)%int16(pow2[3]) == 0, divisible_int16_2to3(int16(i)); got != want {
1155 t.Errorf("divisible_int16_2to3(%d) = %v want %v", i, got, want)
1157 if want, got := int16(i)%int16(pow2[4]) == 0, divisible_int16_2to4(int16(i)); got != want {
1158 t.Errorf("divisible_int16_2to4(%d) = %v want %v", i, got, want)
1160 if want, got := int16(i)%int16(pow2[5]) == 0, divisible_int16_2to5(int16(i)); got != want {
1161 t.Errorf("divisible_int16_2to5(%d) = %v want %v", i, got, want)
1163 if want, got := int16(i)%int16(pow2[6]) == 0, divisible_int16_2to6(int16(i)); got != want {
1164 t.Errorf("divisible_int16_2to6(%d) = %v want %v", i, got, want)
1166 if want, got := int16(i)%int16(pow2[7]) == 0, divisible_int16_2to7(int16(i)); got != want {
1167 t.Errorf("divisible_int16_2to7(%d) = %v want %v", i, got, want)
1169 if want, got := int16(i)%int16(pow2[8]) == 0, divisible_int16_2to8(int16(i)); got != want {
1170 t.Errorf("divisible_int16_2to8(%d) = %v want %v", i, got, want)
1172 if want, got := int16(i)%int16(pow2[9]) == 0, divisible_int16_2to9(int16(i)); got != want {
1173 t.Errorf("divisible_int16_2to9(%d) = %v want %v", i, got, want)
1175 if want, got := int16(i)%int16(pow2[10]) == 0, divisible_int16_2to10(int16(i)); got != want {
1176 t.Errorf("divisible_int16_2to10(%d) = %v want %v", i, got, want)
1178 if want, got := int16(i)%int16(pow2[11]) == 0, divisible_int16_2to11(int16(i)); got != want {
1179 t.Errorf("divisible_int16_2to11(%d) = %v want %v", i, got, want)
1181 if want, got := int16(i)%int16(pow2[12]) == 0, divisible_int16_2to12(int16(i)); got != want {
1182 t.Errorf("divisible_int16_2to12(%d) = %v want %v", i, got, want)
1184 if want, got := int16(i)%int16(pow2[13]) == 0, divisible_int16_2to13(int16(i)); got != want {
1185 t.Errorf("divisible_int16_2to13(%d) = %v want %v", i, got, want)
1187 if want, got := int16(i)%int16(pow2[14]) == 0, divisible_int16_2to14(int16(i)); got != want {
1188 t.Errorf("divisible_int16_2to14(%d) = %v want %v", i, got, want)
1191 // spot check for int32 and int64
1194 two15 int64 = 1 << 15
1195 two26 int64 = 1 << 26
1196 two34 int64 = 1 << 34
1197 two48 int64 = 1 << 48
1198 two57 int64 = 1 << 57
1200 var xs = []int64{two4, two4 + 3, -3 * two4, -3*two4 + 1,
1201 two15, two15 + 3, -3 * two15, -3*two15 + 1,
1202 two26, two26 + 37, -5 * two26, -5*two26 + 2,
1203 two34, two34 + 356, -7 * two34, -7*two34 + 13,
1204 two48, two48 + 3000, -12 * two48, -12*two48 + 1111,
1205 two57, two57 + 397654, -15 * two57, -15*two57 + 11234,
1207 for _, x := range xs {
1208 if int64(int32(x)) == x {
1209 if want, got := int32(x)%int32(two4) == 0, divisible_int32_2to4(int32(x)); got != want {
1210 t.Errorf("divisible_int32_2to4(%d) = %v want %v", x, got, want)
1213 if want, got := int32(x)%int32(two15) == 0, divisible_int32_2to15(int32(x)); got != want {
1214 t.Errorf("divisible_int32_2to15(%d) = %v want %v", x, got, want)
1217 if want, got := int32(x)%int32(two26) == 0, divisible_int32_2to26(int32(x)); got != want {
1218 t.Errorf("divisible_int32_2to26(%d) = %v want %v", x, got, want)
1221 // spot check for int64
1222 if want, got := x%two4 == 0, divisible_int64_2to4(x); got != want {
1223 t.Errorf("divisible_int64_2to4(%d) = %v want %v", x, got, want)
1226 if want, got := x%two15 == 0, divisible_int64_2to15(x); got != want {
1227 t.Errorf("divisible_int64_2to15(%d) = %v want %v", x, got, want)
1230 if want, got := x%two26 == 0, divisible_int64_2to26(x); got != want {
1231 t.Errorf("divisible_int64_2to26(%d) = %v want %v", x, got, want)
1234 if want, got := x%two34 == 0, divisible_int64_2to34(x); got != want {
1235 t.Errorf("divisible_int64_2to34(%d) = %v want %v", x, got, want)
1238 if want, got := x%two48 == 0, divisible_int64_2to48(x); got != want {
1239 t.Errorf("divisible_int64_2to48(%d) = %v want %v", x, got, want)
1242 if want, got := x%two57 == 0, divisible_int64_2to57(x); got != want {
1243 t.Errorf("divisible_int64_2to57(%d) = %v want %v", x, got, want)
1248 func div6_uint8(n uint8) bool {
1253 func div6_uint16(n uint16) bool {
1258 func div6_uint32(n uint32) bool {
1263 func div6_uint64(n uint64) bool {
1268 func div19_uint8(n uint8) bool {
1273 func div19_uint16(n uint16) bool {
1278 func div19_uint32(n uint32) bool {
1283 func div19_uint64(n uint64) bool {
1288 func div6_int8(n int8) bool {
1293 func div6_int16(n int16) bool {
1298 func div6_int32(n int32) bool {
1303 func div6_int64(n int64) bool {
1308 func div19_int8(n int8) bool {
1313 func div19_int16(n int16) bool {
1318 func div19_int32(n int32) bool {
1323 func div19_int64(n int64) bool {
1327 // testDivisibility confirms that rewrite rules x%c ==0 for c constant are correct.
1328 func testDivisibility(t *testing.T) {
1330 // test an even and an odd divisor
1331 var sixU, nineteenU uint64 = 6, 19
1332 // test all inputs for uint8, uint16
1333 for i := uint64(0); i <= math.MaxUint16; i++ {
1334 if i <= math.MaxUint8 {
1335 if want, got := uint8(i)%uint8(sixU) == 0, div6_uint8(uint8(i)); got != want {
1336 t.Errorf("div6_uint8(%d) = %v want %v", i, got, want)
1338 if want, got := uint8(i)%uint8(nineteenU) == 0, div19_uint8(uint8(i)); got != want {
1339 t.Errorf("div6_uint19(%d) = %v want %v", i, got, want)
1342 if want, got := uint16(i)%uint16(sixU) == 0, div6_uint16(uint16(i)); got != want {
1343 t.Errorf("div6_uint16(%d) = %v want %v", i, got, want)
1345 if want, got := uint16(i)%uint16(nineteenU) == 0, div19_uint16(uint16(i)); got != want {
1346 t.Errorf("div19_uint16(%d) = %v want %v", i, got, want)
1349 var maxU32, maxU64 uint64 = math.MaxUint32, math.MaxUint64
1350 // spot check inputs for uint32 and uint64
1353 sixU, 2 * sixU, 3 * sixU, 5 * sixU, 12345 * sixU,
1354 sixU + 1, 2*sixU - 5, 3*sixU + 3, 5*sixU + 4, 12345*sixU - 2,
1355 nineteenU, 2 * nineteenU, 3 * nineteenU, 5 * nineteenU, 12345 * nineteenU,
1356 nineteenU + 1, 2*nineteenU - 5, 3*nineteenU + 3, 5*nineteenU + 4, 12345*nineteenU - 2,
1357 maxU32, maxU32 - 1, maxU32 - 2, maxU32 - 3, maxU32 - 4,
1358 maxU32 - 5, maxU32 - 6, maxU32 - 7, maxU32 - 8,
1359 maxU32 - 9, maxU32 - 10, maxU32 - 11, maxU32 - 12,
1360 maxU32 - 13, maxU32 - 14, maxU32 - 15, maxU32 - 16,
1361 maxU32 - 17, maxU32 - 18, maxU32 - 19, maxU32 - 20,
1362 maxU64, maxU64 - 1, maxU64 - 2, maxU64 - 3, maxU64 - 4,
1363 maxU64 - 5, maxU64 - 6, maxU64 - 7, maxU64 - 8,
1364 maxU64 - 9, maxU64 - 10, maxU64 - 11, maxU64 - 12,
1365 maxU64 - 13, maxU64 - 14, maxU64 - 15, maxU64 - 16,
1366 maxU64 - 17, maxU64 - 18, maxU64 - 19, maxU64 - 20,
1368 for _, x := range xu {
1370 if want, got := uint32(x)%uint32(sixU) == 0, div6_uint32(uint32(x)); got != want {
1371 t.Errorf("div6_uint32(%d) = %v want %v", x, got, want)
1373 if want, got := uint32(x)%uint32(nineteenU) == 0, div19_uint32(uint32(x)); got != want {
1374 t.Errorf("div19_uint32(%d) = %v want %v", x, got, want)
1377 if want, got := x%sixU == 0, div6_uint64(x); got != want {
1378 t.Errorf("div6_uint64(%d) = %v want %v", x, got, want)
1380 if want, got := x%nineteenU == 0, div19_uint64(x); got != want {
1381 t.Errorf("div19_uint64(%d) = %v want %v", x, got, want)
1386 // test an even and an odd divisor
1387 var sixS, nineteenS int64 = 6, 19
1388 // test all inputs for int8, int16
1389 for i := int64(math.MinInt16); i <= math.MaxInt16; i++ {
1390 if math.MinInt8 <= i && i <= math.MaxInt8 {
1391 if want, got := int8(i)%int8(sixS) == 0, div6_int8(int8(i)); got != want {
1392 t.Errorf("div6_int8(%d) = %v want %v", i, got, want)
1394 if want, got := int8(i)%int8(nineteenS) == 0, div19_int8(int8(i)); got != want {
1395 t.Errorf("div6_int19(%d) = %v want %v", i, got, want)
1398 if want, got := int16(i)%int16(sixS) == 0, div6_int16(int16(i)); got != want {
1399 t.Errorf("div6_int16(%d) = %v want %v", i, got, want)
1401 if want, got := int16(i)%int16(nineteenS) == 0, div19_int16(int16(i)); got != want {
1402 t.Errorf("div19_int16(%d) = %v want %v", i, got, want)
1405 var minI32, maxI32, minI64, maxI64 int64 = math.MinInt32, math.MaxInt32, math.MinInt64, math.MaxInt64
1406 // spot check inputs for int32 and int64
1410 sixS, 2 * sixS, 3 * sixS, 5 * sixS, 12345 * sixS,
1411 sixS + 1, 2*sixS - 5, 3*sixS + 3, 5*sixS + 4, 12345*sixS - 2,
1412 -sixS, -2 * sixS, -3 * sixS, -5 * sixS, -12345 * sixS,
1413 -sixS + 1, -2*sixS - 5, -3*sixS + 3, -5*sixS + 4, -12345*sixS - 2,
1414 nineteenS, 2 * nineteenS, 3 * nineteenS, 5 * nineteenS, 12345 * nineteenS,
1415 nineteenS + 1, 2*nineteenS - 5, 3*nineteenS + 3, 5*nineteenS + 4, 12345*nineteenS - 2,
1416 -nineteenS, -2 * nineteenS, -3 * nineteenS, -5 * nineteenS, -12345 * nineteenS,
1417 -nineteenS + 1, -2*nineteenS - 5, -3*nineteenS + 3, -5*nineteenS + 4, -12345*nineteenS - 2,
1418 minI32, minI32 + 1, minI32 + 2, minI32 + 3, minI32 + 4,
1419 minI32 + 5, minI32 + 6, minI32 + 7, minI32 + 8,
1420 minI32 + 9, minI32 + 10, minI32 + 11, minI32 + 12,
1421 minI32 + 13, minI32 + 14, minI32 + 15, minI32 + 16,
1422 minI32 + 17, minI32 + 18, minI32 + 19, minI32 + 20,
1423 maxI32, maxI32 - 1, maxI32 - 2, maxI32 - 3, maxI32 - 4,
1424 maxI32 - 5, maxI32 - 6, maxI32 - 7, maxI32 - 8,
1425 maxI32 - 9, maxI32 - 10, maxI32 - 11, maxI32 - 12,
1426 maxI32 - 13, maxI32 - 14, maxI32 - 15, maxI32 - 16,
1427 maxI32 - 17, maxI32 - 18, maxI32 - 19, maxI32 - 20,
1428 minI64, minI64 + 1, minI64 + 2, minI64 + 3, minI64 + 4,
1429 minI64 + 5, minI64 + 6, minI64 + 7, minI64 + 8,
1430 minI64 + 9, minI64 + 10, minI64 + 11, minI64 + 12,
1431 minI64 + 13, minI64 + 14, minI64 + 15, minI64 + 16,
1432 minI64 + 17, minI64 + 18, minI64 + 19, minI64 + 20,
1433 maxI64, maxI64 - 1, maxI64 - 2, maxI64 - 3, maxI64 - 4,
1434 maxI64 - 5, maxI64 - 6, maxI64 - 7, maxI64 - 8,
1435 maxI64 - 9, maxI64 - 10, maxI64 - 11, maxI64 - 12,
1436 maxI64 - 13, maxI64 - 14, maxI64 - 15, maxI64 - 16,
1437 maxI64 - 17, maxI64 - 18, maxI64 - 19, maxI64 - 20,
1439 for _, x := range xs {
1440 if minI32 <= x && x <= maxI32 {
1441 if want, got := int32(x)%int32(sixS) == 0, div6_int32(int32(x)); got != want {
1442 t.Errorf("div6_int32(%d) = %v want %v", x, got, want)
1444 if want, got := int32(x)%int32(nineteenS) == 0, div19_int32(int32(x)); got != want {
1445 t.Errorf("div19_int32(%d) = %v want %v", x, got, want)
1448 if want, got := x%sixS == 0, div6_int64(x); got != want {
1449 t.Errorf("div6_int64(%d) = %v want %v", x, got, want)
1451 if want, got := x%nineteenS == 0, div19_int64(x); got != want {
1452 t.Errorf("div19_int64(%d) = %v want %v", x, got, want)
1458 func genREV16_1(c uint64) uint64 {
1459 b := ((c & 0xff00ff00ff00ff00) >> 8) | ((c & 0x00ff00ff00ff00ff) << 8)
1464 func genREV16_2(c uint64) uint64 {
1465 b := ((c & 0xff00ff00) >> 8) | ((c & 0x00ff00ff) << 8)
1470 func genREV16W(c uint32) uint32 {
1471 b := ((c & 0xff00ff00) >> 8) | ((c & 0x00ff00ff) << 8)
1475 func TestREV16(t *testing.T) {
1476 x := uint64(0x8f7f6f5f4f3f2f1f)
1477 want1 := uint64(0x7f8f5f6f3f4f1f2f)
1478 want2 := uint64(0x3f4f1f2f)
1480 got1 := genREV16_1(x)
1482 t.Errorf("genREV16_1(%#x) = %#x want %#x", x, got1, want1)
1484 got2 := genREV16_2(x)
1486 t.Errorf("genREV16_2(%#x) = %#x want %#x", x, got2, want2)
1490 func TestREV16W(t *testing.T) {
1491 x := uint32(0x4f3f2f1f)
1492 want := uint32(0x3f4f1f2f)
1496 t.Errorf("genREV16W(%#x) = %#x want %#x", x, got, want)