473,782 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lookup Tables

The future of computer architecture will use lookup tables. Currently
computer processor speed outweighs the benefits of using computer
memory for lookup tables, except in some cases. As computer memory
increases, new ROM chips will be built with lookup tables hardcoded
into them. Here is an example of what using a lookup table can do for
you. The following program divides to integers from 0 to 4 using
lookup tables and times itself against the same operation using the
division operator in c++.

I came up with this idea myself, and met critisism everywhere I brought
it up. It is actually a handy algorithm and you can read more about it
on wikipedia:
http://en.wikipedia.org/wiki/Lookup_table

#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main(int argc, char *argv[]){
time_t t1, t0;
double elapsed;

float div[5][5]={ {0,0,0,0,0}, {1,0.5,0.3333,0 .25,0.2},
{2,1,0.6666,0.5 ,0.4}, {3,1.5,1,0.75,0 .6}, {4,2,1.3333,1,0 .8} };
int a=1, b=2;
float ans=0;

time(&t0); /* start time */
for(int cnt=0; cnt<1000000000; cnt++){

ans=div[a][b];

}
time(&t1);
elapsed = difftime(t1, t0);
cout<<"Time: "<<elapsed< <" seconds."<<endl ;

time(&t0); /* start time */
for(int cnt=0; cnt<1000000000; cnt++){
ans=a/b;
}
time(&t1);
elapsed = difftime(t1, t0);
cout<<"Time: "<<elapsed< <" seconds."<<endl ;
system("PAUSE") ;
return EXIT_SUCCESS;
}

Aug 21 '05 #1
2 5620
Co********@gmai l.com wrote:
The future of computer architecture will use lookup tables. Currently
computer processor speed outweighs the benefits of using computer
memory for lookup tables, except in some cases. As computer memory
increases, new ROM chips will be built with lookup tables hardcoded
into them. Here is an example of what using a lookup table can do for
you. The following program divides to integers from 0 to 4 using
lookup tables and times itself against the same operation using the
division operator in c++.

I came up with this idea myself, and met critisism everywhere I
brought it up. [..]


Well, out of all floating-point divisions, how much do you think is
done with both operands integer and between 0 and 4? I mean, it is
a great idea to use lookup tables where possible and feasible, but
to say that the increase in computer memory will turn the tables on
such thing as lookup tables? Really? Let's say I in my problem need
to divide a floating point value (2^50 or about potential FP numbers)
by, say, a dozen other values (2^4 dividers). I would need to pre-
calculate and keep 2^54 * sizeof(double) results (2^58 bytes or so)
if I were to use a lookup table instead of utilising the CPU's ability
to divide. Is that feasible? Nope. So, lookup tables do have their
application but they are limited. You should definitely promote the
idea (even if you do claim that you "came up with" it yourself), but
try to give a well-rounded set of examples where it is applicable and
does give an advantage. Floating-point division is just not one of
them, trust me. I bet that's why you "met criticism everywhere".

V
Aug 22 '05 #2
On 21 Aug 2005 15:20:24 -0700, Co********@gmai l.com wrote in
comp.lang.c++:
The future of computer architecture will use lookup tables.
That's amazing. I always thought the past and present of computer
architectures used lookup tables. Apparently I was wrong, because
according to you they haven't been invented yet.
Currently
computer processor speed outweighs the benefits of using computer
memory for lookup tables, except in some cases. As computer memory
increases, new ROM chips will be built with lookup tables hardcoded
into them. Here is an example of what using a lookup table can do for
you. The following program divides to integers from 0 to 4 using
lookup tables and times itself against the same operation using the
division operator in c++.

I came up with this idea myself, and met critisism everywhere I brought
it up.
Did you even stop to consider that the critics were right?

They laughed at Einstein. They laughed at the Wright brothers. They
laughed at Corey White. Then they stopped laughing at Einstein and
the Wright brothers.

Exactly what qualifications do you have that we should take your
half-baked and unoriginal ideas seriously? What credentials do you
have? What expertise have you demonstrated in previous post to
comp.lang.c++.
It is actually a handy algorithm and you can read more about it
on wikipedia:
http://en.wikipedia.org/wiki/Lookup_table

#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main(int argc, char *argv[]){
time_t t1, t0;
double elapsed;

float div[5][5]={ {0,0,0,0,0}, {1,0.5,0.3333,0 .25,0.2},
{2,1,0.6666,0.5 ,0.4}, {3,1.5,1,0.75,0 .6}, {4,2,1.3333,1,0 .8} };
int a=1, b=2;
float ans=0;

time(&t0); /* start time */
for(int cnt=0; cnt<1000000000; cnt++){

ans=div[a][b];

}
time(&t1);
elapsed = difftime(t1, t0);
cout<<"Time: "<<elapsed< <" seconds."<<endl ;

time(&t0); /* start time */
for(int cnt=0; cnt<1000000000; cnt++){
ans=a/b;
}
time(&t1);
elapsed = difftime(t1, t0);
cout<<"Time: "<<elapsed< <" seconds."<<endl ;
system("PAUSE") ;
return EXIT_SUCCESS;
}


I will explain to you exactly why, at this time and for at least some
time in the future, your idea is, to put it kindly, impractical. The
greatest limiter on processor performance right now is bandwidth.

On a typical desktop processor today, your toy array of 25 floats
occupies 100 bytes, and ends up in the processor cache quickly. In
fact many compilers will notice that neither 'a', 'b' ever change, and
neither do the contents of the array member 'div[a][b]'. So they
might well read the value of 'div[1][2]' exactly once, or substitute
the value from the initializer.

In fact, a good many compilers will notice that the value assigned to
'ans' is not used, and omit the loop completely.

Now build a two dimensional array for all float values an IEEE 754
representation can represent, some 2^48 values of sizeof(float) bytes.
Then a 2^100 or so matrix of sizeof(double) to accommodate all the
doubles. And of course the long doubles, except on Mickeysoft
implementations .

And after you find a system with enough memory to hold the tables,
start doing your table lookup divisions with random values. Come back
and show us the results.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Aug 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1594
by: DKode | last post by:
Ok, My staff has determined that we will be using custom business objects for a new app we are creating. we have an object that is called Employee. The employee object has about 8 lookup tables with a FK in the employee table and two other tables that will be custom objects themselves.
9
7032
by: Koen | last post by:
Hi all, My application uses a lot of lookup tables. I've splitted the frontend (forms, reports, etc) from the backend (data). The database has around 10 different users. The values in the lookup tables are not likely to change. Question 1: Should I include them in the backend (with rest of data) or the frontend?
3
2922
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two reading about it on google, but there is something I still don't understand, and I'm hoping someone will be willing to explain it to me in small words. Let's say I have a table for addresses, and it includes a field for state. What I would...
3
10667
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
10
3816
by: junky_fellow | last post by:
what are lookup tables ? How can they be used to optimise the code ?
4
4620
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have distilled the problem down to a simple form drawing data from the Northwind database for a representative...
0
1262
by: dbuchanan | last post by:
Hello, For my datagrid I added a datagrid table style to include columns from my lookup tables. These display the values in the lookup tables rather than just the integer key value stored in the data table. When I make selections in bound combo boxes on the form and save the changes the datagrid which is populated by the following stored procedure does not reflect the changes for the referenced lookup tables until I close and reload...
3
2291
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather than the key value that are stored in the table. It works well if the comboboxes are selected when the row is created.
1
3725
by: paulquinlan100 | last post by:
Hi Im having problems getting a column in one of my tables to display the lookup values correctly. The database is split, in the backend the rowsource for this particular field is set to a query of another lookup table, this correctly displays in a dropdown the values i want for that field. However, in the front end the dropdown for this field is blank, when i try to view the table in design mode to set the rowsource i get the
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.