[Beignet] [PATCH] support built-in function mad_sat(int) and mad_sat(uint)

Homer Hsing homer.xing at intel.com
Wed Aug 14 01:23:18 PDT 2013


this patch has been tested by piglit.
piglit test cases "int_mad_sat" and "uint_mad_sat" passed.

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 backend/src/ocl_stdlib.tmpl.h | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h
index d1cc6aa..2b5e470 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -367,13 +367,20 @@ INLINE_OVERLOADABLE ushort mad_sat(ushort a, ushort b, ushort c) {
   return x;
 }
 
-/* XXX not implemented. */
 INLINE_OVERLOADABLE int mad_sat(int a, int b, int c) {
-  return 0;
+  long x = (long)a * (long)b + (long)c;
+  if (x > 0x7FFFFFFF)
+    x = 0x7FFFFFFF;
+  else if (x < -0x7FFFFFFF-1)
+    x = -0x7FFFFFFF-1;
+  return (int)x;
 }
 
 INLINE_OVERLOADABLE uint mad_sat(uint a, uint b, uint c) {
-  return 0;
+  ulong x = (ulong)a * (ulong)b + (ulong)c;
+  if (x > 0xFFFFFFFFu)
+    x = 0xFFFFFFFFu;
+  return (uint)x;
 }
 
 INLINE_OVERLOADABLE uchar __rotate_left(uchar x, uchar y) { return (x << y) | (x >> (8 - y)); }
-- 
1.8.1.2



More information about the Beignet mailing list