tb_bind_ to help with named association of tb_data emissions

This commit is contained in:
ed
2026-08-20 22:35:34 -04:00
parent 85b2205603
commit f1801343e2
3 changed files with 16 additions and 19 deletions
+2
View File
@@ -160,6 +160,8 @@
* ----------------------------------------------------------------------------*/ * ----------------------------------------------------------------------------*/
#define atom_bind(binds_struct) /* atom_bind(binds_struct) */ #define atom_bind(binds_struct) /* atom_bind(binds_struct) */
#define Binds_(type) (tmpl(Binds,type) // TODO(Ed): Do we want to use this?
/* ============================================================================ /* ============================================================================
* atom_label / atom_offset — branch target machinery * atom_label / atom_offset — branch target machinery
* *
+2 -1
View File
@@ -244,7 +244,8 @@ FI_ void tb_data(TapeBuilder* tb, U4 data) { u4_r(tb->ptr)[tb->used] = u4
#define tb_emit_(atom) tb_emit(& tb, atom) #define tb_emit_(atom) tb_emit(& tb, atom)
#define tb_data_(field, data) tb_data(& tb, u4_(data)) #define tb_data_(field, data) tb_data(& tb, u4_(data))
FI_ void tb_emit_bundle(TapeBuilder_R tb, Slice_MipsAtom atoms) { mem_copy(u4_(tb->ptr), u4_(atoms.ptr), S_slice(atoms)); tb->used += atoms.len; } FI_ void tb_bind(TapeBuilder* tb, Slice data) { mem_copy(tb->ptr + tb->used * S_(MipsCode), u4_(data.ptr), data.len); tb->used += data.len / S_(MipsCode); }
#define tb_bind_(tb,type,...) tb_bind(tb, (Slice){ (B1*)(& (type){__VA_ARGS__}), S_(type) }); static_assert(S_(type) % S_(MipsCode) == 0)
FI_ Tape tb_end (TapeBuilder* tb) { tb_emit(tb,tape_exit); return (Tape){ C_(U4*,tb->ptr), tb->used }; } FI_ Tape tb_end (TapeBuilder* tb) { tb_emit(tb,tape_exit); return (Tape){ C_(U4*,tb->ptr), tb->used }; }
FI_ Tape tb_slice(TapeBuilder tb) { return (Tape){ C_(U4*,tb.ptr), tb.used }; } FI_ Tape tb_slice(TapeBuilder tb) { return (Tape){ C_(U4*,tb.ptr), tb.used }; }
+10 -16
View File
@@ -167,15 +167,11 @@ internal void compile_init_atoms(void) {
} }
internal void compile_resolve_look_at(void) { internal void compile_resolve_look_at(void) {
AtomArena ab = atomarena_make(slice_ut_arr(smem.resolve_look_at_mem));
AtomBundle_resolve_look_at_R bundle = C_(void*, smem.resolve_look_at_bundle); AtomBundle_resolve_look_at_R bundle = C_(void*, smem.resolve_look_at_bundle);
AtomArena ab = atomarena_make(slice_ut_arr(smem.resolve_look_at_mem));
/* R_ScratchBase (= R_SP) is a tape carrier preserved across atoms; no carrier
* pin is needed in the regfile. The standard 24-register pool is sufficient. */
RegFile rf = regfile(regfile_abi_mask); RegFile rf = regfile(regfile_abi_mask);
#define ralloc() regfile_alloc(& rf) #define ralloc() regfile_alloc(& rf)
#define ralloc_v3() { ralloc(), ralloc(), ralloc() } #define ralloc_v3() { ralloc(), ralloc(), ralloc() }
bundle->input_and_sub = AtomBundleEntry_(resolve_look_at, input_and_sub)(& ab, bundle->input_and_sub = AtomBundleEntry_(resolve_look_at, input_and_sub)(& ab,
RegUse_(resolve_look_at_input_and_sub) { RegUse_(resolve_look_at_input_and_sub) {
.target_ptr = ralloc(), .target_ptr = ralloc(),
@@ -203,29 +199,26 @@ internal void compile_resolve_look_at(void) {
.r2 = ralloc(), .r2 = ralloc(),
}); });
/* Sanity check: arena didn't overflow. */ assert(ab.used <= ResolveLookAtArena_Size); // Sanity check: arena didn't overflow.
assert(ab.used <= ResolveLookAtArena_Size);
#undef ralloc #undef ralloc
} }
/* Emit the resolve_look_at bundle into the tape. Called once per frame from update(). */ // Emit the resolve_look_at bundle into the tape. Called once per frame from update().
I_ void resolve_look_at(TapeBuilder_R tb I_ void resolve_look_at(TapeBuilder_R tb, MT3_S2S4* look_at, P3_S4* eye, P3_S4* target, V3_S4* up_in) {
, MT3_S2S4* look_at
, P3_S4* eye
, P3_S4* target
, V3_S4* up_in
){
/* Typed view of the scratchpad for field-address arithmetic. */ /* Typed view of the scratchpad for field-address arithmetic. */
ResolveLookAtScratch* sp = C_scratch(ResolveLookAtScratch*); ResolveLookAtScratch* sp = C_scratch(ResolveLookAtScratch*);
AtomBundle_resolve_look_at_R bundle = C_(void*, smem.resolve_look_at_bundle); AtomBundle_resolve_look_at_R bundle = C_(void*, smem.resolve_look_at_bundle);
tb_emit(tb, bundle->input_and_sub); { tb_emit(tb, bundle->input_and_sub); {
tb_data(tb, u4_(target)); tb_data(tb, u4_(target));
tb_data(tb, u4_(eye)); tb_data(tb, u4_(eye));
tb_data(tb, u4_(up_in)); tb_data(tb, u4_(up_in));
} }
tb_emit(tb, bundle->normalize_fwd_uz); { tb_emit(tb, bundle->normalize_fwd_uz); {
tb_data(tb, u4_(O_(ResolveLookAtScratch, fwd) | (O_(ResolveLookAtScratch, uz) << 16))); // tb_data(tb, u4_(O_(ResolveLookAtScratch, fwd) | (O_(ResolveLookAtScratch, uz) << 16)));
tb_bind_(tb, Binds_NormalizeV3S4,
.src_offset = O_(ResolveLookAtScratch,fwd),
.dst_offset = O_(ResolveLookAtScratch,uz),
);
} }
tb_emit(tb, bundle->cross_to_right); { tb_emit(tb, bundle->cross_to_right); {
tb_data(tb, u4_(& sp->uz)); tb_data(tb, u4_(& sp->uz));
@@ -247,6 +240,7 @@ I_ void resolve_look_at(TapeBuilder_R tb
tb_data(tb, u4_(look_at)); tb_data(tb, u4_(look_at));
} }
} }
FI_ void camera_look_at(TapeBuilder_R tb, Camera* c, P3_S4* target, V3_S4* up_in) { resolve_look_at(tb, & c->look_at, & c->pos, target, up_in); }
GCC_OPTIMIZATION_DISABLE GCC_OPTIMIZATION_DISABLE
void update(PrimitiveArena* pa, U4* ordering_buf) void update(PrimitiveArena* pa, U4* ordering_buf)