mirror of
https://github.com/open-goal/jak-project
synced 2026-09-13 05:05:48 -04:00
[decompiler] ASM Branching Support (#677)
* basic example working in geometry * before updating offline' * clean up * temp * progress
This commit is contained in:
@@ -149,7 +149,7 @@ std::unique_ptr<FormRegressionTest::TestData> FormRegressionTest::make_function(
|
||||
// analyze function prologue/epilogue
|
||||
test->func.analyze_prologue(test->file);
|
||||
// build control flow graph
|
||||
test->func.cfg = build_cfg(test->file, 0, test->func, {});
|
||||
test->func.cfg = build_cfg(test->file, 0, test->func, {}, {});
|
||||
EXPECT_TRUE(test->func.cfg->is_fully_resolved());
|
||||
if (!test->func.cfg->is_fully_resolved()) {
|
||||
fmt::print("CFG:\n{}\n", test->func.cfg->to_dot());
|
||||
|
||||
@@ -113,4 +113,17 @@
|
||||
;; otherwise don't ignore it.
|
||||
`(define ,name (lambda :name ,name :behavior ,process-type ,bindings ,@body))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(defmacro b! (pred destination &key (delay '()) &key (likely-delay '()))
|
||||
"Branch!"
|
||||
;; evaluate the predicate
|
||||
`(let ((should-branch ,pred))
|
||||
;; normal delay slot:
|
||||
,delay
|
||||
(when should-branch
|
||||
,likely-delay
|
||||
(goto ,destination)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
;; definition of type curve
|
||||
(deftype curve (structure)
|
||||
((cverts pointer :offset-assert 0)
|
||||
(num-cverts int32 :offset-assert 4)
|
||||
(knots pointer :offset-assert 8)
|
||||
(num-knots int32 :offset-assert 12)
|
||||
(length float :offset-assert 16)
|
||||
((cverts pointer :offset-assert 0)
|
||||
(num-cverts int32 :offset-assert 4)
|
||||
(knots (inline-array vector) :offset-assert 8)
|
||||
(num-knots int32 :offset-assert 12)
|
||||
(length float :offset-assert 16)
|
||||
)
|
||||
:method-count-assert 9
|
||||
:size-assert #x14
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -785,6 +785,7 @@
|
||||
;; ERROR: function was not converted to expressions. Cannot decompile.
|
||||
|
||||
;; definition for function matrix-axis-angle!
|
||||
;; INFO: Return type mismatch matrix vs none.
|
||||
(defun matrix-axis-angle! ((dst matrix) (axis vector) (angle-deg float))
|
||||
(matrix-axis-sin-cos! dst axis (sin angle-deg) (cos angle-deg))
|
||||
(none)
|
||||
|
||||
@@ -598,18 +598,9 @@
|
||||
)
|
||||
|
||||
;; definition for function matrix-with-scale->quaternion
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f0, f3]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f0, f2, f5]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f2, f5]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f1, f3, f6]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f2, f5]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f3, f6]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f2, f4, f7]
|
||||
;; Used lq/sq
|
||||
(defun matrix-with-scale->quaternion ((arg0 quaternion) (arg1 matrix))
|
||||
(local-vars (a1-4 float) (f0-1 float) (f1-2 float) (f2-3 float))
|
||||
(local-vars (a1-4 float))
|
||||
(rlet ((vf1 :class vf)
|
||||
(vf2 :class vf)
|
||||
(vf3 :class vf)
|
||||
@@ -619,50 +610,31 @@
|
||||
(vf7 :class vf)
|
||||
)
|
||||
(let ((v1-0 (new-stack-matrix0)))
|
||||
(let* ((a3-0 (-> arg1 vector))
|
||||
(a2-0 (-> arg1 vector))
|
||||
(f0-0 (-> a3-0 0 x))
|
||||
(f1-0 (-> a3-0 0 y))
|
||||
(f2-0 (-> a3-0 0 z))
|
||||
(f3-0 (-> a2-0 0 x))
|
||||
(f4-0 (-> a2-0 0 y))
|
||||
(f5-0 (-> a2-0 0 z))
|
||||
)
|
||||
(.mula.s f0-0 f3-0)
|
||||
(.madda.s f1-0 f4-0)
|
||||
(.madd.s f0-1 f2-0 f5-0)
|
||||
)
|
||||
(let ((f0-2 f0-1))
|
||||
(let* ((a3-1 (-> arg1 vector 1))
|
||||
(a2-2 (-> arg1 vector 1))
|
||||
)
|
||||
(set! f1-2 (vector-dot a3-1 a2-2))
|
||||
(let*
|
||||
((f0-1
|
||||
(vector-dot
|
||||
(the-as vector (-> arg1 vector))
|
||||
(the-as vector (-> arg1 vector))
|
||||
)
|
||||
)
|
||||
(f1-1 (vector-dot (-> arg1 vector 1) (-> arg1 vector 1)))
|
||||
(f2-1 (vector-dot (-> arg1 vector 2) (-> arg1 vector 2)))
|
||||
(f0-3 (/ 1.0 (sqrtf f0-1)))
|
||||
(f1-3 (/ 1.0 (sqrtf f1-1)))
|
||||
(f2-3 (/ 1.0 (sqrtf f2-1)))
|
||||
)
|
||||
(let ((f1-3 f1-2))
|
||||
(let* ((a3-2 (-> arg1 vector 2))
|
||||
(a2-4 (-> arg1 vector 2))
|
||||
)
|
||||
(set! f2-3 (vector-dot a3-2 a2-4))
|
||||
)
|
||||
(let* ((f2-4 f2-3)
|
||||
(f0-4 (/ 1.0 (sqrtf f0-2)))
|
||||
(f1-5 (/ 1.0 (sqrtf f1-3)))
|
||||
(f2-6 (/ 1.0 (sqrtf f2-4)))
|
||||
)
|
||||
(.lvf vf1 (&-> arg1 vector 0 quad))
|
||||
(.lvf vf2 (&-> arg1 vector 1 quad))
|
||||
(.lvf vf3 (&-> arg1 vector 2 quad))
|
||||
(.lvf vf4 (&-> arg1 vector 3 quad))
|
||||
(let ((a1-1 f0-4))
|
||||
(.mov vf5 a1-1)
|
||||
)
|
||||
(let ((a1-2 f1-5))
|
||||
(.mov vf6 a1-2)
|
||||
)
|
||||
(let ((a1-3 f2-6))
|
||||
(.mov vf7 a1-3)
|
||||
)
|
||||
)
|
||||
(.lvf vf1 (&-> arg1 vector 0 quad))
|
||||
(.lvf vf2 (&-> arg1 vector 1 quad))
|
||||
(.lvf vf3 (&-> arg1 vector 2 quad))
|
||||
(.lvf vf4 (&-> arg1 vector 3 quad))
|
||||
(let ((a1-1 f0-3))
|
||||
(.mov vf5 a1-1)
|
||||
)
|
||||
(let ((a1-2 f1-3))
|
||||
(.mov vf6 a1-2)
|
||||
)
|
||||
(let ((a1-3 f2-3))
|
||||
(.mov vf7 a1-3)
|
||||
)
|
||||
)
|
||||
(.mul.x.vf vf1 vf1 vf5)
|
||||
@@ -1021,18 +993,12 @@
|
||||
)
|
||||
|
||||
;; definition for function quaternion-delta-y
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f0, f3]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f0, f2, f5]
|
||||
(defun quaternion-delta-y ((arg0 quaternion) (arg1 quaternion))
|
||||
(local-vars (f0-1 float))
|
||||
(let ((gp-0 acos))
|
||||
(let* ((s5-0 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg0))
|
||||
(v1-1 (vector-z-quaternion! (new 'stack-no-clear 'vector) arg1))
|
||||
)
|
||||
(set! f0-1 (vector-dot s5-0 v1-1))
|
||||
(acos
|
||||
(vector-dot
|
||||
(vector-z-quaternion! (new 'stack-no-clear 'vector) arg0)
|
||||
(vector-z-quaternion! (new 'stack-no-clear 'vector) arg1)
|
||||
)
|
||||
(gp-0 f0-1)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -433,12 +433,12 @@
|
||||
|
||||
;; definition of type vector
|
||||
(deftype vector (structure)
|
||||
((data float 4 :offset-assert 0)
|
||||
(x float :offset 0)
|
||||
(y float :offset 4)
|
||||
(z float :offset 8)
|
||||
(w float :offset 12)
|
||||
(quad uint128 :offset 0)
|
||||
((x float :offset 0)
|
||||
(y float :offset 4)
|
||||
(z float :offset 8)
|
||||
(w float :offset 12)
|
||||
(data float 4 :offset 0)
|
||||
(quad uint128 :offset 0)
|
||||
)
|
||||
:method-count-assert 9
|
||||
:size-assert #x10
|
||||
@@ -820,23 +820,8 @@
|
||||
)
|
||||
|
||||
;; definition for function vector-dot
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f0, f3]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f0, f2, f5]
|
||||
(defun vector-dot ((arg0 vector) (arg1 vector))
|
||||
(local-vars (f0-1 float))
|
||||
(let ((f0-0 (-> arg0 x))
|
||||
(f1-0 (-> arg0 y))
|
||||
(f2-0 (-> arg0 z))
|
||||
(f3-0 (-> arg1 x))
|
||||
(f4-0 (-> arg1 y))
|
||||
(f5-0 (-> arg1 z))
|
||||
)
|
||||
(.mula.s f0-0 f3-0)
|
||||
(.madda.s f1-0 f4-0)
|
||||
(.madd.s f0-1 f2-0 f5-0)
|
||||
)
|
||||
f0-1
|
||||
(vector-dot arg0 arg1)
|
||||
)
|
||||
|
||||
;; definition for function vector-dot-vu
|
||||
|
||||
@@ -367,12 +367,9 @@
|
||||
|
||||
;; definition for function joint-mod-look-at-handler
|
||||
;; INFO: Return type mismatch int vs none.
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f2, f5]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f1, f3, f6]
|
||||
;; Used lq/sq
|
||||
(defun joint-mod-look-at-handler ((csp cspace) (xform transformq))
|
||||
(local-vars (f1-12 float) (sv-48 vector) (sv-52 vector) (sv-56 vector))
|
||||
(local-vars (sv-48 vector) (sv-52 vector) (sv-56 vector))
|
||||
(let ((gp-0 (the-as joint-mod (-> csp param1))))
|
||||
(cspace<-parented-transformq-joint! csp xform)
|
||||
(set!
|
||||
@@ -468,10 +465,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(let* ((v1-22 sv-52))
|
||||
(set! f1-12 (vector-dot s3-2 v1-22))
|
||||
)
|
||||
(if (< f1-12 0.1)
|
||||
(if (< (vector-dot s3-2 sv-52) 0.1)
|
||||
(set! f0-21 0.0)
|
||||
)
|
||||
(set!
|
||||
@@ -518,12 +512,9 @@
|
||||
|
||||
;; definition for function joint-mod-world-look-at-handler
|
||||
;; INFO: Return type mismatch int vs none.
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f2, f5]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f1, f3, f6]
|
||||
;; Used lq/sq
|
||||
(defun joint-mod-world-look-at-handler ((arg0 cspace) (arg1 transformq))
|
||||
(local-vars (f1-14 float) (sv-48 vector) (sv-52 vector) (sv-56 vector))
|
||||
(local-vars (sv-48 vector) (sv-52 vector) (sv-56 vector))
|
||||
(let ((gp-0 (the-as joint-mod (-> arg0 param1))))
|
||||
(let ((s5-0 (-> arg0 bone transform)))
|
||||
(cspace<-parented-transformq-joint! arg0 arg1)
|
||||
@@ -606,10 +597,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(let* ((v1-14 sv-52))
|
||||
(set! f1-14 (vector-dot s4-4 v1-14))
|
||||
)
|
||||
(if (< f1-14 0.1)
|
||||
(if (< (vector-dot s4-4 sv-52) 0.1)
|
||||
(set! f0-20 0.0)
|
||||
)
|
||||
(set!
|
||||
@@ -792,12 +780,8 @@
|
||||
)
|
||||
|
||||
;; definition for function joint-mod-wheel-callback
|
||||
;; WARN: Unsupported inline assembly instruction kind - [mula.s f0, f3]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madda.s f1, f4]
|
||||
;; WARN: Unsupported inline assembly instruction kind - [madd.s f0, f2, f5]
|
||||
;; Used lq/sq
|
||||
(defun joint-mod-wheel-callback ((arg0 cspace) (arg1 transformq))
|
||||
(local-vars (f0-3 float))
|
||||
(let ((s4-0 (the-as joint-mod-wheel (-> arg0 param1))))
|
||||
(let ((v1-1 (-> s4-0 process root))
|
||||
(s1-0 (new-stack-vector0))
|
||||
@@ -810,14 +794,13 @@
|
||||
(vector<-cspace! s1-0 arg0)
|
||||
(vector-! s3-0 s1-0 (-> s4-0 last-position))
|
||||
(set! (-> s4-0 last-position quad) (-> s1-0 quad))
|
||||
(set! f0-3 (vector-dot s2-0 s3-0))
|
||||
)
|
||||
(let* ((f0-4 f0-3)
|
||||
(f1-1 65536.0)
|
||||
(f2-2 (* 6.28318 (-> s4-0 wheel-radius)))
|
||||
(f0-5 (* (* f1-1 (/ 1.0 f2-2)) f0-4))
|
||||
)
|
||||
(set! (-> s4-0 angle) (+ (-> s4-0 angle) f0-5))
|
||||
(let* ((f0-3 (vector-dot s2-0 s3-0))
|
||||
(f1-0 65536.0)
|
||||
(f2-1 (* 6.28318 (-> s4-0 wheel-radius)))
|
||||
(f0-4 (* (* f1-0 (/ 1.0 f2-1)) f0-3))
|
||||
)
|
||||
(set! (-> s4-0 angle) (+ (-> s4-0 angle) f0-4))
|
||||
)
|
||||
)
|
||||
(quaternion-vector-angle!
|
||||
(-> arg1 quat)
|
||||
|
||||
@@ -1526,4 +1526,100 @@ TEST_F(FormRegressionTest, Method23Trsqv) {
|
||||
std::string expected =
|
||||
"(vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg1 (-> arg0 trans)))";
|
||||
test_with_stack_structures(func, type, expected, R"([[16, "vector"]])");
|
||||
}
|
||||
|
||||
TEST_F(FormRegressionTest, VectorLineDistance) {
|
||||
std::string func =
|
||||
"sll r0, r0, 0\n"
|
||||
"\n"
|
||||
" daddiu sp, sp, -128\n"
|
||||
" sd ra, 0(sp)\n"
|
||||
" sd fp, 8(sp)\n"
|
||||
" or fp, t9, r0\n"
|
||||
" sq s4, 80(sp)\n"
|
||||
" sq s5, 96(sp)\n"
|
||||
" sq gp, 112(sp)\n"
|
||||
" or s5, a0, r0\n"
|
||||
" or s4, a1, r0\n"
|
||||
" lw t9, vector-normalize!(s7)\n"
|
||||
" daddiu a0, sp, 16\n"
|
||||
" sq r0, 0(a0)\n"
|
||||
" or v1, a2, r0\n"
|
||||
" or a1, s4, r0\n"
|
||||
" lqc2 vf4, 0(v1)\n"
|
||||
" lqc2 vf5, 0(a1)\n"
|
||||
" vmove.w vf6, vf0\n"
|
||||
" vsub.xyz vf6, vf4, vf5\n"
|
||||
" sqc2 vf6, 0(a0)\n"
|
||||
//" lw a1, L125(fp)\n"
|
||||
" or a1, r0, r0\n"
|
||||
" jalr ra, t9\n"
|
||||
" sll v0, ra, 0\n"
|
||||
|
||||
" or a1, v0, r0\n"
|
||||
" daddiu gp, sp, 32\n"
|
||||
" sq r0, 0(gp)\n"
|
||||
" lqc2 vf4, 0(s5)\n"
|
||||
" lqc2 vf5, 0(s4)\n"
|
||||
" vmove.w vf6, vf0\n"
|
||||
" vsub.xyz vf6, vf4, vf5\n"
|
||||
" sqc2 vf6, 0(gp)\n"
|
||||
" or a0, a1, r0\n"
|
||||
" or v1, gp, r0\n"
|
||||
" lwc1 f0, 0(a0)\n"
|
||||
" lwc1 f1, 4(a0)\n"
|
||||
" lwc1 f2, 8(a0)\n"
|
||||
" lwc1 f3, 0(v1)\n"
|
||||
" lwc1 f4, 4(v1)\n"
|
||||
" lwc1 f5, 8(v1)\n"
|
||||
" mula.s f0, f3\n"
|
||||
" madda.s f1, f4\n"
|
||||
" madd.s f0, f2, f5\n"
|
||||
" mfc1 v1, f0\n"
|
||||
" mtc1 f0, v1\n"
|
||||
" lw t9, vector-float*!(s7)\n"
|
||||
" daddiu a0, sp, 48\n"
|
||||
" sq r0, 0(a0)\n"
|
||||
" mfc1 a2, f0\n"
|
||||
" jalr ra, t9\n"
|
||||
" sll v0, ra, 0\n"
|
||||
|
||||
" or v1, v0, r0\n"
|
||||
" lw t9, vector-length(s7)\n"
|
||||
" daddiu a0, sp, 64\n"
|
||||
" sq r0, 0(a0)\n"
|
||||
" lqc2 vf4, 0(gp)\n"
|
||||
" lqc2 vf5, 0(v1)\n"
|
||||
" vmove.w vf6, vf0\n"
|
||||
" vsub.xyz vf6, vf4, vf5\n"
|
||||
" sqc2 vf6, 0(a0)\n"
|
||||
" jalr ra, t9\n"
|
||||
" sll v0, ra, 0\n"
|
||||
|
||||
" ld ra, 0(sp)\n"
|
||||
" ld fp, 8(sp)\n"
|
||||
" lq gp, 112(sp)\n"
|
||||
" lq s5, 96(sp)\n"
|
||||
" lq s4, 80(sp)\n"
|
||||
" jr ra\n"
|
||||
" daddiu sp, sp, 128\n"
|
||||
" sll r0, r0, 0\n"
|
||||
" sll r0, r0, 0\n";
|
||||
std::string type = "(function vector vector vector float)";
|
||||
std::string expected =
|
||||
"(let*\n"
|
||||
" ((a1-3\n"
|
||||
" (vector-normalize!\n"
|
||||
" (vector-! (new-stack-vector0) arg2 arg1)\n"
|
||||
" (the-as float 0)\n"
|
||||
" )\n"
|
||||
" )\n"
|
||||
" (gp-1 (vector-! (new-stack-vector0) arg0 arg1))\n"
|
||||
" (f0-1 (vector-dot a1-3 gp-1))\n"
|
||||
" (v1-3 (vector-float*! (new-stack-vector0) a1-3 f0-1))\n"
|
||||
" )\n"
|
||||
" (vector-length (vector-! (new-stack-vector0) gp-1 v1-3))\n"
|
||||
" )";
|
||||
test_with_stack_structures(func, type, expected,
|
||||
R"([[16, "vector"], [32, "vector"], [48, "vector"], [64, "vector"]])");
|
||||
}
|
||||
@@ -50,6 +50,8 @@ const std::unordered_set<std::string> g_functions_expected_to_reject = {
|
||||
// matrix
|
||||
"(method 9 matrix)", // handwritten asm loop
|
||||
"matrix-axis-sin-cos!", "matrix-axis-sin-cos-vu!",
|
||||
// geometry
|
||||
"circle-circle-xz-intersect", // unused not bothering
|
||||
// dma-h
|
||||
"dma-count-until-done", // dma asm loop
|
||||
"dma-sync-with-count", "dma-send-no-scratch", "dma-sync-fast",
|
||||
@@ -117,12 +119,8 @@ const std::unordered_set<std::string> g_functions_to_skip_compiling = {
|
||||
|
||||
/// VECTOR-H
|
||||
"(method 3 vector)", // this function appears twice, which confuses the compiler.
|
||||
"vector-dot", // fpu acc
|
||||
"vector4-dot", // fpu acc
|
||||
|
||||
// quaternion
|
||||
"matrix-with-scale->quaternion", // fpu-acc
|
||||
|
||||
"(method 3 profile-frame)", // double definition.
|
||||
|
||||
// dma-disasm
|
||||
@@ -143,6 +141,11 @@ const std::unordered_set<std::string> g_functions_to_skip_compiling = {
|
||||
"vector-deg-diff",
|
||||
"vector-degi",
|
||||
|
||||
// geometry
|
||||
"calculate-basis-functions-vector!", // asm requiring manual rewrite
|
||||
"curve-evaluate!", // asm requiring manual rewrite
|
||||
"point-in-triangle-cross", // logior on floats manual fixup
|
||||
|
||||
// asm
|
||||
"invalidate-cache-line",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user