By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

lookup tables

P: n/a
what are lookup tables ? How can they be used to optimise the code ?

Nov 14 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a


ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?

Its mainly used for bit fiddling.
See the FAQ's - 20.12 and 20.13
@ http://www.eskimo.com/~scs/C-faq/top.html

- Ravi

Nov 14 '05 #2

P: n/a
ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?

Please do your own homework.

You have posted all the questions of your homework here:
1: padding between variables in a structure
2: Multiple return statements Vs goto's
3: wrinting an optimised code
4: register variables
5: doubt related to string pointers.
6: which is better "switch" or "if-else"
Nov 14 '05 #3

P: n/a

jacob navia wrote:
ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?

Please do your own homework.

You have posted all the questions of your homework here:
1: padding between variables in a structure
2: Multiple return statements Vs goto's
3: wrinting an optimised code
4: register variables
5: doubt related to string pointers.
6: which is better "switch" or "if-else"


I did search the answers on net but got confused more and more.
So, I thought to post them here.

Nov 14 '05 #4

P: n/a
Ravi Uday wrote:


ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?

Its mainly used for bit fiddling.
See the FAQ's - 20.12 and 20.13
@ http://www.eskimo.com/~scs/C-faq/top.html

- Ravi

Wrong.
Many trigonomy (sp?) functions, such as sine and
tangent are implemented using lookup tables. To
my knowledge, this is not bit twiddling; but a
fast method for obtaining a result.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Nov 14 '05 #5

P: n/a
ju**********@yahoo.co.in wrote:
what are lookup tables ? Lookup tables are tables consisting of data either
with a key in the record or an implied key (such
as an array).
How can they be used to optimise the code ?

Many times, lookup tables are used to implement
a function which would take more time to calculate
using a formula. A classic example is the sine
function.

Another usage of lookup tables is to convert values.

A lookup table can also be used for authentication.
As far as optimization goes, lookup tables trade
memory space for execution speed. Sometimes they
trade execution speed for ease of maintenance or
change.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Nov 14 '05 #6

P: n/a


Thomas Matthews wrote:
Ravi Uday wrote:


ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?
Its mainly used for bit fiddling.
See the FAQ's - 20.12 and 20.13
@ http://www.eskimo.com/~scs/C-faq/top.html

- Ravi

Wrong.
Many trigonomy (sp?) functions, such as sine and
tangent are implemented using lookup tables. To
my knowledge, this is not bit twiddling; but a
fast method for obtaining a result.

Did you read the FAQs i had pointed ??

Most common usage of
look-up table that i have seen
is when using a series of function-pointers
which gets invoked based on some input.
There were some sample code posted here some time back :)

- Ravi


Nov 14 '05 #7

P: n/a
On Wed, 18 May 2005 10:50:10 +0530, Ravi Uday <ra******@gmail.com>
wrote:


ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?

Its mainly used for bit fiddling.


Hardly. Lookup tables have many uses. For optimization you might think
of a lookup table as a list of precalculated values, for applications
where it is faster to look up a value than calculate it.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #8

P: n/a
On 17 May 2005 22:11:40 -0700, ju**********@yahoo.co.in wrote:

what are lookup tables ? How can they be used to optimise the code ?


On some machines, they can't. On Cray's, for example, it's faster to
calculate bit values than look them up in a table. You're micro-optimizing
again.
--
#include <standard.disclaimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Nov 14 '05 #9

P: n/a
Thomas Matthews wrote:
Ravi Uday wrote:


ju**********@yahoo.co.in wrote:
what are lookup tables ? How can they be used to optimise the code ?

Its mainly used for bit fiddling.
See the FAQ's - 20.12 and 20.13
@ http://www.eskimo.com/~scs/C-faq/top.html

- Ravi

Wrong.
Many trigonomy (sp?) functions, such as sine and
tangent are implemented using lookup tables. To
my knowledge, this is not bit twiddling; but a
fast method for obtaining a result.


"Trigonometry." Easy to remember: "metry" is "measurement"
and "trigons" are "three-sided polygons," i.e. "triangles."
"Trigonometry" is "the measurement of triangles."

This is an interesting (or mildly interesting) topic in the
history of computing. In the Very Early Days when computational
power was remote, expensive, and slow, the economically effective
thing to do was to print tables of trigonometric functions, often
with "proportional parts" in the margins to assist more accurate
interpolations. Later, when automatic computers showed up, the
State of the Art switched to approximations by polynomials or
ratios of polynomials: the new machines didn't have much memory
for storing tables, but could grind out the computations at a
good enough rate to make themselves useful. Then memories got
larger, and it was back to the tables again: the computer would
store a fairly coarse table and use second- or even third-degree
methods to interpolate with good accuracy. Today the CPUs are
faster than the memory, so the practice has reverted to purely
computational methods. Tomorrow ... well, "Tomorrow and tomorrow
and tomorrow, creeps!" We do not know what tomorrow's economics
may bring to the practice of computing. What we *do* know is that
the Right Way has switched from A to B and back to A and again
to B -- and hence "conventional wisdom" is not a good predictor.

I personally wrote table-based trig functions as recently as
1979 (using one full circle == 65536 "bam," or "binary angular
measurement"). I would not do so today -- but I might do so
tomorrow; who knows where technological trade-offs may take us?
If the history of computing teaches us anything, it teaches that
we are in a fashion-driven industry -- and we don't know what
tomorrow's hemline lengths will be.

--
Eric Sosman
es*****@acm.org
Nov 14 '05 #10

P: n/a
Ravi Uday <ra******@gmail.com> wrote:
Thomas Matthews wrote:
Ravi Uday wrote:
ju**********@yahoo.co.in wrote:

what are lookup tables ? How can they be used to optimise the code ?

Its mainly used for bit fiddling.
See the FAQ's - 20.12 and 20.13
@ http://www.eskimo.com/~scs/C-faq/top.html
Wrong.
Many trigonomy (sp?) functions, such as sine and
tangent are implemented using lookup tables.

Did you read the FAQs i had pointed ??


I did. Those FAQs mention that bit twiddling is often implemented using
lookup tables. This does not mean that bit twiddling is the most
important thing lookup tables are used for at all. That's taking the
relationship the wrong way 'round.

Richard
Nov 14 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.