Skip to content

[libclc] Move fract to the CLC library #137785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
//
//===----------------------------------------------------------------------===//

_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, global __CLC_GENTYPE *iptr);
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, local __CLC_GENTYPE *iptr);
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE fract(__CLC_GENTYPE x, private __CLC_GENTYPE *iptr);
#ifndef __CLC_MATH_CLC_FRACT_H__
#define __CLC_MATH_CLC_FRACT_H__

#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__
1 change: 1 addition & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ math/clc_fmax.cl
math/clc_fmin.cl
math/clc_floor.cl
math/clc_fmod.cl
math/clc_fract.cl
math/clc_frexp.cl
math/clc_hypot.cl
math/clc_ldexp.cl
Expand Down
17 changes: 17 additions & 0 deletions libclc/clc/lib/generic/math/clc_fract.cl
Original file line number Diff line number Diff line change
@@ -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 changes: 38 additions & 0 deletions libclc/clc/lib/generic/math/clc_fract.inc
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion libclc/generic/include/clc/math/fract.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
#undef __CLC_FUNCTION
4 changes: 3 additions & 1 deletion libclc/generic/lib/math/fract.cl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//

#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>
41 changes: 0 additions & 41 deletions libclc/generic/lib/math/fract.inc

This file was deleted.

Loading