From 4777be84d42d4feba3c53bc81bd98513d1f5ae9c Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 20 Oct 2025 20:44:57 -0500 Subject: [PATCH] assembler/vs/validator: only count temp addresses for macro operations --- drm/Makefile | 4 ++-- drm/rotate.vs.asm | 34 +++++++++++++++++----------------- regs/assembler/vs/validator.py | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drm/Makefile b/drm/Makefile index 77759b5..a3c5ae2 100644 --- a/drm/Makefile +++ b/drm/Makefile @@ -9,8 +9,8 @@ LDFLAGS += $(shell pkg-config --libs libdrm) -lm %: %.c $(CC) $(ARCH) $(CFLAGS) $(LDFLAGS) $(OPT) $< -o $@ -%.inc: %.asm - PYTHONPATH=../regs/ python -m assembler $< > $@ +%.vs.inc: %.vs.asm + PYTHONPATH=../regs/ python -m assembler.vs $< > $@ clean: find . -type f ! -name "*.*" -delete diff --git a/drm/rotate.vs.asm b/drm/rotate.vs.asm index 199b524..2f8477f 100644 --- a/drm/rotate.vs.asm +++ b/drm/rotate.vs.asm @@ -1,18 +1,18 @@ -; CONST[0] = {0.159155, 0.5, 6.283185, -3.141593} -; CONST[1] = {rotate, _, _, _} +# CONST[0] = {0.159155, 0.5, 6.283185, -3.141593} +# CONST[1] = {rotate, _, _, _} -; each instruction is only allowed to use a single unique `const` address -; -; instructions may use multiple `temp` addresses, so const[1] is moved to -; temp[0]: -; +# each instruction is only allowed to use a single unique `const` address +# +# instructions may use multiple `temp` addresses, so const[1] is moved to +# temp[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 -; calculation. -; -; This 3-instruction sequence linearly remaps the range [-∞,+∞] to [-π,+π] +# ME_SIN and ME_COS are clamped to the range -π to +π prior to the sin/cos +# calculation. +# +# This 3-instruction sequence linearly remaps the range [-∞,+∞] to [-π,+π] temp[1].x = VE_MAD temp[0].x___ const[0].x___ const[0].y___ temp[2].x = VE_FRC temp[1].x___ 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].y = ME_COS temp[3].___x -; with sin and cos calculated, this now ordinary two-dimensional rotation: -; -; x = position.x * cost - position.y * sint -; y = position.x * sint + position.y * cost -; z = 0 -; w = 1 +# with sin and cos calculated, this now ordinary two-dimensional rotation: +# +# x = position.x * cost - position.y * sint +# y = position.x * sint + position.y * cost +# z = 0 +# w = 1 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 diff --git a/regs/assembler/vs/validator.py b/regs/assembler/vs/validator.py index 3d7f66c..5b6e118 100644 --- a/regs/assembler/vs/validator.py +++ b/regs/assembler/vs/validator.py @@ -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): pass def validate_instruction(ins): - addresses = len(set( + temp_addresses = len(set( source.offset 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: 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"}: