Skip to content

Commit 0d2ef7a

Browse files
authored
[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.
1 parent 3cc852e commit 0d2ef7a

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

libclc/generic/lib/gen_convert.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -241,41 +241,21 @@ def conditional_guard(src, dst):
241241
def generate_default_conversion(src, dst, mode):
242242
close_conditional = conditional_guard(src, dst)
243243

244-
# scalar conversions
245-
print(
246-
"""_CLC_DEF _CLC_OVERLOAD
247-
{DST} convert_{DST}{M}({SRC} x)
248-
{{
249-
return ({DST})x;
244+
for size in vector_sizes:
245+
if not size:
246+
print(
247+
f"""_CLC_DEF _CLC_OVERLOAD {dst} convert_{dst}{mode}({src} x) {{
248+
return ({dst})x;
250249
}}
251-
""".format(
252-
SRC=src, DST=dst, M=mode
253-
)
254-
)
255-
256-
# vector conversions, done through decomposition to components
257-
for size, half_size in half_sizes:
258-
print(
259-
"""_CLC_DEF _CLC_OVERLOAD
260-
{DST}{N} convert_{DST}{N}{M}({SRC}{N} x)
261-
{{
262-
return ({DST}{N})(convert_{DST}{H}(x.lo), convert_{DST}{H}(x.hi));
250+
"""
251+
)
252+
else:
253+
print(
254+
f"""_CLC_DEF _CLC_OVERLOAD {dst}{size} convert_{dst}{size}{mode}({src}{size} x) {{
255+
return __builtin_convertvector(x, {dst}{size});
263256
}}
264-
""".format(
265-
SRC=src, DST=dst, N=size, H=half_size, M=mode
257+
"""
266258
)
267-
)
268-
269-
# 3-component vector conversions
270-
print(
271-
"""_CLC_DEF _CLC_OVERLOAD
272-
{DST}3 convert_{DST}3{M}({SRC}3 x)
273-
{{
274-
return ({DST}3)(convert_{DST}2(x.s01), convert_{DST}(x.s2));
275-
}}""".format(
276-
SRC=src, DST=dst, M=mode
277-
)
278-
)
279259

280260
if close_conditional:
281261
print("#endif")

0 commit comments

Comments
 (0)