Closed zeldin closed 4 months ago
Thanks!
@zeldin would you mind taking a look at #53 which is a duplicate that I completely forgot about. I removed a
but added v
for reasons I don't recall.
Right. It is true that the debug functions clobber v
(or more generally p
). The fc_nyblswap
function also clobbers c
, as you correctly declare. I kind of wonder if this is necessary though -- wouldn't you expect flags to always be clobbered? Otherwise shouldn't z
and n
also be declared as clobbered (by almost any code)?
Anyway, I can try it out later tonight.
So, this is what I found out so far:
mos-clang does not recognize z
, n
, d
or i
in the clobber list. But it does recognize c
and v
as well as p
and the generic cc
(which I assume is equivalent to p
).
As for d
and i
, they are probably out of scope (meaning that the compiler does not track their contents), but n
and z
are actually treated as bits of a special two-bit nz
register, which itself is a subregister of p
. However, nz
is also not recognized in the clobber list.
I think a safe approach would be to declare cc
clobber in any asm that touches any flags at all. I've seen people claim that a cc
clobber does nothing on x86 because the flags are implicitly treated as clobbered anyway. It would make sense if this was also the case for 6502, but I have found no documentation to that effect. At any rate cc
is always supposed to be valid in the clobber list, whether needed or not.
An asm clobber is not allowed to specify a register used as an input or output. In the case of the debug asms which use "a" for input, the accumulator is never actually clobbered by the asm body, so just remove it from the clobber list. In the case of fc_nyblswap, the accumulator is used as both input and output, so declare it as such instead of as a clobber.
Checklist
Thanks a lot for your contribution! Please tick off the following:
make test
)clang-format -i <file>