diff options
author | Junyan He <junyan.he@linux.intel.com> | 2013-07-01 15:00:27 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@linux.intel.com> | 2013-07-01 16:50:38 +0800 |
commit | e13b048a84c677a74a1a538b1d204241e62f8de0 (patch) | |
tree | 4f4c46695e21064366b17d74b9ab3150adf4af6e /backend/src/ocl_stdlib.h | |
parent | fb3600f82d046ba4cce3b76d3f04f7ae653cc6df (diff) | |
download | beignet-e13b048a84c677a74a1a538b1d204241e62f8de0.tar.gz |
Add the builtin function abs() support
Signed-off-by: Junyan He <junyan.he@linux.intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Reviewed-by: Xing, Homer <homer.xing@intel.com>
Reviewed-by: Song, Ruiling <ruiling.song@intel.com>
Diffstat (limited to 'backend/src/ocl_stdlib.h')
-rw-r--r-- | backend/src/ocl_stdlib.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/backend/src/ocl_stdlib.h b/backend/src/ocl_stdlib.h index 148ac4d0..016d4697 100644 --- a/backend/src/ocl_stdlib.h +++ b/backend/src/ocl_stdlib.h @@ -4388,6 +4388,42 @@ DEF(16) #undef DEC8 #undef DEC16 +int __gen_ocl_abs(int x); +#define ABS_I(I, CVT) (CVT)__gen_ocl_abs(x.s##I) +#define ABS_VEC1(CVT) (CVT)__gen_ocl_abs(x) +#define ABS_VEC2(CVT) ABS_I(0, CVT), ABS_I(1, CVT) +#define ABS_VEC4(CVT) ABS_VEC2(CVT), ABS_I(2, CVT), ABS_I(3, CVT) +#define ABS_VEC8(CVT) ABS_VEC4(CVT), ABS_I(4, CVT), ABS_I(5, CVT),\ + ABS_I(6, CVT), ABS_I(7, CVT) +#define ABS_VEC16(CVT) ABS_VEC8(CVT), ABS_I(8, CVT), ABS_I(9, CVT), \ + ABS_I(A, CVT), ABS_I(B, CVT), ABS_I(C, CVT), \ + ABS_I(D, CVT), ABS_I(E, CVT), ABS_I(F, CVT) + +#define DEC_1(TYPE) INLINE_OVERLOADABLE u##TYPE abs(TYPE x) { return ABS_VEC1(u##TYPE); } +#define DEC_N(TYPE, N) INLINE_OVERLOADABLE u##TYPE##N abs(TYPE##N x) { return (u##TYPE##N)(ABS_VEC##N(u##TYPE)); }; +#define DEC(TYPE) DEC_1(TYPE) DEC_N(TYPE, 2) DEC_N(TYPE, 4) DEC_N(TYPE, 8) DEC_N(TYPE, 16) + +DEC(int) +DEC(short) +DEC(char) +#undef DEC_1 +#undef DEC_N +/* For unsigned types, do nothing. */ +#define DEC_1(TYPE) INLINE_OVERLOADABLE TYPE abs(TYPE x) { return x; } +#define DEC_N(TYPE, N) INLINE_OVERLOADABLE TYPE##N abs(TYPE##N x) { return x; } +DEC(uint) +DEC(ushort) +DEC(uchar) +#undef DEC +#undef DEC_1 +#undef DEC_N +#undef ABS_I +#undef ABS_VEC1 +#undef ABS_VEC2 +#undef ABS_VEC4 +#undef ABS_VEC8 +#undef ABS_VEC16 + ///////////////////////////////////////////////////////////////////////////// // Work Items functions (see 6.11.1 of OCL 1.1 spec) ///////////////////////////////////////////////////////////////////////////// |