]> Cypherpunks.ru repositories - gostls13.git/blob - test/armimm.go
cmd/internal/obj: ARM, use immediates instead of constant pool entries
[gostls13.git] / test / armimm.go
1 // run
2
3 // Copyright 2017 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // This file tests the splitting of constants into
8 // multiple immediates on arm.
9
10 package main
11
12 import "fmt"
13
14 const c32 = 0xaa00dd
15 const c64 = 0xaa00dd55000066
16
17 //go:noinline
18 func add32(x uint32) uint32 {
19         return x + c32
20 }
21
22 //go:noinline
23 func sub32(x uint32) uint32 {
24         return x - c32
25 }
26
27 //go:noinline
28 func or32(x uint32) uint32 {
29         return x | c32
30 }
31
32 //go:noinline
33 func xor32(x uint32) uint32 {
34         return x ^ c32
35 }
36
37 //go:noinline
38 func subr32(x uint32) uint32 {
39         return c32 - x
40 }
41
42 //go:noinline
43 func add64(x uint64) uint64 {
44         return x + c64
45 }
46
47 //go:noinline
48 func sub64(x uint64) uint64 {
49         return x - c64
50 }
51
52 //go:noinline
53 func or64(x uint64) uint64 {
54         return x | c64
55 }
56
57 //go:noinline
58 func xor64(x uint64) uint64 {
59         return x ^ c64
60 }
61
62 //go:noinline
63 func subr64(x uint64) uint64 {
64         return c64 - x
65 }
66
67 // Note: x-c gets rewritten to x+(-c), so SUB and SBC are not directly testable.
68 // I disabled that rewrite rule before running this test.
69
70 func main() {
71         test32()
72         test64()
73 }
74
75 func test32() {
76         var a uint32 = 0x11111111
77         var want, got uint32
78         if want, got = a+c32, add32(a); got != want {
79                 panic(fmt.Sprintf("add32(%x) = %x, want %x", a, got, want))
80         }
81         if want, got = a-c32, sub32(a); got != want {
82                 panic(fmt.Sprintf("sub32(%x) = %x, want %x", a, got, want))
83         }
84         if want, got = a|c32, or32(a); got != want {
85                 panic(fmt.Sprintf("or32(%x) = %x, want %x", a, got, want))
86         }
87         if want, got = a^c32, xor32(a); got != want {
88                 panic(fmt.Sprintf("xor32(%x) = %x, want %x", a, got, want))
89         }
90         if want, got = c32-a, subr32(a); got != want {
91                 panic(fmt.Sprintf("subr32(%x) = %x, want %x", a, got, want))
92         }
93 }
94
95 func test64() {
96         var a uint64 = 0x1111111111111111
97         var want, got uint64
98         if want, got = a+c64, add64(a); got != want {
99                 panic(fmt.Sprintf("add64(%x) = %x, want %x", a, got, want))
100         }
101         if want, got = a-c64, sub64(a); got != want {
102                 panic(fmt.Sprintf("sub64(%x) = %x, want %x", a, got, want))
103         }
104         if want, got = a|c64, or64(a); got != want {
105                 panic(fmt.Sprintf("or64(%x) = %x, want %x", a, got, want))
106         }
107         if want, got = a^c64, xor64(a); got != want {
108                 panic(fmt.Sprintf("xor64(%x) = %x, want %x", a, got, want))
109         }
110         if want, got = c64-a, subr64(a); got != want {
111                 panic(fmt.Sprintf("subr64(%x) = %x, want %x", a, got, want))
112         }
113 }