Another 'which is faster' question. :grin:

Currently I'm using static data to store temporary results in a processing pipeline. But I'd like to make it multi-threaded so I can't use the same data. Now, I have two choices:

    [*]Make an exact copy of the function but rename (*) it so different static data is used.
    [*]Use the same function but instead of usings static data store the variables on the stack and use a register as an offset to a second stack.

    Either of the methods is complex to implement in my situation (* run-time generated code). So I have no real preference but was wondering which method would be the fastest. I think static data is faster because the processor doesn't have to make any address calculations. On the other hand it increases code size but on modern processors like the Pentium 4 this doesn't seem like a problem.

    Any experiences? Thanks!
Posted on 2003-11-14 08:47:19 by C0D1F1ED
I think you should use stack data because it's simple. If you have the same routine called several times in a multithread application, doing so you avoid many errors
Posted on 2003-11-14 14:37:38 by greenant
I've done a little test on a Pentium II 300 MHz and static data turned out to be faster but only by a very insignificant difference...

greenant, I figured stack data was the hardest to implent after all. See, my run-time assembler doesn't have a convenient way to work with stack variables. Keeping track of them 'manually' isn't really an option since some parts are conditionally compiled. I could add stack management but I think static variables are easier.

All I have to do (I think) is duplicate every static variable (i.e. an array of two elements). Then I just run-time generate two functions, each using one of the two data sets. The 'interleaving' of the data is probably also good for cache coherency.
Posted on 2003-11-14 17:09:09 by C0D1F1ED