Author Topic: Optimising FPU?  (Read 3930 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Optimising FPU?
« on: August 10, 2006 »
Anyone know much about doing this, I have this piece of code (with several other pieces almost identical) that I think could be improved. There are 2 values already in the fpu stack.

Code: [Select]
    fld dword ptr[eax]
    fld st
    fsub dword ptr[ebx]
    fmul st(2)
    fst dword ptr[ecx+28]
    fmul st(3)
    faddp st(1)
    fstp dword ptr[ecx+4]
   
    fld dword ptr[eax+4]
    fld st
    fsub dword ptr[ebx+4]
    fmul st(2)
    fst dword ptr[ecx+24]
    fmul st(3)
    faddp st(1)
    fstp dword ptr[ecx]

Any help appreciated, Cheers.

Fryer.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Optimising FPU?
« Reply #1 on: August 11, 2006 »
Not much you can do with it.

Things you can try:
avoid storing/using the result of the mul until the latest possible moment - the mul will overlap with other independent instructions if it can.
interleave 2 or more calculations to achieve that.
look at a bigger bit of code to optimise
look at SSE2

Jim
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Optimising FPU?
« Reply #2 on: August 11, 2006 »
OK thanks Jim, I was wondering if there was any way to interleave the 2 pieces of code somehow using something like fxch so that it wouldn't be waiting for each instruction to finish before it could get on with the next one.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Optimising FPU?
« Reply #3 on: August 13, 2006 »
Yes, you'd use fxch to do it, to get the mul result somewhere else in the stack so you can use st0 for more calculations, but it's only mul, div and the other trig/transcendental functions you'd do that for.  Not for adds, subs, loads and stores.

Jim
Challenge Trophies Won: