Welcome, Guest. Please login or register.

Author Topic: jump tables (-Edit- Eliminating conditional statements :-))  (Read 13737 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline minatorb

  • Newbie
  • *
  • Join Date: Feb 2005
  • Posts: 16
    • Show all replies
    • http://www.blachford.info
Re: jump tables
« on: February 22, 2005, 12:53:39 AM »
Quote
Actually I was thinking more about platform independant DSP processing... but there would be a similarity to 68K, yes... as in 16bit instrection word length, etc


None of the techniques above will ensure anything runs in a fixed time - you can't know at compile time what is cached or which branches are mispredicted.

You shold however be able to figure out the worst case scenario and base your timing around that (leaving some CPU time free just in case) - that's the only way you *know* everything will run on time and I believe that's the way it's done in "hard" real time OSs.



I'm in the process of designing a modular synth which has to work in real time so I'm going to have similar problems soon...

I'll probably go for "soft" real time - let the user set the maximum number of voices.  But just to make sure I'll be doing the important processing in very simple C and using AltiVec extensively.
 

Offline minatorb

  • Newbie
  • *
  • Join Date: Feb 2005
  • Posts: 16
    • Show all replies
    • http://www.blachford.info
Re: jump tables
« Reply #1 on: February 22, 2005, 01:57:21 AM »
Quote
A non-jump table based switch/case (ie those that are equivalent to nested if/else if) has a (usually linear) dependency on the position in the construct.


You can also do it with if/else if you can base your condition on a number, Pain in the ar$e to maintain and not terribly readable though.



if (x<2)
   {

   if (x == 0)
     {
     // do 0;
     }

   else
     {
     // do 1;
     }
   else

   }

else  // x is greater than 2
   {

   if (x == 2)
     {
     // do 2;
     }

   else
     {
     // do 3;
     }

   else
   }



//  Naa, stick to case statements....

Um, it's lost all the indentation.

 

Offline minatorb

  • Newbie
  • *
  • Join Date: Feb 2005
  • Posts: 16
    • Show all replies
    • http://www.blachford.info
Re: jump tables
« Reply #2 on: February 23, 2005, 02:28:29 AM »
Why are you using 16 bit values for audio?  Pro audio stuff uses 32 bit floating point or even 64 bit FP these days.

As for registers remember x86 CPUs use rename reisters.  You can't access them directly but you can indirectly just allocate a load of variables in C and work on them.

You can do the same trick with the cache, you can test this by moving big chunks of data around using loads of variables - I tired this years ago on my PC and the speed difference was *amazing*.
 

Offline minatorb

  • Newbie
  • *
  • Join Date: Feb 2005
  • Posts: 16
    • Show all replies
    • http://www.blachford.info
Re: jump tables
« Reply #3 on: February 24, 2005, 01:40:39 PM »
Quote
Well, I kind of think it distracts you from the real code, doesn't it? I mean, Matt should be concentrating on writing the "sound" part of the code, not the interpreter


He's doing this as a hobby so I think this is more of an intellectual excercise than anything else.


Quote
Anyway, just came across this SMALL language. Quite interesting...


If you want a small language do it properly :-D
It was even written on an Amiga!