Skip to content

[libclc] Move copysign to CLC library; fix & optimize #124598

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
Jan 28, 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_copysign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __CLC_MATH_CLC_COPYSIGN_H__
#define __CLC_MATH_CLC_COPYSIGN_H__

#define __CLC_BODY <clc/shared/binary_decl.inc>
#define __CLC_FUNCTION __clc_copysign

#include <clc/math/gentype.inc>

#undef __CLC_BODY
#undef __CLC_FUNCTION

#endif // __CLC_MATH_CLC_COPYSIGN_H__
10 changes: 10 additions & 0 deletions libclc/clc/include/clc/shared/binary_def.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <clc/utils.h>

#ifndef __CLC_FUNCTION
#define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
#endif

_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE FUNCTION(__CLC_GENTYPE a,
__CLC_GENTYPE b) {
return __CLC_FUNCTION(FUNCTION)(a, b);
}
1 change: 1 addition & 0 deletions libclc/clc/lib/clspv/SOURCES
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
../generic/math/clc_ceil.cl
../generic/math/clc_copysign.cl
../generic/math/clc_fabs.cl
../generic/math/clc_floor.cl
../generic/math/clc_mad.cl
Expand Down
1 change: 1 addition & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ geometric/clc_dot.cl
integer/clc_abs.cl
integer/clc_abs_diff.cl
math/clc_ceil.cl
math/clc_copysign.cl
math/clc_fabs.cl
math/clc_floor.cl
math/clc_mad.cl
Expand Down
27 changes: 27 additions & 0 deletions libclc/clc/lib/generic/math/clc_copysign.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <clc/clcmacro.h>
#include <clc/internal/clc.h>

_CLC_DEFINE_BINARY_BUILTIN_NO_SCALARIZE(float, __clc_copysign,
__builtin_elementwise_copysign, float,
float)

#ifdef cl_khr_fp64

#pragma OPENCL EXTENSION cl_khr_fp64 : enable

_CLC_DEFINE_BINARY_BUILTIN_NO_SCALARIZE(double, __clc_copysign,
__builtin_elementwise_copysign, double,
double)

#endif

#ifdef cl_khr_fp16

#pragma OPENCL EXTENSION cl_khr_fp16 : enable

_CLC_DEFINE_BINARY_BUILTIN_NO_SCALARIZE(half, __clc_copysign,
__builtin_elementwise_copysign, half,
half)

#endif

1 change: 1 addition & 0 deletions libclc/clc/lib/spirv/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
../generic/common/clc_smoothstep.cl
../generic/geometric/clc_dot.cl
../generic/math/clc_ceil.cl
../generic/math/clc_copysign.cl
../generic/math/clc_fabs.cl
../generic/math/clc_floor.cl
../generic/math/clc_mad.cl
Expand Down
1 change: 1 addition & 0 deletions libclc/clc/lib/spirv64/SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
../generic/common/clc_smoothstep.cl
../generic/geometric/clc_dot.cl
../generic/math/clc_ceil.cl
../generic/math/clc_copysign.cl
../generic/math/clc_fabs.cl
../generic/math/clc_floor.cl
../generic/math/clc_mad.cl
Expand Down
28 changes: 4 additions & 24 deletions libclc/generic/lib/math/copysign.cl
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <clc/math/clc_copysign.h>

_CLC_DEFINE_BINARY_BUILTIN(float, copysign, __builtin_copysignf, float, float)
#define FUNCTION copysign
#define __CLC_BODY <clc/shared/binary_def.inc>

#ifdef cl_khr_fp64

#pragma OPENCL EXTENSION cl_khr_fp64 : enable

_CLC_DEFINE_BINARY_BUILTIN(double, copysign, __builtin_copysign, double, double)

#endif

#ifdef cl_khr_fp16

#pragma OPENCL EXTENSION cl_khr_fp16 : enable

_CLC_DEF _CLC_OVERLOAD half copysign(half x, half y)
{
ushort sign_x = as_ushort(x) & 0x8000u;
ushort unsigned_y = as_ushort(y) & 0x7ffffu;

return as_half((ushort)(sign_x | unsigned_y));
}
_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, copysign, half, half)

#endif
#include <clc/math/gentype.inc>
Loading