[libclc] 0d2ef7a - [libclc] Use builtin_convertvector to convert between vector types (#115865)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 08:18:37 PST 2024


Author: Fraser Cormack
Date: 2024-11-12T16:18:33Z
New Revision: 0d2ef7af1956b463b87a09500bd87bd4147616d4

URL: https://github.com/llvm/llvm-project/commit/0d2ef7af1956b463b87a09500bd87bd4147616d4
DIFF: https://github.com/llvm/llvm-project/commit/0d2ef7af1956b463b87a09500bd87bd4147616d4.diff

LOG: [libclc] Use builtin_convertvector to convert between vector types (#115865)

This keeps values in vectors, rather than scalarizing them and then
reconstituting the vector. The builtin is identical to performing a
C-style cast on each element, which is what we were doing by recursively
splitting the vector down to calling the "base" conversion function on
each element.

Added: 
    

Modified: 
    libclc/generic/lib/gen_convert.py

Removed: 
    


################################################################################
diff  --git a/libclc/generic/lib/gen_convert.py b/libclc/generic/lib/gen_convert.py
index 41bd8cebf88b60..d2f69e602a29da 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -241,41 +241,21 @@ def conditional_guard(src, dst):
 def generate_default_conversion(src, dst, mode):
     close_conditional = conditional_guard(src, dst)
 
-    # scalar conversions
-    print(
-        """_CLC_DEF _CLC_OVERLOAD
-{DST} convert_{DST}{M}({SRC} x)
-{{
-  return ({DST})x;
+    for size in vector_sizes:
+        if not size:
+            print(
+                f"""_CLC_DEF _CLC_OVERLOAD {dst} convert_{dst}{mode}({src} x) {{
+  return ({dst})x;
 }}
-""".format(
-            SRC=src, DST=dst, M=mode
-        )
-    )
-
-    # vector conversions, done through decomposition to components
-    for size, half_size in half_sizes:
-        print(
-            """_CLC_DEF _CLC_OVERLOAD
-{DST}{N} convert_{DST}{N}{M}({SRC}{N} x)
-{{
-  return ({DST}{N})(convert_{DST}{H}(x.lo), convert_{DST}{H}(x.hi));
+"""
+            )
+        else:
+            print(
+                f"""_CLC_DEF _CLC_OVERLOAD {dst}{size} convert_{dst}{size}{mode}({src}{size} x) {{
+  return __builtin_convertvector(x, {dst}{size});
 }}
-""".format(
-                SRC=src, DST=dst, N=size, H=half_size, M=mode
+"""
             )
-        )
-
-    # 3-component vector conversions
-    print(
-        """_CLC_DEF _CLC_OVERLOAD
-{DST}3 convert_{DST}3{M}({SRC}3 x)
-{{
-  return ({DST}3)(convert_{DST}2(x.s01), convert_{DST}(x.s2));
-}}""".format(
-            SRC=src, DST=dst, M=mode
-        )
-    )
 
     if close_conditional:
         print("#endif")


        


More information about the cfe-commits mailing list