Re: Sort of Gray code to binary converter
- From: Spehro Pefhany <speffSNIP@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 11 Dec 2005 16:38:43 -0500
On Sun, 11 Dec 2005 12:33:50 -0800, the renowned John Larkin
<jjlarkin@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>On Sun, 11 Dec 2005 20:22:42 GMT, Fred Bloggs <nospam@xxxxxxxxxx>
>wrote:
>
>>
>>
>>Frank Bemelman wrote:
>>
>>> This is all very understandable,
>>> as there exists no assembly equivalent for a switch statement, so ...
>>
>>Whatever happened to doing an indirect jump through a table ( of
>>addresses) indexed into by the argument?
>
>Exactly. A 256-entry lookup table, indexed by the eight input bits,
>delivers a 4-bit code for every input combination. Fast. That sure
>beats a bushel of logic.
Something like this?
const unsigned char wlut[256] = {0xFF,0x00,0x02,0x01,0x04,0xFF,
0x03,0xFF,0x06,0xFF,0xFF,0xFF,0x05,0xFF,0xFF,0xFF,0x08,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x0A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0C,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0B,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x0D,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF};
direction = wlut[input];
How fast is that wind direction going to change? ;-) The table can
consume 448 bytes in a typical midrange PIC, which may not be
insignificant, and table lookup is pretty ugly as well (none of your
dedicated CPU32 table instructions.. and paging has to be handled).
>I did a *very* fast 16-bit sine function a while back. It was 128
>kbytes long.
>
>There's nothing you can't do in assembly. If a compiler can generate
>machine code, I can too.
>
>John
Frank's point is that there is no exact equivalent, so the compiler at
least has a chance to do it better than the most obvious way- for
example by presorting the cases and doing a tree. But I agree with
him, most compilers on most platforms will generate a series of
comparisons for a small switch/case construct.
Best regards,
Spehro Pefhany
--
"it's the network..." "The Journey is the reward"
speff@xxxxxxxxxxxx Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com
.
- Follow-Ups:
- Re: Sort of Gray code to binary converter
- From: Frank Bemelman
- Re: Sort of Gray code to binary converter
- References:
- Sort of Gray code to binary converter
- From: John B
- Re: Sort of Gray code to binary converter
- From: Dave
- Re: Sort of Gray code to binary converter
- From: John B
- Re: Sort of Gray code to binary converter
- From: Frank Bemelman
- Re: Sort of Gray code to binary converter
- From: Spehro Pefhany
- Re: Sort of Gray code to binary converter
- From: Frank Bemelman
- Re: Sort of Gray code to binary converter
- From: Fred Bloggs
- Re: Sort of Gray code to binary converter
- From: John Larkin
- Sort of Gray code to binary converter
- Prev by Date: Re: Sort of Gray code to binary converter
- Next by Date: Re: 250mA voltage clamp
- Previous by thread: Re: Sort of Gray code to binary converter
- Next by thread: Re: Sort of Gray code to binary converter
- Index(es):
Relevant Pages
|