Skip to content

Commit c8eb865

Browse files
authored
[libclc] Move mad to the CLC library (#123607)
All targets build `__clc_mad` -- even SPIR-V targets -- since it compiles to the optimal `llvm.fmuladd` intrinsic. There is no change to the bytecode generated for non-SPIR-V targets. The `mix` builtin, which is implemented as a wrapper around `mad`, is left as an OpenCL-layer wrapper of `__clc_mad`. I don't know if it's worth having a specific CLC version of `mix`. The changes to the other CLC files/functions are moving uses of `mad` to `__clc_mad`, and reformatting. There is an additional instance of `trunc` becoming `__clc_trunc`, which was missed before.
1 parent 8368018 commit c8eb865

File tree

22 files changed

+2014
-1840
lines changed

22 files changed

+2014
-1840
lines changed

libclc/clc/include/clc/clcmacro.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@
184184
return BUILTIN(x); \
185185
}
186186

187+
#define _CLC_DEFINE_TERNARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE, \
188+
ARG2_TYPE, ARG3_TYPE) \
189+
_CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x, ARG2_TYPE y, \
190+
ARG3_TYPE z) { \
191+
return BUILTIN(x, y, z); \
192+
} \
193+
_CLC_DEF _CLC_OVERLOAD RET_TYPE##2 FUNCTION(ARG1_TYPE##2 x, ARG2_TYPE##2 y, \
194+
ARG3_TYPE##2 z) { \
195+
return BUILTIN(x, y, z); \
196+
} \
197+
_CLC_DEF _CLC_OVERLOAD RET_TYPE##3 FUNCTION(ARG1_TYPE##3 x, ARG2_TYPE##3 y, \
198+
ARG3_TYPE##3 z) { \
199+
return BUILTIN(x, y, z); \
200+
} \
201+
_CLC_DEF _CLC_OVERLOAD RET_TYPE##4 FUNCTION(ARG1_TYPE##4 x, ARG2_TYPE##4 y, \
202+
ARG3_TYPE##4 z) { \
203+
return BUILTIN(x, y, z); \
204+
} \
205+
_CLC_DEF _CLC_OVERLOAD RET_TYPE##8 FUNCTION(ARG1_TYPE##8 x, ARG2_TYPE##8 y, \
206+
ARG3_TYPE##8 z) { \
207+
return BUILTIN(x, y, z); \
208+
} \
209+
_CLC_DEF _CLC_OVERLOAD RET_TYPE##16 FUNCTION( \
210+
ARG1_TYPE##16 x, ARG2_TYPE##16 y, ARG3_TYPE##16 z) { \
211+
return BUILTIN(x, y, z); \
212+
}
213+
187214
#ifdef cl_khr_fp16
188215

189216
#pragma OPENCL EXTENSION cl_khr_fp16 : enable

libclc/clc/include/clc/math/clc_mad.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __CLC_MATH_CLC_MAD_H__
2+
#define __CLC_MATH_CLC_MAD_H__
3+
4+
#define __CLC_BODY <clc/math/ternary_decl.inc>
5+
#define __CLC_FUNCTION __clc_mad
6+
7+
#include <clc/math/gentype.inc>
8+
9+
#undef __CLC_BODY
10+
#undef __CLC_FUNCTION
11+
12+
#endif // __CLC_MATH_CLC_MAD_H__
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE a,
2+
__CLC_GENTYPE b,
3+
__CLC_GENTYPE c);

libclc/clc/lib/clspv/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
../generic/math/clc_ceil.cl
22
../generic/math/clc_fabs.cl
33
../generic/math/clc_floor.cl
4+
../generic/math/clc_mad.cl
45
../generic/math/clc_rint.cl
56
../generic/math/clc_trunc.cl
67
../generic/shared/clc_clamp.cl

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ integer/clc_abs_diff.cl
77
math/clc_ceil.cl
88
math/clc_fabs.cl
99
math/clc_floor.cl
10+
math/clc_mad.cl
1011
math/clc_rint.cl
1112
math/clc_trunc.cl
1213
relational/clc_all.cl
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <clc/internal/clc.h>
2+
3+
#define __CLC_BODY <clc_mad.inc>
4+
#include <clc/math/gentype.inc>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_mad(__CLC_GENTYPE a, __CLC_GENTYPE b,
2+
__CLC_GENTYPE c) {
3+
#pragma OPENCL FP_CONTRACT ON
4+
return a * b + c;
5+
}

libclc/clc/lib/spirv/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
../generic/math/clc_ceil.cl
66
../generic/math/clc_fabs.cl
77
../generic/math/clc_floor.cl
8+
../generic/math/clc_mad.cl
89
../generic/math/clc_rint.cl
910
../generic/math/clc_trunc.cl
1011
../generic/shared/clc_clamp.cl

libclc/clc/lib/spirv64/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
../generic/math/clc_ceil.cl
66
../generic/math/clc_fabs.cl
77
../generic/math/clc_floor.cl
8+
../generic/math/clc_mad.cl
89
../generic/math/clc_rint.cl
910
../generic/math/clc_trunc.cl
1011
../generic/shared/clc_clamp.cl

libclc/generic/include/clc/math/ternary_decl.inc

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)