diff --git a/decompiler/analysis/variable_naming.cpp b/decompiler/analysis/variable_naming.cpp index 05c5e8ef18..8c40cff181 100644 --- a/decompiler/analysis/variable_naming.cpp +++ b/decompiler/analysis/variable_naming.cpp @@ -359,7 +359,8 @@ SSA make_rc_ssa(const Function& function, const RegUsageInfo& rui, const Functio auto as_set = dynamic_cast(op.get()); if (as_set) { auto dst = as_set->dst().reg(); - if (as_set->src().is_var()) { + if (as_set->src().is_var() || + (as_set->src().kind() == SimpleExpression::Kind::FPR_TO_GPR)) { auto src = as_set->src().get_arg(0).var().reg(); auto& ri = rui.op.at(op_id); if (ri.consumes.find(src) != ri.consumes.end() && diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index bd077987e8..8ecf9b8cef 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -991,7 +991,7 @@ ) (deftype vector16b (structure) - ((data int8 8 :offset-assert 0) + ((data int8 16 :offset-assert 0) (quad uint128 :offset 0) ) :method-count-assert 9 @@ -2786,16 +2786,38 @@ ;;;; PAD ;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~; + +(defenum pad-buttons + :bitfield #t + :type uint32 + (select 0) + (l3 1) + (r3 2) + (start 3) + (up 4) + (right 5) + (down 6) + (left 7) + (l2 8) + (r2 9) + (l1 10) + (r1 11) + (triangle 12) + (circle 13) + (x 14) + (square 15) + ) + (deftype hw-cpad (basic) - ((valid uint8 :offset-assert 4) - (status uint8 :offset-assert 5) - (button0 uint16 :offset-assert 6) - (rightx uint8 :offset-assert 8) - (righty uint8 :offset-assert 9) - (leftx uint8 :offset-assert 10) - (lefty uint8 :offset-assert 11) - (abutton uint8 12 :offset-assert 12) - (dummy uint8 12 :offset-assert 24) + ((valid uint8 :offset-assert 4) + (status uint8 :offset-assert 5) + (button0 uint16 :offset-assert 6) + (rightx uint8 :offset-assert 8) + (righty uint8 :offset-assert 9) + (leftx uint8 :offset-assert 10) + (lefty uint8 :offset-assert 11) + (abutton uint8 12 :offset-assert 12) + (dummy uint8 12 :offset-assert 24) ) :method-count-assert 9 :size-assert #x24 @@ -2805,9 +2827,9 @@ (deftype cpad-info (hw-cpad) ((number int32 :offset-assert 36) (cpad-file int32 :offset-assert 40) - (button0-abs uint32 3 :offset-assert 44) ;; guess - (button0-shadow-abs uint32 1 :offset-assert 56) ;; guess - (button0-rel uint32 3 :offset-assert 60) ;; guess + (button0-abs pad-buttons 3 :offset-assert 44) ;; guess + (button0-shadow-abs pad-buttons 1 :offset-assert 56) ;; guess + (button0-rel pad-buttons 3 :offset-assert 60) ;; guess (stick0-dir float :offset-assert 72) (stick0-speed float :offset-assert 76) (new-pad int32 :offset-assert 80) @@ -4399,7 +4421,7 @@ (define-extern *math-camera* math-camera) ;; unknown type (define-extern *math-camera-fog-correction* fog-corrector) ;; unknown type (define-extern init-for-transform function) -(define-extern move-target-from-pad (function (pointer float) int none)) +(define-extern move-target-from-pad (function transform int none)) (define-extern transform-point-vector! function) (define-extern fog-corrector-setup (function fog-corrector math-camera float)) ;;(define-extern fog-corrector object) ;; unknown type @@ -4487,7 +4509,7 @@ (dest-verts char-verts :inline :offset-assert 752) (justify vector 64 :inline :offset-assert 944) (color-shadow vector4w :inline :offset-assert 1968) - (color-table vector 64 :inline :offset-assert 1984) + (color-table vector16b 64 :inline :offset-assert 1984) (last-color uint64 :offset-assert 3008) (save-last-color uint64 :offset-assert 3016) (buf basic :offset-assert 3024) @@ -33289,12 +33311,12 @@ ;;(define-extern aspect4x3 object) ;; unknown type ;;(define-extern font-work object) ;; unknown type -(define-extern font-set-tex0 (function font-work texture uint uint uint none)) +(define-extern font-set-tex0 (function (pointer gs-tex0) texture uint uint uint none)) (define-extern *font-default-matrix* matrix) ;; unknown type ;;(define-extern char-verts object) ;; unknown type ;;(define-extern char-color object) ;; unknown type ;;(define-extern font-context object) ;; unknown type -;;(define-extern *font-work* object) ;; unknown type +(define-extern *font-work* font-work) ;; unknown type ;;(define-extern decomp-work object) ;; unknown type (define-extern draw-string-xy (function string dma-buffer int int int none)) ;;(define-extern end-draw object) ;; unknown type diff --git a/decompiler/config/jak1_ntsc_black_label/stack_vars.jsonc b/decompiler/config/jak1_ntsc_black_label/stack_vars.jsonc index 37a940d918..e96226974a 100644 --- a/decompiler/config/jak1_ntsc_black_label/stack_vars.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/stack_vars.jsonc @@ -134,6 +134,8 @@ "circle-test": [[16, "sphere"], [32, "sphere"], [48, "vector"], [64, "vector"]], + "move-target-from-pad": [[16, "vector"], [32, "vector"], [48, "matrix"]], + "draw-sprite2d-xy": [[16, "draw-context"]], "screen-gradient": [[16, "draw-context"]], diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index c89d1c7fa2..cb94cdbac2 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -544,7 +544,6 @@ goos::Object bitfield_defs_print(const TypeSpec& type, result.push_back(pretty_print::to_symbol(fmt::format("new 'static '{}", type.print()))); for (auto& def : defs) { if (def.enum_constant) { - assert(false); // this is untested. result.push_back( pretty_print::to_symbol(fmt::format(":{} {}", def.field_name, *def.enum_constant))); } else if (def.is_signed) { diff --git a/goal_src/engine/math/vector-h.gc b/goal_src/engine/math/vector-h.gc index 2d046c8a8f..a30df4f3d9 100644 --- a/goal_src/engine/math/vector-h.gc +++ b/goal_src/engine/math/vector-h.gc @@ -281,7 +281,7 @@ ;; Vector of 16 signed bytes (deftype vector16b (structure) - ((data int8 8 :offset-assert 0) + ((data int8 16 :offset-assert 0) (quad uint128 :offset 0) ) :method-count-assert 9 diff --git a/goal_src/engine/ps2/pad.gc b/goal_src/engine/ps2/pad.gc index 718b702317..c6f4dee8fa 100644 --- a/goal_src/engine/ps2/pad.gc +++ b/goal_src/engine/ps2/pad.gc @@ -5,6 +5,27 @@ ;; name in dgo: pad ;; dgos: GAME, ENGINE +(defenum pad-buttons + :bitfield #t + :type uint32 + (select 0) + (l3 1) + (r3 2) + (start 3) + (up 4) + (right 5) + (down 6) + (left 7) + (l2 8) + (r2 9) + (l1 10) + (r1 11) + (triangle 12) + (circle 13) + (x 14) + (square 15) + ) + ;; these forward declarations should probably go somewhere else... (define-extern get-current-time (function uint)) (define-extern get-integral-current-time (function uint)) @@ -31,22 +52,22 @@ ;; data from hardware + additional info calculated here. (deftype cpad-info (hw-cpad) - ((number int32 :offset-assert 36) - (cpad-file int32 :offset-assert 40) - (button0-abs uint32 3 :offset-assert 44) ;; bitmask of buttons, pressed or not, with history - (button0-shadow-abs uint32 1 :offset-assert 56) ;; modify this to change button history in the future. - (button0-rel uint32 3 :offset-assert 60) ;; bitmask of if button going down. - (stick0-dir float :offset-assert 72) - (stick0-speed float :offset-assert 76) - (new-pad int32 :offset-assert 80) - (state int32 :offset-assert 84) - (align uint8 6 :offset-assert 88) - (direct uint8 6 :offset-assert 94) ;; hardware control of buzzing. - (buzz-val uint8 2 :offset-assert 100) ;; intensity for buzzing - (buzz-time uint64 2 :offset-assert 104) ;; when to stop buzzing - (buzz basic :offset-assert 120) ;; is vibration enabled? - (buzz-act int32 :offset-assert 124) - (change-time uint64 :offset-assert 128) + ((number int32 :offset-assert 36) + (cpad-file int32 :offset-assert 40) + (button0-abs pad-buttons 3 :offset-assert 44) ;; bitmask of buttons, pressed or not, with history + (button0-shadow-abs pad-buttons 1 :offset-assert 56) ;; modify this to change button history in the future. + (button0-rel pad-buttons 3 :offset-assert 60) ;; bitmask of if button going down. + (stick0-dir float :offset-assert 72) + (stick0-speed float :offset-assert 76) + (new-pad int32 :offset-assert 80) + (state int32 :offset-assert 84) + (align uint8 6 :offset-assert 88) + (direct uint8 6 :offset-assert 94) ;; hardware control of buzzing. + (buzz-val uint8 2 :offset-assert 100) ;; intensity for buzzing + (buzz-time uint64 2 :offset-assert 104) ;; when to stop buzzing + (buzz basic :offset-assert 120) ;; is vibration enabled? + (buzz-act int32 :offset-assert 124) + (change-time uint64 :offset-assert 128) ) (:methods (new (symbol type int) _type_ 0) @@ -60,9 +81,9 @@ "Reset all data in a cpad-info" (set! (-> pad valid) (logior (-> pad valid) 128)) (set! (-> pad button0) (the-as uint 0)) - (set! (-> pad button0-abs 0) (the-as uint 0)) - (set! (-> pad button0-shadow-abs 0) (the-as uint 0)) - (set! (-> pad button0-rel 0) (the-as uint 0)) + (set! (-> pad button0-abs 0) (pad-buttons)) + (set! (-> pad button0-shadow-abs 0) (pad-buttons)) + (set! (-> pad button0-rel 0) (pad-buttons)) (dotimes (v1-2 12) (nop!) (set! (-> pad abutton v1-2) 0) @@ -238,7 +259,7 @@ (set! (-> pad button0-rel 2) (-> pad button0-rel 1)) (set! (-> pad button0-rel 1) (-> pad button0-rel 0)) ;; update current button - (let ((current-button0 (-> pad button0))) + (let ((current-button0 (the pad-buttons (-> pad button0)))) (set! (-> pad button0-shadow-abs 0) current-button0) (set! (-> pad button0-abs 0) current-button0) ) diff --git a/test/decompiler/reference/all_forward_declarations.gc b/test/decompiler/reference/all_forward_declarations.gc index 36ddac3bf2..3012372869 100644 --- a/test/decompiler/reference/all_forward_declarations.gc +++ b/test/decompiler/reference/all_forward_declarations.gc @@ -288,6 +288,27 @@ (define-extern set-display (function display int int int int int display)) (define-extern *display* display) +;; pad +(defenum pad-buttons + :bitfield #t + :type uint32 + (select 0) + (l3 1) + (r3 2) + (start 3) + (up 4) + (right 5) + (down 6) + (left 7) + (l2 8) + (r2 9) + (l1 10) + (r1 11) + (triangle 12) + (circle 13) + (x 14) + (square 15) + ) ;; vector ;; only because trig isn't in the reference yet. diff --git a/test/decompiler/reference/euler_REF.gc b/test/decompiler/reference/euler_REF.gc index 47f2c22095..d1fe51932a 100644 --- a/test/decompiler/reference/euler_REF.gc +++ b/test/decompiler/reference/euler_REF.gc @@ -27,9 +27,7 @@ (when (= (logand (sar (the int (-> s5-0 data 3)) 2) 1) 1) (set! (-> s5-0 data 0) (- (-> s5-0 data 0))) (set! (-> s5-0 data 1) (- (-> s5-0 data 1))) - (let ((f0-10 (- (-> s5-0 data 2)))) - (set! (-> s5-0 data 2) f0-10) - ) + (set! (-> s5-0 data 2) (- (-> s5-0 data 2))) ) (let* ((f26-0 (cos (-> s5-0 data 0))) (f30-0 (cos (-> s5-0 data 1))) @@ -127,16 +125,14 @@ ) (+ f1-1 (* f30-0 f2-0)) ) - (let ((f0-19 (+ (- f3-0) (* f30-0 f0-17)))) - (set! - (-> - (the-as - (pointer float) - (+ (+ (shl v1-17 4) (shl v1-17 2)) (the-as int arg0)) - ) + (set! + (-> + (the-as + (pointer float) + (+ (+ (shl v1-17 4) (shl v1-17 2)) (the-as int arg0)) ) - f0-19 ) + (+ (- f3-0) (* f30-0 f0-17)) ) ) (else @@ -212,16 +208,14 @@ ) (* f30-0 f24-0) ) - (let ((f0-25 (* f30-0 f26-0))) - (set! - (-> - (the-as - (pointer float) - (+ (+ (shl v1-17 4) (shl v1-17 2)) (the-as int arg0)) - ) + (set! + (-> + (the-as + (pointer float) + (+ (+ (shl v1-17 4) (shl v1-17 2)) (the-as int arg0)) ) - f0-25 ) + (* f30-0 f26-0) ) ) ) @@ -296,27 +290,24 @@ ) ) ) - (let - ((f0-13 - (atan - (-> - (the-as - (pointer float) - (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1)) - ) - ) - (- - (-> - (the-as - (pointer float) - (+ (+ (shl s3-0 2) (shl s1-0 4)) (the-as int arg1)) - ) - ) + (set! + (-> arg0 data 2) + (atan + (-> + (the-as + (pointer float) + (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1)) + ) + ) + (- + (-> + (the-as + (pointer float) + (+ (+ (shl s3-0 2) (shl s1-0 4)) (the-as int arg1)) ) ) ) ) - (set! (-> arg0 data 2) f0-13) ) ) (else @@ -351,9 +342,7 @@ ) ) ) - (let ((f0-20 0.0)) - (set! (-> arg0 data 2) f0-20) - ) + (set! (-> arg0 data 2) 0.0) ) ) ) @@ -410,25 +399,22 @@ f30-1 ) ) - (let - ((f0-34 - (atan - (-> - (the-as - (pointer float) - (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1)) - ) - ) - (-> - (the-as - (pointer float) - (+ (+ (shl s3-0 2) (shl s3-0 4)) (the-as int arg1)) - ) - ) + (set! + (-> arg0 data 2) + (atan + (-> + (the-as + (pointer float) + (+ (+ (shl s3-0 2) (shl s2-0 4)) (the-as int arg1)) + ) + ) + (-> + (the-as + (pointer float) + (+ (+ (shl s3-0 2) (shl s3-0 4)) (the-as int arg1)) ) ) ) - (set! (-> arg0 data 2) f0-34) ) ) (else @@ -465,9 +451,7 @@ f30-1 ) ) - (let ((f0-42 0.0)) - (set! (-> arg0 data 2) f0-42) - ) + (set! (-> arg0 data 2) 0.0) ) ) ) @@ -476,9 +460,7 @@ (when (= (logand (sar arg2 2) 1) 1) (set! (-> arg0 data 0) (- (-> arg0 data 0))) (set! (-> arg0 data 1) (- (-> arg0 data 1))) - (let ((f0-48 (- (-> arg0 data 2)))) - (set! (-> arg0 data 2) f0-48) - ) + (set! (-> arg0 data 2) (- (-> arg0 data 2))) ) (if (= (logand arg2 1) 1) (let ((f0-49 (-> arg0 data 0))) @@ -511,5 +493,3 @@ - - diff --git a/test/decompiler/reference/matrix_REF.gc b/test/decompiler/reference/matrix_REF.gc index f5a18b1fa5..b2a24d2313 100644 --- a/test/decompiler/reference/matrix_REF.gc +++ b/test/decompiler/reference/matrix_REF.gc @@ -809,9 +809,7 @@ (set! (-> dst data 12) 0.0) (set! (-> dst data 13) 0.0) (set! (-> dst data 14) 0.0) - (let ((f0-12 1.0)) - (set! (-> dst data 15) f0-12) - ) + (set! (-> dst data 15) 1.0) dst ) diff --git a/test/decompiler/reference/pad_REF.gc b/test/decompiler/reference/pad_REF.gc index 505c4de72b..1f5f43d816 100644 --- a/test/decompiler/reference/pad_REF.gc +++ b/test/decompiler/reference/pad_REF.gc @@ -38,22 +38,22 @@ ;; definition of type cpad-info (deftype cpad-info (hw-cpad) - ((number int32 :offset-assert 36) - (cpad-file int32 :offset-assert 40) - (button0-abs uint32 3 :offset-assert 44) - (button0-shadow-abs uint32 1 :offset-assert 56) - (button0-rel uint32 3 :offset-assert 60) - (stick0-dir float :offset-assert 72) - (stick0-speed float :offset-assert 76) - (new-pad int32 :offset-assert 80) - (state int32 :offset-assert 84) - (align uint8 6 :offset-assert 88) - (direct uint8 6 :offset-assert 94) - (buzz-val uint8 2 :offset-assert 100) - (buzz-time uint64 2 :offset-assert 104) - (buzz basic :offset-assert 120) - (buzz-act int32 :offset-assert 124) - (change-time uint64 :offset-assert 128) + ((number int32 :offset-assert 36) + (cpad-file int32 :offset-assert 40) + (button0-abs pad-buttons 3 :offset-assert 44) + (button0-shadow-abs pad-buttons 1 :offset-assert 56) + (button0-rel pad-buttons 3 :offset-assert 60) + (stick0-dir float :offset-assert 72) + (stick0-speed float :offset-assert 76) + (new-pad int32 :offset-assert 80) + (state int32 :offset-assert 84) + (align uint8 6 :offset-assert 88) + (direct uint8 6 :offset-assert 94) + (buzz-val uint8 2 :offset-assert 100) + (buzz-time uint64 2 :offset-assert 104) + (buzz basic :offset-assert 120) + (buzz-act int32 :offset-assert 124) + (change-time uint64 :offset-assert 128) ) :method-count-assert 9 :size-assert #x88 @@ -98,9 +98,9 @@ (defun cpad-invalid! ((pad cpad-info)) (set! (-> pad valid) (logior (-> pad valid) 128)) (set! (-> pad button0) (the-as uint 0)) - (set! (-> pad button0-abs 0) (the-as uint 0)) - (set! (-> pad button0-shadow-abs 0) (the-as uint 0)) - (set! (-> pad button0-rel 0) (the-as uint 0)) + (set! (-> pad button0-abs 0) (pad-buttons)) + (set! (-> pad button0-shadow-abs 0) (pad-buttons)) + (set! (-> pad button0-rel 0) (pad-buttons)) (dotimes (v1-2 12) (nop!) (set! (-> pad abutton v1-2) (the-as uint 0)) @@ -292,12 +292,18 @@ (set! (-> pad button0-rel 2) (-> pad button0-rel 1)) (set! (-> pad button0-rel 1) (-> pad button0-rel 0)) (let ((current-button0 (-> pad button0))) - (set! (-> pad button0-shadow-abs 0) current-button0) - (set! (-> pad button0-abs 0) current-button0) + (set! + (-> pad button0-shadow-abs 0) + (the-as pad-buttons current-button0) + ) + (set! (-> pad button0-abs 0) (the-as pad-buttons current-button0)) ) (set! (-> pad button0-rel 0) - (logand (-> pad button0-abs 0) (lognot (-> pad button0-abs 1))) + (logand + (-> pad button0-abs 0) + (the-as uint (lognot (-> pad button0-abs 1))) + ) ) (when *cpad-debug* (set! (-> pad leftx) (the-as uint 255)) @@ -318,9 +324,7 @@ ) ) (if (< (-> pad stick0-speed) 0.3) - (let ((f0-8 0.0)) - (set! (-> pad stick0-speed) f0-8) - ) + (set! (-> pad stick0-speed) 0.0) ) ) (else @@ -329,9 +333,7 @@ (set! (-> pad rightx) (the-as uint 128)) (set! (-> pad righty) (the-as uint 128)) (set! (-> pad stick0-dir) 0.0) - (let ((f0-10 0.0)) - (set! (-> pad stick0-speed) f0-10) - ) + (set! (-> pad stick0-speed) 0.0) ) ) (if diff --git a/test/decompiler/reference/quaternion_REF.gc b/test/decompiler/reference/quaternion_REF.gc index 000f5928bc..ce4894ead2 100644 --- a/test/decompiler/reference/quaternion_REF.gc +++ b/test/decompiler/reference/quaternion_REF.gc @@ -461,9 +461,7 @@ (let ((f0-5 (/ 0.5 f0-4))) (set! (-> arg0 x) (* f0-5 (- (-> arg1 data 6) (-> arg1 data 9)))) (set! (-> arg0 y) (* f0-5 (- (-> arg1 data 8) (-> arg1 data 2)))) - (let ((f0-6 (* f0-5 (- (-> arg1 data 1) (-> arg1 data 4))))) - (set! (-> arg0 z) f0-6) - ) + (set! (-> arg0 z) (* f0-5 (- (-> arg1 data 1) (-> arg1 data 4)))) ) ) (let ((a2-0 0) @@ -564,28 +562,25 @@ f0-12 ) ) - (let - ((f0-13 - (* - (+ - (-> - (the-as - (pointer float) - (+ (+ (shl v1-1 2) (shl a2-0 4)) (the-as int arg1)) - ) - ) - (-> - (the-as - (pointer float) - (+ (+ (shl a2-0 2) (shl v1-1 4)) (the-as int arg1)) - ) - ) + (set! + (-> arg0 data v1-1) + (* + (+ + (-> + (the-as + (pointer float) + (+ (+ (shl v1-1 2) (shl a2-0 4)) (the-as int arg1)) + ) + ) + (-> + (the-as + (pointer float) + (+ (+ (shl a2-0 2) (shl v1-1 4)) (the-as int arg1)) ) - f0-12 ) ) + f0-12 ) - (set! (-> arg0 data v1-1) f0-13) ) ) ) @@ -718,9 +713,7 @@ ) (set! (-> arg0 x) (* (-> arg1 x) f0-9)) (set! (-> arg0 y) (* (-> arg1 y) f0-9)) - (let ((f0-10 (* (-> arg1 z) f0-9))) - (set! (-> arg0 z) f0-10) - ) + (set! (-> arg0 z) (* (-> arg1 z) f0-9)) ) ) ) @@ -735,9 +728,7 @@ (set! (-> arg0 x) 0.0) (set! (-> arg0 y) 0.0) (set! (-> arg0 z) 0.0) - (let ((f0-4 1.0)) - (set! (-> arg0 w) f0-4) - ) + (set! (-> arg0 w) 1.0) ) (else (let ((s5-0 (new 'stack-no-clear 'vector))) @@ -747,9 +738,7 @@ (set! (-> arg0 y) (* (-> arg1 y) f0-6)) (set! (-> arg0 z) (* (-> arg1 z) f0-6)) ) - (let ((f0-8 (-> s5-0 data 1))) - (set! (-> arg0 w) f0-8) - ) + (set! (-> arg0 w) (-> s5-0 data 1)) ) ) ) diff --git a/test/decompiler/reference/sync-info_REF.gc b/test/decompiler/reference/sync-info_REF.gc index 8efd379701..0cba439e36 100644 --- a/test/decompiler/reference/sync-info_REF.gc +++ b/test/decompiler/reference/sync-info_REF.gc @@ -9,9 +9,8 @@ (set! (-> obj period) arg0) (let* ((f0-1 (the float arg0)) (f1-1 (* arg1 f0-1)) - (f0-3 (- f1-1 (* (the float (the int (/ f1-1 f0-1))) f0-1))) ) - (set! (-> obj offset) f0-3) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-1))) f0-1))) ) 0 ) @@ -24,9 +23,8 @@ (set! (-> obj period) arg0) (let* ((f0-1 (the float arg0)) (f1-1 (* arg1 f0-1)) - (f0-3 (- f1-1 (* (the float (the int (/ f1-1 f0-1))) f0-1))) ) - (set! (-> obj offset) f0-3) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-1))) f0-1))) ) (if (< arg2 0.0) (set! arg2 0.0) @@ -71,9 +69,8 @@ (set! (-> obj period) arg0) (let* ((f0-1 (the float arg0)) (f1-1 (* arg1 f0-1)) - (f0-3 (- f1-1 (* (the float (the int (/ f1-1 f0-1))) f0-1))) ) - (set! (-> obj offset) f0-3) + (set! (-> obj offset) (- f1-1 (* (the float (the int (/ f1-1 f0-1))) f0-1))) ) (cond ((< arg2 0.0) @@ -371,8 +368,9 @@ ) (set! (-> obj start-time) (-> *display* base-frame-counter)) (set! (-> obj timer) (rand-vu-int-range (-> obj min-time) (-> obj max-time))) - (let ((f0-3 (rand-vu-float-range (- (-> obj max-val)) (-> obj max-val)))) - (set! (-> obj value) f0-3) + (set! + (-> obj value) + (rand-vu-float-range (- (-> obj max-val)) (-> obj max-val)) ) ) (-> obj value) @@ -409,10 +407,9 @@ (fmin (-> obj max-vel) (fmax (- (-> obj max-vel)) (-> obj vel))) ) (set! (-> obj vel) (* (-> obj vel) (-> obj damping))) - (let - ((f0-10 (+ (-> obj value) (* (-> obj vel) (-> *display* time-adjust-ratio)))) - ) - (set! (-> obj value) f0-10) + (set! + (-> obj value) + (+ (-> obj value) (* (-> obj vel) (-> *display* time-adjust-ratio))) ) (-> obj value) ) @@ -445,18 +442,14 @@ (when (>= (-> obj osc value) (-> obj max-value)) (set! (-> obj osc value) (-> obj max-value)) (if (< 0.0 (-> obj osc vel)) - (let ((f0-4 (* (-> obj osc vel) (- (-> obj elasticity))))) - (set! (-> obj osc vel) f0-4) - ) + (set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity)))) ) (set! (-> obj state) 1) ) (when (>= (-> obj min-value) (-> obj osc value)) (set! (-> obj osc value) (-> obj min-value)) (if (< (-> obj osc vel) 0.0) - (let ((f0-9 (* (-> obj osc vel) (- (-> obj elasticity))))) - (set! (-> obj osc vel) f0-9) - ) + (set! (-> obj osc vel) (* (-> obj osc vel) (- (-> obj elasticity)))) ) (set! (-> obj state) -1) ) @@ -711,3 +704,5 @@ (-> obj value) ) ) + + diff --git a/test/decompiler/reference/vector-h_REF.gc b/test/decompiler/reference/vector-h_REF.gc index a25daa6903..670899aa6d 100644 --- a/test/decompiler/reference/vector-h_REF.gc +++ b/test/decompiler/reference/vector-h_REF.gc @@ -417,7 +417,7 @@ ;; definition of type vector16b (deftype vector16b (structure) - ((data int8 8 :offset-assert 0) + ((data int8 16 :offset-assert 0) (quad uint128 :offset 0) ) :method-count-assert 9 diff --git a/test/decompiler/reference/vector_REF.gc b/test/decompiler/reference/vector_REF.gc index cf3727170c..defcdf0897 100644 --- a/test/decompiler/reference/vector_REF.gc +++ b/test/decompiler/reference/vector_REF.gc @@ -320,16 +320,12 @@ (cond ((>= max-step step-len) (set! (-> vec data 0) (+ (-> vec data 0) x-step)) - (let ((f0-4 (+ (-> vec data 2) z-step))) - (set! (-> vec data 2) f0-4) - ) + (set! (-> vec data 2) (+ (-> vec data 2) z-step)) ) (else (let ((f2-6 (/ max-step step-len))) (set! (-> vec data 0) (+ (-> vec data 0) (* f2-6 x-step))) - (let ((f0-6 (+ (-> vec data 2) (* f2-6 z-step)))) - (set! (-> vec data 2) f0-6) - ) + (set! (-> vec data 2) (+ (-> vec data 2) (* f2-6 z-step))) ) ) ) @@ -354,16 +350,12 @@ (cond ((>= max-step step-len) (set! (-> vec data 1) (+ (-> vec data 1) y-step)) - (let ((f0-4 (+ (-> vec data 2) z-step))) - (set! (-> vec data 2) f0-4) - ) + (set! (-> vec data 2) (+ (-> vec data 2) z-step)) ) (else (let ((step-scale (/ max-step step-len))) (set! (-> vec data 1) (+ (-> vec data 1) (* step-scale y-step))) - (let ((f0-6 (+ (-> vec data 2) (* step-scale z-step)))) - (set! (-> vec data 2) f0-6) - ) + (set! (-> vec data 2) (+ (-> vec data 2) (* step-scale z-step))) ) ) ) @@ -395,17 +387,13 @@ ((>= max-step step-len) (set! (-> vec data 0) (+ (-> vec data 0) x-step)) (set! (-> vec data 1) (+ (-> vec data 1) y-step)) - (let ((f0-5 (+ (-> vec data 2) z-step))) - (set! (-> vec data 2) f0-5) - ) + (set! (-> vec data 2) (+ (-> vec data 2) z-step)) ) (else (let ((step-scale (/ max-step step-len))) (set! (-> vec data 0) (+ (-> vec data 0) (* step-scale x-step))) (set! (-> vec data 1) (+ (-> vec data 1) (* step-scale y-step))) - (let ((f0-7 (+ (-> vec data 2) (* step-scale z-step)))) - (set! (-> vec data 2) f0-7) - ) + (set! (-> vec data 2) (+ (-> vec data 2) (* step-scale z-step))) ) ) ) @@ -815,9 +803,7 @@ (let ((v1-1 (/ arg2 f0-0))) (set! (-> arg0 data 0) (* (-> arg1 data 0) v1-1)) (set! (-> arg0 data 1) (* (-> arg1 data 1) v1-1)) - (let ((f0-7 (* (-> arg1 data 2) v1-1))) - (set! (-> arg0 data 2) f0-7) - ) + (set! (-> arg0 data 2) (* (-> arg1 data 2) v1-1)) ) ) ) @@ -831,9 +817,7 @@ (if (!= f0-0 0.0) (let ((v1-1 (/ arg1 f0-0))) (set! (-> arg0 data 0) (* (-> arg0 data 0) v1-1)) - (let ((f0-5 (* (-> arg0 data 2) v1-1))) - (set! (-> arg0 data 2) f0-5) - ) + (set! (-> arg0 data 2) (* (-> arg0 data 2) v1-1)) ) ) ) @@ -848,9 +832,7 @@ (when (!= f0-0 0.0) (set! (-> arg0 data 0) (/ (-> arg0 data 0) f0-0)) (set! (-> arg0 data 1) (/ (-> arg0 data 1) f0-0)) - (let ((f0-1 (/ (-> arg0 data 2) f0-0))) - (set! (-> arg0 data 2) f0-1) - ) + (set! (-> arg0 data 2) (/ (-> arg0 data 2) f0-0)) ) ) ) @@ -864,9 +846,7 @@ (set! f0-0 (/ f0-0 arg1)) (when (!= f0-0 0.0) (set! (-> arg0 data 0) (/ (-> arg0 data 0) f0-0)) - (let ((f0-1 (/ (-> arg0 data 2) f0-0))) - (set! (-> arg0 data 2) f0-1) - ) + (set! (-> arg0 data 2) (/ (-> arg0 data 2) f0-0)) ) ) ) @@ -925,9 +905,8 @@ (set! (-> arg0 data 1) f0-0) (let* ((f26-0 (- f0-0)) (f0-4 (- (* f28-0 (cos f26-0)) (* f30-0 (sin f26-0)))) - (f0-5 (atan (- (-> arg1 data 1)) f0-4)) ) - (set! (-> arg0 data 0) f0-5) + (set! (-> arg0 data 0) (atan (- (-> arg1 data 1)) f0-4)) ) ) (set! (-> arg0 data 2) 0.0) @@ -943,9 +922,8 @@ (set! (-> arg0 data 0) f0-1) (let* ((f26-0 (- f0-1)) (f0-5 (- (* f28-0 (cos f26-0)) (* f30-0 (sin f26-0)))) - (f0-6 (atan (-> arg1 data 0) f0-5)) ) - (set! (-> arg0 data 1) f0-6) + (set! (-> arg0 data 1) (atan (-> arg1 data 0) f0-5)) ) ) (set! (-> arg0 data 2) 0.0) @@ -1171,9 +1149,7 @@ (-> out data 2) (deg-lerp-clamp (-> min-val data 2) (-> max-val data 2) in) ) - (let ((f0-11 1.0)) - (set! (-> out data 3) f0-11) - ) + (set! (-> out data 3) 1.0) ) ) out diff --git a/test/decompiler/test_FormExpressionBuild2.cpp b/test/decompiler/test_FormExpressionBuild2.cpp index 7ae4673c38..6c973dc7ee 100644 --- a/test/decompiler/test_FormExpressionBuild2.cpp +++ b/test/decompiler/test_FormExpressionBuild2.cpp @@ -1025,3 +1025,113 @@ TEST_F(FormRegressionTest, DmaBucketInsertTag) { " [3, \"a0\", \"dma-bucket\"]\n" " ]"); } + +TEST_F(FormRegressionTest, StupidFloatMove) { + std::string func = + "sll r0, r0, 0\n" + " daddiu sp, sp, -48\n" + " sd ra, 0(sp)\n" + " sd fp, 8(sp)\n" + " or fp, t9, r0\n" + " sq s5, 16(sp)\n" + " sq gp, 32(sp)\n" + + " or gp, a0, r0\n" + //" lwc1 f0, L47(fp)\n" + " mtc1 f0, r0\n" + " mtc1 f1, a1\n" + " min.s f0, f0, f1\n" + " mfc1 s5, f0\n" + " mtc1 f0, s5\n" + " swc1 f0, 900(gp)\n" + " lw t9, get-video-mode(s7)\n" + " jalr ra, t9\n" + " sll v0, ra, 0\n" + + " or v1, v0, r0\n" + " daddiu a0, s7, pal\n" + " bne v1, a0, L37\n" + " sll r0, r0, 0\n" + + //" lwc1 f0, L42(fp)\n" + " mtc1 f0, r0\n" + " mtc1 f1, s5\n" + " mul.s f0, f0, f1\n" + " swc1 f0, 916(gp)\n" + //" lwc1 f0, L43(fp)\n" + " mtc1 f0, r0\n" + " mtc1 f1, s5\n" + " mul.s f0, f0, f1\n" + " swc1 f0, 904(gp)\n" + //" lwc1 f0, L46(fp)\n" + " mtc1 f0, r0\n" + //" lwc1 f1, L50(fp)\n" + " mtc1 f1, r0\n" + " mtc1 f2, s5\n" + " div.s f1, f1, f2\n" + " mul.s f0, f0, f1\n" + " swc1 f0, 908(gp)\n" + //" lwc1 f0, L49(fp)\n" + " mtc1 f0, r0\n" + " swc1 f0, 912(gp)\n" + " mfc1 v1, f0\n" + " beq r0, r0, L38\n" + " sll r0, r0, 0\n" + + "L37:\n" + " mtc1 f0, s5\n" + " swc1 f0, 916(gp)\n" + //" lwc1 f0, L44(fp)\n" + " mtc1 f0, r0\n" + " mtc1 f1, s5\n" + " mul.s f0, f0, f1\n" + " swc1 f0, 904(gp)\n" + //" lwc1 f0, L45(fp)\n" + " mtc1 f0, r0\n" + //" lwc1 f1, L50(fp)\n" + " mtc1 f1, r0\n" + " mtc1 f2, s5\n" + " div.s f1, f1, f2\n" + " mul.s f0, f0, f1\n" + " swc1 f0, 908(gp)\n" + //" lwc1 f0, L48(fp)\n" + " mtc1 f0, r0\n" + " swc1 f0, 912(gp)\n" + " mfc1 v1, f0\n" + + "L38:\n" + //" lwc1 f0, 900(gp)\n" + " mtc1 f0, r0\n" + " mfc1 v0, f0\n" + " ld ra, 0(sp)\n" + " ld fp, 8(sp)\n" + " lq gp, 32(sp)\n" + " lq s5, 16(sp)\n" + " jr ra\n" + " daddiu sp, sp, 48"; + std::string type = "(function display float float)"; + std::string expected = + "(begin\n" + " (let ((s5-0 (fmin 0.0 arg1)))\n" + " (set! (-> arg0 time-ratio) s5-0)\n" + " (let ((v1-0 (get-video-mode)))\n" + " (cond\n" + " ((= v1-0 (quote pal))\n" + " (set! (-> arg0 time-adjust-ratio) (* 0.0 s5-0))\n" + " (set! (-> arg0 seconds-per-frame) (* 0.0 s5-0))\n" + " (set! (-> arg0 frames-per-second) (* 0.0 (/ 0.0 s5-0)))\n" + " (set! (-> arg0 time-factor) 0.0)\n" + " )\n" + " (else\n" + " (set! (-> arg0 time-adjust-ratio) s5-0)\n" + " (set! (-> arg0 seconds-per-frame) (* 0.0 s5-0))\n" + " (set! (-> arg0 frames-per-second) (* 0.0 (/ 0.0 s5-0)))\n" + " (set! (-> arg0 time-factor) 0.0)\n" + " )\n" + " )\n" + " )\n" + " )\n" + " 0.0\n" + " )"; + test_with_expr(func, type, expected); +}