[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.
This commit is contained in:
Bill Currie 2022-01-03 19:30:32 +09:00
parent b8d04874c3
commit bebc811f11
2 changed files with 397 additions and 0 deletions

21
libs/gamecode/swizzle.py Normal file
View file

@ -0,0 +1,21 @@
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};")