assembler/vs/validator: only count temp addresses for macro operations

This commit is contained in:
Zack Buhman 2025-10-20 20:44:57 -05:00
parent 44dd480549
commit 4777be84d4
3 changed files with 23 additions and 23 deletions

View File

@ -9,8 +9,8 @@ LDFLAGS += $(shell pkg-config --libs libdrm) -lm
%: %.c %: %.c
$(CC) $(ARCH) $(CFLAGS) $(LDFLAGS) $(OPT) $< -o $@ $(CC) $(ARCH) $(CFLAGS) $(LDFLAGS) $(OPT) $< -o $@
%.inc: %.asm %.vs.inc: %.vs.asm
PYTHONPATH=../regs/ python -m assembler $< > $@ PYTHONPATH=../regs/ python -m assembler.vs $< > $@
clean: clean:
find . -type f ! -name "*.*" -delete find . -type f ! -name "*.*" -delete

View File

@ -1,18 +1,18 @@
; CONST[0] = {0.159155, 0.5, 6.283185, -3.141593} # CONST[0] = {0.159155, 0.5, 6.283185, -3.141593}
; CONST[1] = {rotate, _, _, _} # CONST[1] = {rotate, _, _, _}
; each instruction is only allowed to use a single unique `const` address # each instruction is only allowed to use a single unique `const` address
; #
; instructions may use multiple `temp` addresses, so const[1] is moved to # instructions may use multiple `temp` addresses, so const[1] is moved to
; temp[0]: # temp[0]:
; #
temp[0].x = VE_ADD const[1].x___ const[1].0___ temp[0].x = VE_ADD const[1].x___ const[1].0___
; ME_SIN and ME_COS are clamped to the range -π to +π prior to the sin/cos # ME_SIN and ME_COS are clamped to the range -π to +π prior to the sin/cos
; calculation. # calculation.
; #
; This 3-instruction sequence linearly remaps the range [-∞,+∞] to [-π,+π] # This 3-instruction sequence linearly remaps the range [-,+] to [-π,+π]
temp[1].x = VE_MAD temp[0].x___ const[0].x___ const[0].y___ temp[1].x = VE_MAD temp[0].x___ const[0].x___ const[0].y___
temp[2].x = VE_FRC temp[1].x___ temp[2].x = VE_FRC temp[1].x___
temp[3].x = VE_MAD temp[2].x___ const[0].z___ const[0].w___ temp[3].x = VE_MAD temp[2].x___ const[0].z___ const[0].w___
@ -20,11 +20,11 @@ temp[3].x = VE_MAD temp[2].x___ const[0].z___ const[0].w___
temp[4].x = ME_SIN temp[3].___x temp[4].x = ME_SIN temp[3].___x
temp[4].y = ME_COS temp[3].___x temp[4].y = ME_COS temp[3].___x
; with sin and cos calculated, this now ordinary two-dimensional rotation: # with sin and cos calculated, this now ordinary two-dimensional rotation:
; #
; x = position.x * cost - position.y * sint # x = position.x * cost - position.y * sint
; y = position.x * sint + position.y * cost # y = position.x * sint + position.y * cost
; z = 0 # z = 0
; w = 1 # w = 1
temp[5].xy = VE_MUL input[0].yy__ temp[4].xy__ temp[5].xy = VE_MUL input[0].yy__ temp[4].xy__
out[0].xyzw = VE_MAD input[0].xx01 temp[4].yx01 temp[5].-xy00 out[0].xyzw = VE_MAD input[0].xx01 temp[4].yx01 temp[5].-xy00

View File

@ -1,15 +1,15 @@
from assembler.vs.keywords import ME, VE, macro_vector_operations from assembler.vs.keywords import KW, ME, VE, macro_vector_operations
class ValidatorError(Exception): class ValidatorError(Exception):
pass pass
def validate_instruction(ins): def validate_instruction(ins):
addresses = len(set( temp_addresses = len(set(
source.offset source.offset
for source in [ins.source0, ins.source1, ins.source2] for source in [ins.source0, ins.source1, ins.source2]
if source is not None if (source is not None and source.type == KW.temporary)
)) ))
if addresses > 2: if temp_addresses > 2:
if type(ins.destination_op.opcode) is not VE: if type(ins.destination_op.opcode) is not VE:
raise ValidatorError("too many addresses for non-VE instruction", ins) raise ValidatorError("too many addresses for non-VE instruction", ins)
if ins.destination_op.opcode.name not in {b"VE_MULTIPLYX2_ADD", b"VE_MULTIPLY_ADD"}: if ins.destination_op.opcode.name not in {b"VE_MULTIPLYX2_ADD", b"VE_MULTIPLY_ADD"}: