[decomp] collide-func (#1034)

* add mips2c collide functions

* add ref test for collide-func

* fix test
This commit is contained in:
water111
2021-12-28 16:43:13 -05:00
committed by GitHub
parent 359e7bcfdd
commit 9b0ae373f0
13 changed files with 1018 additions and 19 deletions
+39 -5
View File
@@ -526,14 +526,28 @@ Mips2C_Line handle_lwc1(const Instruction& i0,
}
}
Mips2C_Line handle_lw(Mips2C_Output& out, const Instruction& i0, const std::string& instr_str) {
Mips2C_Line handle_lw(Mips2C_Output& out,
const Instruction& i0,
const std::string& instr_str,
const LinkedObjectFile* file) {
if (i0.get_src(1).is_reg(rs7()) && i0.get_src(0).is_sym()) {
// symbol load.
out.require_symbol(i0.get_src(0).get_sym());
return {fmt::format("c->load_symbol({}, cache.{});", reg_to_name(i0.get_dst(0)),
goal_to_c_name(i0.get_src(0).get_sym())),
instr_str};
}
if (i0.get_src(1).is_reg(rfp()) && i0.get_src(0).is_label()) {
const auto& label = file->labels.at(i0.get_src(0).get_label());
assert((label.offset % 4) == 0);
const auto& word = file->words_by_seg.at(label.target_segment).at(label.offset / 4);
assert(word.kind() == LinkedWord::PLAIN_DATA);
u32 val_u32 = word.data;
float val_float;
memcpy(&val_float, &val_u32, 4);
std::string comment = fmt::format("{} {}", instr_str, float_to_string(val_float));
return {fmt::format("c->lw_float_constant({}, 0x{:08x});", reg_to_name(i0.get_dst(0)), val_u32),
comment};
} else {
// fall back to standard loads
return handle_generic_load(i0, instr_str);
@@ -658,7 +672,7 @@ Mips2C_Line handle_or(const Instruction& i0, const std::string& instr_str) {
instr_str};
} else {
// actually do a logical OR of two registers: or a0, a1, a2
return handle_generic_op3(i0, instr_str, "_or");
return handle_generic_op3(i0, instr_str, "or_");
}
}
@@ -735,6 +749,8 @@ Mips2C_Line handle_likely_branch_bc(const Instruction& i0, const std::string& in
return {fmt::format("((s64){}) != ((s64){})", reg64_or_zero(i0.get_src(0)),
reg64_or_zero(i0.get_src(1))),
instr_str};
case InstructionKind::BC1TL:
return {"cop1_bc", instr_str};
default:
return handle_unknown(instr_str);
}
@@ -747,6 +763,13 @@ Mips2C_Line handle_vdiv(const Instruction& i0, const std::string& instr_string)
instr_string};
}
Mips2C_Line handle_vrsqrt(const Instruction& i0, const std::string& instr_string) {
return {fmt::format("c->vrsqrt({}, BC::{}, {}, BC::{});", reg_to_name(i0.get_src(0)),
"xyzw"[i0.get_src(1).get_vf_field()], reg_to_name(i0.get_src(2)),
"xyzw"[i0.get_src(3).get_vf_field()]),
instr_string};
}
Mips2C_Line handle_vsqrt(const Instruction& i0, const std::string& instr_string) {
return {fmt::format("c->vsqrt({}, BC::{});", reg_to_name(i0.get_src(0)),
"xyzw"[i0.get_src(1).get_vf_field()]),
@@ -786,6 +809,12 @@ Mips2C_Line handle_vopmula(const Instruction& i0, const std::string& instr_strin
instr_string};
}
Mips2C_Line handle_vopmsub(const Instruction& i0, const std::string& instr_string) {
return {fmt::format("c->vopmsub({}, {}, {});", reg_to_name(i0.get_dst(0)),
reg_to_name(i0.get_src(0)), reg_to_name(i0.get_src(1))),
instr_string};
}
Mips2C_Line handle_lui(const Instruction& i0, const std::string& instr_string) {
return {fmt::format("c->lui({}, {});", reg_to_name(i0.get_dst(0)), i0.get_src(0).get_imm()),
instr_string};
@@ -808,7 +837,7 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output,
const LinkedObjectFile* file) {
switch (i0.kind) {
case InstructionKind::LW:
return handle_lw(output, i0, instr_str);
return handle_lw(output, i0, instr_str, file);
case InstructionKind::LB:
case InstructionKind::LBU:
case InstructionKind::LWU:
@@ -845,6 +874,8 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output,
return handle_generic_op3_mask(i0, instr_str, "vsub");
case InstructionKind::VMINI:
return handle_generic_op3_mask(i0, instr_str, "vmini");
case InstructionKind::VMAX:
return handle_generic_op3_mask(i0, instr_str, "vmax");
case InstructionKind::OR:
return handle_or(i0, instr_str);
case InstructionKind::SW:
@@ -901,7 +932,6 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output,
case InstructionKind::PMAXW:
case InstructionKind::SUBU:
case InstructionKind::DSRAV:
case InstructionKind::VOPMSUB:
return handle_generic_op3(i0, instr_str, {});
case InstructionKind::MULS:
return handle_generic_op3(i0, instr_str, "muls");
@@ -936,6 +966,8 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output,
return handle_vdiv(i0, instr_str);
case InstructionKind::VSQRT:
return handle_vsqrt(i0, instr_str);
case InstructionKind::VRSQRT:
return handle_vrsqrt(i0, instr_str);
case InstructionKind::VRXOR:
return handle_vrxor(i0, instr_str);
case InstructionKind::VRGET:
@@ -973,6 +1005,8 @@ Mips2C_Line handle_normal_instr(Mips2C_Output& output,
return handle_plain_op(i0, instr_str, "vwaitq");
case InstructionKind::VOPMULA:
return handle_vopmula(i0, instr_str);
case InstructionKind::VOPMSUB:
return handle_vopmsub(i0, instr_str);
case InstructionKind::PMFHL_LH:
return handle_pmfhl_lh(i0, instr_str);
default:
+1 -1
View File
@@ -15613,7 +15613,7 @@
(define-extern ray-triangle-intersect (function vector vector float matrix vector vector float))
(define-extern collide-do-primitives (function float)) ;; NOTE - didn't bother to check input args
(define-extern moving-sphere-sphere-intersect (function vector vector vector vector float))
(define-extern moving-sphere-moving-sphere-intersect (function vector vector vector vector float))
(define-extern moving-sphere-moving-sphere-intersect (function vector vector vector vector vector float))
(define-extern moving-sphere-triangle-intersect (function vector vector float collide-cache-tri vector vector float))
@@ -526,7 +526,9 @@
"draw-inline-array-tfrag",
"stats-tfrag-asm",
"time-of-day-interp-colors-scratch",
"normalize-frame-quaternions"
"normalize-frame-quaternions",
"collide-do-primitives",
"moving-sphere-triangle-intersect"
],
// there are some missing textures. I don't know what the game actually does here.
+1
View File
@@ -60,6 +60,7 @@ set(RUNTIME_SOURCE
kernel/ksocket.cpp
kernel/ksound.cpp
mips2c/mips2c_table.cpp
mips2c/functions/collide_func.cpp
mips2c/functions/draw_string.cpp
mips2c/functions/sky_tng.cpp
mips2c/functions/sparticle.cpp
+20 -8
View File
@@ -300,16 +300,26 @@ void Tie3::render_tree(int idx,
tree.perf.tod_time.add(setup_timer.getSeconds());
int last_texture = -1;
u32 idx_buffer_ptr = 0;
Timer cull_timer;
cull_check_all_slow(settings.planes, tree.vis->vis_nodes, m_cache.vis_temp.data());
tree.perf.cull_time.add(cull_timer.getSeconds());
if (m_debug_all_visible) {
tree.perf.cull_time.add(0);
Timer index_timer;
idx_buffer_ptr = make_all_visible_index_list(m_cache.draw_idx_temp.data(),
m_cache.index_list.data(), *tree.draws);
tree.perf.index_time.add(index_timer.getSeconds());
tree.perf.index_upload = sizeof(u32) * idx_buffer_ptr;
} else {
Timer cull_timer;
cull_check_all_slow(settings.planes, tree.vis->vis_nodes, m_cache.vis_temp.data());
tree.perf.cull_time.add(cull_timer.getSeconds());
Timer index_timer;
int idx_buffer_ptr = make_index_list_from_vis_string(
m_cache.draw_idx_temp.data(), m_cache.index_list.data(), *tree.draws, m_cache.vis_temp);
tree.perf.index_time.add(index_timer.getSeconds());
tree.perf.index_upload = sizeof(u32) * idx_buffer_ptr;
Timer index_timer;
idx_buffer_ptr = make_index_list_from_vis_string(
m_cache.draw_idx_temp.data(), m_cache.index_list.data(), *tree.draws, m_cache.vis_temp);
tree.perf.index_time.add(index_timer.getSeconds());
tree.perf.index_upload = sizeof(u32) * idx_buffer_ptr;
}
Timer draw_timer;
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_ptr * sizeof(u32),
@@ -401,6 +411,8 @@ void Tie3::draw_debug_window() {
ImGui::Checkbox("Override level", &m_override_level);
ImGui::Checkbox("Fast ToD", &m_use_fast_time_of_day);
ImGui::Checkbox("Wireframe", &m_debug_wireframe);
ImGui::SameLine();
ImGui::Checkbox("All Visible", &m_debug_all_visible);
ImGui::Separator();
for (u32 i = 0; i < m_trees.size(); i++) {
auto& perf = m_trees[i].perf;
@@ -73,6 +73,7 @@ class Tie3 : public BucketRenderer {
bool m_override_level = false;
bool m_use_fast_time_of_day = true;
bool m_debug_wireframe = false;
bool m_debug_all_visible = false;
Filtered<float> m_all_tree_time;
TfragPcPortData m_pc_port_data;
@@ -302,6 +302,23 @@ void cull_check_all_slow(const math::Vector4f* planes,
}
}
u32 make_all_visible_index_list(std::pair<int, int>* group_out,
u32* idx_out,
const std::vector<tfrag3::StripDraw>& draws) {
int idx_buffer_ptr = 0;
for (size_t i = 0; i < draws.size(); i++) {
const auto& draw = draws[i];
std::pair<int, int> ds;
ds.first = idx_buffer_ptr;
memcpy(&idx_out[idx_buffer_ptr], draw.vertex_index_stream.data(),
draw.vertex_index_stream.size() * sizeof(u32));
idx_buffer_ptr += draw.vertex_index_stream.size();
ds.second = idx_buffer_ptr;
group_out[i] = ds;
}
return idx_buffer_ptr;
}
u32 make_index_list_from_vis_string(std::pair<int, int>* group_out,
u32* idx_out,
const std::vector<tfrag3::StripDraw>& draws,
@@ -59,4 +59,7 @@ struct TfragPcPortData {
u32 make_index_list_from_vis_string(std::pair<int, int>* group_out,
u32* idx_out,
const std::vector<tfrag3::StripDraw>& draws,
const std::vector<u8>& vis_data);
const std::vector<u8>& vis_data);
u32 make_all_visible_index_list(std::pair<int, int>* group_out,
u32* idx_out,
const std::vector<tfrag3::StripDraw>& draws);
+499
View File
@@ -0,0 +1,499 @@
//--------------------------MIPS2C---------------------
#include "game/mips2c/mips2c_private.h"
#include "game/kernel/kscheme.h"
// clang-format off
namespace Mips2C {
namespace collide_do_primitives {
struct Cache {
void* ray_cylinder_intersect; // ray-cylinder-intersect
void* ray_sphere_intersect; // ray-sphere-intersect
} cache;
u64 execute(void* ctxt) {
auto* c = (ExecutionContext*)ctxt;
bool bc = false;
u32 call_addr = 0;
bool cop1_bc = false;
c->daddiu(sp, sp, -144); // daddiu sp, sp, -144
c->sd(ra, 0, sp); // sd ra, 0(sp)
c->sd(fp, 8, sp); // sd fp, 8(sp)
c->mov64(fp, t9); // or fp, t9, r0
c->sq(s1, 32, sp); // sq s1, 32(sp)
c->sq(s2, 48, sp); // sq s2, 48(sp)
c->sq(s3, 64, sp); // sq s3, 64(sp)
c->sq(s4, 80, sp); // sq s4, 80(sp)
c->sq(s5, 96, sp); // sq s5, 96(sp)
c->sq(gp, 112, sp); // sq gp, 112(sp)
c->swc1(f28, 128, sp); // swc1 f28, 128(sp)
c->swc1(f30, 132, sp); // swc1 f30, 132(sp)
c->mov64(s4, a0); // or s4, a0, r0
c->mov64(s3, a1); // or s3, a1, r0
c->mov64(s1, a2); // or s1, a2, r0
c->mov64(s5, a3); // or s5, a3, r0
c->mov64(gp, t0); // or gp, t0, r0
c->daddiu(s2, sp, 16); // daddiu s2, sp, 16
c->lw_float_constant(v1, 0x40000000); // lw v1, L39(fp) 2.0
c->mtc1(f31, v1); // mtc1 f31, v1
c->mtc1(f28, r0); // mtc1 f28, r0
c->load_symbol(t9, cache.ray_sphere_intersect); // lw t9, ray-sphere-intersect(s7)
c->mov64(a0, s4); // or a0, s4, r0
c->mov64(a1, s3); // or a1, s3, r0
c->daddu(a2, r0, s5); // daddu a2, r0, s5
c->mov64(a3, s1); // or a3, s1, r0
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
c->mtc1(f30, v0); // mtc1 f30, v0
cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28
bc = cop1_bc; // bc1t L17
// nop // sll r0, r0, 0
if (bc) {goto block_2;} // branch non-likely
c->mtc1(f31, v0); // mtc1 f31, v0
c->lqc2(vf31, 0, s5); // lqc2 vf31, 0(s5)
block_2:
c->load_symbol(t9, cache.ray_sphere_intersect); // lw t9, ray-sphere-intersect(s7)
c->mov64(a0, s4); // or a0, s4, r0
c->mov64(a1, s3); // or a1, s3, r0
c->daddiu(a2, s5, 16); // daddiu a2, s5, 16
c->mov64(a3, s1); // or a3, s1, r0
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
c->mtc1(f30, v0); // mtc1 f30, v0
cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28
bc = cop1_bc; // bc1t L18
cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31
if (bc) {goto block_5;} // branch non-likely
bc = !cop1_bc; // bc1f L18
// nop // sll r0, r0, 0
if (bc) {goto block_5;} // branch non-likely
c->mtc1(f31, v0); // mtc1 f31, v0
c->lqc2(vf31, 16, s5); // lqc2 vf31, 16(s5)
block_5:
c->load_symbol(t9, cache.ray_sphere_intersect); // lw t9, ray-sphere-intersect(s7)
c->mov64(a0, s4); // or a0, s4, r0
c->mov64(a1, s3); // or a1, s3, r0
c->daddiu(a2, s5, 32); // daddiu a2, s5, 32
c->mov64(a3, s1); // or a3, s1, r0
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
c->mtc1(f30, v0); // mtc1 f30, v0
cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28
bc = cop1_bc; // bc1t L19
cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31
if (bc) {goto block_8;} // branch non-likely
bc = !cop1_bc; // bc1f L19
// nop // sll r0, r0, 0
if (bc) {goto block_8;} // branch non-likely
c->mtc1(f31, v0); // mtc1 f31, v0
c->lqc2(vf31, 32, s5); // lqc2 vf31, 32(s5)
block_8:
c->lqc2(vf1, 0, s5); // lqc2 vf1, 0(s5)
c->lqc2(vf2, 16, s5); // lqc2 vf2, 16(s5)
c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1
c->vmul(DEST::xyzw, vf3, vf2, vf2); // vmul.xyzw vf3, vf2, vf2
c->vadd_bc(DEST::x, BC::y, vf3, vf3, vf3); // vaddy.x vf3, vf3, vf3
c->vadd_bc(DEST::x, BC::z, vf3, vf3, vf3); // vaddz.x vf3, vf3, vf3
c->vrsqrt(vf0, BC::w, vf3, BC::x); // vrsqrt Q, vf0.w, vf3.x
c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3
c->mtc1(f30, v1); // mtc1 f30, v1
c->sqrts(f30, f30); // sqrt.s f30, f30
c->vwaitq(); // vwaitq
c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q
c->sqc2(vf2, 0, s2); // sqc2 vf2, 0(s2)
c->mfc1(t1, f30); // mfc1 t1, f30
c->load_symbol(t9, cache.ray_cylinder_intersect); // lw t9, ray-cylinder-intersect(s7)
c->mov64(a0, s4); // or a0, s4, r0
c->mov64(a1, s3); // or a1, s3, r0
c->daddu(a2, r0, s5); // daddu a2, r0, s5
c->mov64(a3, s2); // or a3, s2, r0
c->mov64(t0, s1); // or t0, s1, r0
c->mov64(t2, gp); // or t2, gp, r0
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
c->mtc1(f30, v0); // mtc1 f30, v0
cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28
bc = cop1_bc; // bc1t L20
cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31
if (bc) {goto block_11;} // branch non-likely
bc = !cop1_bc; // bc1f L20
// nop // sll r0, r0, 0
if (bc) {goto block_11;} // branch non-likely
c->mtc1(f31, v0); // mtc1 f31, v0
c->lqc2(vf31, 0, gp); // lqc2 vf31, 0(gp)
block_11:
c->lqc2(vf1, 16, s5); // lqc2 vf1, 16(s5)
c->lqc2(vf2, 32, s5); // lqc2 vf2, 32(s5)
c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1
c->vmul(DEST::xyzw, vf3, vf2, vf2); // vmul.xyzw vf3, vf2, vf2
c->vadd_bc(DEST::x, BC::y, vf3, vf3, vf3); // vaddy.x vf3, vf3, vf3
c->vadd_bc(DEST::x, BC::z, vf3, vf3, vf3); // vaddz.x vf3, vf3, vf3
c->vrsqrt(vf0, BC::w, vf3, BC::x); // vrsqrt Q, vf0.w, vf3.x
c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3
c->mtc1(f30, v1); // mtc1 f30, v1
c->sqrts(f30, f30); // sqrt.s f30, f30
c->vwaitq(); // vwaitq
c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q
c->sqc2(vf2, 0, s2); // sqc2 vf2, 0(s2)
c->mfc1(t1, f30); // mfc1 t1, f30
c->load_symbol(t9, cache.ray_cylinder_intersect); // lw t9, ray-cylinder-intersect(s7)
c->mov64(a0, s4); // or a0, s4, r0
c->mov64(a1, s3); // or a1, s3, r0
c->daddiu(a2, s5, 16); // daddiu a2, s5, 16
c->mov64(a3, s2); // or a3, s2, r0
c->mov64(t0, s1); // or t0, s1, r0
c->mov64(t2, gp); // or t2, gp, r0
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
c->mtc1(f30, v0); // mtc1 f30, v0
cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28
bc = cop1_bc; // bc1t L21
cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31
if (bc) {goto block_14;} // branch non-likely
bc = !cop1_bc; // bc1f L21
// nop // sll r0, r0, 0
if (bc) {goto block_14;} // branch non-likely
c->mtc1(f31, v0); // mtc1 f31, v0
c->lqc2(vf31, 0, gp); // lqc2 vf31, 0(gp)
block_14:
c->lqc2(vf1, 32, s5); // lqc2 vf1, 32(s5)
c->lqc2(vf2, 0, s5); // lqc2 vf2, 0(s5)
c->vsub(DEST::xyzw, vf2, vf2, vf1); // vsub.xyzw vf2, vf2, vf1
c->vmul(DEST::xyzw, vf3, vf2, vf2); // vmul.xyzw vf3, vf2, vf2
c->vadd_bc(DEST::x, BC::y, vf3, vf3, vf3); // vaddy.x vf3, vf3, vf3
c->vadd_bc(DEST::x, BC::z, vf3, vf3, vf3); // vaddz.x vf3, vf3, vf3
c->vrsqrt(vf0, BC::w, vf3, BC::x); // vrsqrt Q, vf0.w, vf3.x
c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3
c->mtc1(f30, v1); // mtc1 f30, v1
c->sqrts(f30, f30); // sqrt.s f30, f30
c->vwaitq(); // vwaitq
c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q
c->sqc2(vf2, 0, s2); // sqc2 vf2, 0(s2)
c->mfc1(t1, f30); // mfc1 t1, f30
c->load_symbol(t9, cache.ray_cylinder_intersect); // lw t9, ray-cylinder-intersect(s7)
c->daddiu(a2, s5, 32); // daddiu a2, s5, 32
c->mov64(t2, gp); // or t2, gp, r0
c->mov64(a0, s4); // or a0, s4, r0
c->mov64(a1, s3); // or a1, s3, r0
c->mov64(a3, s2); // or a3, s2, r0
c->mov64(t0, s1); // or t0, s1, r0
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
c->mtc1(f30, v0); // mtc1 f30, v0
cop1_bc = c->fprs[f30] < c->fprs[f28]; // c.lt.s f30, f28
bc = cop1_bc; // bc1t L22
cop1_bc = c->fprs[f30] < c->fprs[f31]; // c.lt.s f30, f31
if (bc) {goto block_17;} // branch non-likely
bc = !cop1_bc; // bc1f L22
// nop // sll r0, r0, 0
if (bc) {goto block_17;} // branch non-likely
c->mtc1(f31, v0); // mtc1 f31, v0
c->lqc2(vf31, 0, gp); // lqc2 vf31, 0(gp)
block_17:
c->fprs[f0] = 1.0; // lwc1 f0, L40(fp)
c->lw_float_constant(v1, 0xccbebc20); // lw v1, L41(fp) -100000000.0
cop1_bc = c->fprs[f0] < c->fprs[f31]; // c.lt.s f0, f31
if (cop1_bc) { // bc1tl L23
c->mtc1(f31, v1); // mtc1 f31, v1
goto block_19;
}
block_19:
c->mfc1(v0, f31); // mfc1 v0, f31
c->sqc2(vf31, 0, gp); // sqc2 vf31, 0(gp)
c->ld(ra, 0, sp); // ld ra, 0(sp)
c->ld(fp, 8, sp); // ld fp, 8(sp)
c->lwc1(f30, 132, sp); // lwc1 f30, 132(sp)
c->lwc1(f28, 128, sp); // lwc1 f28, 128(sp)
c->lq(gp, 112, sp); // lq gp, 112(sp)
c->lq(s5, 96, sp); // lq s5, 96(sp)
c->lq(s4, 80, sp); // lq s4, 80(sp)
c->lq(s3, 64, sp); // lq s3, 64(sp)
c->lq(s2, 48, sp); // lq s2, 48(sp)
c->lq(s1, 32, sp); // lq s1, 32(sp)
//jr ra // jr ra
c->daddiu(sp, sp, 144); // daddiu sp, sp, 144
goto end_of_function; // return
// nop // sll r0, r0, 0
// nop // sll r0, r0, 0
// nop // sll r0, r0, 0
end_of_function:
return c->gprs[v0].du64[0];
}
void link() {
cache.ray_cylinder_intersect = intern_from_c("ray-cylinder-intersect").c();
cache.ray_sphere_intersect = intern_from_c("ray-sphere-intersect").c();
gLinkedFunctionTable.reg("collide-do-primitives", execute, 512);
}
} // namespace collide_do_primitives
} // namespace Mips2C
//--------------------------MIPS2C---------------------
#include "game/mips2c/mips2c_private.h"
#include "game/kernel/kscheme.h"
namespace Mips2C {
namespace moving_sphere_triangle_intersect {
struct Cache {
void* collide_do_primitives; // collide-do-primitives
} cache;
u64 execute(void* ctxt) {
auto* c = (ExecutionContext*)ctxt;
bool bc = false;
u32 call_addr = 0;
c->daddiu(sp, sp, -16); // daddiu sp, sp, -16
c->sd(ra, 0, sp); // sd ra, 0(sp)
c->lqc2(vf14, 0, a0); // lqc2 vf14, 0(a0)
c->lqc2(vf15, 0, a1); // lqc2 vf15, 0(a1)
c->lqc2(vf11, 0, a3); // lqc2 vf11, 0(a3)
c->lqc2(vf12, 16, a3); // lqc2 vf12, 16(a3)
c->lqc2(vf13, 32, a3); // lqc2 vf13, 32(a3)
c->mov128_vf_gpr(vf1, a2); // qmtc2.i vf1, a2
c->vadd(DEST::xyzw, vf6, vf14, vf15); // vadd.xyzw vf6, vf14, vf15
c->vsub(DEST::xyzw, vf11, vf11, vf12); // vsub.xyzw vf11, vf11, vf12
c->vsub(DEST::xyzw, vf13, vf13, vf12); // vsub.xyzw vf13, vf13, vf12
c->vsub(DEST::xyzw, vf14, vf14, vf12); // vsub.xyzw vf14, vf14, vf12
c->vsub(DEST::xyzw, vf6, vf6, vf12); // vsub.xyzw vf6, vf6, vf12
c->vmini(DEST::xyzw, vf2, vf11, vf0); // vmini.xyzw vf2, vf11, vf0
c->vopmula(vf13, vf11); // vopmula.xyz acc, vf13, vf11
c->vopmsub(vf16, vf11, vf13); // vopmsub.xyz vf16, vf11, vf13
c->vmax(DEST::xyzw, vf3, vf11, vf0); // vmax.xyzw vf3, vf11, vf0
c->vmini(DEST::xyzw, vf4, vf14, vf6); // vmini.xyzw vf4, vf14, vf6
c->vmax(DEST::xyzw, vf5, vf14, vf6); // vmax.xyzw vf5, vf14, vf6
c->vmul(DEST::xyzw, vf7, vf16, vf16); // vmul.xyzw vf7, vf16, vf16
c->vmini(DEST::xyzw, vf2, vf2, vf13); // vmini.xyzw vf2, vf2, vf13
c->vmax(DEST::xyzw, vf3, vf3, vf13); // vmax.xyzw vf3, vf3, vf13
c->vsub_bc(DEST::xyzw, BC::x, vf4, vf4, vf1); // vsubx.xyzw vf4, vf4, vf1
c->vadd_bc(DEST::x, BC::y, vf7, vf7, vf7); // vaddy.x vf7, vf7, vf7
c->vadd_bc(DEST::xyzw, BC::x, vf5, vf5, vf1); // vaddx.xyzw vf5, vf5, vf1
// nop // sll r0, r0, 0
c->vsub(DEST::xyzw, vf3, vf3, vf4); // vsub.xyzw vf3, vf3, vf4
c->vadd_bc(DEST::x, BC::z, vf7, vf7, vf7); // vaddz.x vf7, vf7, vf7
c->vsub(DEST::xyzw, vf5, vf5, vf2); // vsub.xyzw vf5, vf5, vf2
// nop // sll r0, r0, 0
c->mov128_gpr_vf(t2, vf3); // qmfc2.i t2, vf3
c->mov128_gpr_vf(v1, vf5); // qmfc2.i v1, vf5
c->vrsqrt(vf0, BC::w, vf7, BC::x); // vrsqrt Q, vf0.w, vf7.x
c->or_(v1, t2, v1); // or v1, t2, v1
c->pcgtw(v1, r0, v1); // pcgtw v1, r0, v1
c->ppach(v1, r0, v1); // ppach v1, r0, v1
c->dsll(v1, v1, 16); // dsll v1, v1, 16
bc = c->sgpr64(v1) != 0; // bne v1, r0, L14
// nop // sll r0, r0, 0
if (bc) {goto block_14;} // branch non-likely
c->vmul(DEST::xyzw, vf2, vf16, vf15); // vmul.xyzw vf2, vf16, vf15
c->vmul(DEST::xyzw, vf3, vf16, vf14); // vmul.xyzw vf3, vf16, vf14
c->vadd_bc(DEST::x, BC::y, vf2, vf2, vf2); // vaddy.x vf2, vf2, vf2
c->vsub_bc(DEST::y, BC::y, vf3, vf0, vf3); // vsuby.y vf3, vf0, vf3
c->vadd_bc(DEST::x, BC::z, vf2, vf2, vf2); // vaddz.x vf2, vf2, vf2
c->vsub_bc(DEST::y, BC::x, vf3, vf3, vf3); // vsubx.y vf3, vf3, vf3
c->vsub_bc(DEST::y, BC::z, vf3, vf3, vf3); // vsubz.y vf3, vf3, vf3
c->vadd_bc(DEST::x, BC::x, vf3, vf0, vf0); // vaddx.x vf3, vf0, vf0
c->vadd_bc(DEST::x, BC::x, vf4, vf0, vf0); // vaddx.x vf4, vf0, vf0
c->vwaitq(); // vwaitq
c->vmulq(DEST::xyzw, vf16, vf16); // vmulq.xyzw vf16, vf16, Q
c->vmove(DEST::w, vf16, vf0); // vmove.w vf16, vf0
c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q
c->vmulq(DEST::xyzw, vf4, vf3); // vmulq.xyzw vf4, vf3, Q
c->vmulq(DEST::xyzw, vf3, vf3); // vmulq.xyzw vf3, vf3, Q
c->sqc2(vf16, 0, t1); // sqc2 vf16, 0(t1)
// nop // vnop
// nop // vnop
c->vdiv(vf0, BC::w, vf2, BC::x); // vdiv Q, vf0.w, vf2.x
c->vadd_bc(DEST::y, BC::x, vf3, vf3, vf1); // vaddx.y vf3, vf3, vf1
c->vsub_bc(DEST::y, BC::x, vf4, vf4, vf1); // vsubx.y vf4, vf4, vf1
c->vwaitq(); // vwaitq
c->vmulq(DEST::xyzw, vf3, vf3); // vmulq.xyzw vf3, vf3, Q
c->vmulq(DEST::xyzw, vf4, vf4); // vmulq.xyzw vf4, vf4, Q
// nop // sll r0, r0, 0
// nop // sll r0, r0, 0
c->mov128_gpr_vf(v1, vf3); // qmfc2.i v1, vf3
c->mov128_gpr_vf(t1, vf4); // qmfc2.i t1, vf4
bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L12
// nop // sll r0, r0, 0
if (bc) {goto block_11;} // branch non-likely
bc = ((s64)c->sgpr64(t1)) < 0; // bltz t1, L13
// nop // sll r0, r0, 0
if (bc) {goto block_12;} // branch non-likely
c->dsubu(v1, v1, t1); // dsubu v1, v1, t1
bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L9
// nop // sll r0, r0, 0
if (bc) {goto block_6;} // branch non-likely
c->vsub_bc(DEST::xyzw, BC::w, vf2, vf4, vf0); // vsubw.xyzw vf2, vf4, vf0
c->mov128_gpr_vf(v1, vf2); // qmfc2.i v1, vf2
bc = ((s64)c->sgpr64(v1)) >= 0; // bgez v1, L14
// nop // sll r0, r0, 0
if (bc) {goto block_14;} // branch non-likely
c->mov128_gpr_vf(v0, vf4); // qmfc2.i v0, vf4
c->vmula_bc(DEST::xyzw, BC::w, vf14, vf0); // vmulaw.xyzw acc, vf14, vf0
c->vmadd_bc(DEST::xyzw, BC::y, vf8, vf15, vf4); // vmaddy.xyzw vf8, vf15, vf4
//beq r0, r0, L10 // beq r0, r0, L10
// nop // sll r0, r0, 0
goto block_8; // branch always
block_6:
c->vsub_bc(DEST::xyzw, BC::w, vf2, vf3, vf0); // vsubw.xyzw vf2, vf3, vf0
c->mov128_gpr_vf(v1, vf2); // qmfc2.i v1, vf2
bc = ((s64)c->sgpr64(v1)) >= 0; // bgez v1, L14
// nop // sll r0, r0, 0
if (bc) {goto block_14;} // branch non-likely
c->vmula_bc(DEST::xyzw, BC::w, vf14, vf0); // vmulaw.xyzw acc, vf14, vf0
c->vmadd_bc(DEST::xyzw, BC::y, vf8, vf15, vf3); // vmaddy.xyzw vf8, vf15, vf3
c->mov128_gpr_vf(v0, vf3); // qmfc2.i v0, vf3
block_8:
c->dsra32(v0, v0, 0); // dsra32 v0, v0, 0
c->vsub(DEST::xyzw, vf9, vf8, vf13); // vsub.xyzw vf9, vf8, vf13
c->vsub(DEST::xyzw, vf10, vf8, vf11); // vsub.xyzw vf10, vf8, vf11
c->vopmula(vf13, vf8); // vopmula.xyz acc, vf13, vf8
c->vopmsub(vf5, vf8, vf13); // vopmsub.xyz vf5, vf8, vf13
c->vopmula(vf8, vf11); // vopmula.xyz acc, vf8, vf11
c->vopmsub(vf6, vf11, vf8); // vopmsub.xyz vf6, vf11, vf8
c->vopmula(vf9, vf10); // vopmula.xyz acc, vf9, vf10
c->vopmsub(vf7, vf10, vf9); // vopmsub.xyz vf7, vf10, vf9
c->vmul(DEST::xyzw, vf5, vf5, vf16); // vmul.xyzw vf5, vf5, vf16
c->vmul(DEST::xyzw, vf6, vf6, vf16); // vmul.xyzw vf6, vf6, vf16
c->vmul(DEST::xyzw, vf7, vf7, vf16); // vmul.xyzw vf7, vf7, vf16
c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5
c->vadd_bc(DEST::y, BC::x, vf6, vf6, vf6); // vaddx.y vf6, vf6, vf6
c->vadd_bc(DEST::y, BC::x, vf7, vf7, vf7); // vaddx.y vf7, vf7, vf7
c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5
c->vadd_bc(DEST::y, BC::z, vf6, vf6, vf6); // vaddz.y vf6, vf6, vf6
c->vadd_bc(DEST::y, BC::z, vf7, vf7, vf7); // vaddz.y vf7, vf7, vf7
c->mov128_gpr_vf(t1, vf5); // qmfc2.i t1, vf5
c->mov128_gpr_vf(t2, vf6); // qmfc2.i t2, vf6
c->mov128_gpr_vf(v1, vf7); // qmfc2.i v1, vf7
c->or_(t1, t1, t2); // or t1, t1, t2
c->or_(v1, t1, v1); // or v1, t1, v1
bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L11
// nop // sll r0, r0, 0
if (bc) {goto block_10;} // branch non-likely
c->vopmula(vf8, vf16); // vopmula.xyz acc, vf8, vf16
c->vopmsub(vf5, vf16, vf8); // vopmsub.xyz vf5, vf16, vf8
c->vopmula(vf16, vf5); // vopmula.xyz acc, vf16, vf5
c->vopmsub(vf5, vf5, vf16); // vopmsub.xyz vf5, vf5, vf16
c->vadd(DEST::xyzw, vf5, vf5, vf12); // vadd.xyzw vf5, vf5, vf12
c->sqc2(vf5, 0, t0); // sqc2 vf5, 0(t0)
//beq r0, r0, L15 // beq r0, r0, L15
// nop // sll r0, r0, 0
goto block_15; // branch always
block_10:
c->load_symbol(t9, cache.collide_do_primitives); // lw t9, collide-do-primitives(s7)
call_addr = c->gprs[t9].du32[0]; // function call:
c->sll(v0, ra, 0); // sll v0, ra, 0
c->jalr(call_addr); // jalr ra, t9
c->mov64(v1, v0); // or v1, v0, r0
//beq r0, r0, L15 // beq r0, r0, L15
// nop // sll r0, r0, 0
goto block_15; // branch always
block_11:
bc = ((s64)c->sgpr64(t1)) < 0; // bltz t1, L14
// nop // sll r0, r0, 0
if (bc) {goto block_14;} // branch non-likely
block_12:
c->vsub(DEST::xyzw, vf9, vf14, vf13); // vsub.xyzw vf9, vf14, vf13
c->vsub(DEST::xyzw, vf10, vf14, vf11); // vsub.xyzw vf10, vf14, vf11
c->vopmula(vf13, vf14); // vopmula.xyz acc, vf13, vf14
c->vopmsub(vf5, vf14, vf13); // vopmsub.xyz vf5, vf14, vf13
c->vopmula(vf14, vf11); // vopmula.xyz acc, vf14, vf11
c->vopmsub(vf6, vf11, vf14); // vopmsub.xyz vf6, vf11, vf14
c->vopmula(vf9, vf10); // vopmula.xyz acc, vf9, vf10
c->vopmsub(vf7, vf10, vf9); // vopmsub.xyz vf7, vf10, vf9
c->vmul(DEST::xyzw, vf5, vf5, vf16); // vmul.xyzw vf5, vf5, vf16
c->vmul(DEST::xyzw, vf6, vf6, vf16); // vmul.xyzw vf6, vf6, vf16
c->vmul(DEST::xyzw, vf7, vf7, vf16); // vmul.xyzw vf7, vf7, vf16
c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5
c->vadd_bc(DEST::y, BC::x, vf6, vf6, vf6); // vaddx.y vf6, vf6, vf6
c->vadd_bc(DEST::y, BC::x, vf7, vf7, vf7); // vaddx.y vf7, vf7, vf7
c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5
c->vadd_bc(DEST::y, BC::z, vf6, vf6, vf6); // vaddz.y vf6, vf6, vf6
c->vadd_bc(DEST::y, BC::z, vf7, vf7, vf7); // vaddz.y vf7, vf7, vf7
c->mov128_gpr_vf(t1, vf5); // qmfc2.i t1, vf5
c->mov128_gpr_vf(t2, vf6); // qmfc2.i t2, vf6
c->mov128_gpr_vf(v1, vf7); // qmfc2.i v1, vf7
c->or_(t1, t1, t2); // or t1, t1, t2
c->or_(v1, t1, v1); // or v1, t1, v1
bc = ((s64)c->sgpr64(v1)) < 0; // bltz v1, L11
// nop // sll r0, r0, 0
if (bc) {goto block_10;} // branch non-likely
c->vopmula(vf14, vf16); // vopmula.xyz acc, vf14, vf16
c->vopmsub(vf5, vf16, vf14); // vopmsub.xyz vf5, vf16, vf14
c->vopmula(vf16, vf5); // vopmula.xyz acc, vf16, vf5
c->vopmsub(vf5, vf5, vf16); // vopmsub.xyz vf5, vf5, vf16
c->vadd(DEST::xyzw, vf5, vf5, vf12); // vadd.xyzw vf5, vf5, vf12
c->sqc2(vf5, 0, t0); // sqc2 vf5, 0(t0)
//beq r0, r0, L15 // beq r0, r0, L15
c->addiu(v0, r0, 0); // addiu v0, r0, 0
goto block_15; // branch always
block_14:
c->lui(v0, -13122); // lui v0, -13122
c->ori(v0, v0, 48160); // ori v0, v0, 48160
block_15:
c->ld(ra, 0, sp); // ld ra, 0(sp)
//jr ra // jr ra
c->daddiu(sp, sp, 16); // daddiu sp, sp, 16
goto end_of_function; // return
// nop // sll r0, r0, 0
// nop // sll r0, r0, 0
// nop // sll r0, r0, 0
end_of_function:
return c->gprs[v0].du64[0];
}
void link() {
cache.collide_do_primitives = intern_from_c("collide-do-primitives").c();
gLinkedFunctionTable.reg("moving-sphere-triangle-intersect", execute, 512);
}
} // namespace moving_sphere_triangle_intersect
} // namespace Mips2C
+23 -1
View File
@@ -155,7 +155,7 @@ struct ExecutionContext {
// EE general purpose registers
u128 gprs[32];
// EE fprs
float fprs[16];
float fprs[32];
// VU0 vf registers
u128 vfs[32];
@@ -231,6 +231,11 @@ struct ExecutionContext {
gprs[dst].ds64[0] = val;
}
void lw_float_constant(int dst, u32 src) {
s32 val = src;
gprs[dst].ds64[0] = val;
}
void lh(int dst, int offset, int src) {
s16 val;
memcpy(&val, g_ee_main_mem + gpr_src(src).du32[0] + offset, 2);
@@ -613,6 +618,17 @@ struct ExecutionContext {
}
}
void vmax(DEST mask, int dest, int src0, int src1) {
auto s0 = vf_src(src0);
auto s1 = vf_src(src1);
for (int i = 0; i < 4; i++) {
if ((u64)mask & (1 << i)) {
vfs[dest].f[i] = std::max(s0.f[i], s1.f[i]);
}
}
}
void vsub(DEST mask, int dest, int src0, int src1) {
auto s0 = vf_src(src0);
auto s1 = vf_src(src1);
@@ -683,6 +699,10 @@ struct ExecutionContext {
Q = vf_src(src0).f[(int)bc0] / vf_src(src1).f[(int)bc1];
}
void vrsqrt(int src0, BC bc0, int src1, BC bc1) {
Q = vf_src(src0).f[(int)bc0] / std::sqrt(std::abs(vf_src(src1).f[(int)bc1]));
}
void vsqrt(int src, BC bc) { Q = std::sqrt(std::abs(vf_src(src).f[(int)bc])); }
void sqrts(int src, int dst) { fprs[dst] = std::sqrt(std::abs(fprs[src])); }
@@ -985,6 +1005,8 @@ struct ExecutionContext {
}
};
static_assert(sizeof(ExecutionContext) <= 1280);
inline void get_fake_spad_addr(int dst, void* sym_addr, u32 offset, ExecutionContext* c) {
u32 val;
memcpy(&val, sym_addr, 4);
+10 -1
View File
@@ -100,6 +100,14 @@ namespace time_of_day_interp_colors_scratch {
extern void link();
}
namespace collide_do_primitives {
extern void link();
}
namespace moving_sphere_triangle_intersect {
extern void link();
}
LinkedFunctionTable gLinkedFunctionTable;
Rng gRng;
std::unordered_map<std::string, std::vector<void (*)()>> gMips2CLinkCallbacks = {
@@ -116,7 +124,8 @@ std::unordered_map<std::string, std::vector<void (*)()>> gMips2CLinkCallbacks =
{init_boundary_regs::link, render_boundary_quad::link, render_boundary_tri::link,
draw_boundary_polygon::link}},
{"tfrag", {draw_inline_array_tfrag::link, stats_tfrag_asm::link}},
{"time-of-day", {time_of_day_interp_colors_scratch::link}}};
{"time-of-day", {time_of_day_interp_colors_scratch::link}},
{"collide-func", {collide_do_primitives::link, moving_sphere_triangle_intersect::link}}};
void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) {
const auto& it = m_executes.insert({name, {exec, Ptr<u8>()}});
+19 -1
View File
@@ -5,7 +5,6 @@
;; name in dgo: collide-func
;; dgos: GAME, ENGINE
(define-extern moving-sphere-triangle-intersect (function vector vector float collide-cache-tri vector vector float))
;; This file contains the primitive intersection functions used for collision.
;; Most take a description of primitive and a "probe"
@@ -383,3 +382,22 @@
)
)
;; ray-triangle-intersect (unused)
;; collide-do-primitives (used in moving-sphere-triangle-intersect)
(def-mips2c collide-do-primitives (function float))
;; moving-sphere-triangle-intersect (used in cam)
(def-mips2c moving-sphere-triangle-intersect (function vector vector float collide-cache-tri vector vector float))
;; moving-sphere-sphere-intersect (used in collide)
(defun moving-sphere-sphere-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector))
(let ((f30-0 (ray-sphere-intersect arg0 arg1 arg2 (+ (-> arg0 w) (-> arg2 w)))))
(when (>= f30-0 0.0)
(let ((s3-1 (vector-normalize! (vector-! (new-stack-vector0) arg2 arg0) (-> arg0 w))))
(vector+*! arg3 arg0 arg1 f30-0)
(vector+! arg3 arg3 s3-1)
)
)
f30-0
)
)
;; moving-sphere-moving-sphere-intersect (unused)
+381
View File
@@ -0,0 +1,381 @@
;;-*-Lisp-*-
(in-package goal)
;; definition for function raw-ray-sphere-intersect
;; INFO: Return type mismatch number vs float.
;; WARN: Bad vector register dependency: vf1
;; WARN: Bad vector register dependency: vf2
(defun raw-ray-sphere-intersect ((arg0 float))
(local-vars (v1-1 float) (v1-2 float) (v1-4 number) (a0-1 float) (a0-2 float) (a0-3 float) (a1-0 float))
(rlet ((Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(init-vf0-vector)
(.mov vf3 arg0)
(.mul.vf vf4 vf2 vf2)
(.mul.vf vf3 vf3 vf3)
(.mul.vf vf6 vf1 vf1)
(.mul.vf vf5 vf2 vf1)
(.add.y.vf vf4 vf4 vf4 :mask #b1)
(let ((result (the-as float 0)))
(.add.x.vf vf6 vf6 vf6 :mask #b10)
(.sub.x.vf vf6 vf6 vf3 :mask #b100)
(.add.z.vf vf4 vf4 vf4 :mask #b1)
(.add.x.vf vf5 vf5 vf5 :mask #b10)
(let ((v1-0 (the-as float 0)))
(.add.z.vf vf6 vf6 vf6 :mask #b10)
(.div.vf Q vf0 vf4 :fsf #b11 :ftf #b0)
(.add.z.vf vf5 vf5 vf5 :mask #b10)
(.mov a0-1 vf4)
(.mul.x.vf vf7 vf6 vf4)
(.mov a1-0 vf6)
(.mul.vf vf8 vf5 vf5)
(b! (< (the-as int a1-0) 0) cfg-7 :delay (set! a0-2 a0-1))
(.mul.vf vf4 vf0 Q :mask #b1000)
(.sub.vf vf9 vf8 vf7)
(b! (= a0-2 v1-0) cfg-6 :delay (.mov v1-1 vf5))
)
(.sqrt.vf Q vf9 :ftf #b1)
(b! (>= (the-as int v1-1) 0) cfg-6 :delay (.mov v1-2 vf9))
(b! (< (the-as int v1-2) 0) cfg-6 :delay 1.0)
(.add.x.vf vf6 vf5 vf4)
(.mov v1-4 vf6)
(.mul.vf vf6 vf6 vf6)
(.mul.vf vf9 vf0 Q :mask #b1000)
(.sub.vf vf6 vf9 vf6)
(.add.w.vf vf9 vf5 vf9 :mask #b10)
(.mov a0-3 vf6)
(.mul.w.vf vf9 vf9 vf4 :mask #b10)
(b! (< (logand (the-as uint v1-4) (the-as uint a0-3)) 0) cfg-6 :delay (.sub.y.vf vf4 vf0 vf9))
(b! #t cfg-7 :delay (.mov result vf4))
(label cfg-6)
(set! result -100000000.0)
(label cfg-7)
(the-as float result)
)
)
)
;; definition for function ray-sphere-intersect
(defun ray-sphere-intersect ((ray-origin vector) (ray-dir vector) (sph-origin vector) (radius float))
(rlet ((vf1 :class vf)
(vf2 :class vf)
)
(.lvf vf1 (&-> ray-origin quad))
(.lvf vf2 (&-> sph-origin quad))
(.sub.vf vf1 vf1 vf2)
(.lvf vf2 (&-> ray-dir quad))
(raw-ray-sphere-intersect radius)
)
)
;; definition for function ray-circle-intersect
(defun ray-circle-intersect ((ray-origin vector) (ray-dir vector) (circle-origin vector) (radius float))
(rlet ((vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
)
(init-vf0-vector)
(.lvf vf1 (&-> ray-origin quad))
(.mov.vf vf1 vf0 :mask #b10)
(.lvf vf2 (&-> circle-origin quad))
(.mov.vf vf2 vf0 :mask #b10)
(.sub.vf vf1 vf1 vf2)
(.lvf vf2 (&-> ray-dir quad))
(.mov.vf vf2 vf0 :mask #b10)
(raw-ray-sphere-intersect radius)
)
)
;; definition for function ray-cylinder-intersect
;; WARN: Using logior on floats
(defun ray-cylinder-intersect ((ray-origin vector)
(ray-dir vector)
(cyl-origin vector)
(cyl-axis vector)
(cyl-rad float)
(cyl-len float)
(arg6 vector)
)
(local-vars (v0-1 float) (v1-0 float) (v1-2 float) (a0-1 float) (a0-2 float) (a0-4 float) (a0-5 float))
(rlet ((vf1 :class vf)
(vf10 :class vf)
(vf11 :class vf)
(vf12 :class vf)
(vf13 :class vf)
(vf14 :class vf)
(vf15 :class vf)
(vf16 :class vf)
(vf17 :class vf)
(vf18 :class vf)
(vf19 :class vf)
(vf2 :class vf)
(vf20 :class vf)
(vf21 :class vf)
)
(.lvf vf10 (&-> ray-origin quad))
(.lvf vf12 (&-> cyl-origin quad))
(.sub.vf vf15 vf10 vf12)
(.lvf vf11 (&-> ray-dir quad))
(.lvf vf13 (&-> cyl-axis quad))
(.mov vf14 cyl-len)
(.mul.vf vf16 vf15 vf13)
(.mul.vf vf17 vf11 vf13)
(.add.x.vf vf16 vf16 vf16 :mask #b10)
(.add.x.vf vf17 vf17 vf17 :mask #b10)
(.add.z.vf vf16 vf16 vf16 :mask #b10)
(.add.z.vf vf17 vf17 vf17 :mask #b10)
(.mul.y.vf vf1 vf13 vf16)
(.add.vf vf18 vf17 vf16)
(.sub.x.vf vf19 vf16 vf14)
(.mul.y.vf vf2 vf13 vf17)
(.mov v1-0 vf16)
(.sub.x.vf vf20 vf18 vf14)
(.mov a0-1 vf18)
(let ((v1-1 (logand v1-0 (the-as uint a0-1))))
(.sub.vf vf1 vf15 vf1)
(b! (< v1-1 0) cfg-6 :delay (.sub.vf vf2 vf11 vf2))
)
(.mov v1-2 vf19)
(.mov a0-2 vf20)
(b! (>= (the-as int (logior v1-2 (the-as uint a0-2))) 0) cfg-6 :delay (nop!))
(let ((v1-4 (raw-ray-sphere-intersect cyl-rad)))
(b! (< (the-as int v1-4) 0) cfg-6 :delay (.mov vf21 v1-4))
(.mul.x.vf vf17 vf17 vf21)
(.add.vf vf16 vf16 vf17)
(.mul.y.vf vf13 vf13 vf16)
(.sub.x.vf vf19 vf16 vf14)
(.mov a0-4 vf16)
(b! (< (the-as int a0-4) 0) cfg-6 :delay (.add.vf vf12 vf12 vf13 :mask #b111))
(.mov a0-5 vf19)
(b! (>= (the-as int a0-5) 0) cfg-6 :delay (.svf (&-> arg6 quad) vf12))
(b! #t cfg-7 :delay (set! v0-1 v1-4))
)
(label cfg-6)
(set! v0-1 -100000000.0)
(label cfg-7)
v0-1
)
)
;; definition for function ray-plane-intersect
(defun ray-plane-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector) (arg4 vector) (arg5 vector) (arg6 vector))
(local-vars (v1-0 float) (v1-1 float) (a2-1 float))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(init-vf0-vector)
(.lvf vf3 (&-> arg5 quad))
(.lvf vf1 (&-> arg4 quad))
(.lvf vf2 (&-> arg6 quad))
(.sub.vf vf1 vf3 vf1)
(.sub.vf vf2 vf3 vf2)
(.lvf vf6 (&-> arg2 quad))
(.lvf vf7 (&-> arg3 quad))
(.sub.vf vf8 vf3 vf6)
(.outer.product.vf vf4 vf2 vf1)
(.mul.vf vf8 vf8 vf4)
(.mul.vf vf9 vf7 vf4)
(.mul.vf vf5 vf4 vf4)
(.add.y.vf vf8 vf8 vf8 :mask #b1)
(.add.y.vf vf9 vf9 vf9 :mask #b1)
(.add.y.vf vf5 vf5 vf5 :mask #b1)
(.add.z.vf vf8 vf8 vf8 :mask #b1)
(.add.z.vf vf9 vf9 vf9 :mask #b1)
(.add.z.vf vf5 vf5 vf5 :mask #b1)
(.mov v1-0 vf9)
(.mov a2-1 vf8)
(.isqrt.vf Q vf0 vf5 :fsf #b11 :ftf #b0)
(let ((f1-0 a2-1)
(f2-0 v1-0)
)
(cond
((!= f2-0 0.0)
(let ((f1-1 (/ f1-0 f2-0)))
(.mov.vf vf4 vf0 :mask #b1000)
(.wait.vf)
(.mul.vf vf4 vf4 Q :mask #b111)
(let ((v0-0 f1-1))
(.mov vf8 v0-0)
(.svf (&-> arg1 quad) vf4)
(.mul.x.vf acc vf7 vf8)
(.add.mul.w.vf vf7 vf6 vf0 acc :mask #b111)
(.svf (&-> arg0 quad) vf7)
(.mov v1-1 vf7)
v0-0
)
)
)
(else
-100000000.0
)
)
)
)
)
;; definition for function ray-triangle-intersect
;; WARN: Using logior on floats
;; WARN: Using logior on floats
;; INFO: Return type mismatch number vs float.
;; WARN: Unsupported inline assembly instruction kind - [sll v1, v1, 1]
(defun ray-triangle-intersect ((arg0 vector) (arg1 vector) (arg2 float) (arg3 matrix) (arg4 vector) (arg5 vector))
(local-vars (v1-0 float) (v1-1 int) (v1-2 float) (a0-1 float) (a0-2 float) (a1-1 float))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf10 :class vf)
(vf11 :class vf)
(vf12 :class vf)
(vf13 :class vf)
(vf14 :class vf)
(vf15 :class vf)
(vf16 :class vf)
(vf17 :class vf)
(vf18 :class vf)
(vf19 :class vf)
(vf2 :class vf)
(vf20 :class vf)
(vf21 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(init-vf0-vector)
(.lvf vf1 (&-> arg3 vector 0 quad))
(.lvf vf2 (&-> arg3 vector 1 quad))
(.lvf vf3 (&-> arg3 vector 2 quad))
(.lvf vf8 (&-> arg0 quad))
(.lvf vf9 (&-> arg1 quad))
(.sub.vf vf4 vf2 vf1)
(.sub.vf vf5 vf2 vf3)
(.sub.vf vf10 vf2 vf8)
(.mul.vf vf17 vf9 vf9)
(.outer.product.vf vf6 vf5 vf4)
(.add.y.vf vf17 vf17 vf17 :mask #b1)
(.mul.vf vf7 vf6 vf6)
(.mul.vf vf10 vf10 vf6)
(.mul.vf vf11 vf9 vf6)
(.add.z.vf vf17 vf17 vf17 :mask #b1)
(.add.y.vf vf7 vf7 vf7 :mask #b1)
(.add.y.vf vf10 vf10 vf10 :mask #b1)
(.add.y.vf vf11 vf11 vf11 :mask #b1)
(.mov vf18 arg2)
(.add.z.vf vf7 vf7 vf7 :mask #b1)
(.add.z.vf vf10 vf10 vf10 :mask #b1)
(.add.z.vf vf11 vf11 vf11 :mask #b1)
(.isqrt.vf Q vf0 vf7 :fsf #b11 :ftf #b0)
(.mov v1-0 vf11)
(.mov a0-1 vf10)
(let* ((f2-0 v1-0)
(f3-0 (/ a0-1 f2-0))
)
(.sll v1-1 v1-0 1)
(.mov.vf vf6 vf0 :mask #b1000)
(b! (zero? v1-1) cfg-5 :delay (.wait.vf))
(.mul.vf vf6 vf6 Q :mask #b111)
(let ((v0-0 (the-as number f3-0)))
(.mov vf12 v0-0)
(.svf (&-> arg5 quad) vf6)
(.mul.x.vf acc vf9 vf12)
(.add.mul.w.vf vf13 vf8 vf0 acc)
(b! (< (the-as int v0-0) 0) cfg-5 :delay (.svf (&-> arg4 quad) vf13))
(.sub.vf vf19 vf2 vf13)
(.sub.vf vf20 vf13 vf3)
(.sub.vf vf21 vf13 vf1)
(.isqrt.vf Q vf0 vf17 :fsf #b11 :ftf #b0)
(.outer.product.vf vf14 vf5 vf19)
(.outer.product.vf vf15 vf19 vf4)
(.outer.product.vf vf16 vf20 vf21)
(.mul.vf vf14 vf14 vf6 :mask #b111)
(.mul.vf vf15 vf15 vf6 :mask #b111)
(.mul.vf vf16 vf16 vf6 :mask #b111)
(.add.x.vf vf14 vf14 vf14 :mask #b10)
(.add.x.vf vf15 vf15 vf15 :mask #b10)
(.add.x.vf vf16 vf16 vf16 :mask #b10)
(.add.z.vf vf14 vf14 vf14 :mask #b10)
(.add.z.vf vf15 vf15 vf15 :mask #b10)
(.add.z.vf vf16 vf16 vf16 :mask #b10)
(.mov a0-2 vf14)
(.mov a1-1 vf15)
(.mov v1-2 vf16)
(b! (< (the-as int (logior (logior a0-2 (the-as uint a1-1)) (the-as uint v1-2))) 0) cfg-5 :delay (nop!))
(b! (zero? (the int arg2)) cfg-6 :delay (nop!))
(.wait.vf)
(.mul.vf vf18 vf18 Q :mask #b1)
(.sub.x.vf vf12 vf12 vf18 :mask #b1)
(.max.x.vf vf12 vf12 vf0 :mask #b1)
(b! #t cfg-6 :delay (.mov v0-0 vf12))
(label cfg-5)
(set! v0-0 -859915232)
(label cfg-6)
(the-as float v0-0)
)
)
)
)
;; definition for function collide-do-primitives
;; ERROR: function was not converted to expressions. Cannot decompile.
;; definition for function moving-sphere-triangle-intersect
;; ERROR: function was not converted to expressions. Cannot decompile.
;; definition for function moving-sphere-sphere-intersect
;; Used lq/sq
(defun moving-sphere-sphere-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector))
(let ((f30-0 (ray-sphere-intersect arg0 arg1 arg2 (+ (-> arg0 w) (-> arg2 w)))))
(when (>= f30-0 0.0)
(let ((s3-1 (vector-normalize! (vector-! (new-stack-vector0) arg2 arg0) (-> arg0 w))))
(vector+*! arg3 arg0 arg1 f30-0)
(vector+! arg3 arg3 s3-1)
)
)
f30-0
)
)
;; definition for function moving-sphere-moving-sphere-intersect
;; Used lq/sq
(defun moving-sphere-moving-sphere-intersect ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 vector) (arg4 vector))
(let ((f30-0 (ray-sphere-intersect arg0 (vector-! (new-stack-vector0) arg1 arg3) arg2 (+ (-> arg0 w) (-> arg2 w))))
)
(cond
((and (>= f30-0 0.0) (>= 1.0 f30-0))
(let ((s3-1 (vector-normalize! (vector-! (new-stack-vector0) arg2 arg0) (-> arg0 w))))
(vector+*! arg4 arg0 arg1 f30-0)
(vector+! arg4 arg4 s3-1)
)
)
(else
(set! f30-0 -100000000.0)
)
)
f30-0
)
)