Make it generate less instructions. Signed-off-by: Ruiling Song <ruiling.s...@intel.com> --- backend/src/libocl/tmpl/ocl_integer.tmpl.cl | 28 +++++---------------------- 1 file 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 b46cf25..7357e16 100644 --- a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl +++ b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl @@ -350,35 +350,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) { \ -- 1.7.10.4 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet