I've looked, but couldn't find the answer for my problem.
Swap the nibbles of a byte / register.
Is that possible in C todo in 1 instruction through a macro or so?
Execution speed is of the essence :roll:
I've looked, but couldn't find the answer for my problem.
Swap the nibbles of a byte / register.
Is that possible in C todo in 1 instruction through a macro or so?
Execution speed is of the essence :roll:
Your best bet would probably create a C macro that implements some inline assembly using the SWAP opcode.
tricksy
very 'tricksy'
I'm pretty sure I've seen GCC generate a SWAP instruction in response
to some combination of 4-bit shifts. It wasn't in time-critical code, so my "inquiry"
was limited to "Gee, isn't that cute?".
Ultimately, though, if you Absolutely Need the compiler to Always generate a
certain instruction (sequence), you need, as EW says, to use (inline) assembly.
tricksy
very 'tricksy'
If you look in the "Inline Asm" section of the avr-libc user manual, it not only is a good tutorial on the subject, it gives you an example using the SWAP instruction.
Ok, its really getting time to look again in the avr libc manual,
I was sortof keeping myself busy with an interpreter / bytecode interpreter. And found it odd that my switch case statement was 'way' (15% ish )slower then a dirty if/elseif list. I did use a continue statement in the switchcase and in the if/elseif but that only a very limited effect speedwise.
Then I started actually reading the lss file to see what gcc had come up with... seems it already was using swaps.
Sometimes I should really take more care into account of asking something. :oops:
un important stuff, just to see why I asked the nibbly question in the first place:
But I didnt understand why it could use 77 cpu cycles to fetch a 16 bit instruction and decode/run it,, especially if it was the 1st to 3rd in the list..
So i was flaming my switch case list till I noticed my power hungry 'Instruction-fetch' routine...
It was almost 10 to 20 times longer then one instruction itself!
Ok, simple fix my instruction grabbing :D