From 9471249b5e7d98bd90db03e0426aaba06285a0bc Mon Sep 17 00:00:00 2001 From: bebbo Date: Fri, 21 Aug 2020 12:04:19 +0200 Subject: [PATCH 1/2] refs #13: fix asm to avoid extending short to int --- template/support/gcc8_c_support.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/template/support/gcc8_c_support.h b/template/support/gcc8_c_support.h index 17d6330a..933d4afe 100644 --- a/template/support/gcc8_c_support.h +++ b/template/support/gcc8_c_support.h @@ -56,20 +56,28 @@ void debug_register_copperlist(const void* addr, const char* name, unsigned int const void* name = &incbin_ ## name ## _start; inline unsigned int muluw(unsigned short a, unsigned short b) { + int r; asm("muluw %1,%0":"+d"(a): "mid"(b): "cc"); - return a; + asm("" : "=d"(r) : "d"(a)); + return r; } inline int mulsw(short a, short b) { + int r; asm("mulsw %1,%0":"+d"(a): "mid"(b): "cc"); - return a; + asm("" : "=d"(r) : "d"(a)); + return r; } inline unsigned short divuw(unsigned int a, unsigned short b) { + int r; asm("divuw %1,%0":"+d"(a): "mid"(b): "cc"); - return a; + asm("" : "=d"(r) : "d"(a)); + return r; } inline short divsw(int a, short b) { + int r; asm("divsw %1,%0":"+d"(a): "mid"(b): "cc"); - return a; + asm("" : "=d"(r) : "d"(a)); + return r; } #ifdef __cplusplus From 8f4e309d20fba8d933f4e93597715239c52cf60d Mon Sep 17 00:00:00 2001 From: bebbo Date: Sat, 22 Aug 2020 07:37:42 +0200 Subject: [PATCH 2/2] refs #13: fix asm to avoid extending short to int - applies only to short^^ --- template/support/gcc8_c_support.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/template/support/gcc8_c_support.h b/template/support/gcc8_c_support.h index 933d4afe..e0f916ee 100644 --- a/template/support/gcc8_c_support.h +++ b/template/support/gcc8_c_support.h @@ -68,16 +68,12 @@ inline int mulsw(short a, short b) { return r; } inline unsigned short divuw(unsigned int a, unsigned short b) { - int r; asm("divuw %1,%0":"+d"(a): "mid"(b): "cc"); - asm("" : "=d"(r) : "d"(a)); - return r; + return a; } inline short divsw(int a, short b) { - int r; asm("divsw %1,%0":"+d"(a): "mid"(b): "cc"); - asm("" : "=d"(r) : "d"(a)); - return r; + return a; } #ifdef __cplusplus