quakeforge/libs/gamecode/swizzle.py
Bill Currie bebc811f11 [gamecode] Implement 4-component 32-bit swizzle
The swizzle instruction is very powerful in that in can do any of the
256 permutations of xyzw, optionally negate any combination of the
resulting components, and zero any combination of the result components
(even all). This means the one instruction can take care of any actual
swizzles, conjugation for complex and quaternion values, zeroing vectors
(not that it's the only way), and probably other weird things.

The python file was used to generate the jump table and actual swizzle
code.
2022-01-03 23:27:01 +09:00

21 lines
582 B
Python

def iter(func):
for i in range(4):
for j in range(4):
for k in range(4):
for l in range(4):
func(i, j, k, l)
coord=['x', 'y', 'z', 'w']
def label(i, j, k, l):
return f"swizzle_{coord[l]}{coord[k]}{coord[j]}{coord[i]}"
def print_ref(i, j, k, l):
print(f"\t\t&&{label(i, j, k, l)},")
def print_op(i, j, k, l):
print(f"\t{label(i, j, k, l)}: vec = swizzle (vec, (pr_ivec4_t) {{ {l}, {k}, {j}, {i} }}); goto negate;")
iter(print_op)
print("\tstatic void *swizzle_table[256] = {")
iter(print_ref)
print("\t};")