Skip to content

Commit

Permalink
Add clang inline asm leaf attribute and clobbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund committed Sep 1, 2024
1 parent eac0745 commit acdedad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
30 changes: 15 additions & 15 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ void debug_msg(char* msg)
__asm__("STA $D643");
__asm__("CLV");
#else
asm volatile("st%0 $d643\n"
"clv\n"
: /* no output operands */
: "a"(*msg) /* input operands */
: /* clobber list */);
__attribute__((leaf)) asm volatile("st%0 $d643\n"
"clv\n"
: /* no output operands */
: "a"(*msg) /* input operands */
: "p" /* clobber list */);
#endif
msg++;
}
Expand All @@ -31,15 +31,15 @@ void debug_msg(char* msg)
__asm__("CLV");
#else
// clearing Z seems to fix occasional xemu freeze. Why?
asm volatile("lda #$0d\n"
"sta $d643\n"
"clv\n"
"lda #$0a\n"
"sta $d643\n"
"clv\n"
"ldz #0\n"
: /* no output operands */
: /* no input operands*/
: "a" /* clobber list */);
__attribute__((leaf)) asm volatile("lda #$0d \n"
"sta $d643 \n"
"clv \n"
"lda #$0a \n"
"sta $d643 \n"
"clv \n"
"ldz #0 \n"
: /* no output operands */
: /* no input operands*/
: "a", "p" /* clobber list */);
#endif
}
16 changes: 9 additions & 7 deletions src/fcio.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ unsigned char fc_nyblswap(unsigned char in) // oh why?!
__asm__("sta %v", swp);
return swp;
#elif defined(__clang__)
asm volatile("asl a\n"
"adc #$80\n"
"rol a\n"
"asl a\n"
"adc #$80\n"
"rol a\n"
: "+a"(in));
__attribute__((leaf)) asm volatile("asl a \n"
"adc #$80 \n"
"rol a \n"
"asl a \n"
"adc #$80 \n"
"rol a \n"
: "+a"(in) /* output */
: /* no input */
: "p" /* clobbers */);
return in;
#else
#pragma GCC warning "fc_nyblswap() is not implemented for this compiler"
Expand Down
37 changes: 22 additions & 15 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ void unit_test_report(
__asm__("STA $D643");
__asm__("CLV");
#else
asm volatile("st%0 $D643\n"
"clv" ::"a"((uint8_t)(issue & 0xff)));
asm volatile("st%0 $D643\n"
"clv" ::"a"((uint8_t)(issue >> 8)));
asm volatile("st%0 $D643\n"
"clv" ::"a"(sub));
asm volatile("st%0 $D643\n"
"clv" ::"a"(status));
__attribute__((leaf)) asm volatile(
"st%0 $D643 \n"
"clv \n" ::"a"((uint8_t)(issue & 0xff))
: "p");
__attribute__((leaf)) asm volatile(
"st%0 $D643 \n"
"clv \n" ::"a"((uint8_t)(issue >> 8))
: "p");
__attribute__((leaf)) asm volatile("st%0 $D643 \n"
"clv \n" ::"a"(sub)
: "p");
__attribute__((leaf)) asm volatile("st%0 $D643 \n"
"clv \n" ::"a"(status)
: "p");
#endif
}

Expand All @@ -78,7 +84,7 @@ void _unit_test_msg(char* msg, char cmd)
unsigned char* current;

unit_test_report(0, 0, cmd);
current = (unsigned char *)msg;
current = (unsigned char*)msg;

while (*current) {
#ifdef __CC65__
Expand All @@ -87,8 +93,9 @@ void _unit_test_msg(char* msg, char cmd)
__asm__("STA $D643");
__asm__("CLV");
#else
asm volatile("st%0 $D643\n"
"clv" ::"a"(*current));
__attribute__((leaf)) asm volatile("st%0 $D643 \n"
"clv \n" ::"a"(*current)
: "p");
#endif
current++;
}
Expand All @@ -98,10 +105,10 @@ void _unit_test_msg(char* msg, char cmd)
__asm__("STA $D643");
__asm__("CLV");
#else
asm volatile("lda #92\n"
"sta $D643\n"
"clv" ::
: "a");
__attribute__((leaf)) asm volatile("lda #92 \n"
"sta $D643 \n"
"clv \n" ::
: "a", "p");
#endif
}

Expand Down

0 comments on commit acdedad

Please sign in to comment.