Skip to content
Snippets Groups Projects
Commit 7659157f authored by Aaron Watry's avatar Aaron Watry
Browse files

Add hadd builtin


(x + y) >> 1 gets changed to:
(x>>1) + (y>>1) + (x&y&1)

Saves us having to do any llvm assembly and overflow checking in the addition.

Reviewed-by: default avatarTom Stellard <thomas.stellard@amd.com>
llvm-svn: 188476
parent d18fcc7a
No related branches found
No related tags found
No related merge requests found
......@@ -65,6 +65,7 @@
#include <clc/integer/abs_diff.h>
#include <clc/integer/add_sat.h>
#include <clc/integer/clz.h>
#include <clc/integer/hadd.h>
#include <clc/integer/mad24.h>
#include <clc/integer/mul24.h>
#include <clc/integer/rotate.h>
......
#define __CLC_BODY <clc/integer/hadd.inc>
#include <clc/integer/gentype.inc>
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE hadd(__CLC_GENTYPE x, __CLC_GENTYPE y);
......@@ -11,6 +11,7 @@ integer/add_sat_impl.ll
integer/clz.cl
integer/clz_if.ll
integer/clz_impl.ll
integer/hadd.cl
integer/mad24.cl
integer/mul24.cl
integer/rotate.cl
......
#include <clc/clc.h>
#define __CLC_BODY <hadd.inc>
#include <clc/integer/gentype.inc>
//hadd = (x+y)>>1
//This can be simplified to x>>1 + y>>1 + (1 if both x and y have the 1s bit set)
//This saves us having to do any checks for overflow in the addition sum
_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE hadd(__CLC_GENTYPE x, __CLC_GENTYPE y) {
return (x>>(__CLC_GENTYPE)1)+(y>>(__CLC_GENTYPE)1)+(x&y&(__CLC_GENTYPE)1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment