Made the atom offset/label metaprogram! Still need to support more than one branch per-atom.

This commit is contained in:
ed
2026-07-06 10:10:02 -04:00
parent c3a7e22743
commit 352a8c9c25
11 changed files with 930 additions and 42 deletions
@@ -0,0 +1,18 @@
// Auto-generated by gen_atom_offsets.lua — DO NOT EDIT
// Source: C:\projects\Pikuma\ps1\code\gte_hello\hello_gte_tape.c
#ifndef HELLO_GTE_TAPE_OFFSETS_H
#define HELLO_GTE_TAPE_OFFSETS_H
#pragma region hello_gte_tape
// Override the placeholder atom_offset() to dispatch via token pasting.
#undef atom_offset
#define atom_offset(name) atom_offset_##name
// --- atom: floor_tri (49 words) ---
#define atom_offset_floor_tri_exit (17)
#pragma endregion hello_gte_tape
#endif // HELLO_GTE_TAPE_OFFSETS_H
+5
View File
@@ -12,7 +12,12 @@
#include "duffle/mips.h"
#include "duffle/gp.h"
#include "duffle/gte.h"
# include "duffle/gen/lottes_tape.offsets.h"
#include "duffle/lottes_tape.h"
# include "tape_atom.metadata.h"
# include "gen/hello_gte_tape.offsets.h"
#include "hello_gte.h"
#include "hello_gte_tape.c"
+4 -1
View File
@@ -1,6 +1,8 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "duffle/lottes_tape.h"
# include "hello_gte.h"
# include "tape_atom.metadata.h"
# include "gen/hello_gte_tape.offsets.h"
#endif
#pragma region MACs
@@ -32,7 +34,7 @@ internal MipsAtom_(floor_tri) {
/* 4. Culling (Branch forward 29 instructions if Backface) */
gte_mf(R_T0, C2_MAC0),
nop, branch_le_zero(R_T0, 29),
nop, branch_le_zero(R_T0, atom_offset(floor_tri_exit)),
nop,
/* 5. Format Primitive */
@@ -54,6 +56,7 @@ internal MipsAtom_(floor_tri) {
add_ui(R_PrimCur, R_PrimCur, S_(Poly_F3)), /* Advance Prim Cursor (5 words) */
/* 9. Advance Input Cursor & Yield (Both branch targets land here) */
atom_label(floor_tri_exit)
add_ui(R_FaceCur, R_FaceCur, S_(S2) * 4), /* Advance Face Cursor (4 * S2 = 8 bytes) */
mac_yield()
};
+39
View File
@@ -0,0 +1,39 @@
// tape_atom.metadata.h
// Single source of truth for instruction-word counts.
// Used by C (to define compile-time constants) AND Python (to count positions).
//
// Format: WORD_COUNT(MACRO_NAME, COUNT)
// One line per macro that appears in your atom sources.
//
// To regenerate: hand-count the instructions in each macro definition.
// (You'll only need to do this once per macro — they don't change often.)
#define WORD_COUNT(name, count) enum { words_##name = (count) };
WORD_COUNT(nop, 1)
WORD_COUNT(branch_le_zero, 1)
WORD_COUNT(branch_equal, 1)
WORD_COUNT(add_ui, 1)
WORD_COUNT(slt_u, 1)
WORD_COUNT(load_ui, 1)
WORD_COUNT(load_word, 1)
WORD_COUNT(load_half_u, 1)
WORD_COUNT(store_word, 1)
WORD_COUNT(gte_mf, 1)
WORD_COUNT(gte_mt, 1)
WORD_COUNT(gte_ct, 1)
WORD_COUNT(gte_sw, 1)
WORD_COUNT(gte_cmdw_rtpt, 1)
WORD_COUNT(gte_cmdw_nclip, 1)
WORD_COUNT(gte_avg_sort_z3, 1)
WORD_COUNT(mac_load_tri_indices, 3)
WORD_COUNT(mac_load_tri_verts, 18)
WORD_COUNT(mac_format_f3_color, 3)
WORD_COUNT(mac_gte_store_f3, 3)
WORD_COUNT(mac_insert_ot_tag, 11)
WORD_COUNT(mac_yield, 4)
#undef WORD_COUNT
// Used to define word markers for the lua metaprogram to calculate offsets from.
#define atom_label(sym)
// #define atom_offset(sym) // will be generated based on usage within a baked atom.