How to use True method of got Package

Best Got code snippet using got.True

arith.go

Source:arith.go Github

copy

Full Screen

1// run2// Copyright 2015 The Go Authors. All rights reserved.3// Use of this source code is governed by a BSD-style4// license that can be found in the LICENSE file.5// Tests arithmetic expressions6package main7import "fmt"8const (9 y = 0x0fffFFFF10)11//go:noinline12func lshNop1(x uint64) uint64 {13 // two outer shifts should be removed14 return (((x << 5) >> 2) << 2)15}16//go:noinline17func lshNop2(x uint64) uint64 {18 return (((x << 5) >> 2) << 3)19}20//go:noinline21func lshNop3(x uint64) uint64 {22 return (((x << 5) >> 2) << 6)23}24//go:noinline25func lshNotNop(x uint64) uint64 {26 // outer shift can't be removed27 return (((x << 5) >> 2) << 1)28}29//go:noinline30func rshNop1(x uint64) uint64 {31 return (((x >> 5) << 2) >> 2)32}33//go:noinline34func rshNop2(x uint64) uint64 {35 return (((x >> 5) << 2) >> 3)36}37//go:noinline38func rshNop3(x uint64) uint64 {39 return (((x >> 5) << 2) >> 6)40}41//go:noinline42func rshNotNop(x uint64) uint64 {43 return (((x >> 5) << 2) >> 1)44}45func testShiftRemoval() {46 allSet := ^uint64(0)47 if want, got := uint64(0x7ffffffffffffff), rshNop1(allSet); want != got {48 println("testShiftRemoval rshNop1 failed, wanted", want, "got", got)49 failed = true50 }51 if want, got := uint64(0x3ffffffffffffff), rshNop2(allSet); want != got {52 println("testShiftRemoval rshNop2 failed, wanted", want, "got", got)53 failed = true54 }55 if want, got := uint64(0x7fffffffffffff), rshNop3(allSet); want != got {56 println("testShiftRemoval rshNop3 failed, wanted", want, "got", got)57 failed = true58 }59 if want, got := uint64(0xffffffffffffffe), rshNotNop(allSet); want != got {60 println("testShiftRemoval rshNotNop failed, wanted", want, "got", got)61 failed = true62 }63 if want, got := uint64(0xffffffffffffffe0), lshNop1(allSet); want != got {64 println("testShiftRemoval lshNop1 failed, wanted", want, "got", got)65 failed = true66 }67 if want, got := uint64(0xffffffffffffffc0), lshNop2(allSet); want != got {68 println("testShiftRemoval lshNop2 failed, wanted", want, "got", got)69 failed = true70 }71 if want, got := uint64(0xfffffffffffffe00), lshNop3(allSet); want != got {72 println("testShiftRemoval lshNop3 failed, wanted", want, "got", got)73 failed = true74 }75 if want, got := uint64(0x7ffffffffffffff0), lshNotNop(allSet); want != got {76 println("testShiftRemoval lshNotNop failed, wanted", want, "got", got)77 failed = true78 }79}80//go:noinline81func parseLE64(b []byte) uint64 {82 // skip the first two bytes, and parse the remaining 8 as a uint6483 return uint64(b[2]) | uint64(b[3])<<8 | uint64(b[4])<<16 | uint64(b[5])<<24 |84 uint64(b[6])<<32 | uint64(b[7])<<40 | uint64(b[8])<<48 | uint64(b[9])<<5685}86//go:noinline87func parseLE32(b []byte) uint32 {88 return uint32(b[2]) | uint32(b[3])<<8 | uint32(b[4])<<16 | uint32(b[5])<<2489}90//go:noinline91func parseLE16(b []byte) uint16 {92 return uint16(b[2]) | uint16(b[3])<<893}94// testLoadCombine tests for issue #14694 where load combining didn't respect the pointer offset.95func testLoadCombine() {96 testData := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}97 if want, got := uint64(0x0908070605040302), parseLE64(testData); want != got {98 println("testLoadCombine failed, wanted", want, "got", got)99 failed = true100 }101 if want, got := uint32(0x05040302), parseLE32(testData); want != got {102 println("testLoadCombine failed, wanted", want, "got", got)103 failed = true104 }105 if want, got := uint16(0x0302), parseLE16(testData); want != got {106 println("testLoadCombine failed, wanted", want, "got", got)107 failed = true108 }109}110var loadSymData = [...]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}111func testLoadSymCombine() {112 w2 := uint16(0x0201)113 g2 := uint16(loadSymData[0]) | uint16(loadSymData[1])<<8114 if g2 != w2 {115 println("testLoadSymCombine failed, wanted", w2, "got", g2)116 failed = true117 }118 w4 := uint32(0x04030201)119 g4 := uint32(loadSymData[0]) | uint32(loadSymData[1])<<8 |120 uint32(loadSymData[2])<<16 | uint32(loadSymData[3])<<24121 if g4 != w4 {122 println("testLoadSymCombine failed, wanted", w4, "got", g4)123 failed = true124 }125 w8 := uint64(0x0807060504030201)126 g8 := uint64(loadSymData[0]) | uint64(loadSymData[1])<<8 |127 uint64(loadSymData[2])<<16 | uint64(loadSymData[3])<<24 |128 uint64(loadSymData[4])<<32 | uint64(loadSymData[5])<<40 |129 uint64(loadSymData[6])<<48 | uint64(loadSymData[7])<<56130 if g8 != w8 {131 println("testLoadSymCombine failed, wanted", w8, "got", g8)132 failed = true133 }134}135//go:noinline136func invalidAdd_ssa(x uint32) uint32 {137 return x + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y + y138}139//go:noinline140func invalidSub_ssa(x uint32) uint32 {141 return x - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y - y142}143//go:noinline144func invalidMul_ssa(x uint32) uint32 {145 return x * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y146}147// testLargeConst tests a situation where larger than 32 bit consts were passed to ADDL148// causing an invalid instruction error.149func testLargeConst() {150 if want, got := uint32(268435440), invalidAdd_ssa(1); want != got {151 println("testLargeConst add failed, wanted", want, "got", got)152 failed = true153 }154 if want, got := uint32(4026531858), invalidSub_ssa(1); want != got {155 println("testLargeConst sub failed, wanted", want, "got", got)156 failed = true157 }158 if want, got := uint32(268435455), invalidMul_ssa(1); want != got {159 println("testLargeConst mul failed, wanted", want, "got", got)160 failed = true161 }162}163// testArithRshConst ensures that "const >> const" right shifts correctly perform164// sign extension on the lhs constant165func testArithRshConst() {166 wantu := uint64(0x4000000000000000)167 if got := arithRshuConst_ssa(); got != wantu {168 println("arithRshuConst failed, wanted", wantu, "got", got)169 failed = true170 }171 wants := int64(-0x4000000000000000)172 if got := arithRshConst_ssa(); got != wants {173 println("arithRshuConst failed, wanted", wants, "got", got)174 failed = true175 }176}177//go:noinline178func arithRshuConst_ssa() uint64 {179 y := uint64(0x8000000000000001)180 z := uint64(1)181 return uint64(y >> z)182}183//go:noinline184func arithRshConst_ssa() int64 {185 y := int64(-0x8000000000000000)186 z := uint64(1)187 return int64(y >> z)188}189//go:noinline190func arithConstShift_ssa(x int64) int64 {191 return x >> 100192}193// testArithConstShift tests that right shift by large constants preserve194// the sign of the input.195func testArithConstShift() {196 want := int64(-1)197 if got := arithConstShift_ssa(-1); want != got {198 println("arithConstShift_ssa(-1) failed, wanted", want, "got", got)199 failed = true200 }201 want = 0202 if got := arithConstShift_ssa(1); want != got {203 println("arithConstShift_ssa(1) failed, wanted", want, "got", got)204 failed = true205 }206}207// overflowConstShift_ssa verifes that constant folding for shift208// doesn't wrap (i.e. x << MAX_INT << 1 doesn't get folded to x << 0).209//go:noinline210func overflowConstShift64_ssa(x int64) int64 {211 return x << uint64(0xffffffffffffffff) << uint64(1)212}213//go:noinline214func overflowConstShift32_ssa(x int64) int32 {215 return int32(x) << uint32(0xffffffff) << uint32(1)216}217//go:noinline218func overflowConstShift16_ssa(x int64) int16 {219 return int16(x) << uint16(0xffff) << uint16(1)220}221//go:noinline222func overflowConstShift8_ssa(x int64) int8 {223 return int8(x) << uint8(0xff) << uint8(1)224}225func testOverflowConstShift() {226 want := int64(0)227 for x := int64(-127); x < int64(127); x++ {228 got := overflowConstShift64_ssa(x)229 if want != got {230 fmt.Printf("overflowShift64 failed, wanted %d got %d\n", want, got)231 }232 got = int64(overflowConstShift32_ssa(x))233 if want != got {234 fmt.Printf("overflowShift32 failed, wanted %d got %d\n", want, got)235 }236 got = int64(overflowConstShift16_ssa(x))237 if want != got {238 fmt.Printf("overflowShift16 failed, wanted %d got %d\n", want, got)239 }240 got = int64(overflowConstShift8_ssa(x))241 if want != got {242 fmt.Printf("overflowShift8 failed, wanted %d got %d\n", want, got)243 }244 }245}246// test64BitConstMult tests that rewrite rules don't fold 64 bit constants247// into multiply instructions.248func test64BitConstMult() {249 want := int64(103079215109)250 if got := test64BitConstMult_ssa(1, 2); want != got {251 println("test64BitConstMult failed, wanted", want, "got", got)252 failed = true253 }254}255//go:noinline256func test64BitConstMult_ssa(a, b int64) int64 {257 return 34359738369*a + b*34359738370258}259// test64BitConstAdd tests that rewrite rules don't fold 64 bit constants260// into add instructions.261func test64BitConstAdd() {262 want := int64(3567671782835376650)263 if got := test64BitConstAdd_ssa(1, 2); want != got {264 println("test64BitConstAdd failed, wanted", want, "got", got)265 failed = true266 }267}268//go:noinline269func test64BitConstAdd_ssa(a, b int64) int64 {270 return a + 575815584948629622 + b + 2991856197886747025271}272// testRegallocCVSpill tests that regalloc spills a value whose last use is the273// current value.274func testRegallocCVSpill() {275 want := int8(-9)276 if got := testRegallocCVSpill_ssa(1, 2, 3, 4); want != got {277 println("testRegallocCVSpill failed, wanted", want, "got", got)278 failed = true279 }280}281//go:noinline282func testRegallocCVSpill_ssa(a, b, c, d int8) int8 {283 return a + -32 + b + 63*c*-87*d284}285func testBitwiseLogic() {286 a, b := uint32(57623283), uint32(1314713839)287 if want, got := uint32(38551779), testBitwiseAnd_ssa(a, b); want != got {288 println("testBitwiseAnd failed, wanted", want, "got", got)289 failed = true290 }291 if want, got := uint32(1333785343), testBitwiseOr_ssa(a, b); want != got {292 println("testBitwiseOr failed, wanted", want, "got", got)293 failed = true294 }295 if want, got := uint32(1295233564), testBitwiseXor_ssa(a, b); want != got {296 println("testBitwiseXor failed, wanted", want, "got", got)297 failed = true298 }299 if want, got := int32(832), testBitwiseLsh_ssa(13, 4, 2); want != got {300 println("testBitwiseLsh failed, wanted", want, "got", got)301 failed = true302 }303 if want, got := int32(0), testBitwiseLsh_ssa(13, 25, 15); want != got {304 println("testBitwiseLsh failed, wanted", want, "got", got)305 failed = true306 }307 if want, got := int32(0), testBitwiseLsh_ssa(-13, 25, 15); want != got {308 println("testBitwiseLsh failed, wanted", want, "got", got)309 failed = true310 }311 if want, got := int32(-13), testBitwiseRsh_ssa(-832, 4, 2); want != got {312 println("testBitwiseRsh failed, wanted", want, "got", got)313 failed = true314 }315 if want, got := int32(0), testBitwiseRsh_ssa(13, 25, 15); want != got {316 println("testBitwiseRsh failed, wanted", want, "got", got)317 failed = true318 }319 if want, got := int32(-1), testBitwiseRsh_ssa(-13, 25, 15); want != got {320 println("testBitwiseRsh failed, wanted", want, "got", got)321 failed = true322 }323 if want, got := uint32(0x3ffffff), testBitwiseRshU_ssa(0xffffffff, 4, 2); want != got {324 println("testBitwiseRshU failed, wanted", want, "got", got)325 failed = true326 }327 if want, got := uint32(0), testBitwiseRshU_ssa(13, 25, 15); want != got {328 println("testBitwiseRshU failed, wanted", want, "got", got)329 failed = true330 }331 if want, got := uint32(0), testBitwiseRshU_ssa(0x8aaaaaaa, 25, 15); want != got {332 println("testBitwiseRshU failed, wanted", want, "got", got)333 failed = true334 }335}336//go:noinline337func testBitwiseAnd_ssa(a, b uint32) uint32 {338 return a & b339}340//go:noinline341func testBitwiseOr_ssa(a, b uint32) uint32 {342 return a | b343}344//go:noinline345func testBitwiseXor_ssa(a, b uint32) uint32 {346 return a ^ b347}348//go:noinline349func testBitwiseLsh_ssa(a int32, b, c uint32) int32 {350 return a << b << c351}352//go:noinline353func testBitwiseRsh_ssa(a int32, b, c uint32) int32 {354 return a >> b >> c355}356//go:noinline357func testBitwiseRshU_ssa(a uint32, b, c uint32) uint32 {358 return a >> b >> c359}360//go:noinline361func testShiftCX_ssa() int {362 v1 := uint8(3)363 v4 := (v1 * v1) ^ v1 | v1 - v1 - v1&v1 ^ uint8(3+2) + v1*1>>0 - v1 | 1 | v1<<(2*3|0-0*0^1)364 v5 := v4>>(3-0-uint(3)) | v1 | v1 + v1 ^ v4<<(0+1|3&1)<<(uint64(1)<<0*2*0<<0) ^ v1365 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 ^ v1366 v7 := v6 & v5 << 0367 v1++368 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 // int369 v7--370 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))371}372func testShiftCX() {373 want := 141374 if got := testShiftCX_ssa(); want != got {375 println("testShiftCX failed, wanted", want, "got", got)376 failed = true377 }378}379// testSubqToNegq ensures that the SUBQ -> NEGQ translation works correctly.380func testSubqToNegq() {381 want := int64(-318294940372190156)382 if got := testSubqToNegq_ssa(1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2); want != got {383 println("testSubqToNegq failed, wanted", want, "got", got)384 failed = true385 }386}387//go:noinline388func testSubqToNegq_ssa(a, b, c, d, e, f, g, h, i, j, k int64) int64 {389 return a + 8207351403619448057 - b - 1779494519303207690 + c*8810076340510052032*d - 4465874067674546219 - e*4361839741470334295 - f + 8688847565426072650*g*8065564729145417479390}391func testOcom() {392 want1, want2 := int32(0x55555555), int32(-0x55555556)393 if got1, got2 := testOcom_ssa(0x55555555, 0x55555555); want1 != got1 || want2 != got2 {394 println("testSubqToNegq failed, wanted", want1, "and", want2,395 "got", got1, "and", got2)396 failed = true397 }398}399//go:noinline400func testOcom_ssa(a, b int32) (int32, int32) {401 return ^^^^a, ^^^^^b402}403func lrot1_ssa(w uint8, x uint16, y uint32, z uint64) (a uint8, b uint16, c uint32, d uint64) {404 a = (w << 5) | (w >> 3)405 b = (x << 13) | (x >> 3)406 c = (y << 29) | (y >> 3)407 d = (z << 61) | (z >> 3)408 return409}410//go:noinline411func lrot2_ssa(w, n uint32) uint32 {412 // Want to be sure that a "rotate by 32" which413 // is really 0 | (w >> 0) == w414 // is correctly compiled.415 return (w << n) | (w >> (32 - n))416}417//go:noinline418func lrot3_ssa(w uint32) uint32 {419 // Want to be sure that a "rotate by 32" which420 // is really 0 | (w >> 0) == w421 // is correctly compiled.422 return (w << 32) | (w >> (32 - 32))423}424func testLrot() {425 wantA, wantB, wantC, wantD := uint8(0xe1), uint16(0xe001),426 uint32(0xe0000001), uint64(0xe000000000000001)427 a, b, c, d := lrot1_ssa(0xf, 0xf, 0xf, 0xf)428 if a != wantA || b != wantB || c != wantC || d != wantD {429 println("lrot1_ssa(0xf, 0xf, 0xf, 0xf)=",430 wantA, wantB, wantC, wantD, ", got", a, b, c, d)431 failed = true432 }433 x := lrot2_ssa(0xb0000001, 32)434 wantX := uint32(0xb0000001)435 if x != wantX {436 println("lrot2_ssa(0xb0000001, 32)=",437 wantX, ", got", x)438 failed = true439 }440 x = lrot3_ssa(0xb0000001)441 if x != wantX {442 println("lrot3_ssa(0xb0000001)=",443 wantX, ", got", x)444 failed = true445 }446}447//go:noinline448func sub1_ssa() uint64 {449 v1 := uint64(3) // uint64450 return v1*v1 - (v1&v1)&v1451}452//go:noinline453func sub2_ssa() uint8 {454 v1 := uint8(0)455 v3 := v1 + v1 + v1 ^ v1 | 3 + v1 ^ v1 | v1 ^ v1456 v1-- // dev.ssa doesn't see this one457 return v1 ^ v1*v1 - v3458}459func testSubConst() {460 x1 := sub1_ssa()461 want1 := uint64(6)462 if x1 != want1 {463 println("sub1_ssa()=", want1, ", got", x1)464 failed = true465 }466 x2 := sub2_ssa()467 want2 := uint8(251)468 if x2 != want2 {469 println("sub2_ssa()=", want2, ", got", x2)470 failed = true471 }472}473//go:noinline474func orPhi_ssa(a bool, x int) int {475 v := 0476 if a {477 v = -1478 } else {479 v = -1480 }481 return x | v482}483func testOrPhi() {484 if want, got := -1, orPhi_ssa(true, 4); got != want {485 println("orPhi_ssa(true, 4)=", got, " want ", want)486 }487 if want, got := -1, orPhi_ssa(false, 0); got != want {488 println("orPhi_ssa(false, 0)=", got, " want ", want)489 }490}491//go:noinline492func addshiftLL_ssa(a, b uint32) uint32 {493 return a + b<<3494}495//go:noinline496func subshiftLL_ssa(a, b uint32) uint32 {497 return a - b<<3498}499//go:noinline500func rsbshiftLL_ssa(a, b uint32) uint32 {501 return a<<3 - b502}503//go:noinline504func andshiftLL_ssa(a, b uint32) uint32 {505 return a & (b << 3)506}507//go:noinline508func orshiftLL_ssa(a, b uint32) uint32 {509 return a | b<<3510}511//go:noinline512func xorshiftLL_ssa(a, b uint32) uint32 {513 return a ^ b<<3514}515//go:noinline516func bicshiftLL_ssa(a, b uint32) uint32 {517 return a &^ (b << 3)518}519//go:noinline520func notshiftLL_ssa(a uint32) uint32 {521 return ^(a << 3)522}523//go:noinline524func addshiftRL_ssa(a, b uint32) uint32 {525 return a + b>>3526}527//go:noinline528func subshiftRL_ssa(a, b uint32) uint32 {529 return a - b>>3530}531//go:noinline532func rsbshiftRL_ssa(a, b uint32) uint32 {533 return a>>3 - b534}535//go:noinline536func andshiftRL_ssa(a, b uint32) uint32 {537 return a & (b >> 3)538}539//go:noinline540func orshiftRL_ssa(a, b uint32) uint32 {541 return a | b>>3542}543//go:noinline544func xorshiftRL_ssa(a, b uint32) uint32 {545 return a ^ b>>3546}547//go:noinline548func bicshiftRL_ssa(a, b uint32) uint32 {549 return a &^ (b >> 3)550}551//go:noinline552func notshiftRL_ssa(a uint32) uint32 {553 return ^(a >> 3)554}555//go:noinline556func addshiftRA_ssa(a, b int32) int32 {557 return a + b>>3558}559//go:noinline560func subshiftRA_ssa(a, b int32) int32 {561 return a - b>>3562}563//go:noinline564func rsbshiftRA_ssa(a, b int32) int32 {565 return a>>3 - b566}567//go:noinline568func andshiftRA_ssa(a, b int32) int32 {569 return a & (b >> 3)570}571//go:noinline572func orshiftRA_ssa(a, b int32) int32 {573 return a | b>>3574}575//go:noinline576func xorshiftRA_ssa(a, b int32) int32 {577 return a ^ b>>3578}579//go:noinline580func bicshiftRA_ssa(a, b int32) int32 {581 return a &^ (b >> 3)582}583//go:noinline584func notshiftRA_ssa(a int32) int32 {585 return ^(a >> 3)586}587//go:noinline588func addshiftLLreg_ssa(a, b uint32, s uint8) uint32 {589 return a + b<<s590}591//go:noinline592func subshiftLLreg_ssa(a, b uint32, s uint8) uint32 {593 return a - b<<s594}595//go:noinline596func rsbshiftLLreg_ssa(a, b uint32, s uint8) uint32 {597 return a<<s - b598}599//go:noinline600func andshiftLLreg_ssa(a, b uint32, s uint8) uint32 {601 return a & (b << s)602}603//go:noinline604func orshiftLLreg_ssa(a, b uint32, s uint8) uint32 {605 return a | b<<s606}607//go:noinline608func xorshiftLLreg_ssa(a, b uint32, s uint8) uint32 {609 return a ^ b<<s610}611//go:noinline612func bicshiftLLreg_ssa(a, b uint32, s uint8) uint32 {613 return a &^ (b << s)614}615//go:noinline616func notshiftLLreg_ssa(a uint32, s uint8) uint32 {617 return ^(a << s)618}619//go:noinline620func addshiftRLreg_ssa(a, b uint32, s uint8) uint32 {621 return a + b>>s622}623//go:noinline624func subshiftRLreg_ssa(a, b uint32, s uint8) uint32 {625 return a - b>>s626}627//go:noinline628func rsbshiftRLreg_ssa(a, b uint32, s uint8) uint32 {629 return a>>s - b630}631//go:noinline632func andshiftRLreg_ssa(a, b uint32, s uint8) uint32 {633 return a & (b >> s)634}635//go:noinline636func orshiftRLreg_ssa(a, b uint32, s uint8) uint32 {637 return a | b>>s638}639//go:noinline640func xorshiftRLreg_ssa(a, b uint32, s uint8) uint32 {641 return a ^ b>>s642}643//go:noinline644func bicshiftRLreg_ssa(a, b uint32, s uint8) uint32 {645 return a &^ (b >> s)646}647//go:noinline648func notshiftRLreg_ssa(a uint32, s uint8) uint32 {649 return ^(a >> s)650}651//go:noinline652func addshiftRAreg_ssa(a, b int32, s uint8) int32 {653 return a + b>>s654}655//go:noinline656func subshiftRAreg_ssa(a, b int32, s uint8) int32 {657 return a - b>>s658}659//go:noinline660func rsbshiftRAreg_ssa(a, b int32, s uint8) int32 {661 return a>>s - b662}663//go:noinline664func andshiftRAreg_ssa(a, b int32, s uint8) int32 {665 return a & (b >> s)666}667//go:noinline668func orshiftRAreg_ssa(a, b int32, s uint8) int32 {669 return a | b>>s670}671//go:noinline672func xorshiftRAreg_ssa(a, b int32, s uint8) int32 {673 return a ^ b>>s674}675//go:noinline676func bicshiftRAreg_ssa(a, b int32, s uint8) int32 {677 return a &^ (b >> s)678}679//go:noinline680func notshiftRAreg_ssa(a int32, s uint8) int32 {681 return ^(a >> s)682}683// test ARM shifted ops684func testShiftedOps() {685 a, b := uint32(10), uint32(42)686 if want, got := a+b<<3, addshiftLL_ssa(a, b); got != want {687 println("addshiftLL_ssa(10, 42) =", got, " want ", want)688 failed = true689 }690 if want, got := a-b<<3, subshiftLL_ssa(a, b); got != want {691 println("subshiftLL_ssa(10, 42) =", got, " want ", want)692 failed = true693 }694 if want, got := a<<3-b, rsbshiftLL_ssa(a, b); got != want {695 println("rsbshiftLL_ssa(10, 42) =", got, " want ", want)696 failed = true697 }698 if want, got := a&(b<<3), andshiftLL_ssa(a, b); got != want {699 println("andshiftLL_ssa(10, 42) =", got, " want ", want)700 failed = true701 }702 if want, got := a|b<<3, orshiftLL_ssa(a, b); got != want {703 println("orshiftLL_ssa(10, 42) =", got, " want ", want)704 failed = true705 }706 if want, got := a^b<<3, xorshiftLL_ssa(a, b); got != want {707 println("xorshiftLL_ssa(10, 42) =", got, " want ", want)708 failed = true709 }710 if want, got := a&^(b<<3), bicshiftLL_ssa(a, b); got != want {711 println("bicshiftLL_ssa(10, 42) =", got, " want ", want)712 failed = true713 }714 if want, got := ^(a << 3), notshiftLL_ssa(a); got != want {715 println("notshiftLL_ssa(10) =", got, " want ", want)716 failed = true717 }718 if want, got := a+b>>3, addshiftRL_ssa(a, b); got != want {719 println("addshiftRL_ssa(10, 42) =", got, " want ", want)720 failed = true721 }722 if want, got := a-b>>3, subshiftRL_ssa(a, b); got != want {723 println("subshiftRL_ssa(10, 42) =", got, " want ", want)724 failed = true725 }726 if want, got := a>>3-b, rsbshiftRL_ssa(a, b); got != want {727 println("rsbshiftRL_ssa(10, 42) =", got, " want ", want)728 failed = true729 }730 if want, got := a&(b>>3), andshiftRL_ssa(a, b); got != want {731 println("andshiftRL_ssa(10, 42) =", got, " want ", want)732 failed = true733 }734 if want, got := a|b>>3, orshiftRL_ssa(a, b); got != want {735 println("orshiftRL_ssa(10, 42) =", got, " want ", want)736 failed = true737 }738 if want, got := a^b>>3, xorshiftRL_ssa(a, b); got != want {739 println("xorshiftRL_ssa(10, 42) =", got, " want ", want)740 failed = true741 }742 if want, got := a&^(b>>3), bicshiftRL_ssa(a, b); got != want {743 println("bicshiftRL_ssa(10, 42) =", got, " want ", want)744 failed = true745 }746 if want, got := ^(a >> 3), notshiftRL_ssa(a); got != want {747 println("notshiftRL_ssa(10) =", got, " want ", want)748 failed = true749 }750 c, d := int32(10), int32(-42)751 if want, got := c+d>>3, addshiftRA_ssa(c, d); got != want {752 println("addshiftRA_ssa(10, -42) =", got, " want ", want)753 failed = true754 }755 if want, got := c-d>>3, subshiftRA_ssa(c, d); got != want {756 println("subshiftRA_ssa(10, -42) =", got, " want ", want)757 failed = true758 }759 if want, got := c>>3-d, rsbshiftRA_ssa(c, d); got != want {760 println("rsbshiftRA_ssa(10, -42) =", got, " want ", want)761 failed = true762 }763 if want, got := c&(d>>3), andshiftRA_ssa(c, d); got != want {764 println("andshiftRA_ssa(10, -42) =", got, " want ", want)765 failed = true766 }767 if want, got := c|d>>3, orshiftRA_ssa(c, d); got != want {768 println("orshiftRA_ssa(10, -42) =", got, " want ", want)769 failed = true770 }771 if want, got := c^d>>3, xorshiftRA_ssa(c, d); got != want {772 println("xorshiftRA_ssa(10, -42) =", got, " want ", want)773 failed = true774 }775 if want, got := c&^(d>>3), bicshiftRA_ssa(c, d); got != want {776 println("bicshiftRA_ssa(10, -42) =", got, " want ", want)777 failed = true778 }779 if want, got := ^(d >> 3), notshiftRA_ssa(d); got != want {780 println("notshiftRA_ssa(-42) =", got, " want ", want)781 failed = true782 }783 s := uint8(3)784 if want, got := a+b<<s, addshiftLLreg_ssa(a, b, s); got != want {785 println("addshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)786 failed = true787 }788 if want, got := a-b<<s, subshiftLLreg_ssa(a, b, s); got != want {789 println("subshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)790 failed = true791 }792 if want, got := a<<s-b, rsbshiftLLreg_ssa(a, b, s); got != want {793 println("rsbshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)794 failed = true795 }796 if want, got := a&(b<<s), andshiftLLreg_ssa(a, b, s); got != want {797 println("andshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)798 failed = true799 }800 if want, got := a|b<<s, orshiftLLreg_ssa(a, b, s); got != want {801 println("orshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)802 failed = true803 }804 if want, got := a^b<<s, xorshiftLLreg_ssa(a, b, s); got != want {805 println("xorshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)806 failed = true807 }808 if want, got := a&^(b<<s), bicshiftLLreg_ssa(a, b, s); got != want {809 println("bicshiftLLreg_ssa(10, 42, 3) =", got, " want ", want)810 failed = true811 }812 if want, got := ^(a << s), notshiftLLreg_ssa(a, s); got != want {813 println("notshiftLLreg_ssa(10) =", got, " want ", want)814 failed = true815 }816 if want, got := a+b>>s, addshiftRLreg_ssa(a, b, s); got != want {817 println("addshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)818 failed = true819 }820 if want, got := a-b>>s, subshiftRLreg_ssa(a, b, s); got != want {821 println("subshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)822 failed = true823 }824 if want, got := a>>s-b, rsbshiftRLreg_ssa(a, b, s); got != want {825 println("rsbshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)826 failed = true827 }828 if want, got := a&(b>>s), andshiftRLreg_ssa(a, b, s); got != want {829 println("andshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)830 failed = true831 }832 if want, got := a|b>>s, orshiftRLreg_ssa(a, b, s); got != want {833 println("orshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)834 failed = true835 }836 if want, got := a^b>>s, xorshiftRLreg_ssa(a, b, s); got != want {837 println("xorshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)838 failed = true839 }840 if want, got := a&^(b>>s), bicshiftRLreg_ssa(a, b, s); got != want {841 println("bicshiftRLreg_ssa(10, 42, 3) =", got, " want ", want)842 failed = true843 }844 if want, got := ^(a >> s), notshiftRLreg_ssa(a, s); got != want {845 println("notshiftRLreg_ssa(10) =", got, " want ", want)846 failed = true847 }848 if want, got := c+d>>s, addshiftRAreg_ssa(c, d, s); got != want {849 println("addshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)850 failed = true851 }852 if want, got := c-d>>s, subshiftRAreg_ssa(c, d, s); got != want {853 println("subshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)854 failed = true855 }856 if want, got := c>>s-d, rsbshiftRAreg_ssa(c, d, s); got != want {857 println("rsbshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)858 failed = true859 }860 if want, got := c&(d>>s), andshiftRAreg_ssa(c, d, s); got != want {861 println("andshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)862 failed = true863 }864 if want, got := c|d>>s, orshiftRAreg_ssa(c, d, s); got != want {865 println("orshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)866 failed = true867 }868 if want, got := c^d>>s, xorshiftRAreg_ssa(c, d, s); got != want {869 println("xorshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)870 failed = true871 }872 if want, got := c&^(d>>s), bicshiftRAreg_ssa(c, d, s); got != want {873 println("bicshiftRAreg_ssa(10, -42, 3) =", got, " want ", want)874 failed = true875 }876 if want, got := ^(d >> s), notshiftRAreg_ssa(d, s); got != want {877 println("notshiftRAreg_ssa(-42, 3) =", got, " want ", want)878 failed = true879 }880}881var failed = false882func main() {883 test64BitConstMult()884 test64BitConstAdd()885 testRegallocCVSpill()886 testSubqToNegq()887 testBitwiseLogic()888 testOcom()889 testLrot()890 testShiftCX()891 testSubConst()892 testOverflowConstShift()893 testArithConstShift()894 testArithRshConst()895 testLargeConst()896 testLoadCombine()897 testLoadSymCombine()898 testShiftRemoval()899 testShiftedOps()900 if failed {901 panic("failed")902 }903}...

Full Screen

Full Screen

shift_test.go

Source:shift_test.go Github

copy

Full Screen

1// Copyright 2016 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.4package gc5import (6 "reflect"7 "testing"8)9// Tests shifts of zero.10//go:noinline11func ofz64l64(n uint64) int64 {12 var x int6413 return x << n14}15//go:noinline16func ofz64l32(n uint32) int64 {17 var x int6418 return x << n19}20//go:noinline21func ofz64l16(n uint16) int64 {22 var x int6423 return x << n24}25//go:noinline26func ofz64l8(n uint8) int64 {27 var x int6428 return x << n29}30//go:noinline31func ofz64r64(n uint64) int64 {32 var x int6433 return x >> n34}35//go:noinline36func ofz64r32(n uint32) int64 {37 var x int6438 return x >> n39}40//go:noinline41func ofz64r16(n uint16) int64 {42 var x int6443 return x >> n44}45//go:noinline46func ofz64r8(n uint8) int64 {47 var x int6448 return x >> n49}50//go:noinline51func ofz64ur64(n uint64) uint64 {52 var x uint6453 return x >> n54}55//go:noinline56func ofz64ur32(n uint32) uint64 {57 var x uint6458 return x >> n59}60//go:noinline61func ofz64ur16(n uint16) uint64 {62 var x uint6463 return x >> n64}65//go:noinline66func ofz64ur8(n uint8) uint64 {67 var x uint6468 return x >> n69}70//go:noinline71func ofz32l64(n uint64) int32 {72 var x int3273 return x << n74}75//go:noinline76func ofz32l32(n uint32) int32 {77 var x int3278 return x << n79}80//go:noinline81func ofz32l16(n uint16) int32 {82 var x int3283 return x << n84}85//go:noinline86func ofz32l8(n uint8) int32 {87 var x int3288 return x << n89}90//go:noinline91func ofz32r64(n uint64) int32 {92 var x int3293 return x >> n94}95//go:noinline96func ofz32r32(n uint32) int32 {97 var x int3298 return x >> n99}100//go:noinline101func ofz32r16(n uint16) int32 {102 var x int32103 return x >> n104}105//go:noinline106func ofz32r8(n uint8) int32 {107 var x int32108 return x >> n109}110//go:noinline111func ofz32ur64(n uint64) uint32 {112 var x uint32113 return x >> n114}115//go:noinline116func ofz32ur32(n uint32) uint32 {117 var x uint32118 return x >> n119}120//go:noinline121func ofz32ur16(n uint16) uint32 {122 var x uint32123 return x >> n124}125//go:noinline126func ofz32ur8(n uint8) uint32 {127 var x uint32128 return x >> n129}130//go:noinline131func ofz16l64(n uint64) int16 {132 var x int16133 return x << n134}135//go:noinline136func ofz16l32(n uint32) int16 {137 var x int16138 return x << n139}140//go:noinline141func ofz16l16(n uint16) int16 {142 var x int16143 return x << n144}145//go:noinline146func ofz16l8(n uint8) int16 {147 var x int16148 return x << n149}150//go:noinline151func ofz16r64(n uint64) int16 {152 var x int16153 return x >> n154}155//go:noinline156func ofz16r32(n uint32) int16 {157 var x int16158 return x >> n159}160//go:noinline161func ofz16r16(n uint16) int16 {162 var x int16163 return x >> n164}165//go:noinline166func ofz16r8(n uint8) int16 {167 var x int16168 return x >> n169}170//go:noinline171func ofz16ur64(n uint64) uint16 {172 var x uint16173 return x >> n174}175//go:noinline176func ofz16ur32(n uint32) uint16 {177 var x uint16178 return x >> n179}180//go:noinline181func ofz16ur16(n uint16) uint16 {182 var x uint16183 return x >> n184}185//go:noinline186func ofz16ur8(n uint8) uint16 {187 var x uint16188 return x >> n189}190//go:noinline191func ofz8l64(n uint64) int8 {192 var x int8193 return x << n194}195//go:noinline196func ofz8l32(n uint32) int8 {197 var x int8198 return x << n199}200//go:noinline201func ofz8l16(n uint16) int8 {202 var x int8203 return x << n204}205//go:noinline206func ofz8l8(n uint8) int8 {207 var x int8208 return x << n209}210//go:noinline211func ofz8r64(n uint64) int8 {212 var x int8213 return x >> n214}215//go:noinline216func ofz8r32(n uint32) int8 {217 var x int8218 return x >> n219}220//go:noinline221func ofz8r16(n uint16) int8 {222 var x int8223 return x >> n224}225//go:noinline226func ofz8r8(n uint8) int8 {227 var x int8228 return x >> n229}230//go:noinline231func ofz8ur64(n uint64) uint8 {232 var x uint8233 return x >> n234}235//go:noinline236func ofz8ur32(n uint32) uint8 {237 var x uint8238 return x >> n239}240//go:noinline241func ofz8ur16(n uint16) uint8 {242 var x uint8243 return x >> n244}245//go:noinline246func ofz8ur8(n uint8) uint8 {247 var x uint8248 return x >> n249}250func TestShiftOfZero(t *testing.T) {251 if got := ofz64l64(5); got != 0 {252 t.Errorf("0<<5 == %d, want 0", got)253 }254 if got := ofz64l32(5); got != 0 {255 t.Errorf("0<<5 == %d, want 0", got)256 }257 if got := ofz64l16(5); got != 0 {258 t.Errorf("0<<5 == %d, want 0", got)259 }260 if got := ofz64l8(5); got != 0 {261 t.Errorf("0<<5 == %d, want 0", got)262 }263 if got := ofz64r64(5); got != 0 {264 t.Errorf("0>>5 == %d, want 0", got)265 }266 if got := ofz64r32(5); got != 0 {267 t.Errorf("0>>5 == %d, want 0", got)268 }269 if got := ofz64r16(5); got != 0 {270 t.Errorf("0>>5 == %d, want 0", got)271 }272 if got := ofz64r8(5); got != 0 {273 t.Errorf("0>>5 == %d, want 0", got)274 }275 if got := ofz64ur64(5); got != 0 {276 t.Errorf("0>>>5 == %d, want 0", got)277 }278 if got := ofz64ur32(5); got != 0 {279 t.Errorf("0>>>5 == %d, want 0", got)280 }281 if got := ofz64ur16(5); got != 0 {282 t.Errorf("0>>>5 == %d, want 0", got)283 }284 if got := ofz64ur8(5); got != 0 {285 t.Errorf("0>>>5 == %d, want 0", got)286 }287 if got := ofz32l64(5); got != 0 {288 t.Errorf("0<<5 == %d, want 0", got)289 }290 if got := ofz32l32(5); got != 0 {291 t.Errorf("0<<5 == %d, want 0", got)292 }293 if got := ofz32l16(5); got != 0 {294 t.Errorf("0<<5 == %d, want 0", got)295 }296 if got := ofz32l8(5); got != 0 {297 t.Errorf("0<<5 == %d, want 0", got)298 }299 if got := ofz32r64(5); got != 0 {300 t.Errorf("0>>5 == %d, want 0", got)301 }302 if got := ofz32r32(5); got != 0 {303 t.Errorf("0>>5 == %d, want 0", got)304 }305 if got := ofz32r16(5); got != 0 {306 t.Errorf("0>>5 == %d, want 0", got)307 }308 if got := ofz32r8(5); got != 0 {309 t.Errorf("0>>5 == %d, want 0", got)310 }311 if got := ofz32ur64(5); got != 0 {312 t.Errorf("0>>>5 == %d, want 0", got)313 }314 if got := ofz32ur32(5); got != 0 {315 t.Errorf("0>>>5 == %d, want 0", got)316 }317 if got := ofz32ur16(5); got != 0 {318 t.Errorf("0>>>5 == %d, want 0", got)319 }320 if got := ofz32ur8(5); got != 0 {321 t.Errorf("0>>>5 == %d, want 0", got)322 }323 if got := ofz16l64(5); got != 0 {324 t.Errorf("0<<5 == %d, want 0", got)325 }326 if got := ofz16l32(5); got != 0 {327 t.Errorf("0<<5 == %d, want 0", got)328 }329 if got := ofz16l16(5); got != 0 {330 t.Errorf("0<<5 == %d, want 0", got)331 }332 if got := ofz16l8(5); got != 0 {333 t.Errorf("0<<5 == %d, want 0", got)334 }335 if got := ofz16r64(5); got != 0 {336 t.Errorf("0>>5 == %d, want 0", got)337 }338 if got := ofz16r32(5); got != 0 {339 t.Errorf("0>>5 == %d, want 0", got)340 }341 if got := ofz16r16(5); got != 0 {342 t.Errorf("0>>5 == %d, want 0", got)343 }344 if got := ofz16r8(5); got != 0 {345 t.Errorf("0>>5 == %d, want 0", got)346 }347 if got := ofz16ur64(5); got != 0 {348 t.Errorf("0>>>5 == %d, want 0", got)349 }350 if got := ofz16ur32(5); got != 0 {351 t.Errorf("0>>>5 == %d, want 0", got)352 }353 if got := ofz16ur16(5); got != 0 {354 t.Errorf("0>>>5 == %d, want 0", got)355 }356 if got := ofz16ur8(5); got != 0 {357 t.Errorf("0>>>5 == %d, want 0", got)358 }359 if got := ofz8l64(5); got != 0 {360 t.Errorf("0<<5 == %d, want 0", got)361 }362 if got := ofz8l32(5); got != 0 {363 t.Errorf("0<<5 == %d, want 0", got)364 }365 if got := ofz8l16(5); got != 0 {366 t.Errorf("0<<5 == %d, want 0", got)367 }368 if got := ofz8l8(5); got != 0 {369 t.Errorf("0<<5 == %d, want 0", got)370 }371 if got := ofz8r64(5); got != 0 {372 t.Errorf("0>>5 == %d, want 0", got)373 }374 if got := ofz8r32(5); got != 0 {375 t.Errorf("0>>5 == %d, want 0", got)376 }377 if got := ofz8r16(5); got != 0 {378 t.Errorf("0>>5 == %d, want 0", got)379 }380 if got := ofz8r8(5); got != 0 {381 t.Errorf("0>>5 == %d, want 0", got)382 }383 if got := ofz8ur64(5); got != 0 {384 t.Errorf("0>>>5 == %d, want 0", got)385 }386 if got := ofz8ur32(5); got != 0 {387 t.Errorf("0>>>5 == %d, want 0", got)388 }389 if got := ofz8ur16(5); got != 0 {390 t.Errorf("0>>>5 == %d, want 0", got)391 }392 if got := ofz8ur8(5); got != 0 {393 t.Errorf("0>>>5 == %d, want 0", got)394 }395}396//go:noinline397func byz64l(n int64) int64 {398 return n << 0399}400//go:noinline401func byz64r(n int64) int64 {402 return n >> 0403}404//go:noinline405func byz64ur(n uint64) uint64 {406 return n >> 0407}408//go:noinline409func byz32l(n int32) int32 {410 return n << 0411}412//go:noinline413func byz32r(n int32) int32 {414 return n >> 0415}416//go:noinline417func byz32ur(n uint32) uint32 {418 return n >> 0419}420//go:noinline421func byz16l(n int16) int16 {422 return n << 0423}424//go:noinline425func byz16r(n int16) int16 {426 return n >> 0427}428//go:noinline429func byz16ur(n uint16) uint16 {430 return n >> 0431}432//go:noinline433func byz8l(n int8) int8 {434 return n << 0435}436//go:noinline437func byz8r(n int8) int8 {438 return n >> 0439}440//go:noinline441func byz8ur(n uint8) uint8 {442 return n >> 0443}444func TestShiftByZero(t *testing.T) {445 {446 var n int64 = 0x5555555555555555447 if got := byz64l(n); got != n {448 t.Errorf("%x<<0 == %x, want %x", n, got, n)449 }450 if got := byz64r(n); got != n {451 t.Errorf("%x>>0 == %x, want %x", n, got, n)452 }453 }454 {455 var n uint64 = 0xaaaaaaaaaaaaaaaa456 if got := byz64ur(n); got != n {457 t.Errorf("%x>>>0 == %x, want %x", n, got, n)458 }459 }460 {461 var n int32 = 0x55555555462 if got := byz32l(n); got != n {463 t.Errorf("%x<<0 == %x, want %x", n, got, n)464 }465 if got := byz32r(n); got != n {466 t.Errorf("%x>>0 == %x, want %x", n, got, n)467 }468 }469 {470 var n uint32 = 0xaaaaaaaa471 if got := byz32ur(n); got != n {472 t.Errorf("%x>>>0 == %x, want %x", n, got, n)473 }474 }475 {476 var n int16 = 0x5555477 if got := byz16l(n); got != n {478 t.Errorf("%x<<0 == %x, want %x", n, got, n)479 }480 if got := byz16r(n); got != n {481 t.Errorf("%x>>0 == %x, want %x", n, got, n)482 }483 }484 {485 var n uint16 = 0xaaaa486 if got := byz16ur(n); got != n {487 t.Errorf("%x>>>0 == %x, want %x", n, got, n)488 }489 }490 {491 var n int8 = 0x55492 if got := byz8l(n); got != n {493 t.Errorf("%x<<0 == %x, want %x", n, got, n)494 }495 if got := byz8r(n); got != n {496 t.Errorf("%x>>0 == %x, want %x", n, got, n)497 }498 }499 {500 var n uint8 = 0x55501 if got := byz8ur(n); got != n {502 t.Errorf("%x>>>0 == %x, want %x", n, got, n)503 }504 }505}506//go:noinline507func two64l(x int64) int64 {508 return x << 1 << 1509}510//go:noinline511func two64r(x int64) int64 {512 return x >> 1 >> 1513}514//go:noinline515func two64ur(x uint64) uint64 {516 return x >> 1 >> 1517}518//go:noinline519func two32l(x int32) int32 {520 return x << 1 << 1521}522//go:noinline523func two32r(x int32) int32 {524 return x >> 1 >> 1525}526//go:noinline527func two32ur(x uint32) uint32 {528 return x >> 1 >> 1529}530//go:noinline531func two16l(x int16) int16 {532 return x << 1 << 1533}534//go:noinline535func two16r(x int16) int16 {536 return x >> 1 >> 1537}538//go:noinline539func two16ur(x uint16) uint16 {540 return x >> 1 >> 1541}542//go:noinline543func two8l(x int8) int8 {544 return x << 1 << 1545}546//go:noinline547func two8r(x int8) int8 {548 return x >> 1 >> 1549}550//go:noinline551func two8ur(x uint8) uint8 {552 return x >> 1 >> 1553}554func TestShiftCombine(t *testing.T) {555 if got, want := two64l(4), int64(16); want != got {556 t.Errorf("4<<1<<1 == %d, want %d", got, want)557 }558 if got, want := two64r(64), int64(16); want != got {559 t.Errorf("64>>1>>1 == %d, want %d", got, want)560 }561 if got, want := two64ur(64), uint64(16); want != got {562 t.Errorf("64>>1>>1 == %d, want %d", got, want)563 }564 if got, want := two32l(4), int32(16); want != got {565 t.Errorf("4<<1<<1 == %d, want %d", got, want)566 }567 if got, want := two32r(64), int32(16); want != got {568 t.Errorf("64>>1>>1 == %d, want %d", got, want)569 }570 if got, want := two32ur(64), uint32(16); want != got {571 t.Errorf("64>>1>>1 == %d, want %d", got, want)572 }573 if got, want := two16l(4), int16(16); want != got {574 t.Errorf("4<<1<<1 == %d, want %d", got, want)575 }576 if got, want := two16r(64), int16(16); want != got {577 t.Errorf("64>>1>>1 == %d, want %d", got, want)578 }579 if got, want := two16ur(64), uint16(16); want != got {580 t.Errorf("64>>1>>1 == %d, want %d", got, want)581 }582 if got, want := two8l(4), int8(16); want != got {583 t.Errorf("4<<1<<1 == %d, want %d", got, want)584 }585 if got, want := two8r(64), int8(16); want != got {586 t.Errorf("64>>1>>1 == %d, want %d", got, want)587 }588 if got, want := two8ur(64), uint8(16); want != got {589 t.Errorf("64>>1>>1 == %d, want %d", got, want)590 }591}592//go:noinline593func three64l(x int64) int64 {594 return x << 3 >> 1 << 2595}596//go:noinline597func three64ul(x uint64) uint64 {598 return x << 3 >> 1 << 2599}600//go:noinline601func three64r(x int64) int64 {602 return x >> 3 << 1 >> 2603}604//go:noinline605func three64ur(x uint64) uint64 {606 return x >> 3 << 1 >> 2607}608//go:noinline609func three32l(x int32) int32 {610 return x << 3 >> 1 << 2611}612//go:noinline613func three32ul(x uint32) uint32 {614 return x << 3 >> 1 << 2615}616//go:noinline617func three32r(x int32) int32 {618 return x >> 3 << 1 >> 2619}620//go:noinline621func three32ur(x uint32) uint32 {622 return x >> 3 << 1 >> 2623}624//go:noinline625func three16l(x int16) int16 {626 return x << 3 >> 1 << 2627}628//go:noinline629func three16ul(x uint16) uint16 {630 return x << 3 >> 1 << 2631}632//go:noinline633func three16r(x int16) int16 {634 return x >> 3 << 1 >> 2635}636//go:noinline637func three16ur(x uint16) uint16 {638 return x >> 3 << 1 >> 2639}640//go:noinline641func three8l(x int8) int8 {642 return x << 3 >> 1 << 2643}644//go:noinline645func three8ul(x uint8) uint8 {646 return x << 3 >> 1 << 2647}648//go:noinline649func three8r(x int8) int8 {650 return x >> 3 << 1 >> 2651}652//go:noinline653func three8ur(x uint8) uint8 {654 return x >> 3 << 1 >> 2655}656func TestShiftCombine3(t *testing.T) {657 if got, want := three64l(4), int64(64); want != got {658 t.Errorf("4<<1<<1 == %d, want %d", got, want)659 }660 if got, want := three64ul(4), uint64(64); want != got {661 t.Errorf("4<<1<<1 == %d, want %d", got, want)662 }663 if got, want := three64r(64), int64(4); want != got {664 t.Errorf("64>>1>>1 == %d, want %d", got, want)665 }666 if got, want := three64ur(64), uint64(4); want != got {667 t.Errorf("64>>1>>1 == %d, want %d", got, want)668 }669 if got, want := three32l(4), int32(64); want != got {670 t.Errorf("4<<1<<1 == %d, want %d", got, want)671 }672 if got, want := three32ul(4), uint32(64); want != got {673 t.Errorf("4<<1<<1 == %d, want %d", got, want)674 }675 if got, want := three32r(64), int32(4); want != got {676 t.Errorf("64>>1>>1 == %d, want %d", got, want)677 }678 if got, want := three32ur(64), uint32(4); want != got {679 t.Errorf("64>>1>>1 == %d, want %d", got, want)680 }681 if got, want := three16l(4), int16(64); want != got {682 t.Errorf("4<<1<<1 == %d, want %d", got, want)683 }684 if got, want := three16ul(4), uint16(64); want != got {685 t.Errorf("4<<1<<1 == %d, want %d", got, want)686 }687 if got, want := three16r(64), int16(4); want != got {688 t.Errorf("64>>1>>1 == %d, want %d", got, want)689 }690 if got, want := three16ur(64), uint16(4); want != got {691 t.Errorf("64>>1>>1 == %d, want %d", got, want)692 }693 if got, want := three8l(4), int8(64); want != got {694 t.Errorf("4<<1<<1 == %d, want %d", got, want)695 }696 if got, want := three8ul(4), uint8(64); want != got {697 t.Errorf("4<<1<<1 == %d, want %d", got, want)698 }699 if got, want := three8r(64), int8(4); want != got {700 t.Errorf("64>>1>>1 == %d, want %d", got, want)701 }702 if got, want := three8ur(64), uint8(4); want != got {703 t.Errorf("64>>1>>1 == %d, want %d", got, want)704 }705}706var (707 one64 int64 = 1708 one64u uint64 = 1709 one32 int32 = 1710 one32u uint32 = 1711 one16 int16 = 1712 one16u uint16 = 1713 one8 int8 = 1714 one8u uint8 = 1715)716func TestShiftLargeCombine(t *testing.T) {717 var N uint64 = 0x8000000000000000718 if one64<<N<<N == 1 {719 t.Errorf("shift overflow mishandled")720 }721 if one64>>N>>N == 1 {722 t.Errorf("shift overflow mishandled")723 }724 if one64u>>N>>N == 1 {725 t.Errorf("shift overflow mishandled")726 }727 if one32<<N<<N == 1 {728 t.Errorf("shift overflow mishandled")729 }730 if one32>>N>>N == 1 {731 t.Errorf("shift overflow mishandled")732 }733 if one32u>>N>>N == 1 {734 t.Errorf("shift overflow mishandled")735 }736 if one16<<N<<N == 1 {737 t.Errorf("shift overflow mishandled")738 }739 if one16>>N>>N == 1 {740 t.Errorf("shift overflow mishandled")741 }742 if one16u>>N>>N == 1 {743 t.Errorf("shift overflow mishandled")744 }745 if one8<<N<<N == 1 {746 t.Errorf("shift overflow mishandled")747 }748 if one8>>N>>N == 1 {749 t.Errorf("shift overflow mishandled")750 }751 if one8u>>N>>N == 1 {752 t.Errorf("shift overflow mishandled")753 }754}755func TestShiftLargeCombine3(t *testing.T) {756 var N uint64 = 0x8000000000000001757 if one64<<N>>2<<N == 1 {758 t.Errorf("shift overflow mishandled")759 }760 if one64u<<N>>2<<N == 1 {761 t.Errorf("shift overflow mishandled")762 }763 if one64>>N<<2>>N == 1 {764 t.Errorf("shift overflow mishandled")765 }766 if one64u>>N<<2>>N == 1 {767 t.Errorf("shift overflow mishandled")768 }769 if one32<<N>>2<<N == 1 {770 t.Errorf("shift overflow mishandled")771 }772 if one32u<<N>>2<<N == 1 {773 t.Errorf("shift overflow mishandled")774 }775 if one32>>N<<2>>N == 1 {776 t.Errorf("shift overflow mishandled")777 }778 if one32u>>N<<2>>N == 1 {779 t.Errorf("shift overflow mishandled")780 }781 if one16<<N>>2<<N == 1 {782 t.Errorf("shift overflow mishandled")783 }784 if one16u<<N>>2<<N == 1 {785 t.Errorf("shift overflow mishandled")786 }787 if one16>>N<<2>>N == 1 {788 t.Errorf("shift overflow mishandled")789 }790 if one16u>>N<<2>>N == 1 {791 t.Errorf("shift overflow mishandled")792 }793 if one8<<N>>2<<N == 1 {794 t.Errorf("shift overflow mishandled")795 }796 if one8u<<N>>2<<N == 1 {797 t.Errorf("shift overflow mishandled")798 }799 if one8>>N<<2>>N == 1 {800 t.Errorf("shift overflow mishandled")801 }802 if one8u>>N<<2>>N == 1 {803 t.Errorf("shift overflow mishandled")804 }805}806func TestShiftGeneric(t *testing.T) {807 for _, test := range [...]struct {808 valueWidth int809 signed bool810 shiftWidth int811 left bool812 f interface{}813 }{814 {64, true, 64, true, func(n int64, s uint64) int64 { return n << s }},815 {64, true, 64, false, func(n int64, s uint64) int64 { return n >> s }},816 {64, false, 64, false, func(n uint64, s uint64) uint64 { return n >> s }},817 {64, true, 32, true, func(n int64, s uint32) int64 { return n << s }},818 {64, true, 32, false, func(n int64, s uint32) int64 { return n >> s }},819 {64, false, 32, false, func(n uint64, s uint32) uint64 { return n >> s }},820 {64, true, 16, true, func(n int64, s uint16) int64 { return n << s }},821 {64, true, 16, false, func(n int64, s uint16) int64 { return n >> s }},822 {64, false, 16, false, func(n uint64, s uint16) uint64 { return n >> s }},823 {64, true, 8, true, func(n int64, s uint8) int64 { return n << s }},824 {64, true, 8, false, func(n int64, s uint8) int64 { return n >> s }},825 {64, false, 8, false, func(n uint64, s uint8) uint64 { return n >> s }},826 {32, true, 64, true, func(n int32, s uint64) int32 { return n << s }},827 {32, true, 64, false, func(n int32, s uint64) int32 { return n >> s }},828 {32, false, 64, false, func(n uint32, s uint64) uint32 { return n >> s }},829 {32, true, 32, true, func(n int32, s uint32) int32 { return n << s }},830 {32, true, 32, false, func(n int32, s uint32) int32 { return n >> s }},831 {32, false, 32, false, func(n uint32, s uint32) uint32 { return n >> s }},832 {32, true, 16, true, func(n int32, s uint16) int32 { return n << s }},833 {32, true, 16, false, func(n int32, s uint16) int32 { return n >> s }},834 {32, false, 16, false, func(n uint32, s uint16) uint32 { return n >> s }},835 {32, true, 8, true, func(n int32, s uint8) int32 { return n << s }},836 {32, true, 8, false, func(n int32, s uint8) int32 { return n >> s }},837 {32, false, 8, false, func(n uint32, s uint8) uint32 { return n >> s }},838 {16, true, 64, true, func(n int16, s uint64) int16 { return n << s }},839 {16, true, 64, false, func(n int16, s uint64) int16 { return n >> s }},840 {16, false, 64, false, func(n uint16, s uint64) uint16 { return n >> s }},841 {16, true, 32, true, func(n int16, s uint32) int16 { return n << s }},842 {16, true, 32, false, func(n int16, s uint32) int16 { return n >> s }},843 {16, false, 32, false, func(n uint16, s uint32) uint16 { return n >> s }},844 {16, true, 16, true, func(n int16, s uint16) int16 { return n << s }},845 {16, true, 16, false, func(n int16, s uint16) int16 { return n >> s }},846 {16, false, 16, false, func(n uint16, s uint16) uint16 { return n >> s }},847 {16, true, 8, true, func(n int16, s uint8) int16 { return n << s }},848 {16, true, 8, false, func(n int16, s uint8) int16 { return n >> s }},849 {16, false, 8, false, func(n uint16, s uint8) uint16 { return n >> s }},850 {8, true, 64, true, func(n int8, s uint64) int8 { return n << s }},851 {8, true, 64, false, func(n int8, s uint64) int8 { return n >> s }},852 {8, false, 64, false, func(n uint8, s uint64) uint8 { return n >> s }},853 {8, true, 32, true, func(n int8, s uint32) int8 { return n << s }},854 {8, true, 32, false, func(n int8, s uint32) int8 { return n >> s }},855 {8, false, 32, false, func(n uint8, s uint32) uint8 { return n >> s }},856 {8, true, 16, true, func(n int8, s uint16) int8 { return n << s }},857 {8, true, 16, false, func(n int8, s uint16) int8 { return n >> s }},858 {8, false, 16, false, func(n uint8, s uint16) uint8 { return n >> s }},859 {8, true, 8, true, func(n int8, s uint8) int8 { return n << s }},860 {8, true, 8, false, func(n int8, s uint8) int8 { return n >> s }},861 {8, false, 8, false, func(n uint8, s uint8) uint8 { return n >> s }},862 } {863 fv := reflect.ValueOf(test.f)864 var args [2]reflect.Value865 for i := 0; i < test.valueWidth; i++ {866 // Build value to be shifted.867 var n int64 = 1868 for j := 0; j < i; j++ {869 n <<= 1870 }871 args[0] = reflect.ValueOf(n).Convert(fv.Type().In(0))872 for s := 0; s <= test.shiftWidth; s++ {873 args[1] = reflect.ValueOf(s).Convert(fv.Type().In(1))874 // Compute desired result. We're testing variable shifts875 // assuming constant shifts are correct.876 r := n877 var op string878 switch {879 case test.left:880 op = "<<"881 for j := 0; j < s; j++ {882 r <<= 1883 }884 switch test.valueWidth {885 case 32:886 r = int64(int32(r))887 case 16:888 r = int64(int16(r))889 case 8:890 r = int64(int8(r))891 }892 case test.signed:893 op = ">>"894 switch test.valueWidth {895 case 32:896 r = int64(int32(r))897 case 16:898 r = int64(int16(r))899 case 8:900 r = int64(int8(r))901 }902 for j := 0; j < s; j++ {903 r >>= 1904 }905 default:906 op = ">>>"907 for j := 0; j < s; j++ {908 r = int64(uint64(r) >> 1)909 }910 }911 // Call function.912 res := fv.Call(args[:])[0].Convert(reflect.ValueOf(r).Type())913 if res.Int() != r {914 t.Errorf("%s%dx%d(%x,%x)=%x, want %x", op, test.valueWidth, test.shiftWidth, n, s, res.Int(), r)915 }916 }917 }918 }919}...

Full Screen

Full Screen

compound.go

Source:compound.go Github

copy

Full Screen

1// run2// Copyright 2015 The Go Authors. All rights reserved.3// Use of this source code is governed by a BSD-style4// license that can be found in the LICENSE file.5// Test compound objects6package main7import "fmt"8func string_ssa(a, b string, x bool) string {9 s := ""10 if x {11 s = a12 } else {13 s = b14 }15 return s16}17func testString() {18 a := "foo"19 b := "barz"20 if want, got := a, string_ssa(a, b, true); got != want {21 fmt.Printf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)22 failed = true23 }24 if want, got := b, string_ssa(a, b, false); got != want {25 fmt.Printf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)26 failed = true27 }28}29//go:noinline30func complex64_ssa(a, b complex64, x bool) complex64 {31 var c complex6432 if x {33 c = a34 } else {35 c = b36 }37 return c38}39//go:noinline40func complex128_ssa(a, b complex128, x bool) complex128 {41 var c complex12842 if x {43 c = a44 } else {45 c = b46 }47 return c48}49func testComplex64() {50 var a complex64 = 1 + 2i51 var b complex64 = 3 + 4i52 if want, got := a, complex64_ssa(a, b, true); got != want {53 fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)54 failed = true55 }56 if want, got := b, complex64_ssa(a, b, false); got != want {57 fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)58 failed = true59 }60}61func testComplex128() {62 var a complex128 = 1 + 2i63 var b complex128 = 3 + 4i64 if want, got := a, complex128_ssa(a, b, true); got != want {65 fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)66 failed = true67 }68 if want, got := b, complex128_ssa(a, b, false); got != want {69 fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)70 failed = true71 }72}73func slice_ssa(a, b []byte, x bool) []byte {74 var s []byte75 if x {76 s = a77 } else {78 s = b79 }80 return s81}82func testSlice() {83 a := []byte{3, 4, 5}84 b := []byte{7, 8, 9}85 if want, got := byte(3), slice_ssa(a, b, true)[0]; got != want {86 fmt.Printf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)87 failed = true88 }89 if want, got := byte(7), slice_ssa(a, b, false)[0]; got != want {90 fmt.Printf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)91 failed = true92 }93}94func interface_ssa(a, b interface{}, x bool) interface{} {95 var s interface{}96 if x {97 s = a98 } else {99 s = b100 }101 return s102}103func testInterface() {104 a := interface{}(3)105 b := interface{}(4)106 if want, got := 3, interface_ssa(a, b, true).(int); got != want {107 fmt.Printf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want)108 failed = true109 }110 if want, got := 4, interface_ssa(a, b, false).(int); got != want {111 fmt.Printf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want)112 failed = true113 }114}115var failed = false116func main() {117 testString()118 testSlice()119 testInterface()120 testComplex64()121 testComplex128()122 if failed {123 panic("failed")124 }125}...

Full Screen

Full Screen

True

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 win.StartLoop()4}5import (6func main() {7 xgb.StartLoop()8}9import (10func main() {11 gotk.StartLoop()12}13import (14func main() {15 gtk.StartLoop()16}17import (18func main() {19 gio.StartLoop()20}

Full Screen

Full Screen

True

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

True

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

True

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(got.True())4}5import (6func main() {7 fmt.Println(got.False())8}9import (10func main() {11 fmt.Println(got.True())12}13import (14func main() {15 fmt.Println(got.False())16}17import (18func main() {19 fmt.Println(got.True())20}21import (22func main() {23 fmt.Println(got.False())24}25import (26func main() {27 fmt.Println(got.True())28}29import (30func main() {31 fmt.Println(got.False())32}33import (34func main() {35 fmt.Println(got.True())36}37import (38func main() {39 fmt.Println(got.False())40}41import (42func main() {43 fmt.Println(got.True())44}45import (46func main() {47 fmt.Println(got.False())

Full Screen

Full Screen

True

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 fmt.Println("Hello, World!")4}5import "fmt"6import "got"7func main(){8 fmt.Println(got.True())9}10import "fmt"11import "got"12func main(){13 fmt.Println(got.False())14}15import "fmt"16import "got"17func main(){18 fmt.Println(got.True())19}20import "fmt"21import "got"22func main(){23 fmt.Println(got.False())24}25import "fmt"26import "got"27func main(){28 fmt.Println(got.True())29}30import "fmt"31import "got"32func main(){33 fmt.Println(got.False())34}35import "fmt"36import "got"37func main(){38 fmt.Println(got.True())39}40import "fmt"41import "got"42func main(){43 fmt.Println(got.False())44}45import "fmt"46import "got"47func main(){48 fmt.Println(got.True())49}50import "fmt"51import "got"52func main(){53 fmt.Println(got.False())54}55import "fmt"56import "got"57func main(){58 fmt.Println(got.True())59}60import "fmt"61import "got"62func main(){63 fmt.Println(got.False())64}

Full Screen

Full Screen

True

Using AI Code Generation

copy

Full Screen

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

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful