]> Cypherpunks.ru repositories - gostls13.git/blob - test/codegen/bool.go
109c3aa0cd67734dac72d684a1b775a594102f10
[gostls13.git] / test / codegen / bool.go
1 // asmcheck
2
3 // Copyright 2020 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 package codegen
8
9 // This file contains codegen tests related to boolean simplifications/optimizations.
10
11 func convertNeq0B(x uint8, c bool) bool {
12         // amd64:"ANDL\t[$]1",-"SETNE"
13         // ppc64x:"RLDICL",-"CMPW",-"ISEL"
14         b := x&1 != 0
15         return c && b
16 }
17
18 func convertNeq0W(x uint16, c bool) bool {
19         // amd64:"ANDL\t[$]1",-"SETNE"
20         // ppc64x:"RLDICL",-"CMPW",-"ISEL"
21         b := x&1 != 0
22         return c && b
23 }
24
25 func convertNeq0L(x uint32, c bool) bool {
26         // amd64:"ANDL\t[$]1",-"SETB"
27         // ppc64x:"RLDICL",-"CMPW",-"ISEL"
28         b := x&1 != 0
29         return c && b
30 }
31
32 func convertNeq0Q(x uint64, c bool) bool {
33         // amd64:"ANDL\t[$]1",-"SETB"
34         // ppc64x:"RLDICL",-"CMP",-"ISEL"
35         b := x&1 != 0
36         return c && b
37 }
38
39 func convertNeqBool32(x uint32) bool {
40         // ppc64x:"RLDICL",-"CMPW",-"ISEL"
41         return x&1 != 0
42 }
43
44 func convertEqBool32(x uint32) bool {
45         // ppc64x:"RLDICL",-"CMPW","XOR",-"ISEL"
46         return x&1 == 0
47 }
48
49 func convertNeqBool64(x uint64) bool {
50         // ppc64x:"RLDICL",-"CMP",-"ISEL"
51         return x&1 != 0
52 }
53
54 func convertEqBool64(x uint64) bool {
55         // ppc64x:"RLDICL","XOR",-"CMP",-"ISEL"
56         return x&1 == 0
57 }
58
59 func TestSetEq64(x uint64, y uint64) bool {
60         // ppc64x/power10:"SETBC\tCR0EQ",-"ISEL"
61         // ppc64x/power9:"CMP","ISEL",-"SETBC\tCR0EQ"
62         // ppc64x/power8:"CMP","ISEL",-"SETBC\tCR0EQ"
63         b := x == y
64         return b
65 }
66 func TestSetNeq64(x uint64, y uint64) bool {
67         // ppc64x/power10:"SETBCR\tCR0EQ",-"ISEL"
68         // ppc64x/power9:"CMP","ISEL",-"SETBCR\tCR0EQ"
69         // ppc64x/power8:"CMP","ISEL",-"SETBCR\tCR0EQ"
70         b := x != y
71         return b
72 }
73 func TestSetLt64(x uint64, y uint64) bool {
74         // ppc64x/power10:"SETBC\tCR0GT",-"ISEL"
75         // ppc64x/power9:"CMP","ISEL",-"SETBC\tCR0GT"
76         // ppc64x/power8:"CMP","ISEL",-"SETBC\tCR0GT"
77         b := x < y
78         return b
79 }
80 func TestSetLe64(x uint64, y uint64) bool {
81         // ppc64x/power10:"SETBCR\tCR0LT",-"ISEL"
82         // ppc64x/power9:"CMP","ISEL",-"SETBCR\tCR0LT"
83         // ppc64x/power8:"CMP","ISEL",-"SETBCR\tCR0LT"
84         b := x <= y
85         return b
86 }
87 func TestSetGt64(x uint64, y uint64) bool {
88         // ppc64x/power10:"SETBC\tCR0LT",-"ISEL"
89         // ppc64x/power9:"CMP","ISEL",-"SETBC\tCR0LT"
90         // ppc64x/power8:"CMP","ISEL",-"SETBC\tCR0LT"
91         b := x > y
92         return b
93 }
94 func TestSetGe64(x uint64, y uint64) bool {
95         // ppc64x/power10:"SETBCR\tCR0GT",-"ISEL"
96         // ppc64x/power9:"CMP","ISEL",-"SETBCR\tCR0GT"
97         // ppc64x/power8:"CMP","ISEL",-"SETBCR\tCR0GT"
98         b := x >= y
99         return b
100 }
101 func TestSetLtFp64(x float64, y float64) bool {
102         // ppc64x/power10:"SETBC\tCR0LT",-"ISEL"
103         // ppc64x/power9:"FCMP","ISEL",-"SETBC\tCR0LT"
104         // ppc64x/power8:"FCMP","ISEL",-"SETBC\tCR0LT"
105         b := x < y
106         return b
107 }
108 func TestSetLeFp64(x float64, y float64) bool {
109         // ppc64x/power10:"SETBC\tCR0LT","SETBC\tCR0EQ","OR",-"ISEL",-"ISEL"
110         // ppc64x/power9:"ISEL","ISEL",-"SETBC\tCR0LT",-"SETBC\tCR0EQ","OR"
111         // ppc64x/power8:"ISEL","ISEL",-"SETBC\tCR0LT",-"SETBC\tCR0EQ","OR"
112         b := x <= y
113         return b
114 }
115 func TestSetGtFp64(x float64, y float64) bool {
116         // ppc64x/power10:"SETBC\tCR0LT",-"ISEL"
117         // ppc64x/power9:"FCMP","ISEL",-"SETBC\tCR0LT"
118         // ppc64x/power8:"FCMP","ISEL",-"SETBC\tCR0LT"
119         b := x > y
120         return b
121 }
122 func TestSetGeFp64(x float64, y float64) bool {
123         // ppc64x/power10:"SETBC\tCR0LT","SETBC\tCR0EQ","OR",-"ISEL",-"ISEL"
124         // ppc64x/power9:"ISEL","ISEL",-"SETBC\tCR0LT",-"SETBC\tCR0EQ","OR"
125         // ppc64x/power8:"ISEL","ISEL",-"SETBC\tCR0LT",-"SETBC\tCR0EQ","OR"
126         b := x >= y
127         return b
128 }
129 func TestSetInvEq64(x uint64, y uint64) bool {
130         // ppc64x/power10:"SETBCR\tCR0EQ",-"ISEL"
131         // ppc64x/power9:"CMP","ISEL",-"SETBCR\tCR0EQ"
132         // ppc64x/power8:"CMP","ISEL",-"SETBCR\tCR0EQ"
133         b := !(x == y)
134         return b
135 }
136 func TestSetInvNeq64(x uint64, y uint64) bool {
137         // ppc64x/power10:"SETBC\tCR0EQ",-"ISEL"
138         // ppc64x/power9:"CMP","ISEL",-"SETBC\tCR0EQ"
139         // ppc64x/power8:"CMP","ISEL",-"SETBC\tCR0EQ"
140         b := !(x != y)
141         return b
142 }
143 func TestSetInvLt64(x uint64, y uint64) bool {
144         // ppc64x/power10:"SETBCR\tCR0GT",-"ISEL"
145         // ppc64x/power9:"CMP","ISEL",-"SETBCR\tCR0GT"
146         // ppc64x/power8:"CMP","ISEL",-"SETBCR\tCR0GT"
147         b := !(x < y)
148         return b
149 }
150 func TestSetInvLe64(x uint64, y uint64) bool {
151         // ppc64x/power10:"SETBC\tCR0LT",-"ISEL"
152         // ppc64x/power9:"CMP","ISEL",-"SETBC\tCR0LT"
153         // ppc64x/power8:"CMP","ISEL",-"SETBC\tCR0LT"
154         b := !(x <= y)
155         return b
156 }
157 func TestSetInvGt64(x uint64, y uint64) bool {
158         // ppc64x/power10:"SETBCR\tCR0LT",-"ISEL"
159         // ppc64x/power9:"CMP","ISEL",-"SETBCR\tCR0LT"
160         // ppc64x/power8:"CMP","ISEL",-"SETBCR\tCR0LT"
161         b := !(x > y)
162         return b
163 }
164 func TestSetInvGe64(x uint64, y uint64) bool {
165         // ppc64x/power10:"SETBC\tCR0GT",-"ISEL"
166         // ppc64x/power9:"CMP","ISEL",-"SETBC\tCR0GT"
167         // ppc64x/power8:"CMP","ISEL",-"SETBC\tCR0GT"
168         b := !(x >= y)
169         return b
170 }
171
172 func TestSetInvEqFp64(x float64, y float64) bool {
173         // ppc64x/power10:"SETBCR\tCR0EQ",-"ISEL"
174         // ppc64x/power9:"FCMP","ISEL",-"SETBCR\tCR0EQ"
175         // ppc64x/power8:"FCMP","ISEL",-"SETBCR\tCR0EQ"
176         b := !(x == y)
177         return b
178 }
179 func TestSetInvNeqFp64(x float64, y float64) bool {
180         // ppc64x/power10:"SETBC\tCR0EQ",-"ISEL"
181         // ppc64x/power9:"FCMP","ISEL",-"SETBC\tCR0EQ"
182         // ppc64x/power8:"FCMP","ISEL",-"SETBC\tCR0EQ"
183         b := !(x != y)
184         return b
185 }
186 func TestSetInvLtFp64(x float64, y float64) bool {
187         // ppc64x/power10:"SETBCR\tCR0LT",-"ISEL"
188         // ppc64x/power9:"FCMP","ISEL",-"SETBCR\tCR0LT"
189         // ppc64x/power8:"FCMP","ISEL",-"SETBCR\tCR0LT"
190         b := !(x < y)
191         return b
192 }
193 func TestSetInvLeFp64(x float64, y float64) bool {
194         // ppc64x/power10:"SETBC\tCR0LT",-"ISEL"
195         // ppc64x/power9:"FCMP","ISEL",-"SETBC\tCR0LT"
196         // ppc64x/power8:"FCMP","ISEL",-"SETBC\tCR0LT"
197         b := !(x <= y)
198         return b
199 }
200 func TestSetInvGtFp64(x float64, y float64) bool {
201         // ppc64x/power10:"SETBCR\tCR0LT",-"ISEL"
202         // ppc64x/power9:"FCMP","ISEL",-"SETBCR\tCR0LT"
203         // ppc64x/power8:"FCMP","ISEL",-"SETBCR\tCR0LT"
204         b := !(x > y)
205         return b
206 }
207 func TestSetInvGeFp64(x float64, y float64) bool {
208         // ppc64x/power10:"SETBC\tCR0LT",-"ISEL"
209         // ppc64x/power9:"FCMP","ISEL",-"SETBC\tCR0LT"
210         // ppc64x/power8:"FCMP","ISEL",-"SETBC\tCR0LT"
211         b := !(x >= y)
212         return b
213 }
214 func TestAndCompareZero(x uint64, y uint64) uint64 {
215         // ppc64x:"ANDCC"
216         b := x&3
217         if b!=0 {
218                 return b
219         }
220         return b+8
221 }