From 21684bd104e11e662039a5f83e4b7f62d240faff Mon Sep 17 00:00:00 2001 From: water Date: Thu, 5 Aug 2021 20:29:36 -0400 Subject: [PATCH] misc bug fixes, now draw string generates dma data --- common/cross_os_debug/xdbg.cpp | 5 + common/cross_os_debug/xdbg.h | 4 +- .../jak1_ntsc_black_label/var_names.jsonc | 41 +++++++ goal_src/engine/draw/drawable.gc | 27 +++-- goal_src/engine/gfx/font-h.gc | 82 ++++++++++--- goal_src/engine/gfx/font.gc | 113 ++++++++++++++++-- goal_src/kernel/gstring.gc | 1 + goalc/debugger/Debugger.cpp | 3 + goalc/regalloc/Allocator_v2.cpp | 13 +- 9 files changed, 247 insertions(+), 42 deletions(-) diff --git a/common/cross_os_debug/xdbg.cpp b/common/cross_os_debug/xdbg.cpp index 0124f2c0ed..8275d82c22 100644 --- a/common/cross_os_debug/xdbg.cpp +++ b/common/cross_os_debug/xdbg.cpp @@ -94,6 +94,11 @@ bool check_stopped(const ThreadID& tid, SignalInfo* out) { int status; int rv = waitpid(tid.id, &status, WNOHANG); if (rv < 0) { + if (errno == ECHILD) { + // the thing died. + out->kind = SignalInfo::DISAPPEARED; + return true; + } printf("[Debugger] Failed to waitpid: %s.\n", strerror(errno)); // assert(false); // todo, temp because I think we should never hit this. return false; diff --git a/common/cross_os_debug/xdbg.h b/common/cross_os_debug/xdbg.h index a2916899d0..21bfcc4e3c 100644 --- a/common/cross_os_debug/xdbg.h +++ b/common/cross_os_debug/xdbg.h @@ -83,7 +83,9 @@ struct SignalInfo { SEGFAULT, // access bad memory BREAK, // hit a breakpoint or execute int3 MATH_EXCEPTION, // divide by zero - UNKNOWN // some other signal that is unsupported + UNKNOWN, // some other signal that is unsupported + DISAPPEARED, // process disappeared (maybe killed by the user) + } kind = UNKNOWN; }; diff --git a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc index f04901b797..783ee66d8d 100644 --- a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc @@ -3090,5 +3090,46 @@ } }, + "draw-string": { + "args":["str-in", "context"], + "vars": { + "v1-5":"fw", + "a1-1":"dma-out", + "t2-0":"flags", + "a3-0":"has-flag-size24", + "a3-1":"font-table-12", + "a3-2":"font-table-to-use", + "t0-0":"q-lo-tmpl", + "t1-0":"q-hi-tmpl", + "t3-0":"in-color", + "t3-1":"color-array-prod", + "t4-0":"fw+col", + "t3-2":"q-verts-0p", + "t5-0":"q-verts-1p", + "t3-3":"q-verts-2p", + "t4-1":"q-verts-3p", + "t5-1":"q-verts-1t", + "t5-2":"q-verts-1", + "t3-4":"q-verts-2t", + "t3-5":"q-verts-2", + "t6-0":"q-verts-0t", + "t6-1":"q-verts-0", + "t4-2":"q-verts-3t", + "t4-3":"q-verts-3", + "t3-6":"fw2", + "t4-4":"str-char", + "t5-3":"not-sc-lit1", + "t5-4":"not-sc-~", + "t4-14":"fc-cr", + "r0-0":"r0", + "r0-1":"r0", + "r0-2":"r0", + "r0-3":"r0" + + + + } + }, + "aaaaaaaaaaaaaaaaaaaaaaa": {} } diff --git a/goal_src/engine/draw/drawable.gc b/goal_src/engine/draw/drawable.gc index f5439b46be..3a61244e19 100644 --- a/goal_src/engine/draw/drawable.gc +++ b/goal_src/engine/draw/drawable.gc @@ -341,12 +341,8 @@ (global-start (-> global-buf data)) (global-end (-> global-buf end)) ) - (format *stdcon* "~0kvu1 buf = ~d~%" - (&- calc-current (the-as uint calc-start)) - ) - (format *stdcon* "~0kglobal buf = ~d~%" - (&- global-current (the-as uint global-start)) - ) + (format *stdcon* "~0kvu1 buf = ~d~%" (&- calc-current (the-as uint calc-start))) + (format *stdcon* "~0kglobal buf = ~d~%" (&- global-current (the-as uint global-start))) (format *stdcon* "~0kbase = #x~x~%" global-current) (format *stdcon* "~0kend = #x~x~%" global-end) ) @@ -406,6 +402,14 @@ ) ) +(#when PC_PORT + (define *disasm-count* 0) + + (defmacro disasm-next-dma (&key (count 1)) + `(set! *disasm-count* ,count) + ) + ) + (defun display-sync ((disp display)) "Switch frames! This assumes that you have called display-frame-finish on the current frame. It will: @@ -458,8 +462,15 @@ ;; begin rendering the next frame (let ((dma-buf-to-send (-> disp frames frame-idx frame calc-buf))) - (if (nonzero? (dma-buffer-length dma-buf-to-send)) - ;; was dma-send-chain originally. + (when (nonzero? (dma-buffer-length dma-buf-to-send)) + ;; was dma-send-chain originally. + (#when PC_PORT + (when (> *disasm-count* 0) + (disasm-dma-list (the-as dma-packet (-> dma-buf-to-send data-buffer)) 'details #t #t -1) + (-! *disasm-count* 1) + ) + ) + ;;(cpu-usage) (__send-gfx-dma-chain (the-as dma-bank-source #x10009000) (cond ;; some buffer for debugging, not used diff --git a/goal_src/engine/gfx/font-h.gc b/goal_src/engine/gfx/font-h.gc index e648c3f2e4..8a656a12c8 100644 --- a/goal_src/engine/gfx/font-h.gc +++ b/goal_src/engine/gfx/font-h.gc @@ -8,6 +8,14 @@ ;; The font system draws all of the strings. ;; The font textures live in the upper 8 bits of the 24-bit texture format depth buffer. +;; flags +;; 1 +;; 2 +;; 4 +;; 8 +;; 16 +;; 32 (use size 24) + (deftype char-verts (structure) ((pos vector 4 :inline :offset-assert 0) (color vector 4 :inline :offset-assert 64) @@ -150,26 +158,62 @@ obj ) -(defmethod new font-context ((allocation symbol) (type-to-make type) (mat matrix) (x int) (y int) (z float) (color int) (flags uint)) - "Allocate a new font-context with the given parameters" - - (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size))))) - (set-mat! obj mat) - (set-origin! obj x y) - (if (= z 0) - (set! (-> obj origin z) (-> *math-camera* isometric data 14)) ;; inlined set-depth! - (set! (-> obj origin z) z) ;; inlined set-depth! - ) - (set-w! obj 1.0) - (set-width! obj 512) - (set-width! obj 256) - (set-projection! obj 1.0) - (set-color! obj color) - (set-flags! obj flags) - (set-start-line! obj (the-as uint 0)) - (set-scale! obj 1.0) - obj +(defmethod + new + font-context + ((allocation symbol) + (type-to-make type) + (mat matrix) + (x int) + (y int) + (z float) + (color int) + (flags uint) + ) + (let + ((obj + (object-new allocation type-to-make (the-as int (-> type-to-make size))) + ) ) + (set! (-> obj mat) mat) + (let ((v1-3 obj)) + (set! (-> v1-3 origin x) (the float x)) + (set! (-> v1-3 origin y) (the float y)) + ) + (cond + ((= z 0.0) + (let ((v1-4 obj)) + (set! (-> v1-4 origin z) (-> *math-camera* isometric vector 3 z)) + ) + ) + (else + (let ((v1-5 obj)) + (set! (-> v1-5 origin z) z) + ) + ) + ) + (let ((v1-6 obj)) + (set! (-> v1-6 origin w) 1.0) + ) + (let ((v1-7 obj)) + (set! (-> v1-7 width) (the float 512)) + ) + (let ((v1-8 obj)) + (set! (-> v1-8 height) (the float 256)) + ) + (let ((v1-9 obj)) + (set! (-> v1-9 projection) 1.0) + ) + (set! (-> obj color) color) + (set! (-> obj flags) flags) + (let ((a0-4 obj)) + (set! (-> a0-4 start-line) (the-as uint 0)) + ) + (let ((v1-13 obj)) + (set! (-> v1-13 scale) 1.0) + ) + obj + ) ) (deftype font-work (structure) diff --git a/goal_src/engine/gfx/font.gc b/goal_src/engine/gfx/font.gc index 38c16edec0..bed3bc3c6d 100644 --- a/goal_src/engine/gfx/font.gc +++ b/goal_src/engine/gfx/font.gc @@ -6,7 +6,8 @@ ;; dgos: GAME, ENGINE (defmacro .sll (result in sa) - `(set! ,result (the-as int (shl (logand ,in #xffffffff) ,sa))) + `(set! ,result (sext32 (the-as int (shl (logand ,in #xffffffff) ,sa)))) + ;`(set! ,result (shl (the-as int ,in) ,sa)) ) (defmacro .movz (result value check) @@ -23,11 +24,18 @@ (defmacro .addu (result a b) - `(set! ,result (logand (+ (the-as int ,a) (the-as int ,b)) #xffffffff)) + `(set! ,result (sext32 (logand (+ (the-as int ,a) (the-as int ,b)) #xffffffff))) + ;`(set! ,result (+ (the-as int ,a) (the-as int ,b))) + ) + +(defmacro sext32 (in) + `(sar (shl ,in 32) 32) ) (defmacro .sra (result in sa) - `(set! ,result (logand #xffffffff (sar (the-as int ,in) ,sa))) + ;;`(set! ,result (sext32 (logand #xffffffff (sar (the-as int ,in) ,sa)))) + `(set! ,result (sext32 (sar (logand #xffffffff (the-as int ,in)) ,sa))) + ;`(sar (the-as int ,in) ,sa) ) @@ -584,11 +592,23 @@ ) ) +(defmacro print-vf (vf &key (name #f)) + "Print out a vf register as a vector." + `(let ((temp (new 'stack 'vector))) + (.svf temp ,vf) + ,(if name + `(format 0 "~A: ~`vector`P~%" (quote ,name) temp) + `(format 0 "~`vector`P~%" temp) + ) + ) + ) + (defun draw-string ((arg0 string) (arg1 dma-buffer) (arg2 font-context)) "Draw a string." ;; note: this function is > 4000 instructions and around 80 kB of x86-64. ;; it contains over 2000 iregisters. ;;(declare (print-asm)) + (local-vars (r0 uint128) (v0-0 float) @@ -722,8 +742,19 @@ (t8-4 uint) (t8-5 int) (f31-0 none) + + (hack-str string) ) + + ;(set! hack-str (new 'debug 'string 256 (the string #f))) + ;(copy-string<-string hack-str arg0) + ;(set! arg0 hack-str) + + (set! r0 (the-as uint128 0)) + + ;;(inspect *font-work*) + (rlet ((acc :class vf) (Q :class vf) (vf0 :class vf) @@ -765,7 +796,9 @@ (.add.w.vf vf26 vf26 vf0 :mask #b1) (let ((v1-1 (-> arg2 mat))) (.lvf vf25 (&-> arg2 context-vec quad)) + ;;(print-vf vf25 :name y-is-ctxt-ht) (.lvf vf23 (&-> arg2 origin quad)) + ;;(print-vf vf23 :name vf23-init) (.lvf vf24 (&-> arg2 origin quad)) (.lvf vf28 (&-> v1-1 vector 0 quad)) (.lvf vf29 (&-> v1-1 vector 1 quad)) @@ -774,6 +807,7 @@ ) (let ((v1-3 *video-parms*)) (.lvf vf1 (+ (the int v1-3) 64)) + ;;(print-vf vf1 :name vid-params) seems legit ) (.mul.vf vf25 vf25 vf1 :mask #b11) (.mul.vf vf23 vf23 vf1 :mask #b11) @@ -864,10 +898,13 @@ (label cfg-4) (let ((t4-4 (-> (the-as (pointer uint8) arg0) 4))) (set! arg0 (the-as string (&-> (the-as (pointer uint8) arg0) 1))) + ;;(format 0 "char at the top is '~c'~%" t4-4) (b! (zero? t4-4) cfg-67 :delay (set! t5-3 (+ t4-4 -1))) (b! (zero? t5-3) cfg-54 :delay (set! t5-4 (+ t4-4 -126))) (b! (nonzero? t5-4) cfg-55) + ;; here, if we have a tilde arg. (set! t4-4 (-> (the-as (pointer uint8) arg0) 4)) + (set! arg0 (the-as string (&-> (the-as (pointer uint8) arg0) 1))) 0 (let ((t6-2 0)) @@ -956,32 +993,44 @@ (b! #t cfg-4 :delay (set! t2-0 (logior t2-0 4))) (label cfg-42) (.mov vf1 t6-2) + ;; (print-vf vf1 :name after-t6-2move) not hit (let ((t4-9 (+ t5-7 -45))) + (b! (zero? t5-7) cfg-46 :delay (.itof.vf vf1 vf1)) (b! (zero? t4-9) cfg-45) ) + ;;(format 0 "AAAA~%") didn't get here (b! #t cfg-4 :delay (.add.x.vf vf23 vf23 vf1 :mask #b1)) (label cfg-45) + ;;(format 0 "ASDFASDF~%") not here (b! #t cfg-4 :delay (.sub.x.vf vf23 vf23 vf1 :mask #b1)) (label cfg-46) + ;;(format 0 "2ASDFASDF~%") not here (b! #t cfg-4 :delay (.add.x.vf vf23 vf0 vf1 :mask #b1)) (label cfg-47) (.mov vf1 t6-2) + ;;(print-vf vf1 :name after-t6-2move) ) (let ((t4-10 (+ t5-7 -45))) (b! (zero? t5-7) cfg-51 :delay (.itof.vf vf1 vf1)) (b! (zero? t4-10) cfg-50) ) + (format 0 "NO~%") (b! #t cfg-4 :delay (.add.x.vf vf23 vf23 vf1 :mask #b10)) (label cfg-50) + (format 0 "NO~%") (b! #t cfg-4 :delay (.sub.x.vf vf23 vf23 vf1 :mask #b10)) (label cfg-51) + (format 0 "NO~%") (b! #t cfg-4 :delay (.add.x.vf vf23 vf0 vf1 :mask #b10)) (label cfg-52) + (format 0 "NO~%") (b! #t cfg-4 :delay (.svf (&-> v1-5 save quad) vf23)) (label cfg-53) + (format 0 "NO~%") (b! #t cfg-4 :delay (.lvf vf23 (&-> v1-5 save quad))) (label cfg-54) + (format 0 "NO~%") (let ((t4-11 (-> (the-as (pointer uint8) arg0) 4))) (set! arg0 (the-as string (&-> (the-as (pointer uint8) arg0) 1))) (.add.vf vf4 vf23 vf15 :mask #b111) @@ -993,9 +1042,16 @@ ) ) (label cfg-55) + ;; gets here with a non-tilde arg + ;;(print-vf vf23 :name next-vf23) ;; these increase, like you'd expect (.add.vf vf4 vf23 vf15 :mask #b111) (.sll t5-9 (the-as int t4-4) 4) + ;;(print-vf vf25 :name vf25) ;; 0.0 in y (suspicious of this) + ;;(print-vf vf23 :name vf23) ;; -18.0 in y (.sub.vf vf1 vf25 vf23) + ;;(print-vf vf1 :name bad-vf1) has -18.0 in y. + + ;;(format 0 "!!!!~d ~c~%" t5-9 t4-4) also see first char here (b! (= t4-4 10) cfg-57 :delay (set! t4-14 (+ t4-4 -13))) ) (b! (nonzero? t4-14) cfg-62) @@ -1038,10 +1094,24 @@ (set! t3-6 (-> (the-as font-work t3-6) font-tmpl gif)) ) (label cfg-62) + ;; stuff above is newline stuff. + ;; here, I think t5-9 is the offset. + ;;(format #t "at render part, offset is ~d~%" t5-9) seems legit (.addu t4-17 t5-9 a3-2) + ;; (format #t "addu ~x ~x ~x~%" t4-17 t5-9 a3-2) (nop!) (.lvf vf5 (+ t4-17 -256)) + ;;(print-vf vf5) (.mov t4-18 vf1) + ;;(format #t "t4-18 = ~d~%" t4-18) we do take this branch, and I am pretty sure this is wrong. + ;;(print-vf vf1) + ;;(format #t "~%") + + + + + ;; PART 2 (the good part) + (b! (< (the-as int t4-18) 0) cfg-67 :delay (.sra t4-19 t4-18 31)) (.mul.vf vf19 vf5 vf13) (b! (zero? (logand t2-0 2)) cfg-65) @@ -1052,7 +1122,10 @@ (label cfg-66) (b! #t cfg-4) (label cfg-67) + ;;(print-vf vf23 :name vf23-good-part) + ;;(format 0 "flag ~d~%" t2-0) (.sub.vf vf1 vf23 vf24) + ;;(print-vf vf1 :name set-vf1) (b! (logtest? t2-0 16) cfg-70 :delay (set! a0-2 (logand t2-0 4))) (b! (nonzero? a0-2) cfg-71) (.add.x.vf vf23 vf0 vf24 :mask #b1) @@ -1064,7 +1137,13 @@ (.svf (&-> (the-as font-work t3-6) justify 0 quad) vf23) ) (label cfg-70) + ;; vf23.x is our position. + ;; vf24 is the origin. + ;; vf1 ?? + ;;(print-vf vf1 :name vf1-sub) + ;;(print-vf vf24 :name vf24-sub) (.sub.vf vf23 vf24 vf1 :mask #b1) + ;;(print-vf vf23 :name vf23-good-part) (nop!) (b! #t @@ -1086,16 +1165,21 @@ (.lvf vf23 (&-> (the-as font-work t2-1) justify 0 quad)) (label cfg-73) (let ((t4-21 (-> t3-7 4))) + ; (format #t "paa char ~c~%" t4-21) ;; we get here with the v. (set! t3-7 (&-> t3-7 1)) (b! (zero? t4-21) cfg-131 :delay (set! t5-10 (+ t4-21 -1))) (b! (zero? t5-10) cfg-121 :delay (set! t5-11 (+ t4-21 -126))) (b! (nonzero? t5-11) cfg-122) + ;; get here as well (set! t4-21 (-> t3-7 4)) + ;;(format #t "eat char ~c~%" t4-21) (set! t3-7 (&-> t3-7 1)) 0 (let ((t6-9 0)) (b! (zero? t4-21) cfg-131 :delay (set! t7-18 (+ t4-21 -43))) + ; (format #t "movz ~d ~d ~d~%" t5-13 t4-21 t7-18) (.movz t5-13 (the-as int t4-21) t7-18) + ; (format #t "res ~d~%" t5-13) (let ((t7-19 (+ t4-21 -45))) (.movz t5-14 (the-as int t4-21) t7-19) ) @@ -1188,6 +1272,7 @@ (label cfg-109) (.mov vf1 t6-9) (let ((t4-26 (+ t5-14 -45))) + ; (format #t "itof122~%") (b! (zero? t5-14) cfg-113 :delay (.itof.vf vf1 vf1)) (b! (zero? t4-26) cfg-112) ) @@ -1200,6 +1285,7 @@ (.mov vf1 t6-9) ) (let ((t4-27 (+ t5-14 -45))) + ; (format #t "itof12323~%") (b! (zero? t5-14) cfg-118 :delay (.itof.vf vf1 vf1)) (b! (zero? t4-27) cfg-117) ) @@ -1237,7 +1323,8 @@ :delay (.lvf vf23 (+ (the-as int t2-1) 944)) ) - (label cfg-125) + (label cfg-125) ;; get here + ; (format #t "aa~%") (.addu t5-18 t5-17 a3-2) (nop!) (.lvf vf5 (+ t5-18 -256)) @@ -1248,6 +1335,7 @@ :delay (.add.vf vf6 vf5 vf16 :mask #b111) ) + ; (format #t "b~%") (.sra t5-20 t5-19 31) (.add.vf vf7 vf5 vf17 :mask #b111) (b! (< t5-20 0) cfg-73 :delay (.add.vf vf8 vf5 vf18 :mask #b111)) @@ -1430,6 +1518,7 @@ (label cfg-132) (let ((t4-30 (-> t3-8 4))) (set! t3-8 (&-> t3-8 1)) + ;;(format #t "yac: ~c~%" t4-30) get the v here as well. (b! (zero? t4-30) cfg-189 :delay (set! t5-24 (+ t4-30 -1))) (b! (zero? t5-24) cfg-179 :delay (set! t5-25 (+ t4-30 -126))) (b! (nonzero? t5-25) cfg-180) @@ -1613,6 +1702,7 @@ (label cfg-167) (.mov vf1 t6-19) (let ((t4-39 (+ t5-28 -45))) + ; (format #t "itof13424~%") (b! (zero? t5-28) cfg-171 :delay (.itof.vf vf1 vf1)) (b! (zero? t4-39) cfg-170) ) @@ -1625,6 +1715,7 @@ (.mov vf1 t6-19) ) (let ((t4-40 (+ t5-28 -45))) + ; (format #t "itof153532~%") (b! (zero? t5-28) cfg-176 :delay (.itof.vf vf1 vf1)) (b! (zero? t4-40) cfg-175) ) @@ -1698,6 +1789,7 @@ ) ) (label cfg-180) + ;;(format #t "aaaa~%") get here (.add.vf vf4 vf23 vf15 :mask #b111) (.sll t5-39 t4-30 4) (.sub.vf vf1 vf25 vf23) @@ -1713,6 +1805,7 @@ (.lvf vf23 (+ (the-as int t2-2) 944)) ) (label cfg-183) + ;;(format #t "ok~%") ;;here as well (.addu t5-40 t5-39 a3-2) (nop!) (.lvf vf5 (+ t5-40 -256)) @@ -1873,6 +1966,7 @@ (.add.vf vf4 vf4 vf27) ;;(s.vf! (+ a1-1 176) vf3) (.svf (+ 176 (the int a1-1)) vf3) + ;;(format #t "here~%") (let ((t4-44 (logand a0-4 2))) (nop!) (b! (zero? t4-44) cfg-187) @@ -1892,13 +1986,13 @@ (nop!) (nop!) ;;(s.vf! (+ a1-1 192) vf8) - (.svf (+ 192 (the int a1-1)) vf3) + (.svf (+ 192 (the int a1-1)) vf8) (nop!) ;;(s.vf! (+ a1-1 208) vf12) - (.svf (+ 208 (the int a1-1)) vf3) + (.svf (+ 208 (the int a1-1)) vf12) (nop!) ;;(s.vf! (+ a1-1 224) vf4) - (.svf (+ 224 (the int a1-1)) vf3) + (.svf (+ 224 (the int a1-1)) vf4) (b! #t cfg-132 :delay (set! a1-1 (the pointer (+ (the-as int a1-1) 240)))) (label cfg-189) (let ((v1-6 (-> v1-5 buf))) @@ -1908,8 +2002,11 @@ ) ) (.lvf vf24 (&-> arg2 origin quad)) + ;; vf23.x is the x position of the string, which somehow moves backward... (.sub.vf vf23 vf23 vf24) (.mov v0-0 vf23) + ;(print-vf vf0) + ;;(format 0 "String result ~f~%" v0-0) v0-0 ) ) @@ -2134,6 +2231,7 @@ ) (defun draw-string-xy ((arg0 string) (arg1 dma-buffer) (arg2 int) (arg3 int) (arg4 int) (arg5 int)) + ;(format #t "call to ds: ~A~%" arg0) (let ((a2-2 (new 'stack 'font-context *font-default-matrix* arg2 @@ -2144,6 +2242,7 @@ ) ) ) + ;;(format 0 "len is ~f~%" (get-string-length arg0 a2-2)) (draw-string arg0 arg1 a2-2) ) (none) diff --git a/goal_src/kernel/gstring.gc b/goal_src/kernel/gstring.gc index 55d3410327..201146878a 100644 --- a/goal_src/kernel/gstring.gc +++ b/goal_src/kernel/gstring.gc @@ -42,6 +42,7 @@ (&+! dst-ptr 1) (&+! src-ptr 1) ) + (set! (-> dst-ptr 0) 0) ) dst ) diff --git a/goalc/debugger/Debugger.cpp b/goalc/debugger/Debugger.cpp index aff84e1954..659e0a7ea9 100644 --- a/goalc/debugger/Debugger.cpp +++ b/goalc/debugger/Debugger.cpp @@ -597,6 +597,9 @@ void Debugger::watcher() { case xdbg::SignalInfo::BREAK: printf("Target has stopped. Run (:di) to get more information.\n"); break; + case xdbg::SignalInfo::MATH_EXCEPTION: + printf("Target has crashed with a MATH_EXCEPTION! Run (:di) to get more information.\n"); + break; default: printf("[Debugger] unhandled signal in watcher: %d\n", int(signal_info.kind)); assert(false); diff --git a/goalc/regalloc/Allocator_v2.cpp b/goalc/regalloc/Allocator_v2.cpp index 846d3731e6..7d929ec283 100644 --- a/goalc/regalloc/Allocator_v2.cpp +++ b/goalc/regalloc/Allocator_v2.cpp @@ -754,14 +754,17 @@ bool check_register_assign(const AllocationInput& input, // so in some cases it's okay to clobber. // loop over our live range - for (int instr_idx = this_var.first_live(); instr_idx < this_var.last_live(); instr_idx++) { + for (int instr_idx = this_var.first_live(); instr_idx <= this_var.last_live(); instr_idx++) { + const auto& instr = input.instructions.at(instr_idx); + if (vector_contains(instr.exclude, reg)) { + return false; + } + // and leave out the ones where we're dead if (!this_var.live(instr_idx)) { continue; } - const auto& instr = input.instructions.at(instr_idx); - if (vector_contains(instr.clobber, reg)) { // there's two cases where this is okay. // 1: if we aren't live-out. The clobber won't clobber anything. @@ -775,10 +778,6 @@ bool check_register_assign(const AllocationInput& input, // 2: we write it after the clobber. } } - - if (vector_contains(instr.exclude, reg)) { - return false; - } } return true;