From 1235d9fc074386a45e6718fa44369386256ca0ab Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Fri, 2 Aug 2024 17:43:34 +0200 Subject: [PATCH] Fix fc_nyblswap on LLVM (#60) With a constraint "a", %0 will expand to "A" in the asm, meaning "ld%0" will become "ldA" without any address. But since we have constrained the operand to already be in A, there is no need to add any load or store instructions anyway, so just remove them. Also the global variable "swp" is not needed either, so remove that as well when using LLVM. --- src/fcio.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/fcio.c b/src/fcio.c index 77f56ed..6cd9efb 100644 --- a/src/fcio.c +++ b/src/fcio.c @@ -191,11 +191,11 @@ void fc_init( fc_textcolor(COLOR_GREEN); } -static unsigned char swp; unsigned char fc_nyblswap(unsigned char in) // oh why?! { - swp = in; #ifdef __CC65__ + static unsigned char swp; + swp = in; __asm__("lda %v", swp); __asm__("asl a"); __asm__("adc #$80"); @@ -204,21 +204,20 @@ unsigned char fc_nyblswap(unsigned char in) // oh why?! __asm__("adc #$80"); __asm__("rol a"); __asm__("sta %v", swp); + return swp; #elif defined(__clang__) -#pragma GCC warning "LLVM assembly needs to be checked in fc_nyblswap()" - asm volatile("ld%0\n" - "asl a\n" + asm volatile("asl a\n" "adc #$80\n" "rol a\n" "asl a\n" "adc #$80\n" "rol a\n" - "st%0" - : "+a"(swp)); + : "+a"(in)); + return in; #else #pragma GCC warning "fc_nyblswap() is not implemented for this compiler" + return in; #endif - return swp; } void fc_flash(byte f)