Skip to content

[libclc] Move nan to the CLC library #128521

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 1 commit into from
Feb 24, 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
12 changes: 12 additions & 0 deletions libclc/clc/include/clc/math/clc_nan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __CLC_MATH_CLC_NAN_H__
#define __CLC_MATH_CLC_NAN_H__

#define __CLC_FUNCTION __clc_nan
#define __CLC_BODY <clc/math/clc_nan.inc>

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif // __CLC_MATH_CLC_NAN_H__
1 change: 1 addition & 0 deletions libclc/clc/include/clc/math/clc_nan.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_nan(__CLC_U_GENTYPE code);
1 change: 1 addition & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ math/clc_floor.cl
math/clc_frexp.cl
math/clc_mad.cl
math/clc_modf.cl
math/clc_nan.cl
math/clc_nextafter.cl
math/clc_rint.cl
math/clc_sw_fma.cl
Expand Down
5 changes: 5 additions & 0 deletions libclc/clc/lib/generic/math/clc_nan.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <clc/internal/clc.h>
#include <clc/utils.h>

#define __CLC_BODY <clc_nan.inc>
#include <clc/math/gentype.inc>
15 changes: 15 additions & 0 deletions libclc/clc/lib/generic/math/clc_nan.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if __CLC_FPSIZE == 64
#define NAN_MASK 0x7ff0000000000000ul
#elif __CLC_FPSIZE == 32
#define NAN_MASK 0x7fc00000
#elif __CLC_FPSIZE == 16
#define NAN_MASK 0x7e00
#endif

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_nan(__CLC_U_GENTYPE code) {
const __CLC_U_GENTYPE mask = NAN_MASK;
const __CLC_U_GENTYPE res = code | mask;
return __CLC_AS_GENTYPE(res);
}

#undef NAN_MASK
5 changes: 2 additions & 3 deletions libclc/generic/lib/math/nan.cl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <clc/clc.h>
#include <clc/utils.h>
#include <clc/clcmacro.h>
#include <clc/math/clc_nan.h>

#define __OPENCL_AS_GENTYPE __CLC_XCONCAT(as_, __CLC_GENTYPE)
#define __CLC_BODY <nan.inc>
#include <clc/math/gentype.inc>
14 changes: 1 addition & 13 deletions libclc/generic/lib/math/nan.inc
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
#if __CLC_FPSIZE == 64
#define NAN_MASK 0x7ff0000000000000ul
#elif __CLC_FPSIZE == 32
#define NAN_MASK 0x7fc00000
#elif __CLC_FPSIZE == 16
#define NAN_MASK 0x7e00
#endif

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE nan(__CLC_U_GENTYPE code) {
const __CLC_U_GENTYPE mask = NAN_MASK;
const __CLC_U_GENTYPE res = code | mask;
return __OPENCL_AS_GENTYPE(res);
return __clc_nan(code);
}

#undef NAN_MASK