Skip to content
Closed
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
14 changes: 14 additions & 0 deletions libclc/clc/include/clc/integer/clc_abs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __CLC_INTEGER_CLC_ABS_H__
#define __CLC_INTEGER_CLC_ABS_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible abs
#define __clc_abs abs
#else

#define __CLC_BODY <clc/integer/clc_abs.inc>
#include <clc/integer/gentype.inc>

#endif

#endif // __CLC_INTEGER_CLC_ABS_H__
1 change: 1 addition & 0 deletions libclc/clc/include/clc/integer/clc_abs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x);
14 changes: 14 additions & 0 deletions libclc/clc/include/clc/integer/clc_abs_diff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef __CLC_INTEGER_CLC_ABS_DIFF_H__
#define __CLC_INTEGER_CLC_ABS_DIFF_H__

#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
// clspv and spir-v targets provide their own OpenCL-compatible abs_diff
#define __clc_abs_diff abs_diff
#else

#define __CLC_BODY <clc/integer/clc_abs_diff.inc>
#include <clc/integer/gentype.inc>

#endif

#endif // __CLC_INTEGER_CLC_ABS_DIFF_H__
2 changes: 2 additions & 0 deletions libclc/clc/include/clc/integer/clc_abs_diff.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_CLC_OVERLOAD _CLC_DECL __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
__CLC_GENTYPE y);
2 changes: 2 additions & 0 deletions libclc/clc/lib/generic/SOURCES
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
geometric/clc_dot.cl
integer/clc_abs.cl
integer/clc_abs_diff.cl
shared/clc_clamp.cl
shared/clc_max.cl
shared/clc_min.cl
4 changes: 4 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_abs.inc>
#include <clc/integer/gentype.inc>
4 changes: 4 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs(__CLC_GENTYPE x) {
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x),
__CLC_U_GENTYPE);
}
4 changes: 4 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs_diff.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <clc/internal/clc.h>

#define __CLC_BODY <clc_abs_diff.inc>
#include <clc/integer/gentype.inc>
6 changes: 6 additions & 0 deletions libclc/clc/lib/generic/integer/clc_abs_diff.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE __clc_abs_diff(__CLC_GENTYPE x,
__CLC_GENTYPE y) {
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
return x > y ? ux - uy : uy - ux;
}
1 change: 1 addition & 0 deletions libclc/generic/lib/integer/abs.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <clc/clc.h>
#include <clc/integer/clc_abs.h>

#define __CLC_BODY <abs.inc>
#include <clc/integer/gentype.inc>
2 changes: 1 addition & 1 deletion libclc/generic/lib/integer/abs.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs(__CLC_GENTYPE x) {
return __builtin_astype((__CLC_GENTYPE)(x > (__CLC_GENTYPE)(0) ? x : -x), __CLC_U_GENTYPE);
return __clc_abs(x);
}
1 change: 1 addition & 0 deletions libclc/generic/lib/integer/abs_diff.cl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <clc/clc.h>
#include <clc/integer/clc_abs_diff.h>

#define __CLC_BODY <abs_diff.inc>
#include <clc/integer/gentype.inc>
4 changes: 1 addition & 3 deletions libclc/generic/lib/integer/abs_diff.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_diff(__CLC_GENTYPE x, __CLC_GENTYPE y) {
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
return x > y ? ux - uy : uy - ux;
return __clc_abs_diff(x, y);
}
6 changes: 4 additions & 2 deletions libclc/generic/lib/math/clc_fma.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <clc/integer/clc_abs.h>
#include <clc/shared/clc_max.h>

#include "config.h"
#include "math.h"
Expand Down Expand Up @@ -84,7 +86,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) {

st_c.mantissa <<= C_ADJUST;
ulong cutoff_bits = 0;
ulong cutoff_mask = (1ul << abs(exp_diff)) - 1ul;
ulong cutoff_mask = (1ul << __clc_abs(exp_diff)) - 1ul;
if (exp_diff > 0) {
cutoff_bits =
exp_diff >= 64 ? st_c.mantissa : (st_c.mantissa & cutoff_mask);
Expand All @@ -97,7 +99,7 @@ _CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c) {

struct fp st_fma;
st_fma.sign = st_mul.sign;
st_fma.exponent = max(st_mul.exponent, st_c.exponent);
st_fma.exponent = __clc_max(st_mul.exponent, st_c.exponent);
if (st_c.sign == st_mul.sign) {
st_fma.mantissa = st_mul.mantissa + st_c.mantissa;
} else {
Expand Down
3 changes: 2 additions & 1 deletion libclc/generic/lib/math/clc_fmod.cl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <clc/clcmacro.h>
#include <clc/math/clc_floor.h>
#include <clc/math/clc_trunc.h>
#include <clc/shared/clc_max.h>

#include <math/clc_remainder.h>
#include "config.h"
Expand Down Expand Up @@ -105,7 +106,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_fmod(double x, double y)
// less than the mantissa of y, ntimes will be one too large
// but it doesn't matter - it just means that we'll go round
// the loop below one extra time.
int ntimes = max(0, (xexp1 - yexp1) / 53);
int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
double w = ldexp(dy, ntimes * 53);
w = ntimes == 0 ? dy : w;
double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
Expand Down
3 changes: 2 additions & 1 deletion libclc/generic/lib/math/clc_hypot.cl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <clc/clc.h>
#include <clc/clcmacro.h>
#include <clc/integer/clc_abs.h>
#include <clc/shared/clc_clamp.h>
#include <math/clc_hypot.h>

Expand Down Expand Up @@ -82,7 +83,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_hypot(double x, double y) {

// If the difference in exponents between x and y is large
double s = x + y;
c = abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
c = __clc_abs(xexp - yexp) > MANTLENGTH_DP64 + 1;
r = c ? s : r;

// Check for NaN
Expand Down
3 changes: 2 additions & 1 deletion libclc/generic/lib/math/clc_remainder.cl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <clc/clcmacro.h>
#include <clc/math/clc_floor.h>
#include <clc/math/clc_trunc.h>
#include <clc/shared/clc_max.h>

#include <math/clc_remainder.h>
#include "config.h"
Expand Down Expand Up @@ -115,7 +116,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remainder(double x, double y)
// less than the mantissa of y, ntimes will be one too large
// but it doesn't matter - it just means that we'll go round
// the loop below one extra time.
int ntimes = max(0, (xexp1 - yexp1) / 53);
int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
double w = ldexp(dy, ntimes * 53);
w = ntimes == 0 ? dy : w;
double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
Expand Down
3 changes: 2 additions & 1 deletion libclc/generic/lib/math/clc_remquo.cl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <clc/clcmacro.h>
#include <clc/math/clc_floor.h>
#include <clc/math/clc_trunc.h>
#include <clc/shared/clc_max.h>

#include <math/clc_remainder.h>
#include "config.h"
Expand Down Expand Up @@ -140,7 +141,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remquo(double x, double y, __private int *pq
// less than the mantissa of y, ntimes will be one too large
// but it doesn't matter - it just means that we'll go round
// the loop below one extra time.
int ntimes = max(0, (xexp1 - yexp1) / 53);
int ntimes = __clc_max(0, (xexp1 - yexp1) / 53);
double w = ldexp(dy, ntimes * 53);
w = ntimes == 0 ? dy : w;
double scale = ntimes == 0 ? 1.0 : 0x1.0p-53;
Expand Down
3 changes: 2 additions & 1 deletion libclc/generic/lib/math/sincos_helpers.cl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <clc/clc.h>
#include <clc/shared/clc_max.h>

#include "math.h"
#include "tables.h"
Expand Down Expand Up @@ -372,7 +373,7 @@ _CLC_DEF void __clc_remainder_piby2_large(double x, double *r, double *rr, int *

long ux = as_long(x);
int e = (int)(ux >> 52) - 1023;
int i = max(23, (e >> 3) + 17);
int i = __clc_max(23, (e >> 3) + 17);
int j = 150 - i;
int j16 = j & ~0xf;
double fract_temp;
Expand Down
Loading