Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(init-vf0-vector) to make vector code a bit more readable #494

Merged
merged 4 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions decompiler/IR2/Form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,7 @@ goos::Object RLetElement::to_form_internal(const Env& env) const {
// NOTE - initialize any relevant registers in the body first
for (auto& reg : sorted_regs) {
if (reg.get_kind() == Reg::RegisterKind::VF && reg.to_string() == "vf0") {
// TODO - a good idea to move this to a macro like initialize-constant-vector! or something.
// There could be some clever way to do this initialization that's faster that a normal static
// load.
rletForm.push_back(
pretty_print::to_symbol("(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))"));
rletForm.push_back(pretty_print::to_symbol("(init-vf0-vector)")); // Defined in vector-h.gc
}
}

Expand Down
6 changes: 3 additions & 3 deletions goal_src/engine/camera/math-camera.gc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
Expand Down Expand Up @@ -427,7 +427,7 @@
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
Expand Down Expand Up @@ -475,7 +475,7 @@
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
Expand Down
8 changes: 4 additions & 4 deletions goal_src/engine/geometry/bounding-box.gc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
(vf4 :class vf)
(vf5 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf3 arg1)
(.lvf vf4 arg0)
(.add.vf vf5 vf4 vf3)
Expand Down Expand Up @@ -104,7 +104,7 @@
(vf5 :class vf)
(vf6 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf4 arg1)
(.lvf vf5 arg0)
(.mov vf1 arg2)
Expand All @@ -129,7 +129,7 @@
(vf2 :class vf)
(vf3 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 arg0)
(.sub.w.vf vf2 vf1 vf1 :mask #b111)
(.add.w.vf vf3 vf1 vf1 :mask #b111)
Expand Down Expand Up @@ -182,7 +182,7 @@
(sph-max :class vf)
(sph :class vf))
;; init constant
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
;; init min/max. in the case we don't have any spheres, we should return (0,0,0,1) for min/max.
(set! current-min vf0)
(set! current-max vf0)
Expand Down
2 changes: 1 addition & 1 deletion goal_src/engine/gfx/wind.gc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(vf1 :class vf)
(vf2 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(let*
((f0-1 (+ (-> arg0 wind-normal w) (rand-vu-float-range -1024.0 1024.0)))
(f30-1 (- f0-1 (* (the float (the int (/ f0-1 65536.0))) 65536.0)))
Expand Down
10 changes: 5 additions & 5 deletions goal_src/engine/math/matrix.gc
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
(vf4 :class vf)
(vf8 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
;; this makes the upper 3x3 correct because R^-1 = R^T for any rotation.
;; but now the transform is in the wrong spot, and needs to be rotated
;; and inverted.
Expand Down Expand Up @@ -433,7 +433,7 @@
(.xor.vf vf23 vf23 vf23)
(.xor.vf vf19 vf19 vf19)

(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
;; (nop!)
;; (nop!)
(.lvf vf23 (&-> src vector 0 quad))
Expand Down Expand Up @@ -929,7 +929,7 @@
(a1 :class i128 :type uint128)
(r0 :class i128 :type uint128)) ;; will be used for zero check.
;; initialize constant vectors
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.xor.p r0 r0 r0)

;; this is an overly complicated check to see if xyz = 0.
Expand Down Expand Up @@ -1334,7 +1334,7 @@
(vf14 :class vf)
(vf15 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf10 (&-> src vector 0 quad))
(.lvf vf11 (&-> src vector 1 quad))
(.lvf vf12 (&-> src vector 2 quad))
Expand Down Expand Up @@ -1939,7 +1939,7 @@
(acc :class vf)
(v1 :type int)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)

;; blez a3, L3
(when-goto (<= count 0) end)
Expand Down
16 changes: 8 additions & 8 deletions goal_src/engine/math/quaternion.gc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
(vf0 :class vf)
(vf1 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg0 vec quad))
(.mul.vf vf1 vf1 vf1)
(.add.z.vf acc vf1 vf1 :mask #b1000)
Expand All @@ -232,7 +232,7 @@
(vf0 :class vf)
(vf1 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg0 vec quad))
(.mul.vf vf1 vf1 vf1)
(.add.z.vf acc vf1 vf1 :mask #b1000)
Expand All @@ -252,7 +252,7 @@
(vf1 :class vf)
(vf2 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg0 vec quad))
(.mul.vf vf2 vf1 vf1)
(.add.z.vf acc vf2 vf2 :mask #b1000)
Expand All @@ -278,7 +278,7 @@
(vf2 :class vf)
(vf3 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg1 vec quad))
(.mul.vf vf2 vf1 vf1)
(.sub.vf vf3 vf3 vf3)
Expand All @@ -305,7 +305,7 @@
(vf1 :class vf)
(vf2 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg0 vec quad))
(.lvf vf2 (&-> arg1 vec quad))
(.mul.vf vf1 vf1 vf2)
Expand All @@ -327,7 +327,7 @@
(vf3 :class vf)
(vf4 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg1 vec quad))
(.lvf vf2 (&-> arg2 vec quad))
(.sub.vf vf4 vf0 vf0 :mask #b1000)
Expand Down Expand Up @@ -413,7 +413,7 @@
(vf4 :class vf)
(vf5 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(.lvf vf1 (&-> arg1 vec quad))
(.add.vf vf5 vf1 vf1)
(.add.w.vf vf2 vf0 vf1 :mask #b1)
Expand Down Expand Up @@ -826,7 +826,7 @@
(vf6 :class vf)
(vf7 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(let ((s4-0 (new 'stack-no-clear 'vector))
(gp-0 (new 'stack-no-clear 'vector))
(s5-0 (new 'stack-no-clear 'vector))
Expand Down
4 changes: 2 additions & 2 deletions goal_src/engine/math/transformq-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
(vf5 :class vf)
(vf6 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
(vector-y-angle
(vector-! (new 'stack-no-clear 'vector) arg0 (-> obj trans))
)
Expand All @@ -83,7 +83,7 @@
(vf5 :class vf)
(vf6 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)

(deg-diff
(y-angle obj)
Expand Down
4 changes: 2 additions & 2 deletions goal_src/engine/math/trigonometry.gc
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
(vf6 :class vf)
(vf9 :class vf) ;; coeffs
(acc :class vf))
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
;;(.lqc2 vf1 0 arg1)
(.lvf vf1 src)
;;(.vsub.xyzw vf2 vf2 vf2)
Expand Down Expand Up @@ -455,7 +455,7 @@
(vf14 :class vf)
(acc :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(init-vf0-vector)
;; (.lqc2 vf1 0 arg2)
(.lvf vf1 src)
;; (.vsub.xyzw vf14 vf14 vf14)
Expand Down
5 changes: 5 additions & 0 deletions goal_src/engine/math/vector-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@
(set! (-> vec w) ,wv)))
)

(defmacro init-vf0-vector ()
"Initializes the VF0 vector which is a constant vector in the VU set to <0,0,0,1>"
`(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
)

(defun vector-dot ((a vector) (b vector))
"Take the dot product of two vectors.
Only does the x, y, z compoments.
Expand Down
Loading