HELP: Fast Integer to Floating-Point Conversion on a Pentium 
Author Message
 HELP: Fast Integer to Floating-Point Conversion on a Pentium

Hi Gordon-

Quote:
> I'm a newbie. I'm writing Pentium assembler code in which unsigned char
> data is converted to floating point. The best way to do this, I think, is
> to move the unsigned char directly into one of the *L registers, say DL,
> thus giving a 32-bit integer in EDX. However, how can I now convert this to
> floating-point using FILD?

[snip code]

Quote:
> Why do I need to move edx to ebp-0C0h before the FILD? And how do I know
> that ebp-00C0h is the right place to put it? Is there a better way to do
> this?

   The reason for moving the edx register to [ebp-0C0h] before the FILD
is because FILD will only work with memory operands, not registers.  So,
you need to have the number in memory to do a FILD.  Perhaps the
simplest way to do this is:

.data
int     dd      0       ; declare and init to zero a dword.
float   dd      ?       ; declare where to store the float.

.code
mov     eax,dword ptr [fArray]
mov     dl,[eax+3]              ; the char is now in dl
mov     byte ptr int,dl         ; the char is now a 32-bit
                                ; unsigned int in memory

fild    int                     ; the int is now a float
                                ; in st(0) for the FPU
fstp    float                   ; store the float into memory

   All this "[ebp-0C0h]" and "[ebp-8Ch]" stuff is the compiler
dealing with automatic variables on the stack.  You don't need
to use these automatic variables if you are not writing a
recursive or re-entrant routine.

   I hope this helps...

         Jim Neil           ___  ___/  ____/   ___  /   ____/   ____/
      Creator of The            /     /       /    /   /       /
TERSE Programming Language     /     ___/      ___/ ____  /   ___/
    http://www.*-*-*.com/       /     /       /  \         /   /

   ISBN:  0-9652660-0-1



Sun, 18 Jun 2000 03:00:00 GMT  
 HELP: Fast Integer to Floating-Point Conversion on a Pentium

Quote:

> Hi Gordon-

> > I'm a newbie. I'm writing Pentium assembler code in which unsigned char
> > data is converted to floating point. The best way to do this, I think, is
> > to move the unsigned char directly into one of the *L registers, say DL,
> > thus giving a 32-bit integer in EDX. However, how can I now convert this to
> > floating-point using FILD?

> [snip code]

> > Why do I need to move edx to ebp-0C0h before the FILD? And how do I know
> > that ebp-00C0h is the right place to put it? Is there a better way to do
> > this?

>    The reason for moving the edx register to [ebp-0C0h] before the FILD
> is because FILD will only work with memory operands, not registers.  So,
> you need to have the number in memory to do a FILD.  Perhaps the
> simplest way to do this is:

Actually, both the simplest and fastest way to handle this is to use a
lookup table!

With just 256 possible values, the table will use just 1KB, which means
that if this is a really time-critical operation (otherwise, why use
asm?), the table will probably stay in L1 cache most of the time.

If it isn't quite so time-critical, by all means use FILD, since this
takes just 3 cycles anyway.

Terje

PS. FILD works on 16-bit ints as well, so the temporary var should be
chosen to fit the code, i.e. if in 16-bit mode, use a 16-bit var,
otherwise use a 32-bit temp variable.

--

Using self-discipline, see http://www.eiffel.com/discipline
"almost all programming can be viewed as an exercise in caching"



Wed, 21 Jun 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Slow floating point to integer conversion in VC++ -- Pentium Pro/II

2. Fast conversion of float to 32.32 fixed point

3. Integer/floating point type conversion in Prolog

4. An alternative to floating point (was Re: Floating point non-exactness)

5. IBM 370 Floating point to IEEE floating point

6. Floating Point Exception on Pentium 300

7. Pentium Floating Point Exception

8. Floating Point Error Pentium

9. Floating point on Pentium 4?

10. Doing bit-wise logical operations in the Pentium and PPro floating point units

11. MAJOR Floating point bug discovered in Pentium II

12. pentium optimized floating point code for basic routines...

 

 
Powered by phpBB® Forum Software