diff options
author | Ruiling Song <ruiling.song@intel.com> | 2015-01-28 15:07:59 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2015-01-29 13:05:47 +0800 |
commit | 081221651d6d1a3c5721bbaf492c757f2b665c4d (patch) | |
tree | ee3902aa5b81f5a83e088fb0186701dcaa1d37c4 | |
parent | 5322f46ae5b13b64c09c18f423f82bccfeb23cca (diff) |
libocl: refine implementation of abs_diff()
Make it generate less instructions.
Signed-off-by: Ruiling Song <ruiling.song@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r-- | backend/src/libocl/tmpl/ocl_integer.tmpl.cl | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl index 4a06f15b..12408ebc 100644 --- a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl +++ b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl @@ -298,35 +298,17 @@ DEC(ulong) /* Char and short type abs diff */ /* promote char and short to int and will be no module overflow */ #define DEC(TYPE, UTYPE) OVERLOADABLE UTYPE abs_diff(TYPE x, TYPE y) \ - { return (UTYPE) (abs((int)x - (int)y)); } + { return y > x ? (y -x) : (x - y); } DEC(char, uchar) DEC(uchar, uchar) DEC(short, ushort) DEC(ushort, ushort) +DEC(int, uint) +DEC(uint, uint) +DEC(long, ulong) +DEC(ulong, ulong) #undef DEC -OVERLOADABLE uint abs_diff (uint x, uint y) { - /* same signed will never overflow. */ - return y > x ? (y -x) : (x - y); -} - -OVERLOADABLE uint abs_diff (int x, int y) { - /* same signed will never module overflow. */ - if ((x >= 0 && y >= 0) || (x <= 0 && y <= 0)) - return abs(x - y); - - return (abs(x) + abs(y)); -} - -OVERLOADABLE ulong abs_diff (long x, long y) { - if ((x >= 0 && y >= 0) || (x <= 0 && y <= 0)) - return abs(x - y); - return abs(x) + abs(y); -} -OVERLOADABLE ulong abs_diff (ulong x, ulong y) { - return y > x ? (y - x) : (x - y); -} - #define DECL_MIN_MAX_CLAMP(TYPE) \ OVERLOADABLE TYPE max(TYPE a, TYPE b) { \ |