Subject:
|
Re: command framing as seen from kernel/program.lrkey_handler
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Sun, 2 Feb 2003 11:48:22 GMT
|
Viewed:
|
4379 times
|
| |
| |
> > To get log2(xx) in O(1) time we could fetch
> > (p[xx & -xx]) i.e. fetch our choice of the bytes
> > at offset x 0 1 2 4 8 10 20 40 80 from some p we like.
>
> Touché. Yes, tables, overlooked that.
>
> > Merely standard C can't easily express that old
> > idea without misleading the linker into wasting
> > x81 - 9 bytes, which I gather would be considered
> > expensive on an H8?
>
> I think that smaller code size is preferable to
> faster execution speed in this instance since this
> section of code would only get executed a few dozen
> or so times per second (and then only when one is
> using the remote).
Just to be more certain we're understanding each other, if that's ok, I'll
mention that ...
1) Newbie that I am, I have no clue how frequently brickos switches on bit
masks. I wonder if only to decode xD2 RemoteCommand.
2) Using log2(xx & -xx) can save both time & space, if the C compiler in
question has a clue.
The space cost for log2(byte) begins low, at 9 bytes rather than 129, if only
we can tell the linker what we mean. But even when the space cost begins high,
we can get a net win, if we pass such results to enough switch statements.
For example, the switch (key) case LRKEY_A1 ... LRKEY_BEEP of lrkey_handler in
program.c will appear coded as an if-else-if by a naive compiler of C. Why?
Because a jump table indexed by key would have to contain nearly 32Ki entries
to let its indices range from x8 to x8000 inclusive. But if only we could tell
the compiler what we mean, then we could get a 13 entry jump table.
Mind you, I don't know when a jump table actually is smaller than if-else-if
for the H8, so maybe the H8 gcc doesn't either.
3) Personally my first well paid programming job was writing the massively
threaded code of synchronous digital chip designs, where log2(xx & -xx) is a
common component, named with jargon like "priority demultiplexer". I remain
astonished - culture shocked - to find this component rarely appearing in C
programs. I haven't yet found log2(byte) in the standard library of a C
compiler, for example.
Pat LaVarre
|
|
Message is in Reply To:
5 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|