mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 21:02:50 +00:00
bebc811f11
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.
21 lines
582 B
Python
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};")
|