[decompiler] Make addition nicer (#733)

* temp

* update refs

* update reference

* fix tests
This commit is contained in:
water111
2021-08-01 18:24:58 -04:00
committed by GitHub
parent e70d179496
commit 12446037bd
42 changed files with 294 additions and 536 deletions
@@ -417,12 +417,9 @@
(*
(+
*profile-x*
(the-as
int
(/
(* (-> block time-stamp) (the-as uint *profile-w*))
(the-as uint *ticks-per-frame*)
)
(/
(* (-> block time-stamp) (the-as uint *profile-w*))
(the-as uint *ticks-per-frame*)
)
)
16
@@ -436,7 +433,7 @@
(-> (the-as (pointer gs-xyzf) t2-8) 0)
(new 'static 'gs-xyzf
:z #x3fffff
:y (* (+ (+ *profile-y* screen-y) *profile-h*) 16)
:y (* (+ *profile-y* screen-y *profile-h*) 16)
:x left
)
)
@@ -951,7 +951,7 @@
(object-new
allocation
type-to-make
(the-as int (+ (-> type-to-make size) (the-as uint (* (+ arg0 -1) 8))))
(the-as int (+ (-> type-to-make size) (* (+ arg0 -1) 8)))
)
)
@@ -164,10 +164,7 @@
(defun merc-fragment-fp-data ((arg0 merc-fragment))
(the-as
pointer
(+
(the-as uint arg0)
(the-as uint (* (-> arg0 header mm-quadword-fp-off) 16))
)
(+ (the-as uint arg0) (* (-> arg0 header mm-quadword-fp-off) 16))
)
)
@@ -259,7 +259,7 @@
(a3-9
(the-as
uint128
(-> *ocean-map* ocean-colors colors (+ (+ a1-11 1) (* 52 a0-16)))
(-> *ocean-map* ocean-colors colors (+ a1-11 1 (* 52 a0-16)))
)
)
(t0-10
@@ -271,12 +271,7 @@
(a0-22
(the-as
uint128
(->
*ocean-map*
ocean-colors
colors
(+ (+ a1-11 1) (* 52 (+ a0-16 1)))
)
(-> *ocean-map* ocean-colors colors (+ a1-11 1 (* 52 (+ a0-16 1))))
)
)
)
@@ -457,23 +452,13 @@
((a0-22
(the-as
uint128
(->
*ocean-map*
ocean-colors
colors
(+ (* 52 (the-as int arg1)) (the-as int arg2))
)
(-> *ocean-map* ocean-colors colors (+ (* 52 (the-as int arg1)) arg2))
)
)
(a1-13
(the-as
uint128
(->
*ocean-map*
ocean-colors
colors
(+ (+ arg2 1) (the-as uint (* 52 (the-as int arg1))))
)
(-> *ocean-map* ocean-colors colors (+ arg2 1 (* 52 (the-as int arg1))))
)
)
(a2-14
@@ -483,7 +468,7 @@
*ocean-map*
ocean-colors
colors
(+ (* 52 (the-as int (+ arg1 1))) (the-as int arg2))
(+ (* 52 (the-as int (+ arg1 1))) arg2)
)
)
)
@@ -494,7 +479,7 @@
*ocean-map*
ocean-colors
colors
(+ (+ arg2 1) (the-as uint (* 52 (the-as int (+ arg1 1)))))
(+ arg2 1 (* 52 (the-as int (+ arg1 1))))
)
)
)
@@ -1136,7 +1121,7 @@
(dotimes (t3-10 4)
(let ((t4-5 (-> sv-40 mask t3-10)))
(when (nonzero? t4-5)
(let ((t5-2 (+ (* a3-1 4) (the-as uint t3-10))))
(let ((t5-2 (+ (* a3-1 4) t3-10)))
(if (< t5-2 (the-as uint a0-11))
(set! a0-11 (the-as int t5-2))
)
@@ -1146,7 +1131,7 @@
)
(dotimes (t5-3 4)
(when (logtest? t4-5 (ash 1 t5-3))
(let ((t6-9 (+ (* t1-0 4) (the-as uint t5-3))))
(let ((t6-9 (+ (* t1-0 4) t5-3)))
(if (< t6-9 (the-as uint a2-2))
(set! a2-2 (the-as int t6-9))
)
@@ -1193,7 +1178,7 @@
*ocean-map*
ocean-trans-indices
data
(+ (* (the-as uint 48) s5-1) (the-as int s3-1))
(+ (* (the-as uint 48) s5-1) s3-1)
)
)
)
@@ -1240,7 +1225,3 @@
0
(none)
)
@@ -196,7 +196,7 @@
(s4-0
(the-as
mei-ripple
(+ (the-as uint a1-6) (the-as uint (* (-> a1-6 ripple-offset) 16)))
(+ (the-as uint a1-6) (* (-> a1-6 ripple-offset) 16))
)
)
(gp-0 (-> v1-1 ripple))
@@ -224,15 +224,10 @@
(dst
(the-as
qword
(+
(the-as uint (-> obj header))
(the-as uint (* (+ (-> obj header data 1) 1) 16))
)
(+ (the-as uint (-> obj header)) (* (+ (-> obj header data 1) 1) 16))
)
)
(tex-dst
(the-as qword (+ (the-as int dst) (the-as int (* shader-count 64))))
)
(tex-dst (the-as qword (+ (the-as int dst) (* shader-count 64))))
(src (the-as qword (-> obj textures)))
)
(dotimes (a0-1 (the-as int shader-count))
@@ -106,7 +106,7 @@
(object-new
allocation
type-to-make
(the-as int (+ (-> type-to-make size) (the-as uint (* (+ size -1) 4))))
(the-as int (+ (-> type-to-make size) (* (+ size -1) 4)))
)
)
)
@@ -460,7 +460,7 @@
int
(+
(-> type-to-make size)
(the-as uint (* (+ (+ adgif-data-size -1) vec-data-size) 16))
(* (+ adgif-data-size -1 vec-data-size) 16)
)
)
)
@@ -496,7 +496,7 @@
int
(+
(-> type-to-make size)
(the-as uint (* (+ (+ adgif-data-size -1) vec-data-size) 16))
(* (+ adgif-data-size -1 vec-data-size) 16)
)
)
)
@@ -739,7 +739,7 @@
(-> pkt2 dma)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:addr (+ (-> sprites vec-data) (the-as uint (* 48 start-sprite-idx)))
:addr (+ (-> sprites vec-data) (* 48 start-sprite-idx))
:qwc qwc-pkt2
)
)
@@ -758,7 +758,7 @@
(-> pkt3 dma)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:addr (+ (-> sprites adgif-data) (the-as uint (* 80 start-sprite-idx)))
:addr (+ (-> sprites adgif-data) (* 80 start-sprite-idx))
:qwc qwc-pkt3
)
)
@@ -854,7 +854,7 @@
(-> pkt2 dma)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:addr (+ (-> sprites vec-data) (the-as uint (* 48 start-sprite-idx)))
:addr (+ (-> sprites vec-data) (* 48 start-sprite-idx))
:qwc qwc-pkt2
)
)
@@ -873,7 +873,7 @@
(-> pkt3 dma)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:addr (+ (-> sprites adgif-data) (the-as uint (* 80 start-sprite-idx)))
:addr (+ (-> sprites adgif-data) (* 80 start-sprite-idx))
:qwc qwc-pkt3
)
)
@@ -23,7 +23,7 @@
;; definition for method 5 of type texture-page
;; INFO: Return type mismatch uint vs int.
(defmethod asize-of texture-page ((obj texture-page))
(the-as int (+ (-> obj type size) (the-as uint (* (-> obj length) 4))))
(the-as int (+ (-> obj type size) (* (-> obj length) 4)))
)
;; definition for method 8 of type texture-page
@@ -638,10 +638,10 @@
(let* ((block-width (gs-block-width tex-format))
(block-height (gs-block-height tex-format))
(real-width
(* (/ (+ (+ block-width -1) tex-width) block-width) block-width)
(* (/ (+ block-width -1 tex-width) block-width) block-width)
)
(real-height
(* (/ (+ (+ block-height -1) tex-height) block-height) block-height)
(* (/ (+ block-height -1 tex-height) block-height) block-height)
)
(width-blocks (/ real-width block-width))
(height-blocks (/ real-height block-height))
@@ -660,11 +660,9 @@
(defun gs-blocks-used ((tex-width int) (tex-height int) (tex-format gs-psm))
(let* ((page-width (gs-page-width tex-format))
(page-height (gs-page-height tex-format))
(real-width
(* (/ (+ (+ page-width -1) tex-width) page-width) page-width)
)
(real-width (* (/ (+ page-width -1 tex-width) page-width) page-width))
(real-height
(* (/ (+ (+ page-height -1) tex-height) page-height) page-height)
(* (/ (+ page-height -1 tex-height) page-height) page-height)
)
(width-blocks (/ real-width page-width))
(height-blocks (/ real-height page-height))
@@ -673,7 +671,8 @@
)
(if (or (< a0-9 page-width) (< a1-7 page-height))
(+
(+ (gs-largest-block a0-9 a1-7 tex-format) 1)
(gs-largest-block a0-9 a1-7 tex-format)
1
(* (+ (* width-blocks height-blocks) -1) 32)
)
(* (* height-blocks width-blocks) 32)
@@ -792,7 +791,7 @@
((obj texture-page) (segment-count int) (additional-size int))
(let ((v1-0 additional-size))
(dotimes (a2-1 segment-count)
(+! v1-0 (the-as int (-> obj segment a2-1 size)))
(+! v1-0 (-> obj segment a2-1 size))
)
(logand (/ v1-0 64) 63)
)
@@ -1009,11 +1008,7 @@
)
)
(dotimes (upload-chunk-idx chunk-count)
(let
((current-dest-chunk
(+ tex-dest-base-chunk (the-as uint upload-chunk-idx))
)
)
(let ((current-dest-chunk (+ tex-dest-base-chunk upload-chunk-idx)))
(cond
((zero? chunks-to-upload-count)
(when (!= (-> pool ids current-dest-chunk) tex-id)
@@ -1025,10 +1020,7 @@
((= (-> pool ids current-dest-chunk) tex-id)
(upload-vram-data
dma-buf
(the-as
int
(* (+ tex-dest-base-chunk (the-as uint first-chunk-idx-to-upload)) 64)
)
(the-as int (* (+ tex-dest-base-chunk first-chunk-idx-to-upload) 64))
(&+ tex-data (shl first-chunk-idx-to-upload 14))
(* chunks-to-upload-count 32)
)
@@ -1046,10 +1038,7 @@
(when (nonzero? chunks-to-upload-count)
(upload-vram-data
dma-buf
(the-as
int
(* (+ tex-dest-base-chunk (the-as uint first-chunk-idx-to-upload)) 64)
)
(the-as int (* (+ tex-dest-base-chunk first-chunk-idx-to-upload) 64))
(&+ tex-data (shl first-chunk-idx-to-upload 14))
(* chunks-to-upload-count 32)
)
@@ -1161,7 +1150,7 @@
)
)
(dotimes (chunk-idx upload-chunks)
(let ((vram-chunk (+ dest-block (the-as uint chunk-idx))))
(let ((vram-chunk (+ dest-block chunk-idx)))
(cond
((zero? modified-chunk-count)
(when (!= (-> pool ids vram-chunk) page-id)
@@ -1223,10 +1212,7 @@
)
)
(dotimes (upload-chunk-idx chunk-count)
(set!
current-dest-chunk
(+ tex-dest-base-chunk (the-as uint upload-chunk-idx))
)
(set! current-dest-chunk (+ tex-dest-base-chunk upload-chunk-idx))
(set!
need-tex
(nonzero? (logand allow-cache-mask (ash 1 upload-chunk-idx)))
@@ -1242,10 +1228,7 @@
((or (= (-> pool ids current-dest-chunk) page-id) (not need-tex))
(upload-vram-data
dma-buf
(the-as
int
(* (+ tex-dest-base-chunk (the-as uint first-chunk-idx-to-upload)) 64)
)
(the-as int (* (+ tex-dest-base-chunk first-chunk-idx-to-upload) 64))
(&+ tex-data (shl first-chunk-idx-to-upload 14))
(* chunks-to-upload-count 32)
)
@@ -1262,10 +1245,7 @@
(when (nonzero? chunks-to-upload-count)
(upload-vram-data
dma-buf
(the-as
int
(* (+ tex-dest-base-chunk (the-as uint first-chunk-idx-to-upload)) 64)
)
(the-as int (* (+ tex-dest-base-chunk first-chunk-idx-to-upload) 64))
(&+ tex-data (shl first-chunk-idx-to-upload 14))
(* chunks-to-upload-count 32)
)
@@ -1353,11 +1333,8 @@
((< (the-as uint #x24000) page-seg-2-size)
(let ((after-seg-2-data (&+ (-> page segment 2 block-data) #x90000)))
(let ((seg-2-data (-> page segment 2 block-data)))
(set! (-> page segment 2 size) (+ -147456 (the-as int page-seg-2-size)))
(set!
(-> page segment 2 dest)
(+ #x24000 (the-as int (-> pool segment-near dest)))
)
(set! (-> page segment 2 size) (+ -147456 page-seg-2-size))
(set! (-> page segment 2 dest) (+ #x24000 (-> pool segment-near dest)))
(set!
(-> heap current)
(&+ (-> page segment 2 block-data) (* (-> page segment 2 size) 4))
@@ -1402,7 +1379,7 @@
(update-vram-pages pool (-> pool segment-near) page 2)
(cond
((< (the-as uint #x24000) seg2-size)
(set! (-> page segment 2 size) (+ -147456 (the-as int seg2-size)))
(set! (-> page segment 2 size) (+ -147456 seg2-size))
(set!
(-> heap current)
(&+ (-> page segment 2 block-data) (* (-> page segment 2 size) 4))
@@ -2793,10 +2770,7 @@
(and
main-font-tx
(-> main-font-tx page)
(=
(-> obj cur)
(+ heap-before-font-tex (the-as int (-> main-font-tx page size)))
)
(= (-> obj cur) (+ heap-before-font-tex (-> main-font-tx page size)))
)
(set! (-> obj cur) heap-before-font-tex)
(format 0 "ERROR: could not resize heap to remove gamefont.~%")
@@ -2810,10 +2784,7 @@
;; definition for method 5 of type texture-page-dir
;; INFO: Return type mismatch uint vs int.
(defmethod asize-of texture-page-dir ((obj texture-page-dir))
(the-as
int
(+ (-> texture-page-dir size) (the-as uint (* 12 (+ (-> obj length) -1))))
)
(the-as int (+ (-> texture-page-dir size) (* 12 (+ (-> obj length) -1))))
)
;; definition for method 4 of type texture-page-dir
@@ -2847,23 +2818,20 @@
(num-mips (-> tex num-mips))
)
(if (zero? seg-id)
(set!
(-> tex clutdest)
(+ (- (-> tex clutdest) dst-block) (the-as uint v1-0))
)
(set! (-> tex clutdest) (+ (- (-> tex clutdest) dst-block) v1-0))
)
(dotimes (mip-id (the-as int num-mips))
(let ((t4-0 mip-id)
(t5-0 num-mips)
)
(if (= seg-id (if (>= (the-as uint 2) t5-0)
(+ (- -1 t4-0) (the-as int t5-0))
(+ (- -1 t4-0) t5-0)
(max 0 (- 2 t4-0))
)
)
(set!
(-> tex dest mip-id)
(+ (- (-> tex dest mip-id) dst-block) (the-as uint v1-0))
(+ (- (-> tex dest mip-id) dst-block) v1-0)
)
)
)
@@ -3181,13 +3149,13 @@
((1)
(set!
(-> arg0 tex1 k)
(+ (+ (logand (ash s5-0 (- 5 (log2 s5-0))) 31) -350) (* (log2 s5-0) 32))
(+ (logand (ash s5-0 (- 5 (log2 s5-0))) 31) -350 (* (log2 s5-0) 32))
)
)
(else
(set!
(-> arg0 tex1 k)
(+ (+ (logand (ash s5-0 (- 4 (log2 s5-0))) 15) -175) (* (log2 s5-0) 16))
(+ (logand (ash s5-0 (- 4 (log2 s5-0))) 15) -175 (* (log2 s5-0) 16))
)
)
)
@@ -32,10 +32,10 @@
(when
(nonzero?
(+
(+
(+ (+ (-> stat groups) (-> stat fragments)) (-> stat tris))
(-> stat dverts)
)
(-> stat groups)
(-> stat fragments)
(-> stat tris)
(-> stat dverts)
(-> stat instances)
)
)
@@ -341,7 +341,7 @@
(when GSH_ENABLE
(let ((bucket GSH_BUCKET))
(let ((which-stat GSH_WHICH_STAT))
(set! gp-0 (+ (* bucket 2) (the-as uint which-stat)))
(set! gp-0 (+ (* bucket 2) which-stat))
)
(when GSH_MAX_DISPLAY
(let
@@ -432,10 +432,10 @@
)
(cond
((zero? a1-63)
(set! a0-64 (+ #x60020 (the-as int a0-64)))
(set! a0-64 (+ #x60020 a0-64))
)
((= a1-63 1)
(set! a0-64 (+ #x300c0 (the-as int a0-64)))
(set! a0-64 (+ #x300c0 a0-64))
)
)
(set! (-> *perf-stats* data v1-27 select) a1-63)
@@ -489,9 +489,9 @@
(.sync.l)
(.sync.p)
(.mfpc a0-1 pcr0)
(+! (-> v1-1 0 accum0) (the-as uint a0-1))
(+! (-> v1-1 0 accum0) a0-1)
(.mfpc a0-3 pcr1)
(+! (-> v1-1 0 accum1) (the-as uint a0-3))
(+! (-> v1-1 0 accum1) a0-3)
)
(label cfg-2)
0
@@ -534,7 +534,3 @@
0
(none)
)
@@ -143,7 +143,7 @@
(format #t "_#x~X________________~%" arg1)
(inspect arg1)
(let ((s4-0 *print-column*))
(set! *print-column* (+ *print-column* (the-as uint 64)))
(set! *print-column* (+ *print-column* 64))
(if (> (-> arg1 front) 0)
(inspect-bsp-tree arg0 (the-as bsp-node (-> arg1 front)))
(format #t "_#x~X________________~%" arg1)
@@ -90,10 +90,7 @@
;; definition for function wind-get-hashed-index
(defun wind-get-hashed-index ((arg0 vector))
(logand
(+
(+ (the int (-> arg0 x)) (the int (-> arg0 z)))
(the-as int (-> *wind-work* wind-time))
)
(+ (the int (-> arg0 x)) (the int (-> arg0 z)) (-> *wind-work* wind-time))
63
)
)