summaryrefslogtreecommitdiff
path: root/src/runtime/builtins.def
blob: 24da33d882fddc8558b0a1499976736110e624d3 (plain)
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def vecf : float2 float3 float4 float8 float16
def veci : int2 int3 int4 int8 int16

def vec : $vecf $veci
def gentype : float $vecf

// gentype acos(gentype)
// REPL is defined in src/core/cpu/builtins.cpp
native float acos float : x:float
    return std::acos(x);
end

native $type acos $vecf : x:$type
    REPL($vecdim)
        result[i] = std::acos(x[i]);
end

// gentype acosh(gentype)
native float acosh float : x:float
    return boost::math::acosh(x);
end

native $type acosh $vecf : x:$type
    REPL($vecdim)
        result[i] = boost::math::acosh(x[i]);
end

// gentype acospi(gentype)
func float acospi float : x:float
    return acos(x) / M_PI;
end

native $type acospi $vecf : x:$type
    REPL($vecdim)
        result[i] = std::acos(x[i]) / M_PI;
end

// gentype asin (gentype)
native float asin float : x:float
    return std::asin(x);
end

native $type asin $vecf : x:$type
    REPL($vecdim)
        result[i] = std::asin(x[i]);
end

// gentype asinh (gentype)
native float asinh float : x:float
    return boost::math::asinh(x);
end

native $type asinh $vecf : x:$type
    REPL($vecdim)
        result[i] = boost::math::asinh(x[i]);
end

// gentype asinpi (gentype x)
func float asinpi float : x:float
    return asin(x) / M_PI;
end

native $type asinpi $vecf : x:$type
    REPL($vecdim)
        result[i] = std::asin(x[i]) / M_PI;
end

// gentype atan (gentype y_over_x)
native float atan float : y_over_x:float
    return std::atan(y_over_x);
end

native $type atan $vecf : y_over_x:$type
    REPL($vecdim)
        result[i] = std::atan(y_over_x[i]);
end

// gentype atan2 (gentype y, gentype x)
func float atan2 float : x:float y:float
    return atan(y / x);
end

native $type atan2 $vecf : x:$type y:$type
    REPL($vecdim)
        result[i] = std::atan(y[i] / x[i]);
end

// gentype atanh (gentype)
native float atanh float : x:float
    return boost::math::atanh(x);
end

native $type atanh $vecf : x:$type
    REPL($vecdim)
        result[i] = boost::math::atanh(x[i]);
end

// gentype atanpi (gentype x)
func float atanpi float : x:float
    return atan(x) / M_PI;
end

native $type atanpi $vecf : x:$type
    REPL($vecdim)
        result[i] = std::atan(x[i]) / M_PI;
end

// gentype atan2pi (gentype y, gentype x)
func float atan2pi float : x:float y:float
    return atan2(y, x) / M_PI;
end

native $type atan2pi $vecf : x:$type y:$type
    REPL($vecdim)
        result[i] = std::atan(y[i] / x[i]) / M_PI;
end

// gentype cbrt (gentype)
native float cbrt float : x:float
    return boost::math::cbrt(x);
end

native $type cbrt $vecf : x:$type
    REPL($vecdim)
        result[i] = boost::math::cbrt(x[i]);
end

// gentype ceil (gentype)
native float ceil float : x:float
    return std::ceil(x);
end

native $type ceil $vecf : x:$type
    REPL($vecdim)
        result[i] = std::ceil(x[i]);
end

// gentype copysign (gentype x, gentype y)
func $type copysign $gentype : x:$type y:$type
    return (
            (x < 0.0f & y > 0.0f) |
            (x > 0.0f & y < 0.0f)
           ? -x : x);
end

//gentype cos (gentype)
native float cos float : x:float
    return std::cos(x);
end

native $type cos $vecf : x:$type
    REPL($vecdim)
        result[i] = std::cos(x[i]);
end

// gentype cosh (gentype)
native float cosh float : x:float
    return std::cosh(x);
end

native $type cosh $vecf : x:$type
    REPL($vecdim)
        result[i] = std::cosh(x[i]);
end

// gentype cospi (gentype x)
func $type cospi $gentype : x:$type
    return cos(x * (float)M_PI);
end

// TODO: gentype erfc (gentype)
// TODO: gentype erf (gentype)

// gentype exp(gentype x)
native float exp float : x:float
    return std::exp(x);
end

native $type exp $vecf : x:$type
    REPL($vecdim)
        result[i] = std::exp(x[i]);
end

// gentype exp2(gentype x)
native float exp2 float : x:float
    return exp2f(x);
end

native $type exp2 $vecf : x:$type
    REPL($vecdim)
        result[i] = exp2f(x[i]);
end

// gentype exp10(gentype x)
native float exp10 float : x:float
    return exp10f(x);
end

native $type exp10 $vecf : x:$type
    REPL($vecdim)
        result[i] = exp10f(x[i]);
end

// gentype expm1(gentype x)
func $type expm1 $gentype : x:$type
    return exp(x) - 1.0f;
end

// gentype fabs(gentype x)
func $type fabs $gentype : x:$type
    return (x < 0.0f ? -x : x);
end

// gentype fdim(x, y)
func $type fdim $gentype : x:$type y:$type
    return (x > y ? x - y : 0.0f);
end

// gentype floor(gentype x) (TODO: SSE fast path : float->int->float)
native float floor float : x:float
    return std::floor(x);
end

native $type floor $vecf : x:$type
    REPL($vecdim)
        result[i] = std::floor(x[i]);
end

// gentype fma(a, b, c) : a*b + c (TODO)
func $type fma $gentype : a:$type b:$type c:$type
    return (a * b) + c;
end

// gentype fmax(x, y)
func $type fmax $gentype : x:$type y:$type
    return (x > y ? x : y);
end

// gentype fmin(x, y)
func $type fmin $gentype : x:$type y:$type
    return (x < y ? x : y);
end

// gentype trunc(x)
native float trunc float : x:float
    return boost::math::trunc(x);
end

native $type trunc $vecf : x:$type
    REPL($vecdim)
        result[i] = boost::math::trunc(x[i]);
end

// gentype fmod(x, y)
func $type fmod $gentype : x:$type y:$type
    return x - y * trunc(x / y);
end

// gentype fract(gentype x, gentype *iptr)
func $type fract $gentype : x:$type iptr:*$type
    *iptr = floor(x);
    return fmin(x - *iptr, 0x1.fffffep-1f);
end

// gentype frexp(gentype x, intn *exp)
native float frexp float : x:float exp:*int
    return std::frexp(x, exp);
end

native $type frexp $vecf : x:$type exp:*int$vecdim
    REPL($vecdim)
        result[i] = std::frexp(x[i], &exp[i]);
end

// gentype sqrt(gentype x)
native float sqrt float : x:float
    return std::sqrt(x);
end

native $type sqrt $vecf : x:$type
    REPL($vecdim)
        result[i] = std::sqrt(x[i]);
end

// gentype hypot(gentype x, gentype y)
func $type hypot $gentype : x:$type y:$type
    return sqrt(x*x + y*y);
end

// intn ilogb(gentype x)
native int ilogb float : x:float
    return ilogb(x);
end

native int$vecdim ilogb $vecf : x:$type
    REPL($vecdim)
        result[i] = ilogb(x[i]);
end

// gentype ldexp(gentype x, intn n)
native float ldexp float : x:float n:int
    return std::ldexp(x, n);
end

native $type ldexp $vecf : x:$type n:int$vecdim
    REPL($vecdim)
        result[i] = std::ldexp(x[i], n[i]);
end