| | |
| | |
| | |
| |
|
| | |
| |
|
| | package main |
| |
|
| | import "testing" |
| |
|
| | |
| | func testLoadStoreOrder(t *testing.T) { |
| | z := uint32(1000) |
| | if testLoadStoreOrder_ssa(&z, 100) == 0 { |
| | t.Errorf("testLoadStoreOrder failed") |
| | } |
| | } |
| |
|
| | |
| | func testLoadStoreOrder_ssa(z *uint32, prec uint) int { |
| | old := *z |
| | *z = uint32(prec) |
| | if *z < old { |
| | return 1 |
| | } |
| | return 0 |
| | } |
| |
|
| | func testStoreSize(t *testing.T) { |
| | a := [4]uint16{11, 22, 33, 44} |
| | testStoreSize_ssa(&a[0], &a[2], 77) |
| | want := [4]uint16{77, 22, 33, 44} |
| | if a != want { |
| | t.Errorf("testStoreSize failed. want = %d, got = %d", want, a) |
| | } |
| | } |
| |
|
| | |
| | func testStoreSize_ssa(p *uint16, q *uint16, v uint32) { |
| | |
| | |
| | |
| | |
| | |
| | |
| | w := uint16(v) |
| | if p != nil { |
| | *p = w |
| | } else { |
| | *q = w |
| | } |
| | } |
| |
|
| | |
| | func testExtStore_ssa(p *byte, b bool) int { |
| | x := *p |
| | *p = 7 |
| | if b { |
| | return int(x) |
| | } |
| | return 0 |
| | } |
| |
|
| | func testExtStore(t *testing.T) { |
| | const start = 8 |
| | var b byte = start |
| | if got := testExtStore_ssa(&b, true); got != start { |
| | t.Errorf("testExtStore failed. want = %d, got = %d", start, got) |
| | } |
| | } |
| |
|
| | var b int |
| |
|
| | |
| | |
| | |
| | |
| | func testDeadStorePanic_ssa(a int) (r int) { |
| | defer func() { |
| | recover() |
| | r = a |
| | }() |
| | a = 2 |
| | b := a - a |
| | c := 4 |
| | a = c / b |
| | a = 3 |
| | r = a |
| | return |
| | } |
| |
|
| | func testDeadStorePanic(t *testing.T) { |
| | if want, got := 2, testDeadStorePanic_ssa(1); want != got { |
| | t.Errorf("testDeadStorePanic failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| |
|
| | |
| | func loadHitStore8(x int8, p *int8) int32 { |
| | x *= x |
| | *p = x |
| | return int32(*p) |
| | } |
| |
|
| | |
| | func loadHitStoreU8(x uint8, p *uint8) uint32 { |
| | x *= x |
| | *p = x |
| | return uint32(*p) |
| | } |
| |
|
| | |
| | func loadHitStore16(x int16, p *int16) int32 { |
| | x *= x |
| | *p = x |
| | return int32(*p) |
| | } |
| |
|
| | |
| | func loadHitStoreU16(x uint16, p *uint16) uint32 { |
| | x *= x |
| | *p = x |
| | return uint32(*p) |
| | } |
| |
|
| | |
| | func loadHitStore32(x int32, p *int32) int64 { |
| | x *= x |
| | *p = x |
| | return int64(*p) |
| | } |
| |
|
| | |
| | func loadHitStoreU32(x uint32, p *uint32) uint64 { |
| | x *= x |
| | *p = x |
| | return uint64(*p) |
| | } |
| |
|
| | func testLoadHitStore(t *testing.T) { |
| | |
| | |
| | { |
| | var in int8 = (1 << 6) + 1 |
| | var p int8 |
| | got := loadHitStore8(in, &p) |
| | want := int32(in * in) |
| | if got != want { |
| | t.Errorf("testLoadHitStore (int8) failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| | { |
| | var in uint8 = (1 << 6) + 1 |
| | var p uint8 |
| | got := loadHitStoreU8(in, &p) |
| | want := uint32(in * in) |
| | if got != want { |
| | t.Errorf("testLoadHitStore (uint8) failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| | { |
| | var in int16 = (1 << 10) + 1 |
| | var p int16 |
| | got := loadHitStore16(in, &p) |
| | want := int32(in * in) |
| | if got != want { |
| | t.Errorf("testLoadHitStore (int16) failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| | { |
| | var in uint16 = (1 << 10) + 1 |
| | var p uint16 |
| | got := loadHitStoreU16(in, &p) |
| | want := uint32(in * in) |
| | if got != want { |
| | t.Errorf("testLoadHitStore (uint16) failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| | { |
| | var in int32 = (1 << 30) + 1 |
| | var p int32 |
| | got := loadHitStore32(in, &p) |
| | want := int64(in * in) |
| | if got != want { |
| | t.Errorf("testLoadHitStore (int32) failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| | { |
| | var in uint32 = (1 << 30) + 1 |
| | var p uint32 |
| | got := loadHitStoreU32(in, &p) |
| | want := uint64(in * in) |
| | if got != want { |
| | t.Errorf("testLoadHitStore (uint32) failed. want = %d, got = %d", want, got) |
| | } |
| | } |
| | } |
| |
|
| | func TestLoadStore(t *testing.T) { |
| | testLoadStoreOrder(t) |
| | testStoreSize(t) |
| | testExtStore(t) |
| | testDeadStorePanic(t) |
| | testLoadHitStore(t) |
| | } |
| |
|