How to use Nineteen method of source Package

Best Mock code snippet using source.Nineteen

arith_test.go

Source:arith_test.go Github

copy

Full Screen

1// Copyright 2015 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4// Tests arithmetic expressions5package main6import (7 "math"8 "runtime"9 "testing"10)11const (12 y = 0x0fffFFFF13)14var (15 g8 int816 g16 int1617 g32 int3218 g64 int6419)20//go:noinline21func lshNop1(x uint64) uint64 {22 // two outer shifts should be removed23 return (((x << 5) >> 2) << 2)24}25//go:noinline26func lshNop2(x uint64) uint64 {27 return (((x << 5) >> 2) << 3)28}29//go:noinline30func lshNop3(x uint64) uint64 {31 return (((x << 5) >> 2) << 6)32}33//go:noinline34func lshNotNop(x uint64) uint64 {35 // outer shift can't be removed36 return (((x << 5) >> 2) << 1)37}38//go:noinline39func rshNop1(x uint64) uint64 {40 return (((x >> 5) << 2) >> 2)41}42//go:noinline43func rshNop2(x uint64) uint64 {44 return (((x >> 5) << 2) >> 3)45}46//go:noinline47func rshNop3(x uint64) uint64 {48 return (((x >> 5) << 2) >> 6)49}50//go:noinline51func rshNotNop(x uint64) uint64 {52 return (((x >> 5) << 2) >> 1)53}54func testShiftRemoval(t *testing.T) {55 allSet := ^uint64(0)56 if want, got := uint64(0x7ffffffffffffff), rshNop1(allSet); want != got {57 t.Errorf("testShiftRemoval rshNop1 failed, wanted %d got %d", want, got)58 }59 if want, got := uint64(0x3ffffffffffffff), rshNop2(allSet); want != got {60 t.Errorf("testShiftRemoval rshNop2 failed, wanted %d got %d", want, got)61 }62 if want, got := uint64(0x7fffffffffffff), rshNop3(allSet); want != got {63 t.Errorf("testShiftRemoval rshNop3 failed, wanted %d got %d", want, got)64 }65 if want, got := uint64(0xffffffffffffffe), rshNotNop(allSet); want != got {66 t.Errorf("testShiftRemoval rshNotNop failed, wanted %d got %d", want, got)67 }68 if want, got := uint64(0xffffffffffffffe0), lshNop1(allSet); want != got {69 t.Errorf("testShiftRemoval lshNop1 failed, wanted %d got %d", want, got)70 }71 if want, got := uint64(0xffffffffffffffc0), lshNop2(allSet); want != got {72 t.Errorf("testShiftRemoval lshNop2 failed, wanted %d got %d", want, got)73 }74 if want, got := uint64(0xfffffffffffffe00), lshNop3(allSet); want != got {75 t.Errorf("testShiftRemoval lshNop3 failed, wanted %d got %d", want, got)76 }77 if want, got := uint64(0x7ffffffffffffff0), lshNotNop(allSet); want != got {78 t.Errorf("testShiftRemoval lshNotNop failed, wanted %d got %d", want, got)79 }80}81//go:noinline82func parseLE64(b []byte) uint64 {83 // skip the first two bytes, and parse the remaining 8 as a uint6484 return uint64(b[2]) | uint64(b[3])<<8 | uint64(b[4])<<16 | uint64(b[5])<<24 |85 uint64(b[6])<<32 | uint64(b[7])<<40 | uint64(b[8])<<48 | uint64(b[9])<<5686}87//go:noinline88func parseLE32(b []byte) uint32 {89 return uint32(b[2]) | uint32(b[3])<<8 | uint32(b[4])<<16 | uint32(b[5])<<2490}91//go:noinline92func parseLE16(b []byte) uint16 {93 return uint16(b[2]) | uint16(b[3])<<894}95// testLoadCombine tests for issue #14694 where load combining didn't respect the pointer offset.96func testLoadCombine(t *testing.T) {97 testData := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}98 if want, got := uint64(0x0908070605040302), parseLE64(testData); want != got {99 t.Errorf("testLoadCombine failed, wanted %d got %d", want, got)100 }101 if want, got := uint32(0x05040302), parseLE32(testData); want != got {102 t.Errorf("testLoadCombine failed, wanted %d got %d", want, got)103 }104 if want, got := uint16(0x0302), parseLE16(testData); want != got {105 t.Errorf("testLoadCombine failed, wanted %d got %d", want, got)106 }107}108var loadSymData = [...]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}109func testLoadSymCombine(t *testing.T) {110 w2 := uint16(0x0201)111 g2 := uint16(loadSymData[0]) | uint16(loadSymData[1])<<8112 if g2 != w2 {113 t.Errorf("testLoadSymCombine failed, wanted %d got %d", w2, g2)114 }115 w4 := uint32(0x04030201)116 g4 := uint32(loadSymData[0]) | uint32(loadSymData[1])<<8 |117 uint32(loadSymData[2])<<16 | uint32(loadSymData[3])<<24118 if g4 != w4 {119 t.Errorf("testLoadSymCombine failed, wanted %d got %d", w4, g4)120 }121 w8 := uint64(0x0807060504030201)122 g8 := uint64(loadSymData[0]) | uint64(loadSymData[1])<<8 |123 uint64(loadSymData[2])<<16 | uint64(loadSymData[3])<<24 |124 uint64(loadSymData[4])<<32 | uint64(loadSymData[5])<<40 |125 uint64(loadSymData[6])<<48 | uint64(loadSymData[7])<<56126 if g8 != w8 {127 t.Errorf("testLoadSymCombine failed, wanted %d got %d", w8, g8)128 }129}130//go:noinline131func invalidAdd_ssa(x uint32) uint32 {132 return x + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y133}134//go:noinline135func invalidSub_ssa(x uint32) uint32 {136 return x - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y137}138//go:noinline139func invalidMul_ssa(x uint32) uint32 {140 return x * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y141}142// testLargeConst tests a situation where larger than 32 bit consts were passed to ADDL143// causing an invalid instruction error.144func testLargeConst(t *testing.T) {145 if want, got := uint32(268435440), invalidAdd_ssa(1); want != got {146 t.Errorf("testLargeConst add failed, wanted %d got %d", want, got)147 }148 if want, got := uint32(4026531858), invalidSub_ssa(1); want != got {149 t.Errorf("testLargeConst sub failed, wanted %d got %d", want, got)150 }151 if want, got := uint32(268435455), invalidMul_ssa(1); want != got {152 t.Errorf("testLargeConst mul failed, wanted %d got %d", want, got)153 }154}155// testArithRshConst ensures that "const >> const" right shifts correctly perform156// sign extension on the lhs constant157func testArithRshConst(t *testing.T) {158 wantu := uint64(0x4000000000000000)159 if got := arithRshuConst_ssa(); got != wantu {160 t.Errorf("arithRshuConst failed, wanted %d got %d", wantu, got)161 }162 wants := int64(-0x4000000000000000)163 if got := arithRshConst_ssa(); got != wants {164 t.Errorf("arithRshConst failed, wanted %d got %d", wants, got)165 }166}167//go:noinline168func arithRshuConst_ssa() uint64 {169 y := uint64(0x8000000000000001)170 z := uint64(1)171 return uint64(y >> z)172}173//go:noinline174func arithRshConst_ssa() int64 {175 y := int64(-0x8000000000000000)176 z := uint64(1)177 return int64(y >> z)178}179//go:noinline180func arithConstShift_ssa(x int64) int64 {181 return x >> 100182}183// testArithConstShift tests that right shift by large constants preserve184// the sign of the input.185func testArithConstShift(t *testing.T) {186 want := int64(-1)187 if got := arithConstShift_ssa(-1); want != got {188 t.Errorf("arithConstShift_ssa(-1) failed, wanted %d got %d", want, got)189 }190 want = 0191 if got := arithConstShift_ssa(1); want != got {192 t.Errorf("arithConstShift_ssa(1) failed, wanted %d got %d", want, got)193 }194}195// overflowConstShift_ssa verifes that constant folding for shift196// doesn't wrap (i.e. x << MAX_INT << 1 doesn't get folded to x << 0).197//go:noinline198func overflowConstShift64_ssa(x int64) int64 {199 return x << uint64(0xffffffffffffffff) << uint64(1)200}201//go:noinline202func overflowConstShift32_ssa(x int64) int32 {203 return int32(x) << uint32(0xffffffff) << uint32(1)204}205//go:noinline206func overflowConstShift16_ssa(x int64) int16 {207 return int16(x) << uint16(0xffff) << uint16(1)208}209//go:noinline210func overflowConstShift8_ssa(x int64) int8 {211 return int8(x) << uint8(0xff) << uint8(1)212}213func testOverflowConstShift(t *testing.T) {214 want := int64(0)215 for x := int64(-127); x < int64(127); x++ {216 got := overflowConstShift64_ssa(x)217 if want != got {218 t.Errorf("overflowShift64 failed, wanted %d got %d", want, got)219 }220 got = int64(overflowConstShift32_ssa(x))221 if want != got {222 t.Errorf("overflowShift32 failed, wanted %d got %d", want, got)223 }224 got = int64(overflowConstShift16_ssa(x))225 if want != got {226 t.Errorf("overflowShift16 failed, wanted %d got %d", want, got)227 }228 got = int64(overflowConstShift8_ssa(x))229 if want != got {230 t.Errorf("overflowShift8 failed, wanted %d got %d", want, got)231 }232 }233}234// test64BitConstMult tests that rewrite rules don't fold 64 bit constants235// into multiply instructions.236func test64BitConstMult(t *testing.T) {237 want := int64(103079215109)238 if got := test64BitConstMult_ssa(1, 2); want != got {239 t.Errorf("test64BitConstMult failed, wanted %d got %d", want, got)240 }241}242//go:noinline243func test64BitConstMult_ssa(a, b int64) int64 {244 return 34359738369*a + b*34359738370245}246// test64BitConstAdd tests that rewrite rules don't fold 64 bit constants247// into add instructions.248func test64BitConstAdd(t *testing.T) {249 want := int64(3567671782835376650)250 if got := test64BitConstAdd_ssa(1, 2); want != got {251 t.Errorf("test64BitConstAdd failed, wanted %d got %d", want, got)252 }253}254//go:noinline255func test64BitConstAdd_ssa(a, b int64) int64 {256 return a + 575815584948629622 + b + 2991856197886747025257}258// testRegallocCVSpill tests that regalloc spills a value whose last use is the259// current value.260func testRegallocCVSpill(t *testing.T) {261 want := int8(-9)262 if got := testRegallocCVSpill_ssa(1, 2, 3, 4); want != got {263 t.Errorf("testRegallocCVSpill failed, wanted %d got %d", want, got)264 }265}266//go:noinline267func testRegallocCVSpill_ssa(a, b, c, d int8) int8 {268 return a + -32 + b + 63*c*-87*d269}270func testBitwiseLogic(t *testing.T) {271 a, b := uint32(57623283), uint32(1314713839)272 if want, got := uint32(38551779), testBitwiseAnd_ssa(a, b); want != got {273 t.Errorf("testBitwiseAnd failed, wanted %d got %d", want, got)274 }275 if want, got := uint32(1333785343), testBitwiseOr_ssa(a, b); want != got {276 t.Errorf("testBitwiseOr failed, wanted %d got %d", want, got)277 }278 if want, got := uint32(1295233564), testBitwiseXor_ssa(a, b); want != got {279 t.Errorf("testBitwiseXor failed, wanted %d got %d", want, got)280 }281 if want, got := int32(832), testBitwiseLsh_ssa(13, 4, 2); want != got {282 t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got)283 }284 if want, got := int32(0), testBitwiseLsh_ssa(13, 25, 15); want != got {285 t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got)286 }287 if want, got := int32(0), testBitwiseLsh_ssa(-13, 25, 15); want != got {288 t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got)289 }290 if want, got := int32(-13), testBitwiseRsh_ssa(-832, 4, 2); want != got {291 t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got)292 }293 if want, got := int32(0), testBitwiseRsh_ssa(13, 25, 15); want != got {294 t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got)295 }296 if want, got := int32(-1), testBitwiseRsh_ssa(-13, 25, 15); want != got {297 t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got)298 }299 if want, got := uint32(0x3ffffff), testBitwiseRshU_ssa(0xffffffff, 4, 2); want != got {300 t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got)301 }302 if want, got := uint32(0), testBitwiseRshU_ssa(13, 25, 15); want != got {303 t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got)304 }305 if want, got := uint32(0), testBitwiseRshU_ssa(0x8aaaaaaa, 25, 15); want != got {306 t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got)307 }308}309//go:noinline310func testBitwiseAnd_ssa(a, b uint32) uint32 {311 return a & b312}313//go:noinline314func testBitwiseOr_ssa(a, b uint32) uint32 {315 return a | b316}317//go:noinline318func testBitwiseXor_ssa(a, b uint32) uint32 {319 return a ^ b320}321//go:noinline322func testBitwiseLsh_ssa(a int32, b, c uint32) int32 {323 return a << b << c324}325//go:noinline326func testBitwiseRsh_ssa(a int32, b, c uint32) int32 {327 return a >> b >> c328}329//go:noinline330func testBitwiseRshU_ssa(a uint32, b, c uint32) uint32 {331 return a >> b >> c332}333//go:noinline334func testShiftCX_ssa() int {335 v1 := uint8(3)336 v4 := (v1 * v1) ^ v1 | v1 - v1 - v1&v1 ^ uint8(3+2) + v1*1>>0 - v1 | 1 | v1<<(2*3|0-0*0^1)337 v5 := v4>>(3-0-uint(3)) | v1 | v1 + v1 ^ v4<<(0+1|3&1)<<(uint64(1)<<0*2*0<<0) ^ v1338 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 ^ v1339 v7 := v6 & v5 << 0340 v1++341 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 // int342 v7--343 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))344}345func testShiftCX(t *testing.T) {346 want := 141347 if got := testShiftCX_ssa(); want != got {348 t.Errorf("testShiftCX failed, wanted %d got %d", want, got)349 }350}351// testSubqToNegq ensures that the SUBQ -> NEGQ translation works correctly.352func testSubqToNegq(t *testing.T) {353 want := int64(-318294940372190156)354 if got := testSubqToNegq_ssa(1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2); want != got {355 t.Errorf("testSubqToNegq failed, wanted %d got %d", want, got)356 }357}358//go:noinline359func testSubqToNegq_ssa(a, b, c, d, e, f, g, h, i, j, k int64) int64 {360 return a + 8207351403619448057 - b - 1779494519303207690 + c*8810076340510052032*d - 4465874067674546219 - e*4361839741470334295 - f + 8688847565426072650*g*8065564729145417479361}362func testOcom(t *testing.T) {363 want1, want2 := int32(0x55555555), int32(-0x55555556)364 if got1, got2 := testOcom_ssa(0x55555555, 0x55555555); want1 != got1 || want2 != got2 {365 t.Errorf("testOcom failed, wanted %d and %d got %d and %d", want1, want2, got1, got2)366 }367}368//go:noinline369func testOcom_ssa(a, b int32) (int32, int32) {370 return ^^^^a, ^^^^^b371}372func lrot1_ssa(w uint8, x uint16, y uint32, z uint64) (a uint8, b uint16, c uint32, d uint64) {373 a = (w << 5) | (w >> 3)374 b = (x << 13) | (x >> 3)375 c = (y << 29) | (y >> 3)376 d = (z << 61) | (z >> 3)377 return378}379//go:noinline380func lrot2_ssa(w, n uint32) uint32 {381 // Want to be sure that a "rotate by 32" which382 // is really 0 | (w >> 0) == w383 // is correctly compiled.384 return (w << n) | (w >> (32 - n))385}386//go:noinline387func lrot3_ssa(w uint32) uint32 {388 // Want to be sure that a "rotate by 32" which389 // is really 0 | (w >> 0) == w390 // is correctly compiled.391 return (w << 32) | (w >> (32 - 32))392}393func testLrot(t *testing.T) {394 wantA, wantB, wantC, wantD := uint8(0xe1), uint16(0xe001),395 uint32(0xe0000001), uint64(0xe000000000000001)396 a, b, c, d := lrot1_ssa(0xf, 0xf, 0xf, 0xf)397 if a != wantA || b != wantB || c != wantC || d != wantD {398 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)399 }400 x := lrot2_ssa(0xb0000001, 32)401 wantX := uint32(0xb0000001)402 if x != wantX {403 t.Errorf("lrot2_ssa(0xb0000001, 32)=%d, got %d", wantX, x)404 }405 x = lrot3_ssa(0xb0000001)406 if x != wantX {407 t.Errorf("lrot3_ssa(0xb0000001)=%d, got %d", wantX, x)408 }409}410//go:noinline411func sub1_ssa() uint64 {412 v1 := uint64(3) // uint64413 return v1*v1 - (v1&v1)&v1414}415//go:noinline416func sub2_ssa() uint8 {417 v1 := uint8(0)418 v3 := v1 + v1 + v1 ^ v1 | 3 + v1 ^ v1 | v1 ^ v1419 v1-- // dev.ssa doesn't see this one420 return v1 ^ v1*v1 - v3421}422func testSubConst(t *testing.T) {423 x1 := sub1_ssa()424 want1 := uint64(6)425 if x1 != want1 {426 t.Errorf("sub1_ssa()=%d, got %d", want1, x1)427 }428 x2 := sub2_ssa()429 want2 := uint8(251)430 if x2 != want2 {431 t.Errorf("sub2_ssa()=%d, got %d", want2, x2)432 }433}434//go:noinline435func orPhi_ssa(a bool, x int) int {436 v := 0437 if a {438 v = -1439 } else {440 v = -1441 }442 return x | v443}444func testOrPhi(t *testing.T) {445 if want, got := -1, orPhi_ssa(true, 4); got != want {446 t.Errorf("orPhi_ssa(true, 4)=%d, want %d", got, want)447 }448 if want, got := -1, orPhi_ssa(false, 0); got != want {449 t.Errorf("orPhi_ssa(false, 0)=%d, want %d", got, want)450 }451}452//go:noinline453func addshiftLL_ssa(a, b uint32) uint32 {454 return a + b<<3455}456//go:noinline457func subshiftLL_ssa(a, b uint32) uint32 {458 return a - b<<3459}460//go:noinline461func rsbshiftLL_ssa(a, b uint32) uint32 {462 return a<<3 - b463}464//go:noinline465func andshiftLL_ssa(a, b uint32) uint32 {466 return a & (b << 3)467}468//go:noinline469func orshiftLL_ssa(a, b uint32) uint32 {470 return a | b<<3471}472//go:noinline473func xorshiftLL_ssa(a, b uint32) uint32 {474 return a ^ b<<3475}476//go:noinline477func bicshiftLL_ssa(a, b uint32) uint32 {478 return a &^ (b << 3)479}480//go:noinline481func notshiftLL_ssa(a uint32) uint32 {482 return ^(a << 3)483}484//go:noinline485func addshiftRL_ssa(a, b uint32) uint32 {486 return a + b>>3487}488//go:noinline489func subshiftRL_ssa(a, b uint32) uint32 {490 return a - b>>3491}492//go:noinline493func rsbshiftRL_ssa(a, b uint32) uint32 {494 return a>>3 - b495}496//go:noinline497func andshiftRL_ssa(a, b uint32) uint32 {498 return a & (b >> 3)499}500//go:noinline501func orshiftRL_ssa(a, b uint32) uint32 {502 return a | b>>3503}504//go:noinline505func xorshiftRL_ssa(a, b uint32) uint32 {506 return a ^ b>>3507}508//go:noinline509func bicshiftRL_ssa(a, b uint32) uint32 {510 return a &^ (b >> 3)511}512//go:noinline513func notshiftRL_ssa(a uint32) uint32 {514 return ^(a >> 3)515}516//go:noinline517func addshiftRA_ssa(a, b int32) int32 {518 return a + b>>3519}520//go:noinline521func subshiftRA_ssa(a, b int32) int32 {522 return a - b>>3523}524//go:noinline525func rsbshiftRA_ssa(a, b int32) int32 {526 return a>>3 - b527}528//go:noinline529func andshiftRA_ssa(a, b int32) int32 {530 return a & (b >> 3)531}532//go:noinline533func orshiftRA_ssa(a, b int32) int32 {534 return a | b>>3535}536//go:noinline537func xorshiftRA_ssa(a, b int32) int32 {538 return a ^ b>>3539}540//go:noinline541func bicshiftRA_ssa(a, b int32) int32 {542 return a &^ (b >> 3)543}544//go:noinline545func notshiftRA_ssa(a int32) int32 {546 return ^(a >> 3)547}548//go:noinline549func addshiftLLreg_ssa(a, b uint32, s uint8) uint32 {550 return a + b<<s551}552//go:noinline553func subshiftLLreg_ssa(a, b uint32, s uint8) uint32 {554 return a - b<<s555}556//go:noinline557func rsbshiftLLreg_ssa(a, b uint32, s uint8) uint32 {558 return a<<s - b559}560//go:noinline561func andshiftLLreg_ssa(a, b uint32, s uint8) uint32 {562 return a & (b << s)563}564//go:noinline565func orshiftLLreg_ssa(a, b uint32, s uint8) uint32 {566 return a | b<<s567}568//go:noinline569func xorshiftLLreg_ssa(a, b uint32, s uint8) uint32 {570 return a ^ b<<s571}572//go:noinline573func bicshiftLLreg_ssa(a, b uint32, s uint8) uint32 {574 return a &^ (b << s)575}576//go:noinline577func notshiftLLreg_ssa(a uint32, s uint8) uint32 {578 return ^(a << s)579}580//go:noinline581func addshiftRLreg_ssa(a, b uint32, s uint8) uint32 {582 return a + b>>s583}584//go:noinline585func subshiftRLreg_ssa(a, b uint32, s uint8) uint32 {586 return a - b>>s587}588//go:noinline589func rsbshiftRLreg_ssa(a, b uint32, s uint8) uint32 {590 return a>>s - b591}592//go:noinline593func andshiftRLreg_ssa(a, b uint32, s uint8) uint32 {594 return a & (b >> s)595}596//go:noinline597func orshiftRLreg_ssa(a, b uint32, s uint8) uint32 {598 return a | b>>s599}600//go:noinline601func xorshiftRLreg_ssa(a, b uint32, s uint8) uint32 {602 return a ^ b>>s603}604//go:noinline605func bicshiftRLreg_ssa(a, b uint32, s uint8) uint32 {606 return a &^ (b >> s)607}608//go:noinline609func notshiftRLreg_ssa(a uint32, s uint8) uint32 {610 return ^(a >> s)611}612//go:noinline613func addshiftRAreg_ssa(a, b int32, s uint8) int32 {614 return a + b>>s615}616//go:noinline617func subshiftRAreg_ssa(a, b int32, s uint8) int32 {618 return a - b>>s619}620//go:noinline621func rsbshiftRAreg_ssa(a, b int32, s uint8) int32 {622 return a>>s - b623}624//go:noinline625func andshiftRAreg_ssa(a, b int32, s uint8) int32 {626 return a & (b >> s)627}628//go:noinline629func orshiftRAreg_ssa(a, b int32, s uint8) int32 {630 return a | b>>s631}632//go:noinline633func xorshiftRAreg_ssa(a, b int32, s uint8) int32 {634 return a ^ b>>s635}636//go:noinline637func bicshiftRAreg_ssa(a, b int32, s uint8) int32 {638 return a &^ (b >> s)639}640//go:noinline641func notshiftRAreg_ssa(a int32, s uint8) int32 {642 return ^(a >> s)643}644// test ARM shifted ops645func testShiftedOps(t *testing.T) {646 a, b := uint32(10), uint32(42)647 if want, got := a+b<<3, addshiftLL_ssa(a, b); got != want {648 t.Errorf("addshiftLL_ssa(10, 42) = %d want %d", got, want)649 }650 if want, got := a-b<<3, subshiftLL_ssa(a, b); got != want {651 t.Errorf("subshiftLL_ssa(10, 42) = %d want %d", got, want)652 }653 if want, got := a<<3-b, rsbshiftLL_ssa(a, b); got != want {654 t.Errorf("rsbshiftLL_ssa(10, 42) = %d want %d", got, want)655 }656 if want, got := a&(b<<3), andshiftLL_ssa(a, b); got != want {657 t.Errorf("andshiftLL_ssa(10, 42) = %d want %d", got, want)658 }659 if want, got := a|b<<3, orshiftLL_ssa(a, b); got != want {660 t.Errorf("orshiftLL_ssa(10, 42) = %d want %d", got, want)661 }662 if want, got := a^b<<3, xorshiftLL_ssa(a, b); got != want {663 t.Errorf("xorshiftLL_ssa(10, 42) = %d want %d", got, want)664 }665 if want, got := a&^(b<<3), bicshiftLL_ssa(a, b); got != want {666 t.Errorf("bicshiftLL_ssa(10, 42) = %d want %d", got, want)667 }668 if want, got := ^(a << 3), notshiftLL_ssa(a); got != want {669 t.Errorf("notshiftLL_ssa(10) = %d want %d", got, want)670 }671 if want, got := a+b>>3, addshiftRL_ssa(a, b); got != want {672 t.Errorf("addshiftRL_ssa(10, 42) = %d want %d", got, want)673 }674 if want, got := a-b>>3, subshiftRL_ssa(a, b); got != want {675 t.Errorf("subshiftRL_ssa(10, 42) = %d want %d", got, want)676 }677 if want, got := a>>3-b, rsbshiftRL_ssa(a, b); got != want {678 t.Errorf("rsbshiftRL_ssa(10, 42) = %d want %d", got, want)679 }680 if want, got := a&(b>>3), andshiftRL_ssa(a, b); got != want {681 t.Errorf("andshiftRL_ssa(10, 42) = %d want %d", got, want)682 }683 if want, got := a|b>>3, orshiftRL_ssa(a, b); got != want {684 t.Errorf("orshiftRL_ssa(10, 42) = %d want %d", got, want)685 }686 if want, got := a^b>>3, xorshiftRL_ssa(a, b); got != want {687 t.Errorf("xorshiftRL_ssa(10, 42) = %d want %d", got, want)688 }689 if want, got := a&^(b>>3), bicshiftRL_ssa(a, b); got != want {690 t.Errorf("bicshiftRL_ssa(10, 42) = %d want %d", got, want)691 }692 if want, got := ^(a >> 3), notshiftRL_ssa(a); got != want {693 t.Errorf("notshiftRL_ssa(10) = %d want %d", got, want)694 }695 c, d := int32(10), int32(-42)696 if want, got := c+d>>3, addshiftRA_ssa(c, d); got != want {697 t.Errorf("addshiftRA_ssa(10, -42) = %d want %d", got, want)698 }699 if want, got := c-d>>3, subshiftRA_ssa(c, d); got != want {700 t.Errorf("subshiftRA_ssa(10, -42) = %d want %d", got, want)701 }702 if want, got := c>>3-d, rsbshiftRA_ssa(c, d); got != want {703 t.Errorf("rsbshiftRA_ssa(10, -42) = %d want %d", got, want)704 }705 if want, got := c&(d>>3), andshiftRA_ssa(c, d); got != want {706 t.Errorf("andshiftRA_ssa(10, -42) = %d want %d", got, want)707 }708 if want, got := c|d>>3, orshiftRA_ssa(c, d); got != want {709 t.Errorf("orshiftRA_ssa(10, -42) = %d want %d", got, want)710 }711 if want, got := c^d>>3, xorshiftRA_ssa(c, d); got != want {712 t.Errorf("xorshiftRA_ssa(10, -42) = %d want %d", got, want)713 }714 if want, got := c&^(d>>3), bicshiftRA_ssa(c, d); got != want {715 t.Errorf("bicshiftRA_ssa(10, -42) = %d want %d", got, want)716 }717 if want, got := ^(d >> 3), notshiftRA_ssa(d); got != want {718 t.Errorf("notshiftRA_ssa(-42) = %d want %d", got, want)719 }720 s := uint8(3)721 if want, got := a+b<<s, addshiftLLreg_ssa(a, b, s); got != want {722 t.Errorf("addshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)723 }724 if want, got := a-b<<s, subshiftLLreg_ssa(a, b, s); got != want {725 t.Errorf("subshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)726 }727 if want, got := a<<s-b, rsbshiftLLreg_ssa(a, b, s); got != want {728 t.Errorf("rsbshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)729 }730 if want, got := a&(b<<s), andshiftLLreg_ssa(a, b, s); got != want {731 t.Errorf("andshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)732 }733 if want, got := a|b<<s, orshiftLLreg_ssa(a, b, s); got != want {734 t.Errorf("orshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)735 }736 if want, got := a^b<<s, xorshiftLLreg_ssa(a, b, s); got != want {737 t.Errorf("xorshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)738 }739 if want, got := a&^(b<<s), bicshiftLLreg_ssa(a, b, s); got != want {740 t.Errorf("bicshiftLLreg_ssa(10, 42, 3) = %d want %d", got, want)741 }742 if want, got := ^(a << s), notshiftLLreg_ssa(a, s); got != want {743 t.Errorf("notshiftLLreg_ssa(10) = %d want %d", got, want)744 }745 if want, got := a+b>>s, addshiftRLreg_ssa(a, b, s); got != want {746 t.Errorf("addshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)747 }748 if want, got := a-b>>s, subshiftRLreg_ssa(a, b, s); got != want {749 t.Errorf("subshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)750 }751 if want, got := a>>s-b, rsbshiftRLreg_ssa(a, b, s); got != want {752 t.Errorf("rsbshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)753 }754 if want, got := a&(b>>s), andshiftRLreg_ssa(a, b, s); got != want {755 t.Errorf("andshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)756 }757 if want, got := a|b>>s, orshiftRLreg_ssa(a, b, s); got != want {758 t.Errorf("orshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)759 }760 if want, got := a^b>>s, xorshiftRLreg_ssa(a, b, s); got != want {761 t.Errorf("xorshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)762 }763 if want, got := a&^(b>>s), bicshiftRLreg_ssa(a, b, s); got != want {764 t.Errorf("bicshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want)765 }766 if want, got := ^(a >> s), notshiftRLreg_ssa(a, s); got != want {767 t.Errorf("notshiftRLreg_ssa(10) = %d want %d", got, want)768 }769 if want, got := c+d>>s, addshiftRAreg_ssa(c, d, s); got != want {770 t.Errorf("addshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)771 }772 if want, got := c-d>>s, subshiftRAreg_ssa(c, d, s); got != want {773 t.Errorf("subshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)774 }775 if want, got := c>>s-d, rsbshiftRAreg_ssa(c, d, s); got != want {776 t.Errorf("rsbshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)777 }778 if want, got := c&(d>>s), andshiftRAreg_ssa(c, d, s); got != want {779 t.Errorf("andshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)780 }781 if want, got := c|d>>s, orshiftRAreg_ssa(c, d, s); got != want {782 t.Errorf("orshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)783 }784 if want, got := c^d>>s, xorshiftRAreg_ssa(c, d, s); got != want {785 t.Errorf("xorshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)786 }787 if want, got := c&^(d>>s), bicshiftRAreg_ssa(c, d, s); got != want {788 t.Errorf("bicshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want)789 }790 if want, got := ^(d >> s), notshiftRAreg_ssa(d, s); got != want {791 t.Errorf("notshiftRAreg_ssa(-42, 3) = %d want %d", got, want)792 }793}794// TestArithmetic tests that both backends have the same result for arithmetic expressions.795func TestArithmetic(t *testing.T) {796 test64BitConstMult(t)797 test64BitConstAdd(t)798 testRegallocCVSpill(t)799 testSubqToNegq(t)800 testBitwiseLogic(t)801 testOcom(t)802 testLrot(t)803 testShiftCX(t)804 testSubConst(t)805 testOverflowConstShift(t)806 testArithConstShift(t)807 testArithRshConst(t)808 testLargeConst(t)809 testLoadCombine(t)810 testLoadSymCombine(t)811 testShiftRemoval(t)812 testShiftedOps(t)813 testDivFixUp(t)814 testDivisibleSignedPow2(t)815 testDivisibility(t)816}817// testDivFixUp ensures that signed division fix-ups are being generated.818func testDivFixUp(t *testing.T) {819 defer func() {820 if r := recover(); r != nil {821 t.Error("testDivFixUp failed")822 if e, ok := r.(runtime.Error); ok {823 t.Logf("%v\n", e.Error())824 }825 }826 }()827 var w int8 = -128828 var x int16 = -32768829 var y int32 = -2147483648830 var z int64 = -9223372036854775808831 for i := -5; i < 0; i++ {832 g8 = w / int8(i)833 g16 = x / int16(i)834 g32 = y / int32(i)835 g64 = z / int64(i)836 g8 = w % int8(i)837 g16 = x % int16(i)838 g32 = y % int32(i)839 g64 = z % int64(i)840 }841}842//go:noinline843func divisible_int8_2to1(x int8) bool {844 return x%(1<<1) == 0845}846//go:noinline847func divisible_int8_2to2(x int8) bool {848 return x%(1<<2) == 0849}850//go:noinline851func divisible_int8_2to3(x int8) bool {852 return x%(1<<3) == 0853}854//go:noinline855func divisible_int8_2to4(x int8) bool {856 return x%(1<<4) == 0857}858//go:noinline859func divisible_int8_2to5(x int8) bool {860 return x%(1<<5) == 0861}862//go:noinline863func divisible_int8_2to6(x int8) bool {864 return x%(1<<6) == 0865}866//go:noinline867func divisible_int16_2to1(x int16) bool {868 return x%(1<<1) == 0869}870//go:noinline871func divisible_int16_2to2(x int16) bool {872 return x%(1<<2) == 0873}874//go:noinline875func divisible_int16_2to3(x int16) bool {876 return x%(1<<3) == 0877}878//go:noinline879func divisible_int16_2to4(x int16) bool {880 return x%(1<<4) == 0881}882//go:noinline883func divisible_int16_2to5(x int16) bool {884 return x%(1<<5) == 0885}886//go:noinline887func divisible_int16_2to6(x int16) bool {888 return x%(1<<6) == 0889}890//go:noinline891func divisible_int16_2to7(x int16) bool {892 return x%(1<<7) == 0893}894//go:noinline895func divisible_int16_2to8(x int16) bool {896 return x%(1<<8) == 0897}898//go:noinline899func divisible_int16_2to9(x int16) bool {900 return x%(1<<9) == 0901}902//go:noinline903func divisible_int16_2to10(x int16) bool {904 return x%(1<<10) == 0905}906//go:noinline907func divisible_int16_2to11(x int16) bool {908 return x%(1<<11) == 0909}910//go:noinline911func divisible_int16_2to12(x int16) bool {912 return x%(1<<12) == 0913}914//go:noinline915func divisible_int16_2to13(x int16) bool {916 return x%(1<<13) == 0917}918//go:noinline919func divisible_int16_2to14(x int16) bool {920 return x%(1<<14) == 0921}922//go:noinline923func divisible_int32_2to4(x int32) bool {924 return x%(1<<4) == 0925}926//go:noinline927func divisible_int32_2to15(x int32) bool {928 return x%(1<<15) == 0929}930//go:noinline931func divisible_int32_2to26(x int32) bool {932 return x%(1<<26) == 0933}934//go:noinline935func divisible_int64_2to4(x int64) bool {936 return x%(1<<4) == 0937}938//go:noinline939func divisible_int64_2to15(x int64) bool {940 return x%(1<<15) == 0941}942//go:noinline943func divisible_int64_2to26(x int64) bool {944 return x%(1<<26) == 0945}946//go:noinline947func divisible_int64_2to34(x int64) bool {948 return x%(1<<34) == 0949}950//go:noinline951func divisible_int64_2to48(x int64) bool {952 return x%(1<<48) == 0953}954//go:noinline955func divisible_int64_2to57(x int64) bool {956 return x%(1<<57) == 0957}958// testDivisibleSignedPow2 confirms that x%(1<<k)==0 is rewritten correctly959func testDivisibleSignedPow2(t *testing.T) {960 var i int64961 var pow2 = []int64{962 1,963 1 << 1,964 1 << 2,965 1 << 3,966 1 << 4,967 1 << 5,968 1 << 6,969 1 << 7,970 1 << 8,971 1 << 9,972 1 << 10,973 1 << 11,974 1 << 12,975 1 << 13,976 1 << 14,977 }978 // exhaustive test for int8979 for i = math.MinInt8; i <= math.MaxInt8; i++ {980 if want, got := int8(i)%int8(pow2[1]) == 0, divisible_int8_2to1(int8(i)); got != want {981 t.Errorf("divisible_int8_2to1(%d) = %v want %v", i, got, want)982 }983 if want, got := int8(i)%int8(pow2[2]) == 0, divisible_int8_2to2(int8(i)); got != want {984 t.Errorf("divisible_int8_2to2(%d) = %v want %v", i, got, want)985 }986 if want, got := int8(i)%int8(pow2[3]) == 0, divisible_int8_2to3(int8(i)); got != want {987 t.Errorf("divisible_int8_2to3(%d) = %v want %v", i, got, want)988 }989 if want, got := int8(i)%int8(pow2[4]) == 0, divisible_int8_2to4(int8(i)); got != want {990 t.Errorf("divisible_int8_2to4(%d) = %v want %v", i, got, want)991 }992 if want, got := int8(i)%int8(pow2[5]) == 0, divisible_int8_2to5(int8(i)); got != want {993 t.Errorf("divisible_int8_2to5(%d) = %v want %v", i, got, want)994 }995 if want, got := int8(i)%int8(pow2[6]) == 0, divisible_int8_2to6(int8(i)); got != want {996 t.Errorf("divisible_int8_2to6(%d) = %v want %v", i, got, want)997 }998 }999 // exhaustive test for int161000 for i = math.MinInt16; i <= math.MaxInt16; i++ {1001 if want, got := int16(i)%int16(pow2[1]) == 0, divisible_int16_2to1(int16(i)); got != want {1002 t.Errorf("divisible_int16_2to1(%d) = %v want %v", i, got, want)1003 }1004 if want, got := int16(i)%int16(pow2[2]) == 0, divisible_int16_2to2(int16(i)); got != want {1005 t.Errorf("divisible_int16_2to2(%d) = %v want %v", i, got, want)1006 }1007 if want, got := int16(i)%int16(pow2[3]) == 0, divisible_int16_2to3(int16(i)); got != want {1008 t.Errorf("divisible_int16_2to3(%d) = %v want %v", i, got, want)1009 }1010 if want, got := int16(i)%int16(pow2[4]) == 0, divisible_int16_2to4(int16(i)); got != want {1011 t.Errorf("divisible_int16_2to4(%d) = %v want %v", i, got, want)1012 }1013 if want, got := int16(i)%int16(pow2[5]) == 0, divisible_int16_2to5(int16(i)); got != want {1014 t.Errorf("divisible_int16_2to5(%d) = %v want %v", i, got, want)1015 }1016 if want, got := int16(i)%int16(pow2[6]) == 0, divisible_int16_2to6(int16(i)); got != want {1017 t.Errorf("divisible_int16_2to6(%d) = %v want %v", i, got, want)1018 }1019 if want, got := int16(i)%int16(pow2[7]) == 0, divisible_int16_2to7(int16(i)); got != want {1020 t.Errorf("divisible_int16_2to7(%d) = %v want %v", i, got, want)1021 }1022 if want, got := int16(i)%int16(pow2[8]) == 0, divisible_int16_2to8(int16(i)); got != want {1023 t.Errorf("divisible_int16_2to8(%d) = %v want %v", i, got, want)1024 }1025 if want, got := int16(i)%int16(pow2[9]) == 0, divisible_int16_2to9(int16(i)); got != want {1026 t.Errorf("divisible_int16_2to9(%d) = %v want %v", i, got, want)1027 }1028 if want, got := int16(i)%int16(pow2[10]) == 0, divisible_int16_2to10(int16(i)); got != want {1029 t.Errorf("divisible_int16_2to10(%d) = %v want %v", i, got, want)1030 }1031 if want, got := int16(i)%int16(pow2[11]) == 0, divisible_int16_2to11(int16(i)); got != want {1032 t.Errorf("divisible_int16_2to11(%d) = %v want %v", i, got, want)1033 }1034 if want, got := int16(i)%int16(pow2[12]) == 0, divisible_int16_2to12(int16(i)); got != want {1035 t.Errorf("divisible_int16_2to12(%d) = %v want %v", i, got, want)1036 }1037 if want, got := int16(i)%int16(pow2[13]) == 0, divisible_int16_2to13(int16(i)); got != want {1038 t.Errorf("divisible_int16_2to13(%d) = %v want %v", i, got, want)1039 }1040 if want, got := int16(i)%int16(pow2[14]) == 0, divisible_int16_2to14(int16(i)); got != want {1041 t.Errorf("divisible_int16_2to14(%d) = %v want %v", i, got, want)1042 }1043 }1044 // spot check for int32 and int641045 var (1046 two4 int64 = 1 << 41047 two15 int64 = 1 << 151048 two26 int64 = 1 << 261049 two34 int64 = 1 << 341050 two48 int64 = 1 << 481051 two57 int64 = 1 << 571052 )1053 var xs = []int64{two4, two4 + 3, -3 * two4, -3*two4 + 1,1054 two15, two15 + 3, -3 * two15, -3*two15 + 1,1055 two26, two26 + 37, -5 * two26, -5*two26 + 2,1056 two34, two34 + 356, -7 * two34, -7*two34 + 13,1057 two48, two48 + 3000, -12 * two48, -12*two48 + 1111,1058 two57, two57 + 397654, -15 * two57, -15*two57 + 11234,1059 }1060 for _, x := range xs {1061 if int64(int32(x)) == x {1062 if want, got := int32(x)%int32(two4) == 0, divisible_int32_2to4(int32(x)); got != want {1063 t.Errorf("divisible_int32_2to4(%d) = %v want %v", x, got, want)1064 }1065 if want, got := int32(x)%int32(two15) == 0, divisible_int32_2to15(int32(x)); got != want {1066 t.Errorf("divisible_int32_2to15(%d) = %v want %v", x, got, want)1067 }1068 if want, got := int32(x)%int32(two26) == 0, divisible_int32_2to26(int32(x)); got != want {1069 t.Errorf("divisible_int32_2to26(%d) = %v want %v", x, got, want)1070 }1071 }1072 // spot check for int641073 if want, got := x%two4 == 0, divisible_int64_2to4(x); got != want {1074 t.Errorf("divisible_int64_2to4(%d) = %v want %v", x, got, want)1075 }1076 if want, got := x%two15 == 0, divisible_int64_2to15(x); got != want {1077 t.Errorf("divisible_int64_2to15(%d) = %v want %v", x, got, want)1078 }1079 if want, got := x%two26 == 0, divisible_int64_2to26(x); got != want {1080 t.Errorf("divisible_int64_2to26(%d) = %v want %v", x, got, want)1081 }1082 if want, got := x%two34 == 0, divisible_int64_2to34(x); got != want {1083 t.Errorf("divisible_int64_2to34(%d) = %v want %v", x, got, want)1084 }1085 if want, got := x%two48 == 0, divisible_int64_2to48(x); got != want {1086 t.Errorf("divisible_int64_2to48(%d) = %v want %v", x, got, want)1087 }1088 if want, got := x%two57 == 0, divisible_int64_2to57(x); got != want {1089 t.Errorf("divisible_int64_2to57(%d) = %v want %v", x, got, want)1090 }1091 }1092}1093func div6_uint8(n uint8) bool {1094 return n%6 == 01095}1096//go:noinline1097func div6_uint16(n uint16) bool {1098 return n%6 == 01099}1100//go:noinline1101func div6_uint32(n uint32) bool {1102 return n%6 == 01103}1104//go:noinline1105func div6_uint64(n uint64) bool {1106 return n%6 == 01107}1108//go:noinline1109func div19_uint8(n uint8) bool {1110 return n%19 == 01111}1112//go:noinline1113func div19_uint16(n uint16) bool {1114 return n%19 == 01115}1116//go:noinline1117func div19_uint32(n uint32) bool {1118 return n%19 == 01119}1120//go:noinline1121func div19_uint64(n uint64) bool {1122 return n%19 == 01123}1124//go:noinline1125func div6_int8(n int8) bool {1126 return n%6 == 01127}1128//go:noinline1129func div6_int16(n int16) bool {1130 return n%6 == 01131}1132//go:noinline1133func div6_int32(n int32) bool {1134 return n%6 == 01135}1136//go:noinline1137func div6_int64(n int64) bool {1138 return n%6 == 01139}1140//go:noinline1141func div19_int8(n int8) bool {1142 return n%19 == 01143}1144//go:noinline1145func div19_int16(n int16) bool {1146 return n%19 == 01147}1148//go:noinline1149func div19_int32(n int32) bool {1150 return n%19 == 01151}1152//go:noinline1153func div19_int64(n int64) bool {1154 return n%19 == 01155}1156// testDivisibility confirms that rewrite rules x%c ==0 for c constant are correct.1157func testDivisibility(t *testing.T) {1158 // unsigned tests1159 // test an even and an odd divisor1160 var sixU, nineteenU uint64 = 6, 191161 // test all inputs for uint8, uint161162 for i := uint64(0); i <= math.MaxUint16; i++ {1163 if i <= math.MaxUint8 {1164 if want, got := uint8(i)%uint8(sixU) == 0, div6_uint8(uint8(i)); got != want {1165 t.Errorf("div6_uint8(%d) = %v want %v", i, got, want)1166 }1167 if want, got := uint8(i)%uint8(nineteenU) == 0, div19_uint8(uint8(i)); got != want {1168 t.Errorf("div6_uint19(%d) = %v want %v", i, got, want)1169 }1170 }1171 if want, got := uint16(i)%uint16(sixU) == 0, div6_uint16(uint16(i)); got != want {1172 t.Errorf("div6_uint16(%d) = %v want %v", i, got, want)1173 }1174 if want, got := uint16(i)%uint16(nineteenU) == 0, div19_uint16(uint16(i)); got != want {1175 t.Errorf("div19_uint16(%d) = %v want %v", i, got, want)1176 }1177 }1178 var maxU32, maxU64 uint64 = math.MaxUint32, math.MaxUint641179 // spot check inputs for uint32 and uint641180 xu := []uint64{1181 0, 1, 2, 3, 4, 5,1182 sixU, 2 * sixU, 3 * sixU, 5 * sixU, 12345 * sixU,1183 sixU + 1, 2*sixU - 5, 3*sixU + 3, 5*sixU + 4, 12345*sixU - 2,1184 nineteenU, 2 * nineteenU, 3 * nineteenU, 5 * nineteenU, 12345 * nineteenU,1185 nineteenU + 1, 2*nineteenU - 5, 3*nineteenU + 3, 5*nineteenU + 4, 12345*nineteenU - 2,1186 maxU32, maxU32 - 1, maxU32 - 2, maxU32 - 3, maxU32 - 4,1187 maxU32 - 5, maxU32 - 6, maxU32 - 7, maxU32 - 8,1188 maxU32 - 9, maxU32 - 10, maxU32 - 11, maxU32 - 12,1189 maxU32 - 13, maxU32 - 14, maxU32 - 15, maxU32 - 16,1190 maxU32 - 17, maxU32 - 18, maxU32 - 19, maxU32 - 20,1191 maxU64, maxU64 - 1, maxU64 - 2, maxU64 - 3, maxU64 - 4,1192 maxU64 - 5, maxU64 - 6, maxU64 - 7, maxU64 - 8,1193 maxU64 - 9, maxU64 - 10, maxU64 - 11, maxU64 - 12,1194 maxU64 - 13, maxU64 - 14, maxU64 - 15, maxU64 - 16,1195 maxU64 - 17, maxU64 - 18, maxU64 - 19, maxU64 - 20,1196 }1197 for _, x := range xu {1198 if x <= maxU32 {1199 if want, got := uint32(x)%uint32(sixU) == 0, div6_uint32(uint32(x)); got != want {1200 t.Errorf("div6_uint32(%d) = %v want %v", x, got, want)1201 }1202 if want, got := uint32(x)%uint32(nineteenU) == 0, div19_uint32(uint32(x)); got != want {1203 t.Errorf("div19_uint32(%d) = %v want %v", x, got, want)1204 }1205 }1206 if want, got := x%sixU == 0, div6_uint64(x); got != want {1207 t.Errorf("div6_uint64(%d) = %v want %v", x, got, want)1208 }1209 if want, got := x%nineteenU == 0, div19_uint64(x); got != want {1210 t.Errorf("div19_uint64(%d) = %v want %v", x, got, want)1211 }1212 }1213 // signed tests1214 // test an even and an odd divisor1215 var sixS, nineteenS int64 = 6, 191216 // test all inputs for int8, int161217 for i := int64(math.MinInt16); i <= math.MaxInt16; i++ {1218 if math.MinInt8 <= i && i <= math.MaxInt8 {1219 if want, got := int8(i)%int8(sixS) == 0, div6_int8(int8(i)); got != want {1220 t.Errorf("div6_int8(%d) = %v want %v", i, got, want)1221 }1222 if want, got := int8(i)%int8(nineteenS) == 0, div19_int8(int8(i)); got != want {1223 t.Errorf("div6_int19(%d) = %v want %v", i, got, want)1224 }1225 }1226 if want, got := int16(i)%int16(sixS) == 0, div6_int16(int16(i)); got != want {1227 t.Errorf("div6_int16(%d) = %v want %v", i, got, want)1228 }1229 if want, got := int16(i)%int16(nineteenS) == 0, div19_int16(int16(i)); got != want {1230 t.Errorf("div19_int16(%d) = %v want %v", i, got, want)1231 }1232 }1233 var minI32, maxI32, minI64, maxI64 int64 = math.MinInt32, math.MaxInt32, math.MinInt64, math.MaxInt641234 // spot check inputs for int32 and int641235 xs := []int64{1236 0, 1, 2, 3, 4, 5,1237 -1, -2, -3, -4, -5,1238 sixS, 2 * sixS, 3 * sixS, 5 * sixS, 12345 * sixS,1239 sixS + 1, 2*sixS - 5, 3*sixS + 3, 5*sixS + 4, 12345*sixS - 2,1240 -sixS, -2 * sixS, -3 * sixS, -5 * sixS, -12345 * sixS,1241 -sixS + 1, -2*sixS - 5, -3*sixS + 3, -5*sixS + 4, -12345*sixS - 2,1242 nineteenS, 2 * nineteenS, 3 * nineteenS, 5 * nineteenS, 12345 * nineteenS,1243 nineteenS + 1, 2*nineteenS - 5, 3*nineteenS + 3, 5*nineteenS + 4, 12345*nineteenS - 2,1244 -nineteenS, -2 * nineteenS, -3 * nineteenS, -5 * nineteenS, -12345 * nineteenS,1245 -nineteenS + 1, -2*nineteenS - 5, -3*nineteenS + 3, -5*nineteenS + 4, -12345*nineteenS - 2,1246 minI32, minI32 + 1, minI32 + 2, minI32 + 3, minI32 + 4,1247 minI32 + 5, minI32 + 6, minI32 + 7, minI32 + 8,1248 minI32 + 9, minI32 + 10, minI32 + 11, minI32 + 12,1249 minI32 + 13, minI32 + 14, minI32 + 15, minI32 + 16,1250 minI32 + 17, minI32 + 18, minI32 + 19, minI32 + 20,1251 maxI32, maxI32 - 1, maxI32 - 2, maxI32 - 3, maxI32 - 4,1252 maxI32 - 5, maxI32 - 6, maxI32 - 7, maxI32 - 8,1253 maxI32 - 9, maxI32 - 10, maxI32 - 11, maxI32 - 12,1254 maxI32 - 13, maxI32 - 14, maxI32 - 15, maxI32 - 16,1255 maxI32 - 17, maxI32 - 18, maxI32 - 19, maxI32 - 20,1256 minI64, minI64 + 1, minI64 + 2, minI64 + 3, minI64 + 4,1257 minI64 + 5, minI64 + 6, minI64 + 7, minI64 + 8,1258 minI64 + 9, minI64 + 10, minI64 + 11, minI64 + 12,1259 minI64 + 13, minI64 + 14, minI64 + 15, minI64 + 16,1260 minI64 + 17, minI64 + 18, minI64 + 19, minI64 + 20,1261 maxI64, maxI64 - 1, maxI64 - 2, maxI64 - 3, maxI64 - 4,1262 maxI64 - 5, maxI64 - 6, maxI64 - 7, maxI64 - 8,1263 maxI64 - 9, maxI64 - 10, maxI64 - 11, maxI64 - 12,1264 maxI64 - 13, maxI64 - 14, maxI64 - 15, maxI64 - 16,1265 maxI64 - 17, maxI64 - 18, maxI64 - 19, maxI64 - 20,1266 }1267 for _, x := range xs {1268 if minI32 <= x && x <= maxI32 {1269 if want, got := int32(x)%int32(sixS) == 0, div6_int32(int32(x)); got != want {1270 t.Errorf("div6_int32(%d) = %v want %v", x, got, want)1271 }1272 if want, got := int32(x)%int32(nineteenS) == 0, div19_int32(int32(x)); got != want {1273 t.Errorf("div19_int32(%d) = %v want %v", x, got, want)1274 }1275 }1276 if want, got := x%sixS == 0, div6_int64(x); got != want {1277 t.Errorf("div6_int64(%d) = %v want %v", x, got, want)1278 }1279 if want, got := x%nineteenS == 0, div19_int64(x); got != want {1280 t.Errorf("div19_int64(%d) = %v want %v", x, got, want)1281 }1282 }1283}...

Full Screen

Full Screen

Nineteen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(source.Nineteen())4}5import (6func main() {7 fmt.Println(source.Nineteen())8}9func Nineteen() int {10}11import "testing"12func TestNineteen(t *testing.T) {13 if Nineteen() != 19 {14 t.Errorf("Nineteen() should be 19")15 }16}17--- PASS: TestNineteen (0.00s)18func Nineteen() int {19}20import "testing"21func TestNineteen(t *testing.T) {22 if Nineteen() != 19 {23 t.Errorf("Nineteen() should be 19")24 }25}26--- PASS: TestNineteen (0.00s)27In this method, we will create a separate test package and import the testing package

Full Screen

Full Screen

Nineteen

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, world")4}5import "fmt"6import "github.com/abc/xyz"7func main() {8 fmt.Println("Hello, world")9}10import "fmt"11import "github.com/abc/xyz"12func main() {13 fmt.Println("Hello, world")14}15import "fmt"16import "github.com/abc/xyz"17func main() {18 fmt.Println("Hello, world")19}20import "fmt"21import "github.com/abc/xyz"22func main() {23 fmt.Println("Hello, world")24}25import "fmt"26import "github.com/abc/xyz"27func main() {28 fmt.Println("Hello, world")29}30import "fmt"31import "github.com/abc/xyz"32func main() {33 fmt.Println("Hello, world")34}35import "fmt"36import "github.com/abc/xyz"37func main() {38 fmt.Println("Hello, world")39}40import "fmt"41import "github.com/abc/xyz"42func main() {43 fmt.Println("Hello, world")44}45import "fmt"46import "github.com/abc/xyz"47func main() {48 fmt.Println("Hello, world")49}50import "fmt"51import "github.com/abc/xyz"52func main() {53 fmt.Println("Hello, world

Full Screen

Full Screen

Nineteen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(x.Nineteen())4}5import (6func main() {7 fmt.Println(x.Nineteen())8}9import (10func main() {11 fmt.Println(x.Nineteen())12}13import (14func main() {15 fmt.Println(x.Nineteen())16}17import (18func main() {19 fmt.Println(x.Nineteen())20}21import (22func main() {23 fmt.Println(x.Nineteen())24}25import (26func main() {27 fmt.Println(x.Nineteen())28}29import (30func main() {31 fmt.Println(x.Nineteen())32}33import (34func main() {35 fmt.Println(x.Nineteen())36}37import (38func main() {

Full Screen

Full Screen

Nineteen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 source := new(source.Source)5 source.Nineteen()6}

Full Screen

Full Screen

Nineteen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 source.Nineteen()5}6import (7func main() {8 fmt.Println("Hello, playground")9 source.Nineteen()10}11import (12func main() {13 fmt.Println("Hello, playground")14 source.Nineteen()15}16import (17func main() {18 fmt.Println("Hello, playground")19 Source.Nineteen()20}21import (22func main() {23 fmt.Println("Hello, playground")24 Source.Nineteen()25}26import (27func main() {28 fmt.Println("Hello, playground")29 Source.Nineteen()30}31 /usr/local/go/src/Source (from $GOROOT)32 /home/username/go/src/Source (from $GOPATH)

Full Screen

Full Screen

Nineteen

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello Nineteen")4 fmt.Println("Nineteen :", source.Nineteen())5}6func Nineteen() int {7}8import (9func main() {10 fmt.Println("Hello Nineteen")11 fmt.Println("Nineteen :", source.Nineteen())12}13func Nineteen() int {14}15import (16func main() {17 fmt.Println("Hello Nineteen")18 fmt.Println("Nineteen :", source.Nineteen())19}20func Nineteen() int {21}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful