I would expect the clock cycle for a compare with 0 and a bit test to be the same.
Indeed.
Compare the TST and CMP instructions (TEQ also if I'm being complete).
TST R0,#1<<10
for example (1 cycle).
The difference is that the bit test might require an extra parameter (and thus increase the instruction size).
I'm not sure you mean size there - all ARM instructions are 32-bit on the StrongARM (and other ARMs with Thumb support still have fixed-length instructions of 32 or 16 bits for ARM and Thumb respectively).
Back to the original question:
I wish to use minimal storage, but not by sacrificing performance.
It really depends on what you're doing. A bit-field using 32-bit words (unsigned is more intuitive for bit-fields) should cover you nicely and you can do it cheaply using the ARM's "free" (until XScale) barrel-shifter, I imagine.
Is there a substantial difference in processing time between evaulating long, short and char as a boolean?
My guess would be:
No difference for the compare.
However, it takes the same amount of time to load each item through the cache-line and the "larger" your padding (for a byte you're wasting 7 bits, for a 32-bit word you're wasting 31 bits), the less "efficient it is cache/memory-wise.
Does signed / unsigned make a difference?
Loading and storing
signed bytes / half-words
might give you an unwelcome performance penalty. Unsigned is always ok.
How much more expensive is masking individual bits in a long compared to the fastest method above? (if (val & 0x0010)) do_something;)
Not much - I'd go for that method every time. If you have a bit-field then to get a bit you'd just do something like:
- Code:
; R0 = number of bit in field
; R1 = address of bit-field
; R2 = 1
; Find out which word we want to load
mov r4,r0,LSR #5
; load the word ('extra' penalty on XScale for scaled register I think)
ldr r3,[r1,r4,LSL #2]
and r4,r0,#31 ; which bit in the word do we want?
tst r3,r2,lsl r4 ; (might be a penalty for a register shift)
; processor flags are now set accordingly if your bit is set or not
(A compiler
should make a
fairly good job of optimising C code to do the same thing).
Obviously it's much cleaner if you want to iterate sequentially over the bitfield.
Cheers,
Ref.