On Jan 31, 2012, at 12:23 PM, Sean Conner wrote:
-spc (But I'm still interested in my original
question though ... )
Well, this solves the half of your original question that dealt with the compatibility,
assuming the C compiler uses strings in whatever your native format is; if you're
indexing into a string, whatever character comes out of your routine will be in the
appropriate native format, whereas your previous version assumed that
'0'-'9' were contiguous (not a guarantee) and that 'A' was located
at a specific offset from '9' (which will almost certainly be wrong for non-ASCII)
and that 'A'-'F' are contiguous (also not guaranteed; EBCDIC has
non-contiguous letters, though A-F are at least contiguous).
As far as the speed, branches will almost always be comparatively slow if you have a
random chance; the prediction logic can't reasonably predict the direction it's
going to go if you have a 3/8 chance of taking it and 5/8 not. Thus you'll introduce
pipeline stalls, which will absolutely destroy performance on modern processors.
On the other hand, if you're doing table lookups on a 16-byte table (really 17-byte,
but the NUL doesn't really matter), the table will probably remain in the cache for
the duration of your inner loop (and possibly your outer loop as well) and the loop branch
will be predicted away until termination.
- Dave