Skip to content

Commit 78b5bb7

Browse files
authored
[libclc][NFC] Move key math headers to CLC (#124739)
1 parent 3a975d6 commit 78b5bb7

Some content is hidden

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

66 files changed

+178
-212
lines changed

libclc/generic/include/config.h renamed to libclc/clc/include/clc/math/clc_subnormal_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
* THE SOFTWARE.
2121
*/
22+
#ifndef __CLC_MATH_CLC_SUBNORMAL_CONFIG_H__
23+
#define __CLC_MATH_CLC_SUBNORMAL_CONFIG_H__
2224

2325
#include <clc/clcfunc.h>
2426

2527
_CLC_DECL bool __clc_subnormals_disabled();
2628
_CLC_DECL bool __clc_fp16_subnormals_supported();
2729
_CLC_DECL bool __clc_fp32_subnormals_supported();
2830
_CLC_DECL bool __clc_fp64_subnormals_supported();
31+
32+
#endif // __CLC_MATH_CLC_SUBNORMAL_CONFIG_H__

libclc/generic/lib/math/math.h renamed to libclc/clc/include/clc/math/math.h

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
* THE SOFTWARE.
2121
*/
2222

23-
#ifndef __CLC_MATH_H_
24-
#define __CLC_MATH_H_
23+
#ifndef __CLC_MATH_MATH_H__
24+
#define __CLC_MATH_MATH_H__
2525

26-
#include "clc/clcfunc.h"
27-
#include "clc/as_type.h"
28-
#include "config.h"
26+
#include <clc/clc_as_type.h>
27+
#include <clc/clcfunc.h>
28+
#include <clc/math/clc_subnormal_config.h>
2929

3030
#define SNAN 0x001
3131
#define QNAN 0x002
@@ -54,64 +54,64 @@ bool __attribute__((noinline)) __clc_runtime_has_hw_fma32(void);
5454
#define MATH_RECIP(X) (1.0f / (X))
5555
#define MATH_SQRT(X) sqrt(X)
5656

57-
#define SIGNBIT_SP32 0x80000000
58-
#define EXSIGNBIT_SP32 0x7fffffff
59-
#define EXPBITS_SP32 0x7f800000
60-
#define MANTBITS_SP32 0x007fffff
61-
#define ONEEXPBITS_SP32 0x3f800000
62-
#define TWOEXPBITS_SP32 0x40000000
63-
#define HALFEXPBITS_SP32 0x3f000000
64-
#define IMPBIT_SP32 0x00800000
65-
#define QNANBITPATT_SP32 0x7fc00000
57+
#define SIGNBIT_SP32 0x80000000
58+
#define EXSIGNBIT_SP32 0x7fffffff
59+
#define EXPBITS_SP32 0x7f800000
60+
#define MANTBITS_SP32 0x007fffff
61+
#define ONEEXPBITS_SP32 0x3f800000
62+
#define TWOEXPBITS_SP32 0x40000000
63+
#define HALFEXPBITS_SP32 0x3f000000
64+
#define IMPBIT_SP32 0x00800000
65+
#define QNANBITPATT_SP32 0x7fc00000
6666
#define INDEFBITPATT_SP32 0xffc00000
67-
#define PINFBITPATT_SP32 0x7f800000
68-
#define NINFBITPATT_SP32 0xff800000
69-
#define EXPBIAS_SP32 127
67+
#define PINFBITPATT_SP32 0x7f800000
68+
#define NINFBITPATT_SP32 0xff800000
69+
#define EXPBIAS_SP32 127
7070
#define EXPSHIFTBITS_SP32 23
71-
#define BIASEDEMIN_SP32 1
72-
#define EMIN_SP32 -126
73-
#define BIASEDEMAX_SP32 254
74-
#define EMAX_SP32 127
75-
#define LAMBDA_SP32 1.0e30
76-
#define MANTLENGTH_SP32 24
77-
#define BASEDIGITS_SP32 7
71+
#define BIASEDEMIN_SP32 1
72+
#define EMIN_SP32 -126
73+
#define BIASEDEMAX_SP32 254
74+
#define EMAX_SP32 127
75+
#define LAMBDA_SP32 1.0e30
76+
#define MANTLENGTH_SP32 24
77+
#define BASEDIGITS_SP32 7
7878

79-
_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x)
80-
{
81-
int ix = as_int(x);
82-
if (!__clc_fp32_subnormals_supported() &&
83-
((ix & EXPBITS_SP32) == 0) && ((ix & MANTBITS_SP32) != 0)) {
84-
ix &= SIGNBIT_SP32;
85-
x = as_float(ix);
86-
}
87-
return x;
79+
_CLC_OVERLOAD _CLC_INLINE float __clc_flush_denormal_if_not_supported(float x) {
80+
int ix = __clc_as_int(x);
81+
if (!__clc_fp32_subnormals_supported() && ((ix & EXPBITS_SP32) == 0) &&
82+
((ix & MANTBITS_SP32) != 0)) {
83+
ix &= SIGNBIT_SP32;
84+
x = __clc_as_float(ix);
85+
}
86+
return x;
8887
}
8988

9089
#ifdef cl_khr_fp64
9190

92-
#define SIGNBIT_DP64 0x8000000000000000L
93-
#define EXSIGNBIT_DP64 0x7fffffffffffffffL
94-
#define EXPBITS_DP64 0x7ff0000000000000L
95-
#define MANTBITS_DP64 0x000fffffffffffffL
96-
#define ONEEXPBITS_DP64 0x3ff0000000000000L
97-
#define TWOEXPBITS_DP64 0x4000000000000000L
98-
#define HALFEXPBITS_DP64 0x3fe0000000000000L
99-
#define IMPBIT_DP64 0x0010000000000000L
100-
#define QNANBITPATT_DP64 0x7ff8000000000000L
91+
#define SIGNBIT_DP64 0x8000000000000000L
92+
#define EXSIGNBIT_DP64 0x7fffffffffffffffL
93+
#define EXPBITS_DP64 0x7ff0000000000000L
94+
#define MANTBITS_DP64 0x000fffffffffffffL
95+
#define ONEEXPBITS_DP64 0x3ff0000000000000L
96+
#define TWOEXPBITS_DP64 0x4000000000000000L
97+
#define HALFEXPBITS_DP64 0x3fe0000000000000L
98+
#define IMPBIT_DP64 0x0010000000000000L
99+
#define QNANBITPATT_DP64 0x7ff8000000000000L
101100
#define INDEFBITPATT_DP64 0xfff8000000000000L
102-
#define PINFBITPATT_DP64 0x7ff0000000000000L
103-
#define NINFBITPATT_DP64 0xfff0000000000000L
104-
#define EXPBIAS_DP64 1023
101+
#define PINFBITPATT_DP64 0x7ff0000000000000L
102+
#define NINFBITPATT_DP64 0xfff0000000000000L
103+
#define EXPBIAS_DP64 1023
105104
#define EXPSHIFTBITS_DP64 52
106-
#define BIASEDEMIN_DP64 1
107-
#define EMIN_DP64 -1022
108-
#define BIASEDEMAX_DP64 2046 /* 0x7fe */
109-
#define EMAX_DP64 1023 /* 0x3ff */
110-
#define LAMBDA_DP64 1.0e300
111-
#define MANTLENGTH_DP64 53
112-
#define BASEDIGITS_DP64 15
105+
#define BIASEDEMIN_DP64 1
106+
#define EMIN_DP64 -1022
107+
#define BIASEDEMAX_DP64 2046 /* 0x7fe */
108+
#define EMAX_DP64 1023 /* 0x3ff */
109+
#define LAMBDA_DP64 1.0e300
110+
#define MANTLENGTH_DP64 53
111+
#define BASEDIGITS_DP64 15
113112

114113
#endif // cl_khr_fp64
115114

116-
#define ALIGNED(x) __attribute__((aligned(x)))
117-
#endif // __CLC_MATH_H_
115+
#define ALIGNED(x) __attribute__((aligned(x)))
116+
117+
#endif // __CLC_MATH_MATH_H__

libclc/generic/lib/math/tables.h renamed to libclc/clc/include/clc/math/tables.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,30 @@
2020
* THE SOFTWARE.
2121
*/
2222

23+
#ifndef __CLC_MATH_TABLES_H__
24+
#define __CLC_MATH_TABLES_H__
25+
2326
#include <clc/clctypes.h>
2427

2528
#define TABLE_SPACE __constant
2629

2730
#define TABLE_MANGLE(NAME) __clc_##NAME
2831

29-
#define DECLARE_TABLE(TYPE,NAME,LENGTH) \
30-
TABLE_SPACE TYPE NAME [ LENGTH ]
32+
#define DECLARE_TABLE(TYPE, NAME, LENGTH) TABLE_SPACE TYPE NAME[LENGTH]
3133

32-
#define TABLE_FUNCTION(TYPE,TABLE,NAME) \
33-
TYPE TABLE_MANGLE(NAME)(size_t idx) { \
34-
return TABLE[idx]; \
35-
}
34+
#define TABLE_FUNCTION(TYPE, TABLE, NAME) \
35+
TYPE TABLE_MANGLE(NAME)(size_t idx) { return TABLE[idx]; }
3636

37-
#define TABLE_FUNCTION_DECL(TYPE, NAME) \
38-
TYPE TABLE_MANGLE(NAME)(size_t idx);
37+
#define TABLE_FUNCTION_DECL(TYPE, NAME) TYPE TABLE_MANGLE(NAME)(size_t idx);
3938

40-
#define USE_TABLE(NAME, IDX) \
41-
TABLE_MANGLE(NAME)(IDX)
39+
#define USE_TABLE(NAME, IDX) TABLE_MANGLE(NAME)(IDX)
4240

4341
TABLE_FUNCTION_DECL(float2, loge_tbl);
4442
TABLE_FUNCTION_DECL(float, log_inv_tbl);
4543
TABLE_FUNCTION_DECL(float2, log_inv_tbl_ep);
4644
TABLE_FUNCTION_DECL(float2, log2_tbl);
4745
TABLE_FUNCTION_DECL(float2, log10_tbl);
48-
TABLE_FUNCTION_DECL(uint4, pibits_tbl);
46+
TABLE_FUNCTION_DECL(uint4, pibits_tbl);
4947
TABLE_FUNCTION_DECL(float2, sinhcosh_tbl);
5048
TABLE_FUNCTION_DECL(float2, cbrt_tbl);
5149
TABLE_FUNCTION_DECL(float, exp_tbl);
@@ -67,3 +65,5 @@ TABLE_FUNCTION_DECL(double2, powlog_tbl);
6765
TABLE_FUNCTION_DECL(double2, log_f_inv_tbl);
6866

6967
#endif // cl_khr_fp64
68+
69+
#endif // __CLC_MATH_TABLES_H__

libclc/clspv/lib/math/fma.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
// (__clc_sw_fma), but avoids the use of ulong in favor of uint2. The logic has
2525
// been updated as appropriate.
2626

27-
#include "../../../generic/lib/math/math.h"
2827
#include <clc/clc.h>
2928
#include <clc/clcmacro.h>
29+
#include <clc/math/math.h>
3030

3131
struct fp {
3232
uint2 mantissa;

libclc/clspv/lib/subnormal_config.cl

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

2323
#include <clc/clc.h>
24-
25-
#include "config.h"
24+
#include <clc/math/clc_subnormal_config.h>
2625

2726
_CLC_DEF bool __clc_fp16_subnormals_supported() { return false; }
2827

libclc/generic/include/math/clc_ldexp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <clc/clcfunc.h>
2+
13
_CLC_DEF _CLC_OVERLOAD float __clc_ldexp(float, int);
24

35
#ifdef cl_khr_fp64

libclc/generic/lib/math/acos.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
* THE SOFTWARE.
2121
*/
22+
2223
#include <clc/clc.h>
2324
#include <clc/clcmacro.h>
24-
25-
#include "math.h"
25+
#include <clc/math/math.h>
2626

2727
_CLC_OVERLOAD _CLC_DEF float acos(float x) {
2828
// Computes arccos(x).

libclc/generic/lib/math/acosh.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
* THE SOFTWARE.
2121
*/
2222

23+
#include "ep_log.h"
2324
#include <clc/clc.h>
2425
#include <clc/clcmacro.h>
25-
26-
#include "ep_log.h"
27-
#include "math.h"
26+
#include <clc/math/math.h>
2827

2928
_CLC_OVERLOAD _CLC_DEF float acosh(float x) {
3029
uint ux = as_uint(x);

libclc/generic/lib/math/acospi.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
25+
#include <clc/math/math.h>
2726

2827
_CLC_OVERLOAD _CLC_DEF float acospi(float x) {
2928
// Computes arccos(x).

libclc/generic/lib/math/asin.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
25+
#include <clc/math/math.h>
2726

2827
_CLC_OVERLOAD _CLC_DEF float asin(float x) {
2928
// Computes arcsin(x).

libclc/generic/lib/math/asinh.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
* THE SOFTWARE.
2121
*/
2222

23+
#include "ep_log.h"
2324
#include <clc/clc.h>
2425
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
27-
#include "ep_log.h"
26+
#include <clc/math/math.h>
2827

2928
_CLC_OVERLOAD _CLC_DEF float asinh(float x) {
3029
uint ux = as_uint(x);

libclc/generic/lib/math/asinpi.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
25+
#include <clc/math/math.h>
2726

2827
_CLC_OVERLOAD _CLC_DEF float asinpi(float x) {
2928
// Computes arcsin(x).

libclc/generic/lib/math/atan.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
25+
#include <clc/math/math.h>
2726

2827
_CLC_OVERLOAD _CLC_DEF float atan(float x)
2928
{

libclc/generic/lib/math/atan2.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
27-
#include "tables.h"
25+
#include <clc/math/math.h>
26+
#include <clc/math/tables.h>
2827

2928
_CLC_OVERLOAD _CLC_DEF float atan2(float y, float x)
3029
{

libclc/generic/lib/math/atan2pi.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
27-
#include "tables.h"
25+
#include <clc/math/math.h>
26+
#include <clc/math/tables.h>
2827

2928
_CLC_OVERLOAD _CLC_DEF float atan2pi(float y, float x) {
3029
const float pi = 0x1.921fb6p+1f;

libclc/generic/lib/math/atanh.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
25+
#include <clc/math/math.h>
2726

2827
_CLC_OVERLOAD _CLC_DEF float atanh(float x) {
2928
uint ux = as_uint(x);

libclc/generic/lib/math/atanpi.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
25+
#include <clc/math/math.h>
2726

2827
_CLC_OVERLOAD _CLC_DEF float atanpi(float x) {
2928
const float pi = 3.1415926535897932f;

libclc/generic/lib/math/cbrt.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
25-
26-
#include "math.h"
27-
#include "tables.h"
25+
#include <clc/math/math.h>
26+
#include <clc/math/tables.h>
2827

2928
_CLC_OVERLOAD _CLC_DEF float cbrt(float x) {
3029

libclc/generic/lib/math/clc_exp10.cl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
2525
#include <clc/math/clc_mad.h>
26+
#include <clc/math/clc_subnormal_config.h>
27+
#include <clc/math/math.h>
28+
#include <clc/math/tables.h>
2629
#include <clc/relational/clc_isnan.h>
2730

28-
#include "config.h"
29-
#include "math.h"
30-
#include "tables.h"
31-
3231
// Algorithm:
3332
//
3433
// e^x = 2^(x/ln(2)) = 2^(x*(64/ln(2))/64)

libclc/generic/lib/math/clc_fma.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
#include <clc/clc.h>
2424
#include <clc/clcmacro.h>
2525
#include <clc/integer/clc_abs.h>
26+
#include <clc/math/clc_subnormal_config.h>
27+
#include <clc/math/math.h>
2628
#include <clc/relational/clc_isinf.h>
2729
#include <clc/relational/clc_isnan.h>
2830
#include <clc/shared/clc_max.h>
2931

30-
#include "config.h"
31-
#include "math.h"
32-
3332
struct fp {
3433
ulong mantissa;
3534
int exponent;

0 commit comments

Comments
 (0)