[Beignet] [PATCH 04/18] Add the as functions into the libocl.

junyan.he at inbox.com junyan.he at inbox.com
Tue Aug 12 00:31:29 PDT 2014


From: Junyan He <junyan.he at linux.intel.com>

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/libocl/Makefile.in           |  12 ++-
 backend/src/libocl/include/ocl.h         |   6 +-
 backend/src/libocl/script/gen_as.sh      | 124 +++++++++++++++++++++++++++++++
 backend/src/libocl/script/gen_common.inc |  11 +++
 4 files changed, 149 insertions(+), 4 deletions(-)
 create mode 100755 backend/src/libocl/script/gen_as.sh
 create mode 100644 backend/src/libocl/script/gen_common.inc

diff --git a/backend/src/libocl/Makefile.in b/backend/src/libocl/Makefile.in
index cc74fcb..0264391 100644
--- a/backend/src/libocl/Makefile.in
+++ b/backend/src/libocl/Makefile.in
@@ -3,8 +3,8 @@
 HEADER_INSTALL_PREFIX=@OCL_HEADER_DIR@
 BITCODE_INSTALL_PREFIX=@OCL_BITCODE_DIR@
 
-GENERATED_FILES=
-GENERATED_HEADERS=ocl_defines.h
+GENERATED_FILES=ocl_as.cl
+GENERATED_HEADERS=ocl_defines.h ocl_as.h
 GENERATED_CL_SRCS=$(addprefix lib/, $(GENERATED_FILES))
 GENERATED_CL_HEADERS=$(addprefix include/, $(GENERATED_HEADERS))
 CL_FILE_NAMES=ocl_workitem.cl $(GENERATED_FILES)
@@ -22,6 +22,14 @@ all:$(GENERATED_CL_HEADERS) $(GENERATED_CL_SRCS) lib/beignet.bc
 lib/beignet.bc:$(GENERATED_CL_HEADERS) $(GENERATED_CL_SRCS) $(CL_BITCODES) $(LL_BITCODES)
 	llvm-link -o $@ $(CL_BITCODES) $(LL_BITCODES)
 
+lib/ocl_as.cl:script/gen_common.inc
+	@echo "Generate the source:  $@"
+	@script/gen_as.sh > $@
+
+include/ocl_as.h:script/gen_common.inc
+	@echo "Generate the header:  $@"
+	@script/gen_as.sh -p > $@
+
 include/ocl_defines.h:include/ocl_defines.inh
 	@echo "Generate the header:  $@"
 	@rm -f $@
diff --git a/backend/src/libocl/include/ocl.h b/backend/src/libocl/include/ocl.h
index ef8b40a..5e150bf 100644
--- a/backend/src/libocl/include/ocl.h
+++ b/backend/src/libocl/include/ocl.h
@@ -1,7 +1,9 @@
 #ifndef __OCL_H__
 #define __OCL_H__
 
-//#include "ocl_defines.h"
-//#include "ocl_types.h"
+#include "ocl_defines.h"
+#include "ocl_types.h"
+#include "ocl_as.h"
+#include "ocl_workitem.h"
 
 #endif
diff --git a/backend/src/libocl/script/gen_as.sh b/backend/src/libocl/script/gen_as.sh
new file mode 100755
index 0000000..f8c9333
--- /dev/null
+++ b/backend/src/libocl/script/gen_as.sh
@@ -0,0 +1,124 @@
+#! /bin/sh -e
+
+if [ $1"a" = "-pa" ]; then
+    echo "#ifndef __OCL_AS_H__"
+    echo "#define __OCL_AS_H__"
+    echo "#include \"ocl_types.h\""
+    echo
+else
+    echo "#include \"ocl_as.h\""
+    echo
+fi
+
+#should be called at parent dir
+. ./script/gen_common.inc
+
+# Generate list of union sizes
+for type in $TYPES; do
+        size=`IFS=:; set -- dummy $type; echo $3`
+        for vector_length in $VECTOR_LENGTHS; do
+                if test $vector_length -eq 3; then
+                      continue;
+                fi
+                union_sizes="$union_sizes `expr $vector_length \* $size`"
+        done
+done
+union_sizes="`echo $union_sizes | tr ' ' '\n' | sort -n | uniq`"
+
+# For each union size
+for union_size in $union_sizes; do
+
+    if [ $1"a" != "-pa" ]; then
+	# Define an union that contains all vector types that have the same size as the union
+	unionname="union _type_cast_${union_size}_b"
+	echo "$unionname {"
+	for type in $TYPES; do
+	    basetype=`IFS=:; set -- dummy $type; echo $2`
+	    basesize=`IFS=:; set -- dummy $type; echo $3`
+	    for vector_length in $VECTOR_LENGTHS; do
+		if test $vector_length -eq 3; then
+		    vector_size_length="4"
+		else
+		    vector_size_length=$vector_length;
+		fi
+		vector_size_in_union="`expr $vector_size_length \* $basesize`"
+		if test $union_size -ne $vector_size_in_union; then
+		    continue
+		fi
+		if test $vector_length -eq 1; then
+		    vectortype=$basetype
+		else
+		    vectortype=$basetype$vector_length
+		fi
+		echo "  $vectortype _$vectortype;"
+	    done
+
+	done
+	echo "};"
+	echo
+    fi
+
+    # For each tuple of vector types that has the same size as the current union size,
+    # define an as_* function that converts types without changing binary representation.
+    for ftype in $TYPES; do
+	fbasetype=`IFS=:; set -- dummy $ftype; echo $2`
+	fbasesize=`IFS=:; set -- dummy $ftype; echo $3`
+	for fvector_length in $VECTOR_LENGTHS; do
+	    if test $fvector_length -eq 3; then
+		fvector_size_length="4"
+	    else
+		fvector_size_length=$fvector_length;
+	    fi
+	    fvector_size_in_union="`expr $fvector_size_length \* $fbasesize`"
+	    if test $union_size -ne $fvector_size_in_union; then
+		continue
+	    fi
+	    if test $fvector_length -eq 1; then
+		fvectortype=$fbasetype
+	    else
+		fvectortype=$fbasetype$fvector_length
+	    fi
+	    for ttype in $TYPES; do
+		tbasetype=`IFS=:; set -- dummy $ttype; echo $2`
+		tbasesize=`IFS=:; set -- dummy $ttype; echo $3`
+		if test $fbasetype = $tbasetype; then
+		    continue
+		fi
+		for tvector_length in $VECTOR_LENGTHS; do
+		    if test $tvector_length -eq 3; then
+			tvector_size_length="4"
+		    else
+			tvector_size_length=$tvector_length;
+		    fi
+		    tvector_size_in_union="`expr $tvector_size_length \* $tbasesize`"
+		    if test $union_size -ne $tvector_size_in_union; then
+			continue
+		    fi
+		    if test $tvector_length -eq 1; then
+			tvectortype=$tbasetype
+		    else
+			tvectortype=$tbasetype$tvector_length
+		    fi
+
+		    if [ $1"a" = "-pa" ]; then
+			echo "OVERLOADABLE $tvectortype as_$tvectortype($fvectortype v);"
+		    else
+			echo "OVERLOADABLE $tvectortype as_$tvectortype($fvectortype v) {"
+			echo "  $unionname u;"
+			echo "  u._$fvectortype = v;"
+			echo "  return u._$tvectortype;"
+			echo "}"
+			echo
+		    fi
+		done
+	    done
+	done
+
+    done
+
+done
+
+
+if [ $1"a" = "-pa" ]; then
+    echo "#endif /* __OCL_AS_H__ */"
+fi
diff --git a/backend/src/libocl/script/gen_common.inc b/backend/src/libocl/script/gen_common.inc
new file mode 100644
index 0000000..689499e
--- /dev/null
+++ b/backend/src/libocl/script/gen_common.inc
@@ -0,0 +1,11 @@
+#! /bin/false
+# This is to be sourced by the generation scripts
+
+# Supported base types and their lengths
+TYPES="long:8 ulong:8 int:4 uint:4 short:2 ushort:2 char:1 uchar:1 double:8 float:4"
+
+# 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