0

Sorry for such simple question, (learning assembly from few days) but i was browsing through books and couldnt find answer

what is a proper quick way to count 1/f where f is some float on x86 fpu

is it

    fld dword [ebp+8]
    fld1
    fdivrp            ; fdivrp st0 st1 ?

?

it is proper (im mean literally cause i am not sure as to fdivr args) or is some quickest simplest way ?

//EDIT

Is this a best way to div 1/f (or 1/sqrt(f) in classical fpu asm ? (without sse, and without carmack trick - I will try it l8er, now I'm tryin just do 'proper fpu' )

grunge fightr
  • 1,360
  • 2
  • 19
  • 38

1 Answers1

4

From the Intel CPU doc:

FDIVRP - Divide ST(0) by ST(1), store result in ST(1), and pop the register stack.

Read the doc.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
  • allright, checked it and it seem to be working (sloow 43 cycles :( ) But I am reasonably new in fpu asm (renewing contact to be precise after 15 years) and I am not sure if it is the fastest way, (I am not talkimg about SSE simply fpu) Is there maybe some distinct instructions to quick calculate 1/float (or 1/sqrt(float) - I am trying to write 'normalize vector of floats' in fpu asembly :( – grunge fightr Aug 11 '12 at 08:50
  • 2
    @grungefightr there are some crazy tricks (http://en.wikipedia.org/wiki/Fast_inverse_square_root) but why not just use SSE? – harold Aug 11 '12 at 08:59
  • @harold - i will use SSE/AVX, sure, i like it :) But now I am trying to understand fpu - above trick is also nice, like such things too ;-) Got some 'simply fpu' tutorial for example, but canntot fins some nice sources of fpu routines to learn from it (google in not so much terribly helpful in fpu/sse - often cannot find things i searching for, in fpu theme) – grunge fightr Aug 11 '12 at 09:06
  • 1
    you can do non-floating calculations while fpu is busy with divison – huseyin tugrul buyukisik Aug 11 '12 at 10:56
  • dont forget to make equally located fpu-divison instructions. Example: 1 division then 20-30 ALU instructions than 1 division again and than 20-30 ALU again – huseyin tugrul buyukisik Aug 11 '12 at 10:58