lookup tables

J

jacob navia

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"
 
J

junky_fellow

jacob said:
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.
 
T

Thomas Matthews

Ravi said:
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
 
T

Thomas Matthews

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
 
R

Ravi Uday

Thomas said:
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
 
A

Alan Balmer

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.
 
K

Kevin D. Quitt

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.
 
E

Eric Sosman

Thomas said:
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.
 
R

Richard Bos

Ravi Uday said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top