Skip to content

Commit 293c78b

Browse files
authored
[libclc] Move ceil/fabs/floor/rint/trunc to CLC library (llvm#114774)
These functions are all mapped to LLVM intrinsics. The clspv and spirv targets don't declare or define any of these CLC functions, and instead map these to their corresponding OpenCL symbols.
1 parent b5dc7b8 commit 293c78b

25 files changed

+145
-45
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_MATH_CLC_CEIL_H__
2+
#define __CLC_MATH_CLC_CEIL_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible ceil
6+
#define __clc_ceil ceil
7+
#else
8+
9+
// Map the function to an LLVM intrinsic
10+
#define __CLC_FUNCTION __clc_ceil
11+
#define __CLC_INTRINSIC "llvm.ceil"
12+
#include <clc/math/unary_intrin.inc>
13+
14+
#undef __CLC_INTRINSIC
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_MATH_CLC_CEIL_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_MATH_CLC_FABS_H__
2+
#define __CLC_MATH_CLC_FABS_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible fabs
6+
#define __clc_fabs fabs
7+
#else
8+
9+
// Map the function to an LLVM intrinsic
10+
#define __CLC_FUNCTION __clc_fabs
11+
#define __CLC_INTRINSIC "llvm.fabs"
12+
#include <clc/math/unary_intrin.inc>
13+
14+
#undef __CLC_INTRINSIC
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_MATH_CLC_FABS_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_MATH_CLC_FLOOR_H__
2+
#define __CLC_MATH_CLC_FLOOR_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible floor
6+
#define __clc_floor floor
7+
#else
8+
9+
// Map the function to an LLVM intrinsic
10+
#define __CLC_FUNCTION __clc_floor
11+
#define __CLC_INTRINSIC "llvm.floor"
12+
#include <clc/math/unary_intrin.inc>
13+
14+
#undef __CLC_INTRINSIC
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_MATH_CLC_FLOOR_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_MATH_CLC_RINT_H__
2+
#define __CLC_MATH_CLC_RINT_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible rint
6+
#define __clc_rint rint
7+
#else
8+
9+
// Map the function to an LLVM intrinsic
10+
#define __CLC_FUNCTION __clc_rint
11+
#define __CLC_INTRINSIC "llvm.rint"
12+
#include <clc/math/unary_intrin.inc>
13+
14+
#undef __CLC_INTRINSIC
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_MATH_CLC_RINT_H__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CLC_MATH_CLC_TRUNC_H__
2+
#define __CLC_MATH_CLC_TRUNC_H__
3+
4+
#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
5+
// clspv and spir-v targets provide their own OpenCL-compatible trunc
6+
#define __clc_trunc trunc
7+
#else
8+
9+
// Map the function to an LLVM intrinsic
10+
#define __CLC_FUNCTION __clc_trunc
11+
#define __CLC_INTRINSIC "llvm.trunc"
12+
#include <clc/math/unary_intrin.inc>
13+
14+
#undef __CLC_INTRINSIC
15+
#undef __CLC_FUNCTION
16+
17+
#endif
18+
19+
#endif // __CLC_MATH_CLC_TRUNC_H__

libclc/generic/include/math/unary_intrin.inc renamed to libclc/clc/include/clc/math/unary_intrin.inc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ _CLC_OVERLOAD float2 __CLC_FUNCTION(float2 f) __asm(__CLC_INTRINSIC ".v2f32");
33
_CLC_OVERLOAD float3 __CLC_FUNCTION(float3 f) __asm(__CLC_INTRINSIC ".v3f32");
44
_CLC_OVERLOAD float4 __CLC_FUNCTION(float4 f) __asm(__CLC_INTRINSIC ".v4f32");
55
_CLC_OVERLOAD float8 __CLC_FUNCTION(float8 f) __asm(__CLC_INTRINSIC ".v8f32");
6-
_CLC_OVERLOAD float16 __CLC_FUNCTION(float16 f) __asm(__CLC_INTRINSIC ".v16f32");
6+
_CLC_OVERLOAD float16 __CLC_FUNCTION(float16 f) __asm(__CLC_INTRINSIC
7+
".v16f32");
78

89
#ifdef cl_khr_fp64
910
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -12,11 +13,12 @@ _CLC_OVERLOAD double2 __CLC_FUNCTION(double2 d) __asm(__CLC_INTRINSIC ".v2f64");
1213
_CLC_OVERLOAD double3 __CLC_FUNCTION(double3 d) __asm(__CLC_INTRINSIC ".v3f64");
1314
_CLC_OVERLOAD double4 __CLC_FUNCTION(double4 d) __asm(__CLC_INTRINSIC ".v4f64");
1415
_CLC_OVERLOAD double8 __CLC_FUNCTION(double8 d) __asm(__CLC_INTRINSIC ".v8f64");
15-
_CLC_OVERLOAD double16 __CLC_FUNCTION(double16 d) __asm(__CLC_INTRINSIC ".v16f64");
16+
_CLC_OVERLOAD double16 __CLC_FUNCTION(double16 d) __asm(__CLC_INTRINSIC
17+
".v16f64");
1618
#endif
1719

1820
#ifdef cl_khr_fp16
19-
#pragma OPENCL EXTENSION cl_khr_fp16: enable
21+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
2022
_CLC_OVERLOAD half __CLC_FUNCTION(half d) __asm(__CLC_INTRINSIC ".f16");
2123
_CLC_OVERLOAD half2 __CLC_FUNCTION(half2 d) __asm(__CLC_INTRINSIC ".v2f16");
2224
_CLC_OVERLOAD half3 __CLC_FUNCTION(half3 d) __asm(__CLC_INTRINSIC ".v3f16");

libclc/clc/include/clc/utils.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef __CLC_UTILS_H__
2+
#define __CLC_UTILS_H__
3+
4+
#define __CLC_CONCAT(x, y) x##y
5+
#define __CLC_XCONCAT(x, y) __CLC_CONCAT(x, y)
6+
7+
#define __CLC_STR(x) #x
8+
#define __CLC_XSTR(x) __CLC_STR(x)
9+
10+
#endif // __CLC_UTILS_H__

libclc/generic/lib/clcmacro.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <clc/clc.h>
12
#include <utils.h>
23

34
#define _CLC_UNARY_VECTORIZE(DECLSPEC, RET_TYPE, FUNCTION, ARG1_TYPE) \

libclc/generic/lib/math/ceil.cl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
#include <clc/clc.h>
21
#include "../clcmacro.h"
3-
4-
// Map the llvm intrinsic to an OpenCL function.
5-
#define __CLC_FUNCTION __clc_ceil
6-
#define __CLC_INTRINSIC "llvm.ceil"
7-
#include "math/unary_intrin.inc"
2+
#include <clc/clc.h>
3+
#include <clc/math/clc_ceil.h>
84

95
#undef __CLC_FUNCTION
106
#define __CLC_FUNCTION ceil

0 commit comments

Comments
 (0)