CLM on SGI's: 400% speedup!

Tobias Kunze t@ulysses.Stanford.EDU
Sun, 9 Mar 1997 11:21:42 -0800


[Applies to SGI machines only.]

I just noticed that some clm instruments (for instance, Scott
vanDuyne's piano.ins, when used with a :singleStringDecayRateFactor
as small as 1/10) could easily spend up to 95% in floating-point
exceptions generated by FPU underflow conditions.  Since noone
really cares about underflows in DSP, and since its sometimes
hard to predict them, we might as well flush straight to zero instead.

Example:  Last with-sound example call in piano.ins, at 44.1kHz

  - with FPU exceptions:

    Duration: 10.7501, Last begin time: 0.0000
    Compute time: 15.378, Compute ratios: 1.43 (1.43)

  - with FPU underflow exceptions disabled:

    Duration: 10.7501, Last begin time: 0.0000
    Compute time: 3.803, Compute ratios: 0.35 (0.35)

which corresponds to a 404.36497% speedup!  ;)


What to do:
-----------

  - compile your instrument as usual
  - edit the clm-generated c file:
  - add #include <sys/fpu.h>  to the beginning of the file
  - insert

       union fpc_csr f;

       f.fc_word = get_fpc_csr();
       f.fc_struct.flush = 1;
       set_fpc_csr(f.fc_word);

    right between variable declarations and function body in EVERY
    instrument definition.
  - reload the fasl.

That's admittedly suboptimal, but the system handles exceptions on a
per-object basis (I believe), i.e., disabling exceptions does not work
across so's in ACL.  Ideally, this should be done in some sort of
"main" routine, but so's don't have a "main", so you'll have to put
it in the instrument function itself.  In the CLISP case, Bill could
probably add the code to the beginning of rc's main.

Enjoy,

-Tobias