www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/30/00:33:09

From: Mike <mike AT no DOT email>
Newsgroups: comp.os.msdos.djgpp
Subject: float to int conversion question
Date: Fri, 28 Nov 1997 00:32:04 -0500
Organization: Digital Equipment Corporation - Marlboro, MA
Lines: 101
Message-ID: <347E55F7.14688311@no.email>
NNTP-Posting-Host: hlorem105.hlo.dec.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

When converting a group of floating point values to integer values, the
compiled code seems to unnecessarily set and reset the FP Control Word
every time.

Is there a compiler switch or #pragma that can help here, or do I have
to clean this up by hand?

============================

#include <iostream.h>

int main (void)
{
   int i0, i1, i2;
   float f0, f1, f2, f3;

   f0 = 1.0 * f3;
   f1 = 2.0 * f3;
   f2 = 3.0 * f3;
   i0 = (int)f0;
   i1 = (int)f1;
   i2 = (int)f2;

   cout << i0 << i1 << i2;
}

============================

Compiled like this:
gcc -O2 -i486 -fomit-frame-pointer -ffast-math -S junk.cc

============================

        .file   "junk.cc"
gcc2_compiled.:
___gnu_compiled_cplusplus:
.text
        .align 2
LC0:
        .long 0x0,0x40080000
        .align 2
.globl _main
_main:
        subl $16,%esp
        pushl %ebx
        call ___main
        flds 4(%esp)
        fld %st(0)
        fadd %st(1),%st
        fstps 16(%esp)
        flds 16(%esp)
        fldl LC0
        fmulp %st,%st(2)
        fxch %st(1)
        fstps 16(%esp)
        flds 16(%esp)
        flds 4(%esp)
        fnstcw 12(%esp)
        movl 12(%esp),%eax
        movb $12,%ah
        movl %eax,8(%esp)
        fldcw 8(%esp)
        subl $4,%esp
        fistpl (%esp)
        popl %ecx
        fldcw 12(%esp)
        fxch %st(1)
        fnstcw 12(%esp)
        movl 12(%esp),%eax
        movb $12,%ah
        movl %eax,8(%esp)
        fldcw 8(%esp)
        subl $4,%esp
        fistpl (%esp)
        popl %edx
        fldcw 12(%esp)
        fnstcw 12(%esp)
        movl 12(%esp),%ebx
        movb $12,%bh
        movl %ebx,8(%esp)
        fldcw 8(%esp)
        subl $4,%esp
        fistpl (%esp)
        popl %eax
        fldcw 12(%esp)
        pushl %eax
        pushl %edx
        pushl %ecx
        pushl $_cout
        call ___ls__7ostreami
        addl $8,%esp
        pushl %eax
        call ___ls__7ostreami
        addl $8,%esp
        pushl %eax
        call ___ls__7ostreami
        addl $8,%esp
        xorl %eax,%eax
        popl %ebx
        addl $16,%esp
        ret

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019