Spehro Pefhany
Guest
|
Posted:
Mon Dec 12, 2005 1:35 am Post subject:
Re: Sort of Gray code to binary converter |
|
|
On Sun, 11 Dec 2005 12:33:50 -0800, the renowned John Larkin
<jjlarkin@highNOTlandTHIStechnologyPART.com> wrote:
| Quote: | On Sun, 11 Dec 2005 20:22:42 GMT, Fred Bloggs <nospam@nospam.com
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).
| Quote: | 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@interlog.com Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog Info for designers: http://www.speff.com |
|