diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index 38f71dbdee0c..ae212eddef53 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -68,6 +68,7 @@ #include #include #include +#include #include #include #include diff --git a/libclc/generic/include/clc/integer/rhadd.h b/libclc/generic/include/clc/integer/rhadd.h new file mode 100644 index 000000000000..69b43faeebd2 --- /dev/null +++ b/libclc/generic/include/clc/integer/rhadd.h @@ -0,0 +1,2 @@ +#define __CLC_BODY +#include diff --git a/libclc/generic/include/clc/integer/rhadd.inc b/libclc/generic/include/clc/integer/rhadd.inc new file mode 100644 index 000000000000..88ccaf09fd5e --- /dev/null +++ b/libclc/generic/include/clc/integer/rhadd.inc @@ -0,0 +1 @@ +_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE rhadd(__CLC_GENTYPE x, __CLC_GENTYPE y); diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index e936fbc6d94b..5a68d07a402c 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -14,6 +14,7 @@ integer/clz_impl.ll integer/hadd.cl integer/mad24.cl integer/mul24.cl +integer/rhadd.cl integer/rotate.cl integer/sub_sat.cl integer/sub_sat_if.ll diff --git a/libclc/generic/lib/integer/rhadd.cl b/libclc/generic/lib/integer/rhadd.cl new file mode 100644 index 000000000000..c985870f7c7a --- /dev/null +++ b/libclc/generic/lib/integer/rhadd.cl @@ -0,0 +1,4 @@ +#include + +#define __CLC_BODY +#include diff --git a/libclc/generic/lib/integer/rhadd.inc b/libclc/generic/lib/integer/rhadd.inc new file mode 100644 index 000000000000..3d6076874808 --- /dev/null +++ b/libclc/generic/lib/integer/rhadd.inc @@ -0,0 +1,6 @@ +//rhadd = (x+y+1)>>1 +//This can be simplified to x>>1 + y>>1 + (1 if either x or y have the 1s bit set) +//This saves us having to do any checks for overflow in the addition sums +_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE rhadd(__CLC_GENTYPE x, __CLC_GENTYPE y) { + return (x>>(__CLC_GENTYPE)1)+(y>>(__CLC_GENTYPE)1)+((x&(__CLC_GENTYPE)1)|(y&(__CLC_GENTYPE)1)); +}