perf: glyph cache A/B testing, fast hash, frustumCull rcpss+cvtss2si

- glyph cache: add A/B toggle so BASELINE/CUSTOM periods alternate
  between original function and shadow cache. Swap Murmur2 hash for
  fast golden-ratio integer mix (3 insns vs multi-step).
- frustumCullBBox: fastRecip (vrcpss+NR) and cvtss2si replace vdivss
  and @round bloat. 2.0x speedup (was 1.6x).
- Fix all Zig operator precedence bugs in silicon_sse: & and | bind
  looser than == in Zig, so (flags & 0x8 == 0) was always false.
  Affected frustumCullBBox and processLinkedListCollision.
This commit is contained in:
MarcelineVQ
2026-03-23 21:15:15 -07:00
parent 0576a06ef0
commit 4b5fcd6fa6
+10 -1
View File
@@ -878,8 +878,10 @@ fn glyphDetour(a: u32, b: u32, c: u32, d: u32) callconv(hook.cc.fastcall) ?*anyo
const s = rdtsc(); const s = rdtsc();
if (ab_use_custom) {
// a=ECX=FontObject*, b=EDX=unused, c=charCode, d=param2 // a=ECX=FontObject*, b=EDX=unused, c=charCode, d=param2
const hash = std.hash.Murmur2_32.hashUint32WithSeed(c, a ^ d) & GLYPH_CACHE_MASK; // Fast integer mix — golden ratio hash. Murmur2 was overkill for 3 integer keys.
const hash = ((a ^ c *% 0x9E3779B9) ^ d) & GLYPH_CACHE_MASK;
const entry = &glyph_cache[hash]; const entry = &glyph_cache[hash];
if (entry.font_ptr == a and entry.char_code == c and entry.param2 == d) { if (entry.font_ptr == a and entry.char_code == c and entry.param2 == d) {
@@ -914,6 +916,13 @@ fn glyphDetour(a: u32, b: u32, c: u32, d: u32) callconv(hook.cc.fastcall) ?*anyo
prof.glyph_calls +|= 1; prof.glyph_calls +|= 1;
return ret; return ret;
} }
// BASELINE: just call original, measure cycles
const ret = glyph_hook.callOriginal(.{ a, b, c, d });
prof.glyph_cycles +|= rdtsc() - s;
prof.glyph_calls +|= 1;
return ret;
}
fn particleDetour(a: u32, b: u32, c: u32, d: u32) callconv(hook.cc.fastcall) ?*anyopaque { fn particleDetour(a: u32, b: u32, c: u32, d: u32) callconv(hook.cc.fastcall) ?*anyopaque {
const s = rdtsc(); const s = rdtsc();
const ret = particle_hook.callOriginal(.{ a, b, c, d }); const ret = particle_hook.callOriginal(.{ a, b, c, d });