Skip to content

Commit 079115e

Browse files
authored
[libclc] Move modf to the CLC library (#127828)
The "generic" unary_(def|decl)_with_ptr files are intended to be re-used by the sincos and fract builtins in the future as they share an identical type signature.
1 parent 3df03db commit 079115e

File tree

8 files changed

+65
-27
lines changed

8 files changed

+65
-27
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef __CLC_MATH_CLC_MODF_H__
2+
#define __CLC_MATH_CLC_MODF_H__
3+
4+
#define __CLC_FUNCTION __clc_modf
5+
#define __CLC_BODY <clc/math/unary_decl_with_ptr.inc>
6+
#include <clc/math/gentype.inc>
7+
8+
#undef __CLC_BODY
9+
#undef __CLC_FUNCTION
10+
11+
#endif // __CLC_MATH_CLC_MODF_H__
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
2+
global __CLC_GENTYPE *ptr);
3+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
4+
local __CLC_GENTYPE *ptr);
5+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE
6+
__CLC_FUNCTION(__CLC_GENTYPE x, private __CLC_GENTYPE *ptr);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <clc/utils.h>
2+
3+
#ifndef __CLC_FUNCTION
4+
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
5+
#endif
6+
7+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
8+
private __CLC_GENTYPE *ptr) {
9+
return __CLC_FUNCTION(FUNCTION)(x, ptr);
10+
}
11+
12+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
13+
global __CLC_GENTYPE *ptr) {
14+
return __CLC_FUNCTION(FUNCTION)(x, ptr);
15+
}
16+
17+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE x,
18+
local __CLC_GENTYPE *ptr) {
19+
return __CLC_FUNCTION(FUNCTION)(x, ptr);
20+
}

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ math/clc_copysign.cl
2222
math/clc_fabs.cl
2323
math/clc_floor.cl
2424
math/clc_mad.cl
25+
math/clc_modf.cl
2526
math/clc_nextafter.cl
2627
math/clc_rint.cl
2728
math/clc_trunc.cl

libclc/generic/include/clc/math/modf.inc renamed to libclc/clc/lib/generic/math/clc_modf.cl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2015 Advanced Micro Devices, Inc.
2+
* Copyright (c) 2015 Advanced Micro Devices, Inc.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -20,6 +20,11 @@
2020
* THE SOFTWARE.
2121
*/
2222

23-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, global __CLC_GENTYPE *iptr);
24-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, local __CLC_GENTYPE *iptr);
25-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE modf(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr);
23+
#include <clc/internal/clc.h>
24+
#include <clc/math/clc_copysign.h>
25+
#include <clc/math/clc_trunc.h>
26+
#include <clc/math/math.h>
27+
#include <clc/relational/clc_isinf.h>
28+
29+
#define __CLC_BODY <clc_modf.inc>
30+
#include <clc/math/gentype.inc>

libclc/generic/lib/math/modf.inc renamed to libclc/clc/lib/generic/math/clc_modf.inc

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,22 @@
1919
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
* THE SOFTWARE.
2121
*/
22-
23-
#if __CLC_FPSIZE == 64
24-
#define ZERO 0.0
25-
#elif __CLC_FPSIZE == 32
26-
#define ZERO 0.0f
27-
#elif __CLC_FPSIZE == 16
28-
#define ZERO 0.0h
29-
#endif
30-
31-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x,
32-
private __CLC_GENTYPE *iptr) {
33-
*iptr = trunc(x);
34-
return copysign(isinf(x) ? ZERO : x - *iptr, x);
22+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_modf(__CLC_GENTYPE x,
23+
private __CLC_GENTYPE *iptr) {
24+
*iptr = __clc_trunc(x);
25+
return __clc_copysign(__clc_isinf(x) ? __CLC_FP_LIT(0.0) : x - *iptr, x);
3526
}
3627

37-
#define MODF_DEF(addrspace) \
38-
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE modf(__CLC_GENTYPE x, \
39-
addrspace __CLC_GENTYPE *iptr) { \
28+
#define CLC_MODF_DEF(addrspace) \
29+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_modf( \
30+
__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \
4031
__CLC_GENTYPE private_iptr; \
41-
__CLC_GENTYPE ret = modf(x, &private_iptr); \
32+
__CLC_GENTYPE ret = __clc_modf(x, &private_iptr); \
4233
*iptr = private_iptr; \
4334
return ret; \
4435
}
4536

46-
MODF_DEF(local);
47-
MODF_DEF(global);
37+
CLC_MODF_DEF(local);
38+
CLC_MODF_DEF(global);
4839

49-
#undef ZERO
40+
#undef CLC_MODF_DEF

libclc/generic/include/clc/math/modf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
* THE SOFTWARE.
2121
*/
2222

23-
#define __CLC_BODY <clc/math/modf.inc>
23+
#define __CLC_FUNCTION modf
24+
#define __CLC_BODY <clc/math/unary_decl_with_ptr.inc>
2425
#include <clc/math/gentype.inc>
26+
27+
#undef __CLC_FUNCTION

libclc/generic/lib/math/modf.cl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
*/
2222

2323
#include <clc/clc.h>
24-
#include <clc/math/math.h>
24+
#include <clc/math/clc_modf.h>
2525

26-
#define __CLC_BODY <modf.inc>
26+
#define FUNCTION modf
27+
#define __CLC_BODY <clc/math/unary_def_with_ptr.inc>
2728
#include <clc/math/gentype.inc>

0 commit comments

Comments
 (0)