Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computing > NZ Computing > Table Lookup Considered Harmful

Reply
Thread Tools

Table Lookup Considered Harmful

 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      03-24-2010
In the source code for DVDAuthor (in subfont.c, if you want to follow
along), in the “generate_tables” routine, there is this sequence:

omtp = desc->tables.omt;
for (i = 0; i < 256; i++)
{
for (mx = 0; mx < desc->tables.o_size; mx++)
*omtp++ = (i * desc->tables.om[mx] + base / 2) / base;
} /*for*/

What this is doing is precomputing the results of multiplying every
element of the “om” table by every one of the 256 possible 8-bit pixel
values.

The precomputed values are then used in the “outline” routine like this
(“m” is the pointer to the “omt” table as computed above, “src” is the
source pixel value):

const register unsigned char * mp = m + msize * src + y1 * mwidth;
int my;
for (my = y1; my < y2; my++)
{
register int mx;
for (mx = x1; mx < x2; mx++)
{
if (dstp[mx] < mp[mx])
dstp[mx] = mp[mx];
} /*for*/
dstp += stride;
mp += mwidth;
} /*for*/

This may have been a smart thing to do back in the 1980s, maybe even the
1990s. But it isn’t any more. CPUs are so fast now that you might as
well make use of them, don’t try to save instruction cycles by looking
things up in memory instead. Do that, and you’re just asking to be
bogged down by cache misses. Forget the lookup table, do the
multiplication in the pixel-computation loop. It’ll be quicker.

I gather this code originally came from MPlayer several years ago. I
wonder what their version looks like now?

 
Reply With Quote
 
 
 
 
Adam
Guest
Posts: n/a
 
      03-24-2010
Lawrence D'Oliveiro wrote:

> In the source code for DVDAuthor (in subfont.c, if you want to follow
> along), in the ?generate_tables? routine, there is this sequence:
>
> omtp = desc->tables.omt;
> for (i = 0; i < 256; i++)
> {
> for (mx = 0; mx < desc->tables.o_size; mx++)
> *omtp++ = (i * desc->tables.om[mx] + base / 2) / base;
> } /*for*/
>
> What this is doing is precomputing the results of multiplying every
> element of the ?om? table by every one of the 256 possible 8-bit pixel
> values.
>
> The precomputed values are then used in the ?outline? routine like this
> (?m? is the pointer to the ?omt? table as computed above, ?src? is the
> source pixel value):
>
> const register unsigned char * mp = m + msize * src + y1
> * mwidth; int my;
> for (my = y1; my < y2; my++)
> {
> register int mx;
> for (mx = x1; mx < x2; mx++)
> {
> if (dstp[mx] < mp[mx])
> dstp[mx] = mp[mx];
> } /*for*/
> dstp += stride;
> mp += mwidth;
> } /*for*/
>
> This may have been a smart thing to do back in the 1980s, maybe even the
> 1990s. But it isn?t any more. CPUs are so fast now that you might as
> well make use of them, don?t try to save instruction cycles by looking
> things up in memory instead. Do that, and you?re just asking to be
> bogged down by cache misses. Forget the lookup table, do the
> multiplication in the pixel-computation loop. It?ll be quicker.
>
> I gather this code originally came from MPlayer several years ago. I
> wonder what their version looks like now?


Take a look in spudec.c of MPlayer.
Where similar looking stuff seems to be going on.
Although I'm not sure where that example above exactly comes from.

Through to the keeper for that one. Am busy tinkering with
org-mode on Emacs again.


 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      03-24-2010
In message <hodv4t$qim$>, Adam wrote:

> Am busy tinkering with org-mode on Emacs again.


I have the following custom-set-variables entry in my Emacs prefs:

'(auto-mode-alist (quote (("" . fundamental-mode))) t)


 
Reply With Quote
 
Adam
Guest
Posts: n/a
 
      03-25-2010
For anyone on MS Windows wanting to use Emacs, see below.

Not for the faint-hearted. Simply great for programming.
http://en.wikipedia.org/wiki/Emacs

a beta:
http://alpha.gnu.org/gnu/emacs/pretest/windows/

or the regular version:
http://ftp.gnu.org/pub/gnu/emacs/windows/

This has some more good stuff to install Emacs on Windows:
http://derekslager.com/blog/posts/20...n-windows.ashx


 
Reply With Quote
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      03-25-2010
In message <hoebmm$217$>, Adam wrote:

> For anyone on MS Windows wanting to use Emacs ...


Hey, if they could handle Emacs, why would they be using Windows?
 
Reply With Quote
 
Enkidu
Guest
Posts: n/a
 
      03-25-2010
Adam wrote:
>
> For anyone on MS Windows wanting to use Emacs, see below.
>

Oh great. The worst of both worlds.

Come here for a decent editor:

http://www.vim.org/download.php#pc

Cheers,

Cliff

--

The ends justifies the means - Niccol di Bernardo dei Machiavelli.

The end excuses any evil - Sophocles
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XTech conference considered harmful? Andy Dingley HTML 2 02-14-2006 12:11 AM
String.intern() still "considered harmful"? Robert Mischke Java 3 05-19-2005 09:15 AM
Alternate Stylesheets Considered Harmful (by me, for the time being) Toby A Inkster HTML 19 01-29-2004 03:29 PM
Python is not [yet] Considered Harmful mike420@ziplip.com Python 9 10-31-2003 08:23 AM
Python is Considered Harmful mike420@ziplip.com Python 25 10-31-2003 02:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57