math-intrins.ll
7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
; RUN: llc < %s | FileCheck %s
target triple = "nvptx64-nvidia-cuda"
; Checks that llvm intrinsics for math functions are correctly lowered to PTX.
declare float @llvm.ceil.f32(float) #0
declare double @llvm.ceil.f64(double) #0
declare float @llvm.floor.f32(float) #0
declare double @llvm.floor.f64(double) #0
declare float @llvm.round.f32(float) #0
declare double @llvm.round.f64(double) #0
declare float @llvm.nearbyint.f32(float) #0
declare double @llvm.nearbyint.f64(double) #0
declare float @llvm.rint.f32(float) #0
declare double @llvm.rint.f64(double) #0
declare float @llvm.trunc.f32(float) #0
declare double @llvm.trunc.f64(double) #0
declare float @llvm.fabs.f32(float) #0
declare double @llvm.fabs.f64(double) #0
declare float @llvm.minnum.f32(float, float) #0
declare double @llvm.minnum.f64(double, double) #0
declare float @llvm.maxnum.f32(float, float) #0
declare double @llvm.maxnum.f64(double, double) #0
declare float @llvm.fma.f32(float, float, float) #0
declare double @llvm.fma.f64(double, double, double) #0
; ---- ceil ----
; CHECK-LABEL: ceil_float
define float @ceil_float(float %a) {
; CHECK: cvt.rpi.f32.f32
%b = call float @llvm.ceil.f32(float %a)
ret float %b
}
; CHECK-LABEL: ceil_float_ftz
define float @ceil_float_ftz(float %a) #1 {
; CHECK: cvt.rpi.ftz.f32.f32
%b = call float @llvm.ceil.f32(float %a)
ret float %b
}
; CHECK-LABEL: ceil_double
define double @ceil_double(double %a) {
; CHECK: cvt.rpi.f64.f64
%b = call double @llvm.ceil.f64(double %a)
ret double %b
}
; ---- floor ----
; CHECK-LABEL: floor_float
define float @floor_float(float %a) {
; CHECK: cvt.rmi.f32.f32
%b = call float @llvm.floor.f32(float %a)
ret float %b
}
; CHECK-LABEL: floor_float_ftz
define float @floor_float_ftz(float %a) #1 {
; CHECK: cvt.rmi.ftz.f32.f32
%b = call float @llvm.floor.f32(float %a)
ret float %b
}
; CHECK-LABEL: floor_double
define double @floor_double(double %a) {
; CHECK: cvt.rmi.f64.f64
%b = call double @llvm.floor.f64(double %a)
ret double %b
}
; ---- round ----
; CHECK-LABEL: round_float
define float @round_float(float %a) {
; check the use of sign mask and 0.5 to implement round
; CHECK: and.b32 [[R1:%r[0-9]+]], {{.*}}, -2147483648;
; CHECK: or.b32 {{.*}}, [[R1]], 1056964608;
%b = call float @llvm.round.f32(float %a)
ret float %b
}
; CHECK-LABEL: round_float_ftz
define float @round_float_ftz(float %a) #1 {
; check the use of sign mask and 0.5 to implement round
; CHECK: and.b32 [[R1:%r[0-9]+]], {{.*}}, -2147483648;
; CHECK: or.b32 {{.*}}, [[R1]], 1056964608;
%b = call float @llvm.round.f32(float %a)
ret float %b
}
; CHECK-LABEL: round_double
define double @round_double(double %a) {
; check the use of 0.5 to implement round
; CHECK: setp.lt.f64 {{.*}}, [[R:%fd[0-9]+]], 0d3FE0000000000000;
; CHECK: add.rn.f64 {{.*}}, [[R]], 0d3FE0000000000000;
%b = call double @llvm.round.f64(double %a)
ret double %b
}
; ---- nearbyint ----
; CHECK-LABEL: nearbyint_float
define float @nearbyint_float(float %a) {
; CHECK: cvt.rni.f32.f32
%b = call float @llvm.nearbyint.f32(float %a)
ret float %b
}
; CHECK-LABEL: nearbyint_float_ftz
define float @nearbyint_float_ftz(float %a) #1 {
; CHECK: cvt.rni.ftz.f32.f32
%b = call float @llvm.nearbyint.f32(float %a)
ret float %b
}
; CHECK-LABEL: nearbyint_double
define double @nearbyint_double(double %a) {
; CHECK: cvt.rni.f64.f64
%b = call double @llvm.nearbyint.f64(double %a)
ret double %b
}
; ---- rint ----
; CHECK-LABEL: rint_float
define float @rint_float(float %a) {
; CHECK: cvt.rni.f32.f32
%b = call float @llvm.rint.f32(float %a)
ret float %b
}
; CHECK-LABEL: rint_float_ftz
define float @rint_float_ftz(float %a) #1 {
; CHECK: cvt.rni.ftz.f32.f32
%b = call float @llvm.rint.f32(float %a)
ret float %b
}
; CHECK-LABEL: rint_double
define double @rint_double(double %a) {
; CHECK: cvt.rni.f64.f64
%b = call double @llvm.rint.f64(double %a)
ret double %b
}
; ---- trunc ----
; CHECK-LABEL: trunc_float
define float @trunc_float(float %a) {
; CHECK: cvt.rzi.f32.f32
%b = call float @llvm.trunc.f32(float %a)
ret float %b
}
; CHECK-LABEL: trunc_float_ftz
define float @trunc_float_ftz(float %a) #1 {
; CHECK: cvt.rzi.ftz.f32.f32
%b = call float @llvm.trunc.f32(float %a)
ret float %b
}
; CHECK-LABEL: trunc_double
define double @trunc_double(double %a) {
; CHECK: cvt.rzi.f64.f64
%b = call double @llvm.trunc.f64(double %a)
ret double %b
}
; ---- abs ----
; CHECK-LABEL: abs_float
define float @abs_float(float %a) {
; CHECK: abs.f32
%b = call float @llvm.fabs.f32(float %a)
ret float %b
}
; CHECK-LABEL: abs_float_ftz
define float @abs_float_ftz(float %a) #1 {
; CHECK: abs.ftz.f32
%b = call float @llvm.fabs.f32(float %a)
ret float %b
}
; CHECK-LABEL: abs_double
define double @abs_double(double %a) {
; CHECK: abs.f64
%b = call double @llvm.fabs.f64(double %a)
ret double %b
}
; ---- min ----
; CHECK-LABEL: min_float
define float @min_float(float %a, float %b) {
; CHECK: min.f32
%x = call float @llvm.minnum.f32(float %a, float %b)
ret float %x
}
; CHECK-LABEL: min_imm1
define float @min_imm1(float %a) {
; CHECK: min.f32
%x = call float @llvm.minnum.f32(float %a, float 0.0)
ret float %x
}
; CHECK-LABEL: min_imm2
define float @min_imm2(float %a) {
; CHECK: min.f32
%x = call float @llvm.minnum.f32(float 0.0, float %a)
ret float %x
}
; CHECK-LABEL: min_float_ftz
define float @min_float_ftz(float %a, float %b) #1 {
; CHECK: min.ftz.f32
%x = call float @llvm.minnum.f32(float %a, float %b)
ret float %x
}
; CHECK-LABEL: min_double
define double @min_double(double %a, double %b) {
; CHECK: min.f64
%x = call double @llvm.minnum.f64(double %a, double %b)
ret double %x
}
; ---- max ----
; CHECK-LABEL: max_imm1
define float @max_imm1(float %a) {
; CHECK: max.f32
%x = call float @llvm.maxnum.f32(float %a, float 0.0)
ret float %x
}
; CHECK-LABEL: max_imm2
define float @max_imm2(float %a) {
; CHECK: max.f32
%x = call float @llvm.maxnum.f32(float 0.0, float %a)
ret float %x
}
; CHECK-LABEL: max_float
define float @max_float(float %a, float %b) {
; CHECK: max.f32
%x = call float @llvm.maxnum.f32(float %a, float %b)
ret float %x
}
; CHECK-LABEL: max_float_ftz
define float @max_float_ftz(float %a, float %b) #1 {
; CHECK: max.ftz.f32
%x = call float @llvm.maxnum.f32(float %a, float %b)
ret float %x
}
; CHECK-LABEL: max_double
define double @max_double(double %a, double %b) {
; CHECK: max.f64
%x = call double @llvm.maxnum.f64(double %a, double %b)
ret double %x
}
; ---- fma ----
; CHECK-LABEL: @fma_float
define float @fma_float(float %a, float %b, float %c) {
; CHECK: fma.rn.f32
%x = call float @llvm.fma.f32(float %a, float %b, float %c)
ret float %x
}
; CHECK-LABEL: @fma_float_ftz
define float @fma_float_ftz(float %a, float %b, float %c) #1 {
; CHECK: fma.rn.ftz.f32
%x = call float @llvm.fma.f32(float %a, float %b, float %c)
ret float %x
}
; CHECK-LABEL: @fma_double
define double @fma_double(double %a, double %b, double %c) {
; CHECK: fma.rn.f64
%x = call double @llvm.fma.f64(double %a, double %b, double %c)
ret double %x
}
attributes #0 = { nounwind readnone }
attributes #1 = { "nvptx-f32ftz" = "true" }