[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.
This commit is contained in:
@@ -6,6 +6,15 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, global __CLC_GENTYPE *iptr);
|
#ifndef __CLC_MATH_CLC_FRACT_H__
|
||||||
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, local __CLC_GENTYPE *iptr);
|
#define __CLC_MATH_CLC_FRACT_H__
|
||||||
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr);
|
|
||||||
|
#define __CLC_FUNCTION __clc_fract
|
||||||
|
#define __CLC_BODY <clc/math/unary_decl_with_ptr.inc>
|
||||||
|
|
||||||
|
#include <clc/math/gentype.inc>
|
||||||
|
|
||||||
|
#undef __CLC_BODY
|
||||||
|
#undef __CLC_FUNCTION
|
||||||
|
|
||||||
|
#endif // __CLC_MATH_CLC_FRACT_H__
|
||||||
@@ -46,6 +46,7 @@ math/clc_fmax.cl
|
|||||||
math/clc_fmin.cl
|
math/clc_fmin.cl
|
||||||
math/clc_floor.cl
|
math/clc_floor.cl
|
||||||
math/clc_fmod.cl
|
math/clc_fmod.cl
|
||||||
|
math/clc_fract.cl
|
||||||
math/clc_frexp.cl
|
math/clc_frexp.cl
|
||||||
math/clc_hypot.cl
|
math/clc_hypot.cl
|
||||||
math/clc_ldexp.cl
|
math/clc_ldexp.cl
|
||||||
|
|||||||
17
libclc/clc/lib/generic/math/clc_fract.cl
Normal file
17
libclc/clc/lib/generic/math/clc_fract.cl
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include <clc/clcmacro.h>
|
||||||
|
#include <clc/internal/clc.h>
|
||||||
|
#include <clc/math/clc_floor.h>
|
||||||
|
#include <clc/math/clc_fmin.h>
|
||||||
|
#include <clc/relational/clc_isinf.h>
|
||||||
|
#include <clc/relational/clc_isnan.h>
|
||||||
|
|
||||||
|
#define __CLC_BODY <clc_fract.inc>
|
||||||
|
#include <clc/math/gentype.inc>
|
||||||
38
libclc/clc/lib/generic/math/clc_fract.inc
Normal file
38
libclc/clc/lib/generic/math/clc_fract.inc
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#if __CLC_FPSIZE == 64
|
||||||
|
#define MIN_CONSTANT 0x1.fffffffffffffp-1
|
||||||
|
#elif __CLC_FPSIZE == 32
|
||||||
|
#define MIN_CONSTANT 0x1.fffffep-1f
|
||||||
|
#elif __CLC_FPSIZE == 16
|
||||||
|
#define MIN_CONSTANT 0x1.ffcp-1h
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fract(__CLC_GENTYPE x,
|
||||||
|
private __CLC_GENTYPE *iptr) {
|
||||||
|
*iptr = __clc_floor(x);
|
||||||
|
__CLC_GENTYPE r = __clc_fmin(x - *iptr, MIN_CONSTANT);
|
||||||
|
r = __clc_isinf(x) ? __CLC_FP_LIT(0.0) : r;
|
||||||
|
r = __clc_isnan(x) ? x : r;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define FRACT_DEF(addrspace) \
|
||||||
|
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_fract( \
|
||||||
|
__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \
|
||||||
|
__CLC_GENTYPE private_iptr; \
|
||||||
|
__CLC_GENTYPE ret = __clc_fract(x, &private_iptr); \
|
||||||
|
*iptr = private_iptr; \
|
||||||
|
return ret; \
|
||||||
|
}
|
||||||
|
|
||||||
|
FRACT_DEF(local);
|
||||||
|
FRACT_DEF(global);
|
||||||
|
|
||||||
|
#undef MIN_CONSTANT
|
||||||
@@ -6,5 +6,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#define __CLC_BODY <clc/math/fract.inc>
|
#define __CLC_FUNCTION fract
|
||||||
|
#define __CLC_BODY <clc/math/unary_decl_with_ptr.inc>
|
||||||
#include <clc/math/gentype.inc>
|
#include <clc/math/gentype.inc>
|
||||||
|
#undef __CLC_FUNCTION
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include <clc/clc.h>
|
#include <clc/clc.h>
|
||||||
|
#include <clc/math/clc_fract.h>
|
||||||
|
|
||||||
#define __CLC_BODY <fract.inc>
|
#define FUNCTION fract
|
||||||
|
#define __CLC_BODY <clc/math/unary_def_with_ptr.inc>
|
||||||
#include <clc/math/gentype.inc>
|
#include <clc/math/gentype.inc>
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
|
||||||
//
|
|
||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
||||||
// See https://llvm.org/LICENSE.txt for license information.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
#if __CLC_FPSIZE == 64
|
|
||||||
#define MIN_CONSTANT 0x1.fffffffffffffp-1
|
|
||||||
#define ZERO 0.0
|
|
||||||
#elif __CLC_FPSIZE == 32
|
|
||||||
#define MIN_CONSTANT 0x1.fffffep-1f
|
|
||||||
#define ZERO 0.0f
|
|
||||||
#elif __CLC_FPSIZE == 16
|
|
||||||
#define MIN_CONSTANT 0x1.ffcp-1h
|
|
||||||
#define ZERO 0.0h
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fract(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr) {
|
|
||||||
*iptr = floor(x);
|
|
||||||
__CLC_GENTYPE r = fmin(x - *iptr, MIN_CONSTANT);
|
|
||||||
r = isinf(x) ? ZERO : r;
|
|
||||||
r = isnan(x) ? x : r;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define FRACT_DEF(addrspace) \
|
|
||||||
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE fract(__CLC_GENTYPE x, addrspace __CLC_GENTYPE *iptr) { \
|
|
||||||
__CLC_GENTYPE private_iptr; \
|
|
||||||
__CLC_GENTYPE ret = fract(x, &private_iptr); \
|
|
||||||
*iptr = private_iptr; \
|
|
||||||
return ret; \
|
|
||||||
}
|
|
||||||
|
|
||||||
FRACT_DEF(local);
|
|
||||||
FRACT_DEF(global);
|
|
||||||
|
|
||||||
#undef MIN_CONSTANT
|
|
||||||
#undef ZERO
|
|
||||||
Reference in New Issue
Block a user