Re: Thou shalt have no other gods before the ANSI C standard

From: Hank Oredson (horedson_at_earthlink.net)
Date: 02/28/05


Date: Mon, 28 Feb 2005 03:07:10 GMT


-- 
  ... Hank
http://home.earthlink.net/~horedson
http://home.earthlink.net/~w0rli
"Randy Howard" <randyhoward@FOOverizonBAR.net> wrote in message 
news:MPG.1c8c40beff2c372398a0e6@news.verizon.net...
> In article <opsmvwoptdzgicya@hyrrokkin>, tom@kednos.com says...
>> On Sun, 27 Feb 2005 20:22:15 -0500, Douglas A. Gwyn <DAGwyn@null.net>
>> wrote:
>> > You won't be able to address the question about what
>> > optimizations C compilers perform by exhibiting PL/I
>> > examples.
>>
>> Doesn't matter whether it is PL/I or C, we were discussing, I
>> thought, code hoisting in one case strlen and in the other length.
>
> Perhaps some have taken a more generic path, but I thought the
> question was fairly specific:
>
>   Will a C compiler (with or without optimizer) hoist a
>   strlen() call out of a for loop, particular the body of the
>   "for(...)" itself?
>
> I prefer empirical evidence to theory on this, and so far,
> half a dozen compilers have answered "no" to this question.
> Again, if anyone can point to one that answers "yes", I'd
> like to know.
Here is Borland BCC 4.02, which was at hand on this machine:
No hoisting.
 ;   for (n = 0; n < strlen(argv[1]); n++);
mov  word ptr [bp-10],0
jmp  short @7@86
@7@58:
inc  word ptr [bp-10]
@7@86:
les  bx,dword ptr [bp+8]
push  dword ptr es:[bx+4]
call  far ptr _strlen
add  sp,4
cmp  ax,word ptr [bp-10]
ja  short @7@58
> The more important question of course is that if the
> outcome is compiler dependent (at best) and likely to
> fail on the most commonly used C compilers in existence,
> why would a programmer *not* hoist the call themselves?
>
> I am afraid that the answer may be that far too many
> people, comprised of students, textbook authors, teachers
> and even experienced developers think that it will, and
> never bother to find out for themselves.
>
> You can add the whole "what does volatile really do?", and
> the endless debates on what magical properties it may or
> may not convey on an object (C sense) to this debate as
> a corollary.
>
> -- 
> Randy Howard (2reply remove FOOBAR)
> "Rally Mohawks, and bring your axes
> and tell King George we'll pay no taxes" 


Relevant Pages

  • Re: Paying developers to get features faster
    ... >>programmer who considers this poor style is way out of the mainstream. ... >test was an invalid test was a case of a pointer that should have been ... guaranteed to come out as false if ptr is a null pointer. ... The trick of "if " arose in the days before compilers had optimizers, ...
    (comp.os.linux.development.system)
  • Re: Paying developers to get features faster
    ... >>programmer who considers this poor style is way out of the mainstream. ... >test was an invalid test was a case of a pointer that should have been ... guaranteed to come out as false if ptr is a null pointer. ... The trick of "if " arose in the days before compilers had optimizers, ...
    (comp.security.misc)
  • Re: Paying developers to get features faster
    ... >>programmer who considers this poor style is way out of the mainstream. ... >test was an invalid test was a case of a pointer that should have been ... guaranteed to come out as false if ptr is a null pointer. ... The trick of "if " arose in the days before compilers had optimizers, ...
    (comp.os.linux.security)
  • Re: Paying developers to get features faster
    ... >>programmer who considers this poor style is way out of the mainstream. ... >test was an invalid test was a case of a pointer that should have been ... guaranteed to come out as false if ptr is a null pointer. ... The trick of "if " arose in the days before compilers had optimizers, ...
    (comp.os.linux.misc)
  • Re: [OT] Intel Compilers vs. Microsoft Compilers Optimization/Performance on Math Calculations,....
    ... Generally, "optimization" of loops no longer buys as much as it used to, because the x86 ... for cache hits, you will get *substantially* faster computations than if you do not. ... The difference between the Intel and Microsoft compilers might be 10% ... One page fault masks all other optimizations by 5-6 orders of magnitude ...
    (microsoft.public.vc.mfc)

Quantcast