delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/02/16/14:32:46

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Mon, 16 Feb 2004 13:19:48 -0600
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: Fwd: C99 Functions Under Development and Checkout
In-reply-to: <12f.3ba2dc0b.2d5fd363@aol.com>
To: djgpp-workers AT delorie DOT com
Message-id: <403117D4.8020807@cyberoptics.com>
Organization: CyberOptics
MIME-version: 1.0
X-Accept-Language: en,pdf
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20030925
References: <12f DOT 3ba2dc0b DOT 2d5fd363 AT aol DOT com>
X-MailScanner-Information: Please contact the ISP for more information
X-MailScanner: Found to be clean
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Kbwms AT aol DOT com wrote:

>Can anyone help me here?
>
>One set of functions comes to mind immediately because it is on my "to do 
>list" and is described in C99 paragraph 7.12.13 -- Floating multiply add with 
>subtitle, "The fma functions."  My knowledge of assembler would be extended 
>beyond its limit trying to figure out how to calculate (x*y)+z as one ternary 
>operation.
>
This one is actually pretty difficult to do, if you want to comply with 
the letter of the law.  The description of the function in C99 talks 
about delivering the correctly-rounded result.  On the x87 chip is it 
possible to come pretty close by using the native 64-bit precision, but 
it's not correct rounding in all cases.  gcc actually generates this 
64-bit code by simply writing

double fma(double x, double y, double z) {
   return x*y + z;
}

but it is not guaranteed that the intermediate product will be held in 
the 64-bit x87 register, as it currently seems to be.  Assembler will 
ensure that the intermediate product is held to 64-bit precision, but 
that doesn't even guarantee a correctly-rounded result, as the C99 
standard requires.

If you want assembler, just compile the above fragment with the -S,  
-O2, and -fomit-frame-pointer options and you will get assembler output, 
which, for this particular function, is as good as can be done by hand.

-Eric Rudd

- Raw text -


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