Skip to content

Commit 53f5bfd

Browse files
committed
[libc][libm][GPU] Populating 'libmgpu.a' for math on the GPU
This commit populates `libmgpu.a` with wrappers for the following built-ins - modf, modff - nearbyint, nearbyintf - remainder, remainderf - remquo, remquof - rint, rintf - scalbn, scalbnf - sqrt, sqrtf - tan, tanf - tanh, tanhf - trunc, truncf and wrappers the following vendor implementations - nextafter, nextafterf - sincos, sincosf - sinh, sinhf - sinf - tan, tanf - tanh, tanhf Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D153395
1 parent 5754f5a commit 53f5bfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1027
-10
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,32 @@ set(TARGET_LIBM_ENTRYPOINTS
150150
libc.src.math.pow
151151
libc.src.math.powf
152152
libc.src.math.sin
153+
libc.src.math.modf
154+
libc.src.math.modff
155+
libc.src.math.nearbyint
156+
libc.src.math.nearbyintf
157+
libc.src.math.nextafter
158+
libc.src.math.nextafterf
159+
libc.src.math.remainder
160+
libc.src.math.remainderf
161+
libc.src.math.remquo
162+
libc.src.math.remquof
163+
libc.src.math.rint
164+
libc.src.math.rintf
153165
libc.src.math.round
154166
libc.src.math.roundf
155-
libc.src.math.roundl
167+
libc.src.math.scalbn
168+
libc.src.math.scalbnf
169+
libc.src.math.sinh
170+
libc.src.math.sinhf
171+
libc.src.math.sqrt
172+
libc.src.math.sqrtf
173+
libc.src.math.tan
174+
libc.src.math.tanf
175+
libc.src.math.tanh
176+
libc.src.math.tanhf
177+
libc.src.math.trunc
178+
libc.src.math.truncf
156179
)
157180

158181
set(TARGET_LLVMLIBC_ENTRYPOINTS

libc/src/math/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ add_math_entrypoint_object(sincosf)
198198

199199
add_math_entrypoint_object(sin)
200200
add_math_entrypoint_object(sinf)
201+
202+
add_math_entrypoint_object(sinh)
201203
add_math_entrypoint_object(sinhf)
202204

203205
add_math_entrypoint_object(sqrt)
@@ -206,6 +208,8 @@ add_math_entrypoint_object(sqrtl)
206208

207209
add_math_entrypoint_object(tan)
208210
add_math_entrypoint_object(tanf)
211+
212+
add_math_entrypoint_object(tanh)
209213
add_math_entrypoint_object(tanhf)
210214

211215
add_math_entrypoint_object(trunc)

libc/src/math/gpu/CMakeLists.txt

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,106 @@ add_math_entrypoint_gpu_object(
203203
-O2
204204
)
205205

206+
add_math_entrypoint_gpu_object(
207+
modf
208+
SRCS
209+
modf.cpp
210+
HDRS
211+
../modf.h
212+
COMPILE_OPTIONS
213+
-O2
214+
)
215+
216+
add_math_entrypoint_gpu_object(
217+
modff
218+
SRCS
219+
modff.cpp
220+
HDRS
221+
../modff.h
222+
COMPILE_OPTIONS
223+
-O2
224+
)
225+
226+
add_math_entrypoint_gpu_object(
227+
nearbyint
228+
SRCS
229+
nearbyint.cpp
230+
HDRS
231+
../nearbyint.h
232+
COMPILE_OPTIONS
233+
-O2
234+
)
235+
236+
add_math_entrypoint_gpu_object(
237+
nearbyintf
238+
SRCS
239+
nearbyintf.cpp
240+
HDRS
241+
../nearbyintf.h
242+
COMPILE_OPTIONS
243+
-O2
244+
)
245+
246+
add_math_entrypoint_gpu_object(
247+
remainder
248+
SRCS
249+
remainder.cpp
250+
HDRS
251+
../remainder.h
252+
COMPILE_OPTIONS
253+
-O2
254+
)
255+
256+
add_math_entrypoint_gpu_object(
257+
remainderf
258+
SRCS
259+
remainderf.cpp
260+
HDRS
261+
../remainderf.h
262+
COMPILE_OPTIONS
263+
-O2
264+
)
265+
266+
add_math_entrypoint_gpu_object(
267+
remquo
268+
SRCS
269+
remquo.cpp
270+
HDRS
271+
../remquo.h
272+
COMPILE_OPTIONS
273+
-O2
274+
)
275+
276+
add_math_entrypoint_gpu_object(
277+
remquof
278+
SRCS
279+
remquof.cpp
280+
HDRS
281+
../remquof.h
282+
COMPILE_OPTIONS
283+
-O2
284+
)
285+
286+
add_math_entrypoint_gpu_object(
287+
rint
288+
SRCS
289+
rint.cpp
290+
HDRS
291+
../rint.h
292+
COMPILE_OPTIONS
293+
-O2
294+
)
295+
296+
add_math_entrypoint_gpu_object(
297+
rintf
298+
SRCS
299+
rintf.cpp
300+
HDRS
301+
../rintf.h
302+
COMPILE_OPTIONS
303+
-O2
304+
)
305+
206306
add_math_entrypoint_gpu_object(
207307
round
208308
SRCS
@@ -212,3 +312,123 @@ add_math_entrypoint_gpu_object(
212312
COMPILE_OPTIONS
213313
-O2
214314
)
315+
316+
add_math_entrypoint_gpu_object(
317+
scalbn
318+
SRCS
319+
scalbn.cpp
320+
HDRS
321+
../scalbn.h
322+
COMPILE_OPTIONS
323+
-O2
324+
)
325+
326+
add_math_entrypoint_gpu_object(
327+
scalbnf
328+
SRCS
329+
scalbnf.cpp
330+
HDRS
331+
../scalbnf.h
332+
COMPILE_OPTIONS
333+
-O2
334+
)
335+
336+
add_math_entrypoint_gpu_object(
337+
sinh
338+
SRCS
339+
sinh.cpp
340+
HDRS
341+
../sinh.h
342+
COMPILE_OPTIONS
343+
-O2
344+
)
345+
346+
add_math_entrypoint_gpu_object(
347+
sinhf
348+
SRCS
349+
sinhf.cpp
350+
HDRS
351+
../sinhf.h
352+
COMPILE_OPTIONS
353+
-O2
354+
)
355+
356+
add_math_entrypoint_gpu_object(
357+
sqrt
358+
SRCS
359+
sqrt.cpp
360+
HDRS
361+
../sqrt.h
362+
COMPILE_OPTIONS
363+
-O2
364+
)
365+
366+
add_math_entrypoint_gpu_object(
367+
sqrtf
368+
SRCS
369+
sqrtf.cpp
370+
HDRS
371+
../sqrtf.h
372+
COMPILE_OPTIONS
373+
-O2
374+
)
375+
376+
add_math_entrypoint_gpu_object(
377+
tan
378+
SRCS
379+
tan.cpp
380+
HDRS
381+
../tan.h
382+
COMPILE_OPTIONS
383+
-O2
384+
)
385+
386+
add_math_entrypoint_gpu_object(
387+
tanf
388+
SRCS
389+
tanf.cpp
390+
HDRS
391+
../tanf.h
392+
COMPILE_OPTIONS
393+
-O2
394+
)
395+
396+
add_math_entrypoint_gpu_object(
397+
tanh
398+
SRCS
399+
tanh.cpp
400+
HDRS
401+
../tanh.h
402+
COMPILE_OPTIONS
403+
-O2
404+
)
405+
406+
add_math_entrypoint_gpu_object(
407+
tanhf
408+
SRCS
409+
tanhf.cpp
410+
HDRS
411+
../tanhf.h
412+
COMPILE_OPTIONS
413+
-O2
414+
)
415+
416+
add_math_entrypoint_gpu_object(
417+
trunc
418+
SRCS
419+
trunc.cpp
420+
HDRS
421+
../trunc.h
422+
COMPILE_OPTIONS
423+
-O2
424+
)
425+
426+
add_math_entrypoint_gpu_object(
427+
truncf
428+
SRCS
429+
truncf.cpp
430+
HDRS
431+
../truncf.h
432+
COMPILE_OPTIONS
433+
-O2
434+
)

libc/src/math/gpu/modf.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of the GPU modf function ---------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/modf.h"
10+
#include "src/__support/common.h"
11+
12+
namespace __llvm_libc {
13+
14+
LLVM_LIBC_FUNCTION(double, modf, (double x, double *iptr)) {
15+
return __builtin_modf(x, iptr);
16+
}
17+
18+
} // namespace __llvm_libc

libc/src/math/gpu/modff.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of the GPU modff function --------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/modff.h"
10+
#include "src/__support/common.h"
11+
12+
namespace __llvm_libc {
13+
14+
LLVM_LIBC_FUNCTION(float, modff, (float x, float *iptr)) {
15+
return __builtin_modff(x, iptr);
16+
}
17+
18+
} // namespace __llvm_libc

libc/src/math/gpu/nearbyint.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of the GPU nearbyint function ----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/nearbyint.h"
10+
#include "src/__support/common.h"
11+
12+
namespace __llvm_libc {
13+
14+
LLVM_LIBC_FUNCTION(double, nearbyint, (double x)) {
15+
return __builtin_nearbyint(x);
16+
}
17+
18+
} // namespace __llvm_libc

libc/src/math/gpu/nearbyintf.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of the GPU nearbyintf function ---------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/nearbyintf.h"
10+
#include "src/__support/common.h"
11+
12+
namespace __llvm_libc {
13+
14+
LLVM_LIBC_FUNCTION(float, nearbyintf, (float x)) {
15+
return __builtin_nearbyintf(x);
16+
}
17+
18+
} // namespace __llvm_libc

libc/src/math/gpu/remainder.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of the GPU remainder function ----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/remainder.h"
10+
#include "src/__support/common.h"
11+
12+
namespace __llvm_libc {
13+
14+
LLVM_LIBC_FUNCTION(double, remainder, (double x, double y)) {
15+
return __builtin_remainder(x, y);
16+
}
17+
18+
} // namespace __llvm_libc

libc/src/math/gpu/remainderf.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Implementation of the GPU remainderf function ---------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/remainderf.h"
10+
#include "src/__support/common.h"
11+
12+
namespace __llvm_libc {
13+
14+
LLVM_LIBC_FUNCTION(float, remainderf, (float x, float y)) {
15+
return __builtin_remainderf(x, y);
16+
}
17+
18+
} // namespace __llvm_libc

0 commit comments

Comments
 (0)