Skip to content

Commit e480113

Browse files
committed
[libclc] Move __clc_remainder to CLC library
It was already nominally in the CLC namespace; this commit just formally moves it over. Note that a fp16 version of __clc_remainder is now provided. It is defined as forwarding on to the fp32 version. This makes a difference in the OpenCL layer, where the fp16 remainder builtin will forward to the fp16 __clc_remainder builtin, rather than directly forwarding onto the fp32 __clc_remainder builtin. No changes to the generated code for non-SPIR-V targets is observed.
1 parent 3284559 commit e480113

File tree

11 files changed

+50
-15
lines changed

11 files changed

+50
-15
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===----------------------------------------------------------------------===//
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+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
10+
__CLC_GENTYPE y) {
11+
return __CLC_CONVERT_GENTYPE(
12+
__CLC_FUNCTION(__CLC_CONVERT_FLOATN(x), __CLC_CONVERT_FLOATN(y)));
13+
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifndef __CLC_MATH_CLC_REMAINDER_H__
10+
#define __CLC_MATH_CLC_REMAINDER_H__
11+
912
#define __CLC_FUNCTION __clc_remainder
10-
#define __CLC_BODY <clc/math/binary_decl_tt.inc>
13+
#define __CLC_BODY <clc/shared/binary_decl.inc>
14+
1115
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_BODY
1218
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_MATH_CLC_REMAINDER_H__

libclc/clc/include/clc/math/gentype.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#define __CLC_CONVERT_S_GENTYPE __CLC_XCONCAT(__clc_convert_, __CLC_S_GENTYPE)
6969
#define __CLC_CONVERT_U_GENTYPE __CLC_XCONCAT(__clc_convert_, __CLC_U_GENTYPE)
7070

71+
#if (!defined(__HALF_ONLY) && !defined(__DOUBLE_ONLY))
7172
#define __CLC_SCALAR_GENTYPE float
7273
#define __CLC_FPSIZE 32
7374
#define __CLC_FP_LIT(x) x##F
@@ -133,7 +134,9 @@
133134
#undef __CLC_FPSIZE
134135
#undef __CLC_SCALAR_GENTYPE
135136

136-
#ifndef __FLOAT_ONLY
137+
#endif
138+
139+
#if (!defined(__HALF_ONLY) && !defined(__FLOAT_ONLY))
137140
#ifdef cl_khr_fp64
138141
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
139142

@@ -204,7 +207,7 @@
204207
#endif
205208
#endif
206209

207-
#ifndef __FLOAT_ONLY
210+
#if (!defined(__FLOAT_ONLY) && !defined(__DOUBLE_ONLY))
208211
#ifdef cl_khr_fp16
209212
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
210213

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ math/clc_mad.cl
4545
math/clc_modf.cl
4646
math/clc_nan.cl
4747
math/clc_nextafter.cl
48+
math/clc_remainder.cl
4849
math/clc_rint.cl
4950
math/clc_round.cl
5051
math/clc_rsqrt.cl

libclc/generic/lib/math/clc_remainder.cl renamed to libclc/clc/lib/generic/math/clc_remainder.cl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clc.h>
109
#include <clc/clc_convert.h>
1110
#include <clc/clcmacro.h>
1211
#include <clc/integer/clc_clz.h>
12+
#include <clc/internal/clc.h>
1313
#include <clc/math/clc_floor.h>
1414
#include <clc/math/clc_fma.h>
15-
#include <clc/math/clc_subnormal_config.h>
15+
#include <clc/math/clc_ldexp.h>
16+
#include <clc/math/clc_remainder.h>
1617
#include <clc/math/clc_trunc.h>
1718
#include <clc/math/math.h>
1819
#include <clc/shared/clc_max.h>
19-
#include <math/clc_remainder.h>
2020

2121
_CLC_DEF _CLC_OVERLOAD float __clc_remainder(float x, float y) {
2222
int ux = __clc_as_int(x);
@@ -77,6 +77,9 @@ _CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, float, __clc_remainder, float,
7777
float);
7878

7979
#ifdef cl_khr_fp64
80+
81+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
82+
8083
_CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y) {
8184
ulong ux = __clc_as_ulong(x);
8285
ulong ax = ux & ~SIGNBIT_DP64;
@@ -104,7 +107,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y) {
104107
// but it doesn't matter - it just means that we'll go round
105108
// the loop below one extra time.
106109
int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
107-
double w = ldexp(dy, ntimes * 53);
110+
double w = __clc_ldexp(dy, ntimes * 53);
108111
w = ntimes == 0 ? dy : w;
109112
double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
110113

@@ -207,3 +210,15 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y) {
207210
_CLC_BINARY_VECTORIZE(_CLC_DEF _CLC_OVERLOAD, double, __clc_remainder, double,
208211
double);
209212
#endif
213+
214+
#ifdef cl_khr_fp16
215+
216+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
217+
218+
// Forward the half version of this builtin onto the float one
219+
#define __HALF_ONLY
220+
#define __CLC_FUNCTION __clc_remainder
221+
#define __CLC_BODY <clc/math/binary_def_via_fp32.inc>
222+
#include <clc/math/gentype.inc>
223+
224+
#endif

libclc/clspv/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ subnormal_config.cl
2121
../../generic/lib/math/clc_pow.cl
2222
../../generic/lib/math/clc_pown.cl
2323
../../generic/lib/math/clc_powr.cl
24-
../../generic/lib/math/clc_remainder.cl
2524
../../generic/lib/math/clc_remquo.cl
2625
../../generic/lib/math/clc_rootn.cl
2726
../../generic/lib/math/clc_tan.cl

libclc/generic/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ math/clc_pown.cl
163163
math/pown.cl
164164
math/clc_powr.cl
165165
math/powr.cl
166-
math/clc_remainder.cl
167166
math/remainder.cl
168167
math/clc_remquo.cl
169168
math/remquo.cl

libclc/generic/lib/math/clc_fmod.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <clc/math/clc_trunc.h>
1717
#include <clc/math/math.h>
1818
#include <clc/shared/clc_max.h>
19-
#include <math/clc_remainder.h>
2019

2120
_CLC_DEF _CLC_OVERLOAD float __clc_fmod(float x, float y) {
2221
int ux = __clc_as_int(x);

libclc/generic/lib/math/clc_remquo.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <clc/math/clc_trunc.h>
1717
#include <clc/math/math.h>
1818
#include <clc/shared/clc_max.h>
19-
#include <math/clc_remainder.h>
2019

2120
_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y,
2221
__private int *quo) {

libclc/generic/lib/math/remainder.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include <clc/clc.h>
10-
#include <math/clc_remainder.h>
10+
#include <clc/math/clc_remainder.h>
1111

12-
#define __CLC_FUNC remainder
13-
#define __CLC_BODY <clc_sw_binary.inc>
12+
#define FUNCTION remainder
13+
#define __CLC_BODY <clc/shared/binary_def.inc>
1414
#include <clc/math/gentype.inc>

libclc/spirv/lib/SOURCES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ math/fma.cl
6565
../../generic/lib/math/pown.cl
6666
../../generic/lib/math/clc_powr.cl
6767
../../generic/lib/math/powr.cl
68-
../../generic/lib/math/clc_remainder.cl
6968
../../generic/lib/math/remainder.cl
7069
../../generic/lib/math/clc_remquo.cl
7170
../../generic/lib/math/remquo.cl

0 commit comments

Comments
 (0)