Re: Hex to NSString or NSData
Re: Hex to NSString or NSData
- Subject: Re: Hex to NSString or NSData
- From: Marcel Weiher <email@hidden>
- Date: Sat, 9 May 2009 14:20:25 -0700
Hi Andreas,
that's an interesting way to do the conversion.
On May 9, 2009, at 10:50 , Andreas Grosam wrote:
int hexDigitToInt(char d)
{
int result;
switch (d) {
case '0': result = 0; break;
case '1': result = 1; break;
[snip]
case 'E': result = 14; break;
case 'F': result = 15; break;
default:
result = 0xFF;
}
return result;
}
Although it might look ugly, this is one of the fasted methods using
standard C that converts a hex digit (nibble) to an int (2 machine
instructions).
OK, how do you get it to compile to just two instructions? I've been
looking at various optimization options, and as far as I can tell it
is at least doing the following (non-contiguous):
00001e67 subl $0x30,êx
00001e6d cmpl $0x36,êx
00001e70 jal 0x00001f67
00001e76 movl 0x00000038(ëx,êx,4),êx
00001e7d addl ëx,êx
00001e7f jmp *êx
So that's 6 instructions to set up and perform the indexed jump to
which the switch/case is being compiled.
At the jump sites, typically another 2 instructions:
00001f60 movl $0x0000000f,êx
00001f65 jmp 0x00001fd2
So that's a total of 8 instructions, with 2 taken and one typically
non-taken jump and one of the taken jumps computed, so probably not
predictable. I must be missing something obvious.
Marcel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden