checkpoint nothing

This commit is contained in:
ed
2026-08-13 02:13:47 -04:00
parent d5f28b83ea
commit 7f0bdefbcb
7 changed files with 155 additions and 58 deletions
+89 -10
View File
@@ -519,8 +519,9 @@ internal MipsAtom* resolve_look_at__populate_proc(AtomArena_R aa
mac_yield()
})
/* Atom 6b in the bundle: GTE matrix-vector product off = R * (-eye).
* Reads -eye from scratch, mvmva with mx=0/cv=3/sf=1/v=3, stores MAC1/2/3 to scratch+96 (off, overwriting eye since it's no longer needed).
/* Atom 6b in the bundle: matrix-vector product off = R * (-eye) >> 12.
* Uses mac_apply_matrix_lv (RTPS path) which loads the RT matrix from look_at
* and computes MAC = RT * V0 >> 12. Stores off to scratch+96 (overwriting eye).
*
* GPR codes (assigned by resolve_look_at_init):
* r_scratch : R_ResolveScratch (R_T4) — scratch base
@@ -532,38 +533,116 @@ internal MipsAtom* resolve_look_at__populate_proc(AtomArena_R aa
internal MipsAtom* resolve_look_at__matrix_vector_proc(AtomArena_R aa
, U4 r_scratch
, U4 r_peye
, U4 r_look_at
, U4 r_tmp0, U4 r_tmp1, U4 r_tmp2
, U4 r_tmp3, U4 r_tmp4, U4 r_tmp5
) MipsAtom_Proc_(resolve_look_at__matrix_vector, aa, {
/* r_peye = &eye (slot +96, will be overwritten with off after MVMVA). */
/* r_peye = &eye (slot +96, will be overwritten with off). */
add_si(r_peye, r_scratch, O_(ResolveLookAtScratch,eye)),
nop,
/* pos = -eye: load eye.x/y/z, negate via sub_u from R_0. */
/* Load pos = -eye from scratch. */
load_word(r_tmp0, r_peye, O_(P3_S4,x)),
load_word(r_tmp1, r_peye, O_(P3_S4,y)),
load_word(r_tmp2, r_peye, O_(P3_S4,z)),
nop,
sub_u(r_tmp0, R_0, r_tmp0), /* pos.x = -eye.x */
sub_u(r_tmp0, R_0, r_tmp0),
sub_u(r_tmp1, R_0, r_tmp1),
sub_u(r_tmp2, R_0, r_tmp2),
/* mtc2 IR1/2/3 = pos (for MVMVA input). */
/* Pop look_at* from tape for RT matrix loading. */
load_word(r_look_at, R_TapePtr, O_(Binds_ResolveLookAtPopAndTrans,look_at)),
add_ui_self( R_TapePtr, S_(Binds_ResolveLookAtPopAndTrans)),
/* Load RT matrix from look_at into C2[0..4] via ctc2.
* Uses the interleaved load+ctc2 pattern (same as set_gte_mt3s2s4
* and libgte's ApplyMatrixLV): load 2 words, ctc2 both, etc.
* MT3_S2S4 stores m[i][j] as S2 (16-bit) packed row-major. */
load_word( r_tmp3, r_look_at, 0), load_word( r_tmp4, r_look_at, 4),
gte_mv_to_ctrl_r(r_tmp3, gte_cr_RT11), gte_mv_to_ctrl_r(r_tmp4, gte_cr_RT12),
load_word( r_tmp3, r_look_at, 8), load_word( r_tmp4, r_look_at, 12), load_word(r_tmp5, r_look_at, 16),
gte_mv_to_ctrl_r(r_tmp3, gte_cr_RT13), gte_mv_to_ctrl_r(r_tmp4, gte_cr_RT21), gte_mv_to_ctrl_r(r_tmp5, gte_cr_RT22),
nop2,
/* === Two-pass MVMVA decomposition (replicates libgte's ApplyMatrixLV) ===
* Pass 1: RT · (pos >> 15) with sf=0 → contributes (result << 3) to final.
* Pass 2: RT · (pos & 0x7FFF) with sf=1 → contributes (result >> 12) to final.
* Combined: final = (pass1 << 3) + pass2 = (RT · pos) >> 12.
* pos is in r_tmp0/1/2 (S4, 32-bit). High bits → r_tmp3/4/5. Low bits →
* back into r_tmp0/1/2 (reusing pos slots since they're consumed).
*
* For pos fitting in S16 range (|pos| < 32768), pos >> 15 = 0 for
* positive and -1 for negative. SRA fills with sign bit, so
* shift_aright gives the correct high bits directly.
* For low bits: negu + andi 0x7FFF + negu preserves sign.
* Since the full decomposition for 3 components needs branches and
* more GPRs than we have, and for |pos| < 32768 the high bits are
* just 0 or -1, we simplify: pass1 = RT · {0 or -1} << 3. */
/* pos.x decomposition: high = pos.x >> 15 (SRA, sign-fills).
* Low bits = pos.x & 0x7FFF with sign preserved.
* For |pos| < 32768, high = 0 (positive) or -1 (negative). */
shift_aright_var(r_tmp3, r_tmp0, 15), /* r_tmp3 = pos.x >> 15 (SRA) */
/* Low bits: if negative, negu+andi+negu; if positive, just andi.
* For S16-fitting values, andi 0x7FFF preserves bit 15 via the
* negu dance. But since pos.x fits in S16 for our case,
* we can just use pos.x & 0x7FFF and OR with the sign bit:
* low = (pos.x & 0x7FFF) | (pos.x & 0x8000).
* Simpler: for our camera positions, pos fits in S16 so the
* negu+andi+negu pattern just gives pos.x back. We can skip it
* and use pos.x directly for pass 2 IR input. */
/* r_tmp0 still has pos.x (S4, 32-bit). Pass 2 needs S16 in IR. */
/* mtc2 IR1/2/3 = high bits. */
gte_mv_to_data_r(r_tmp3, C2_IR1),
gte_mv_to_data_r(r_tmp4, C2_IR2),
gte_mv_to_data_r(r_tmp5, C2_IR3),
nop2, /* MTC2 retirement */
/* Pass 1 MVMVA: sf=0 (no shift), v=3 (IR), cv=3 (no TR), mx=0 (RT). */
gte_cmdw_mvmva_sf0_ir,
nop,
/* mfc2 MAC1/2/3 → r_tmp3/4/5 (pass 1 results). */
gte_mv_from_data_r(r_tmp3, C2_MAC1),
gte_mv_from_data_r(r_tmp4, C2_MAC2),
gte_mv_from_data_r(r_tmp5, C2_MAC3),
nop,
/* mtc2 IR1/2/3 = low bits.
* For S16-fitting pos, the low bits are just pos & 0x7FFF with
* sign preserved. Since pos.x = -eye.x fits in S16 for camera
* positions, we can use pos.x & 0xFFFF (which preserves the sign
* bit via the full 32-bit value). The GTE takes low 16 bits. */
and_i(r_tmp0, r_tmp0, 0xFFFF), /* pos.x low 16 bits */
and_i(r_tmp1, r_tmp1, 0xFFFF), /* pos.y low 16 bits */
and_i(r_tmp2, r_tmp2, 0xFFFF), /* pos.z low 16 bits */
gte_mv_to_data_r(r_tmp0, C2_IR1),
gte_mv_to_data_r(r_tmp1, C2_IR2),
gte_mv_to_data_r(r_tmp2, C2_IR3),
nop2,
/* MVMVA: sf=1 (integer, no shift), cv=3 (no TR), mx=0 (rotation matrix),
* v=3 (IR vector). Pre-set rotation matrix is the one set by set_gte_world. */
/* Pass 2 MVMVA: sf=1 (>>12), v=3 (IR), cv=3 (no TR), mx=0 (RT). */
gte_cmdw_mvmva_ir,
nop, /* GTE interlock */
nop,
/* mfc2 MAC1/2/3 → r_tmp0/r_tmp1/r_tmp2 (sign-extended into 32-bit GPRs). */
/* mfc2 MAC1/2/3 → r_tmp0/1/2 (pass 2 results). */
gte_mv_from_data_r(r_tmp0, C2_MAC1),
gte_mv_from_data_r(r_tmp1, C2_MAC2),
gte_mv_from_data_r(r_tmp2, C2_MAC3),
nop,
/* Combine: final = (pass1 << 3) + pass2.
* shift_lleft shifts left by 3. Since pass1 result fits in
* GPR (32-bit), sll by 3 is safe (worst case: shifts sign bit
* out, which is fine for the >>12 result). */
shift_lleft(r_tmp3, r_tmp3, 3),
add_u(r_tmp0, r_tmp0, r_tmp3),
shift_lleft(r_tmp4, r_tmp4, 3),
add_u(r_tmp1, r_tmp1, r_tmp4),
shift_lleft(r_tmp5, r_tmp5, 3),
add_u(r_tmp2, r_tmp2, r_tmp5),
/* Store off → scratch+96 (overwriting eye). Atom 6c reads from here. */
store_word(r_tmp0, r_peye, O_(V3_S4,x)),
store_word(r_tmp1, r_peye, O_(V3_S4,y)),