delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/02/17/09:59:59

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Tue, 17 Feb 2004 09:01:28 -0600
From: Eric Rudd <rudd AT cyberoptics DOT com>
Subject: Re: C99 Functions Under Development and Checkout
In-reply-to: <148.2235d751.2d6287e3@aol.com>
To: djgpp-workers AT delorie DOT com
Message-id: <40322CC8.5060004@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: <148 DOT 2235d751 DOT 2d6287e3 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:

>In a message dated 2/16/2004 2:33:43 PM Eastern Standard Time, 
>rudd AT cyberoptics DOT com writes:
>
>>f 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.
>>
>This prompts me to ask, "What's the point of going to assembler when the C 
>code is just as good?"
>
One advantage of assembler is confidence that the code won't change if 
the compiler changes, or if some well-intentioned programmer makes some 
seemingly-innocuous changes to the code.  For instance, there is no 
guarantee that the compiler won't round the product x*y to double 
precision before doing the addition; in fact, some argue that the 
product of two doubles is a double, and must be rounded to be a double.  
I tried to get around that by writing

   return (double) ((long double) x * (long double) y) + (long double z))

but I found that extra code was generated: the result was stored to the 
stack and then popped off into the coprocessor again, which is wasteful 
and unnecessary.

If you aren't very comfortable with your assembler skills, a good way to 
get the control over the code that assembler provides is to compile the 
C code to assembler, once, such that you get good code; then check in 
that assembler.  This will prevent the code from changing.

-Eric Rudd

- Raw text -


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