[Beignet] [PATCH] support converting with rounding mode

Homer Hsing homer.xing at intel.com
Thu Oct 17 22:51:36 PDT 2013


support built-in functions of converting with rounding mode,
such as "convert_DSTTYPE_rtz, rte, rtp, rtn".

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 backend/src/gen_convert.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++
 backend/src/genconfig.sh   |  1 +
 2 files changed, 91 insertions(+)

diff --git a/backend/src/gen_convert.sh b/backend/src/gen_convert.sh
index 047cc19..1d1c0e7 100755
--- a/backend/src/gen_convert.sh
+++ b/backend/src/gen_convert.sh
@@ -224,3 +224,93 @@ for vector_length in $VECTOR_LENGTHS; do
     done
   done
 done
+
+echo '
+float __gen_ocl_rndz(float x);
+float __gen_ocl_rnde(float x);
+float __gen_ocl_rndu(float x);
+float __gen_ocl_rndd(float x);
+'
+
+# convert_DSTTYPE_ROUNDING function
+for vector_length in $VECTOR_LENGTHS; do
+  for ftype in $TYPES; do
+    fbasetype=`IFS=:; set -- dummy $ftype; echo $2`
+    if test $fbasetype = "double"; then continue; fi
+
+    for ttype in $TYPES; do
+      tbasetype=`IFS=:; set -- dummy $ttype; echo $2`
+      if test $tbasetype = "double"; then continue; fi
+
+      if test $vector_length -eq 1; then
+        echo "INLINE_OVERLOADABLE $tbasetype convert_${tbasetype}_rte($fbasetype x)"
+        if test $fbasetype = "float" -a $tbasetype != "float"; then
+          echo "{ return __gen_ocl_rnde(x); }"
+        else
+          echo "{ return x; }"
+        fi
+
+        echo "INLINE_OVERLOADABLE $tbasetype convert_${tbasetype}_rtz($fbasetype x)"
+        if test $fbasetype = "float" -a $tbasetype != "float"; then
+          echo "{ return __gen_ocl_rndz(x); }"
+        else
+          echo "{ return x; }"
+        fi
+
+        echo "INLINE_OVERLOADABLE $tbasetype convert_${tbasetype}_rtp($fbasetype x)"
+        if test $fbasetype = "float" -a $tbasetype != "float"; then
+          echo "{ return __gen_ocl_rndu(x); }"
+        else
+          echo "{ return x; }"
+        fi
+
+        echo "INLINE_OVERLOADABLE $tbasetype convert_${tbasetype}_rtn($fbasetype x)"
+        if test $fbasetype = "float" -a $tbasetype != "float"; then
+          echo "{ return __gen_ocl_rndd(x); }"
+        else
+          echo "{ return x; }"
+        fi
+
+        continue
+      fi
+
+      for rounding in $ROUNDING_MODES; do
+        fvectortype=$fbasetype$vector_length
+        tvectortype=$tbasetype$vector_length
+        conv="convert_${tbasetype}_${rounding}"
+
+        construct="$conv(v.s0)"
+        if test $vector_length -gt 1; then
+          construct="$construct, $conv(v.s1)"
+        fi
+        if test $vector_length -gt 2; then
+          construct="$construct, $conv(v.s2)"
+        fi
+        if test $vector_length -gt 3; then
+          construct="$construct, $conv(v.s3)"
+        fi
+        if test $vector_length -gt 4; then
+          construct="$construct, $conv(v.s4)"
+          construct="$construct, $conv(v.s5)"
+          construct="$construct, $conv(v.s6)"
+          construct="$construct, $conv(v.s7)"
+        fi
+        if test $vector_length -gt 8; then
+          construct="$construct, $conv(v.s8)"
+          construct="$construct, $conv(v.s9)"
+          construct="$construct, $conv(v.sA)"
+          construct="$construct, $conv(v.sB)"
+          construct="$construct, $conv(v.sC)"
+          construct="$construct, $conv(v.sD)"
+          construct="$construct, $conv(v.sE)"
+          construct="$construct, $conv(v.sF)"
+        fi
+
+        echo "INLINE OVERLOADABLE $tvectortype convert_${tvectortype}_${rounding}($fvectortype v) {"
+        echo "  return ($tvectortype)($construct);"
+        echo "}"
+        echo
+      done
+    done
+  done
+done
diff --git a/backend/src/genconfig.sh b/backend/src/genconfig.sh
index f55b670..689499e 100644
--- a/backend/src/genconfig.sh
+++ b/backend/src/genconfig.sh
@@ -7,4 +7,5 @@ TYPES="long:8 ulong:8 int:4 uint:4 short:2 ushort:2 char:1 uchar:1 double:8 floa
 # Supported vector lengths
 VECTOR_LENGTHS="1 2 3 4 8 16"
 
+ROUNDING_MODES="rte rtz rtp rtn"
 ## No user serviceable parts below here
-- 
1.8.3.2



More information about the Beignet mailing list