Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ User's Guide - this group of options deals with control over the type of floating-point http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
This group of options deals with control over the type of floating-point
instructions that the compiler generates.  There are two basic types -
floating-point calls (FPC) or floating-point instructions (FPI).  They are
selectable through the use of one of the compiler options described below.
 You may wish to use the following list when deciding which option best
suits your requirements.  Here is a summary of advantages/disadvantages to
both.

FPC

     1. not IEEE floating-point

     2. not tailorable to processor

     3. uses coprocessor if present; simulates otherwise

     4. 32-bit/64-bit accuracy

     5. runs somewhat faster if coprocessor present

     6. faster emulation (fewer bits of accuracy)

     7. leaner "math" library

     8. fatter application code (calls to library rather than in-line
        instructions)

     9. application cannot trap floating-point exceptions

    10. ideal for ROM applications

FPI, FPI87

     1. IEEE floating-point

     2. tailorable to processor (see fp2, fp3, fp5, fp6)

     3. uses coprocessor if present; emulates IEEE otherwise

     4. up to 80-bit accuracy

     5. runs "full-tilt" if coprocessor present

     6. slower emulation (more bits of accuracy)

     7. fatter "math" library

     8. leaner application code (in-line instructions)

     9. application can trap floating-point exceptions

    10. ideal for general-purpose applications


To see the difference in the type of code generated, consider the following
small example.

Example:

     #include <stdio.h>
     #include <time.h>

     void main()
     {
         clock_t  cstart, cend;
         cstart = clock();
         /*  .
             .
             .
         */
         cend = clock();
         printf( "%4.2f seconds to calculate\n",
                 ((float)cend - cstart) / CLOCKS_PER_SEC );
     }

The following 32-bit code is generated by the Watcom C compiler (wcc386)
using the "fpc" option.


     main_   push    ebx
             push    edx
             call    clock_
             mov     edx,eax
             call    clock_
             call    __U4FS  ; unsigned 4 to floating single
             mov     ebx,eax
             mov     eax,edx
             call    __U4FS  ; unsigned 4 to floating single
             mov     edx,eax
             mov     eax,ebx
             call    __FSS   ; floating single subtract
             mov     edx,3c23d70aH
             call    __FSM   ; floating single multiply
             call    __FSFD  ; floating single to floating double
             push    edx
             push    eax
             push    offset L1
             call    printf_
             add     esp,0000000cH
             pop     edx
             pop     ebx
             ret

The following 32-bit code is generated by the Watcom C compiler (wcc386)
using the "fpi" option.


     main_   push    ebx
             push    edx
             sub     esp,00000010H
             call    clock_
             mov     edx,eax
             call    clock_
             xor     ebx,ebx
             mov     [esp],eax
             mov     +4H[esp],ebx
             mov     +8H[esp],edx
             mov     +0cH[esp],ebx
             fild    qword ptr [esp]     ; integer to double
             fild    qword ptr +8H[esp]  ; integer to double
             fsubp   st(1),st            ; subtract
             fmul    dword ptr L2        ; multiply
             sub     esp,00000008H
             fstp    qword ptr [esp]     ; store into memory
             push    offset L1
             call    printf_
             add     esp,0000000cH
             add     esp,00000010H
             pop     edx
             pop     ebx
             ret

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson