universal fast & compact code:
#define ChangeBitsHW(Dest,New,Mask) asm volatile ("mov.w #%1,w1 \n" \
";disi #3 \n ;??????????"\
"xor.w %2,WREG \n" \
"and.w w1,w0,w0 \n" \
"xor.w %2 \n" \
: : "a"(New) , "g"(Mask), "T"(Dest) : "w1" );
I don't see how this macro can be safe noticed that w1 and w0 might have already been used by the calling routine. Am I missing something with this inline assembly?
You might want to refer to the inline macro section of the compiler manual :)
There is one thing missing for absolute safety in the macro, but the compiler is aware of the macro's use of w1 and takes it into account. The last line of the macro not only tells the compiler what types of objects to allow when the macro is used, but also what is modified by the macro. In the case of w1, it's inclusion at the end of the last line after the last semicolon tells the compiler that W1 is clobbered - so it takes that into account.
While usually w0 is considered scratch, to be 100% safe even with compiler changes, w0 should be included with w1 in the list of clobbered registers.