Skip to content

Commit 78d95cc

Browse files
authored
[libclc] Move fract to the CLC library (#137785)
The builtin was already vectorized so there's no difference to codegen for non-SPIR-V targets.
1 parent faf87e1 commit 78d95cc

File tree

7 files changed

+74
-46
lines changed

7 files changed

+74
-46
lines changed

libclc/generic/include/clc/math/fract.inc renamed to libclc/clc/include/clc/math/clc_fract.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, global __CLC_GENTYPE *iptr);
10-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, local __CLC_GENTYPE *iptr);
11-
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr);
9+
#ifndef __CLC_MATH_CLC_FRACT_H__
10+
#define __CLC_MATH_CLC_FRACT_H__
11+
12+
#define __CLC_FUNCTION __clc_fract
13+
#define __CLC_BODY <clc/math/unary_decl_with_ptr.inc>
14+
15+
#include <clc/math/gentype.inc>
16+
17+
#undef __CLC_BODY
18+
#undef __CLC_FUNCTION
19+
20+
#endif // __CLC_MATH_CLC_FRACT_H__

libclc/clc/lib/generic/SOURCES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ math/clc_fmax.cl
4646
math/clc_fmin.cl
4747
math/clc_floor.cl
4848
math/clc_fmod.cl
49+
math/clc_fract.cl
4950
math/clc_frexp.cl
5051
math/clc_hypot.cl
5152
math/clc_ldexp.cl
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
#include <clc/clcmacro.h>
10+
#include <clc/internal/clc.h>
11+
#include <clc/math/clc_floor.h>
12+
#include <clc/math/clc_fmin.h>
13+
#include <clc/relational/clc_isinf.h>
14+
#include <clc/relational/clc_isnan.h>
15+
16+
#define __CLC_BODY <clc_fract.inc>
17+
#include <clc/math/gentype.inc>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
#if __CLC_FPSIZE == 64
10+
#define MIN_CONSTANT 0x1.fffffffffffffp-1
11+
#elif __CLC_FPSIZE == 32
12+
#define MIN_CONSTANT 0x1.fffffep-1f
13+
#elif __CLC_FPSIZE == 16
14+
#define MIN_CONSTANT 0x1.ffcp-1h
15+
#endif
16+
17+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fract(__CLC_GENTYPE x,
18+
private __CLC_GENTYPE *iptr) {
19+
*iptr = __clc_floor(x);
20+
__CLC_GENTYPE r = __clc_fmin(x - *iptr, MIN_CONSTANT);
21+
r = __clc_isinf(x) ? __CLC_FP_LIT(0.0) : r;
22+
r = __clc_isnan(x) ? x : r;
23+
return r;
24+
}
25+
26+
#define FRACT_DEF(addrspace) \
27+
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fract( \
28+
__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \
29+
__CLC_GENTYPE private_iptr; \
30+
__CLC_GENTYPE ret = __clc_fract(x, &private_iptr); \
31+
*iptr = private_iptr; \
32+
return ret; \
33+
}
34+
35+
FRACT_DEF(local);
36+
FRACT_DEF(global);
37+
38+
#undef MIN_CONSTANT

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

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

9-
#define __CLC_BODY <clc/math/fract.inc>
9+
#define __CLC_FUNCTION fract
10+
#define __CLC_BODY <clc/math/unary_decl_with_ptr.inc>
1011
#include <clc/math/gentype.inc>
12+
#undef __CLC_FUNCTION

libclc/generic/lib/math/fract.cl

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

99
#include <clc/clc.h>
10+
#include <clc/math/clc_fract.h>
1011

11-
#define __CLC_BODY <fract.inc>
12+
#define FUNCTION fract
13+
#define __CLC_BODY <clc/math/unary_def_with_ptr.inc>
1214
#include <clc/math/gentype.inc>

libclc/generic/lib/math/fract.inc

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)