comp.lang.ada
 help / color / mirror / Atom feed
* What is faster Ada or C?
@ 2001-12-01  1:22 Heiko Hamann
  2001-12-01  1:43 ` Aaro Koskinen
                   ` (4 more replies)
  0 siblings, 5 replies; 74+ messages in thread
From: Heiko Hamann @ 2001-12-01  1:22 UTC (permalink / raw)


Hi!

I have a program written in Ada that is very processor intensiv. It does bit
and integer operations. What would you guess is the faster languages for
this task? Ada or C - or another language (excpet Assembler)? Can that be
said in common? What is about some benchmarks concerning this case?

Bye

Heiko.





^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:22 What is faster Ada or C? Heiko Hamann
@ 2001-12-01  1:43 ` Aaro Koskinen
  2001-12-03  8:49   ` John McCabe
  2001-12-10 15:18   ` Dale Pontius
  2001-12-01  3:44 ` Nick Roberts
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 74+ messages in thread
From: Aaro Koskinen @ 2001-12-01  1:43 UTC (permalink / raw)


"Heiko Hamann" <aggo@freenet.de> writes:
> I have a program written in Ada that is very processor intensiv. It
> does bit and integer operations. What would you guess is the faster
> languages for this task? Ada or C - or another language (excpet
> Assembler)? Can that be said in common? What is about some
> benchmarks concerning this case?

Depends heavily on the compiler, really. Basically, if you use the
same set of language features you will get the same performance (i.e.
turn run-time checks off from the Ada program; similarly don't use
assertions in the C program). Ada is very much like the C in the way
that it allows you to control *exactly* what's going on at the
execution level so you can write very efficient code without worrying
about any "implicit overhead".

(Also, I would imagine that with Ada's strong typing, the compiler can
do better optimizations than an average C compiler. However, I don't
have any evidence for this...)

A.

-- 
Aaro Koskinen, aaro@iki.fi, http://www.iki.fi/aaro



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:22 What is faster Ada or C? Heiko Hamann
  2001-12-01  1:43 ` Aaro Koskinen
@ 2001-12-01  3:44 ` Nick Roberts
  2001-12-01 20:09   ` Heiko Hamann
  2001-12-01  9:26 ` Gisle Sælensminde
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 74+ messages in thread
From: Nick Roberts @ 2001-12-01  3:44 UTC (permalink / raw)


"Heiko Hamann" <aggo@freenet.de> wrote in message
news:3c08314d$0$158$9b622d9e@news.freenet.de...
> I have a program written in Ada that is very processor intensiv. It does
bit
> and integer operations. What would you guess is the faster languages for
> this task? Ada or C - or another language (excpet Assembler)?

What might be a practical approach to getting more speed would be to use
assembly for the critical bits, and a higher level language for the rest. I
guess you've considered this (?).

It's possible that, in practice, a Fortran compiler might get you a touch
more speed, but this is a guess.

I'd say the difference is not likely to be great between any of those
languages whose compilers are intended to be 'true' native code compilers,
and that the most difference in speed will be due to differences in actual
compilers.

Which Ada compiler do you use (and what is the target machine)? Have you
tried turning off checks (using the Suppress pragma)? I'd be interested to
know if that made any difference!

> Can that be said in common?

The saying is "horses for courses". You use a particular language for a
variety of reasons, rather than just speed. If you need raw speed above all,
you probably need to use assembly.

> What is about some benchmarks concerning this case?

Others might have some data on this.

--
Best wishes,
Nick Roberts







^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:22 What is faster Ada or C? Heiko Hamann
  2001-12-01  1:43 ` Aaro Koskinen
  2001-12-01  3:44 ` Nick Roberts
@ 2001-12-01  9:26 ` Gisle Sælensminde
  2001-12-01 10:13 ` Pascal Obry
  2001-12-03 14:39 ` Ted Dennison
  4 siblings, 0 replies; 74+ messages in thread
From: Gisle Sælensminde @ 2001-12-01  9:26 UTC (permalink / raw)


In article <3c08314d$0$158$9b622d9e@news.freenet.de>, Heiko Hamann wrote:
> Hi!
> 
> I have a program written in Ada that is very processor intensiv. It does bit
> and integer operations. What would you guess is the faster languages for
> this task? Ada or C - or another language (excpet Assembler)? Can that be
> said in common? What is about some benchmarks concerning this case?
> 

It depends on the compiler. Both Ada and C makes it possible to write
efficient code, given a good compiler. If Borland C++ is used to compile
the C code, and GNAT is used to compile the Ada code, The Ada program 
will probably be faster, because GNAT has a better optimizer. If the 
Ada compiler is Aonix and the compiler used to compile the C code is
Microsoft C++, the C program will usually win. 

This is in general, and will not always be true. The numbers comes from 
my experirience from optimization using these compilers, including things
like dumping the assembly output to see which code the compiler emits.
My point is that compilers is more important than the language, especially 
when you compare two system programing languages like C and Ada. 

I have used C++ compilers as example, which arguable can be said to
be incorrect, given that C (no longer?) is a subset of C++, but I don't 
think it will make my point invalid in this case.

Another important point is that before optimization makes sense, the program
have to be correct and stable. That is easier to archive in Ada than C,
because all the unsafe features of C.

--
Gisle S�lensminde ( gisle@ii.uib.no )   

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going
to land, and it could be dangerous sitting under them as they fly
overhead. (from RFC 1925)



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:22 What is faster Ada or C? Heiko Hamann
                   ` (2 preceding siblings ...)
  2001-12-01  9:26 ` Gisle Sælensminde
@ 2001-12-01 10:13 ` Pascal Obry
  2001-12-02 17:49   ` Bertrand Augereau
  2001-12-03 14:39 ` Ted Dennison
  4 siblings, 1 reply; 74+ messages in thread
From: Pascal Obry @ 2001-12-01 10:13 UTC (permalink / raw)



"Heiko Hamann" <aggo@freenet.de> writes:

> Hi!
> 
> I have a program written in Ada that is very processor intensiv. It does bit
> and integer operations. What would you guess is the faster languages for
> this task? Ada or C - or another language (excpet Assembler)? Can that be
> said in common? What is about some benchmarks concerning this case?

Ada is known to be 1867 times faster than C ;)

No seriously, there is no reserved words in the Ada language that looks like
'high_speed', 'do_this_as_quickly_as_possible' or whatever!

The fastest program is the one that use the right algorithm and a good
compiler. So if your question is: Is there some good Ada compilers around that
does high optimization ? Then the answer is definitly yes.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  3:44 ` Nick Roberts
@ 2001-12-01 20:09   ` Heiko Hamann
  2001-12-02  4:49     ` Jeffrey Carter
  2001-12-02 10:07     ` Mark Lundquist
  0 siblings, 2 replies; 74+ messages in thread
From: Heiko Hamann @ 2001-12-01 20:09 UTC (permalink / raw)



"Nick Roberts" <nickroberts@adaos.worldonline.co.uk> schrieb im Newsbeitrag
news:9uau3a$79113$1@ID-25716.news.dfncis.de...

> What might be a practical approach to getting more speed would be to use
> assembly for the critical bits, and a higher level language for the rest.
> I guess you've considered this (?).

Yes, I considered this - but only theoretical ;-) because I can't do this.
Anyway I heard that good compilers produce much better assembler code than
humans (?).

> Which Ada compiler do you use (and what is the target machine)?

I use GNAT. I am working on a AMD Athlon and Win98.

>Have you tried turning off checks (using the Suppress pragma)? I'd be
> interested to know if that made any difference!

Well, _any_ difference? Hey, this is unbelievable! The difference between
the program compiled with
standard options and the program compiled with -gnatp and -O3 is terrific.
The acceleration is about 70%! The new compilation needs only about 1/4 of
time the old one needed. I can't believe it.
The new program is about 1/5 smaller than the old one.

I thank you very much. I never thought that might make such a great
difference. I guess I will never use standard options of compilers any more
in future :-)

Bye,

Heiko.







^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01 20:09   ` Heiko Hamann
@ 2001-12-02  4:49     ` Jeffrey Carter
  2001-12-02 10:44       ` Pascal Obry
  2001-12-04 11:43       ` john mann
  2001-12-02 10:07     ` Mark Lundquist
  1 sibling, 2 replies; 74+ messages in thread
From: Jeffrey Carter @ 2001-12-02  4:49 UTC (permalink / raw)


Heiko Hamann wrote:
> 
> Well, _any_ difference? Hey, this is unbelievable! The difference between
> the program compiled with
> standard options and the program compiled with -gnatp and -O3 is terrific.
> The acceleration is about 70%! The new compilation needs only about 1/4 of
> time the old one needed. I can't believe it.
> The new program is about 1/5 smaller than the old one.

Most of this difference is probably due to optimization. GNAT produces
very poor code with no optimization. Even -O1 often makes a significant
difference. Suppressing run-time checks rarely saves more than about
10%.

-- 
Jeff Carter
"I blow my nose on you."
Monty Python & the Holy Grail



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01 20:09   ` Heiko Hamann
  2001-12-02  4:49     ` Jeffrey Carter
@ 2001-12-02 10:07     ` Mark Lundquist
  2001-12-03 14:43       ` Ted Dennison
  2001-12-09 12:31       ` Robert Dewar
  1 sibling, 2 replies; 74+ messages in thread
From: Mark Lundquist @ 2001-12-02 10:07 UTC (permalink / raw)



"Heiko Hamann" <aggo@freenet.de> wrote in message
news:3c093895$0$160$9b622d9e@news.freenet.de...
> I thank you very much. I never thought that might make such a great
> difference. I guess I will never use standard options of compilers any
more
> in future :-)

But don't "throw the baby out with the bath water" :-)

The run-time checks are valuable, and a habit of compiling everything with
checks suppressed may result in a lot of needless time spent debugging.

I'd recommend using pragma Suppress in the source code (or as a
configuration pragma), in only the performance-intensive parts of your
program.

You also might consider using gnatprep to conditionalize these pragmas so
that you only turn them on when doing the "production" build of the program.

Cheers,
Mark Lundquist




^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-02  4:49     ` Jeffrey Carter
@ 2001-12-02 10:44       ` Pascal Obry
  2001-12-04 11:43       ` john mann
  1 sibling, 0 replies; 74+ messages in thread
From: Pascal Obry @ 2001-12-02 10:44 UTC (permalink / raw)



Jeffrey Carter <jrcarter@acm.org> writes:

> Heiko Hamann wrote:
> > 
> > Well, _any_ difference? Hey, this is unbelievable! The difference between
> > the program compiled with
> > standard options and the program compiled with -gnatp and -O3 is terrific.
> > The acceleration is about 70%! The new compilation needs only about 1/4 of
> > time the old one needed. I can't believe it.
> > The new program is about 1/5 smaller than the old one.
> 
> Most of this difference is probably due to optimization. GNAT produces
> very poor code with no optimization. Even -O1 often makes a significant

Indeed. The -O0 (default option) of GCC/GNAT is doing just no optimization at
all. It even does not try to be smart :)

The first "real" optimization steps for GCC/GNAT is done at -02.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01 10:13 ` Pascal Obry
@ 2001-12-02 17:49   ` Bertrand Augereau
  0 siblings, 0 replies; 74+ messages in thread
From: Bertrand Augereau @ 2001-12-02 17:49 UTC (permalink / raw)


> The fastest program is the one that use the right algorithm and a good
> compiler. So if your question is: Is there some good Ada compilers around
that
> does high optimization ? Then the answer is definitly yes.

Yes, but the OP wants to do integer and bit twiddling intensive
computations, which is a particular field.

My advice is that, for this kind of low-level stuff,
First, try to stay in the cache, whatever the language. Prefetch if
possible.
Second, try to use vector operations by using the right vector-friendly
algorithm (you'll likely need assembly for that).

So you can use whatever language you prefer, if you follow those 2 rules.
If you don't put assembly for the inner loops and want to stay at a higher
level, chances are that on your platform, you got a C++ compiler with better
codegen/optimizer (Intel C++ on x86 for instance).
Try both.







^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
@ 2001-12-02 19:37 Gautier Write-only-address
  0 siblings, 0 replies; 74+ messages in thread
From: Gautier Write-only-address @ 2001-12-02 19:37 UTC (permalink / raw)
  To: comp.lang.ada

>From: "Heiko Hamann"

>Well, _any_ difference? Hey, this is unbelievable! The difference between
>the program compiled with
>standard options and the program compiled with -gnatp and -O3 is terrific.
>The acceleration is about 70%! The new compilation needs only about 1/4 of
>time the old one needed. I can't believe it.
>The new program is about 1/5 smaller than the old one.

If you want still better, try
  -O2 and manually selected inlined subprograms (pragma inline)
  -funroll-loops
  -gnatn (cross-unit inling)

HTH
________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: Do not answer to sender address, visit the Web site!


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:43 ` Aaro Koskinen
@ 2001-12-03  8:49   ` John McCabe
  2001-12-04 23:00     ` Florian Weimer
  2001-12-10 15:18   ` Dale Pontius
  1 sibling, 1 reply; 74+ messages in thread
From: John McCabe @ 2001-12-03  8:49 UTC (permalink / raw)


On 01 Dec 2001 03:43:53 +0200, aaro@iki.fi (Aaro Koskinen) wrote:

>Depends heavily on the compiler, really.

And the application.

>(Also, I would imagine that with Ada's strong typing, the compiler can
>do better optimizations than an average C compiler. However, I don't
>have any evidence for this...)

It's been mentioned before on a couple of occasions, but Tartan (as
was) wrote a paper identifying why their Ada compiler produced faster
code than assembler. As far as I can remember, many of the points
raised related to optimisation and, in particular, how the use of
package specifications allowed them to make valid assumptions that had
an positive impact on the optimisations they could use. C compilers
were, as far as I remember, also mentioned.




^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:22 What is faster Ada or C? Heiko Hamann
                   ` (3 preceding siblings ...)
  2001-12-01 10:13 ` Pascal Obry
@ 2001-12-03 14:39 ` Ted Dennison
  2001-12-03 16:19   ` Jeffrey Carter
  4 siblings, 1 reply; 74+ messages in thread
From: Ted Dennison @ 2001-12-03 14:39 UTC (permalink / raw)


In article <3c08314d$0$158$9b622d9e@news.freenet.de>, Heiko Hamann says...
>I have a program written in Ada that is very processor intensiv. It does bit
>and integer operations. What would you guess is the faster languages for
>this task? Ada or C - or another language (excpet Assembler)? Can that be
>said in common? What is about some benchmarks concerning this case?

This gets asked here a lot. In truth, its a bad question. There really is no
such thing as a fast or slow language. A language can't have a speed, its an
abstract concept.

If you were to ask which language's compilers would, in theory, be able to
produce faster executables, the answer would be Ada. Ada's a lot more strict
than C, which means its optimizer has a lot more information to work with. 

However, this isn't the question you really care about the answer to. What you
need to know is which of your available compilers will you be able to create
faster executables with. The main variables here aren't language, but rather the
effort the various compiler writers put into optimization, and the quality of
*your* code.

For example, the Aonix Ada compiler has *no* user-visible optimization options
(last I checked anyway). Its intended audience appears to be Windows GUI
programmers, and speed just isn't as important to them as good Windows support.
I'm sure there are several Windows-based C compilers with this same philosophy.
Green Hills, on the other hand, produces Ada compilers with oodles of
optimization options. The same numeric computation code most likely going to run
much faster when compiled and properly optimized with a GreenHills x86 compiler
than with one of those others.

Gnat on the other hand, uses the same code generation back end as Gcc. Thus a
fair comparison between C and Ada code when both are compiled with GCC is liable
to show you no difference at all.

Also, large amounts of compiler optimization aren't liable to save you if you
perform slow operations with one language and faster ones with another. Your
algorithms have to be comparable, or all bets are off.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-02 10:07     ` Mark Lundquist
@ 2001-12-03 14:43       ` Ted Dennison
  2001-12-09 12:31       ` Robert Dewar
  1 sibling, 0 replies; 74+ messages in thread
From: Ted Dennison @ 2001-12-03 14:43 UTC (permalink / raw)


In article <S3nO7.2430$KY6.1181@rwcrnsc53>, Mark Lundquist says...
>
>The run-time checks are valuable, and a habit of compiling everything with
>checks suppressed may result in a lot of needless time spent debugging.
>
>I'd recommend using pragma Suppress in the source code (or as a
>configuration pragma), in only the performance-intensive parts of your
>program.

I'd go further than that: You should only supress checks when analysis
(including actual measurement) shows that you need the extra speed that you get
by doing this. Don't leave C, only to reproduce its buffer overflow exploits in
Ada.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 14:39 ` Ted Dennison
@ 2001-12-03 16:19   ` Jeffrey Carter
  2001-12-03 19:04     ` Ted Dennison
  2001-12-07 13:21     ` Jacob Sparre Andersen
  0 siblings, 2 replies; 74+ messages in thread
From: Jeffrey Carter @ 2001-12-03 16:19 UTC (permalink / raw)


Ted Dennison wrote:
> 
> Gnat on the other hand, uses the same code generation back end as Gcc. Thus a
> fair comparison between C and Ada code when both are compiled with GCC is liable
> to show you no difference at all.

Robert Dewar has stated here on several occasions that he has some
equivalent Ada and C programs that produce identical object code when
compiled with gcc.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 16:19   ` Jeffrey Carter
@ 2001-12-03 19:04     ` Ted Dennison
  2001-12-03 20:56       ` Georg Bauhaus
  2001-12-07 13:21     ` Jacob Sparre Andersen
  1 sibling, 1 reply; 74+ messages in thread
From: Ted Dennison @ 2001-12-03 19:04 UTC (permalink / raw)


In article <3C0BA624.7A12BFA1@boeing.com>, Jeffrey Carter says...
>Robert Dewar has stated here on several occasions that he has some
>equivalent Ada and C programs that produce identical object code when
>compiled with gcc.

That was "hello world", I believe. I think he actually posted that example at
one point many years back. It sort of cheated, in that it pragma-interface'd to
C for stuff like the IO routines. But then again, there's nothing stopping you
from doing that too if you really want to. :-)

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 19:04     ` Ted Dennison
@ 2001-12-03 20:56       ` Georg Bauhaus
  2001-12-03 21:17         ` Preben Randhol
                           ` (2 more replies)
  0 siblings, 3 replies; 74+ messages in thread
From: Georg Bauhaus @ 2001-12-03 20:56 UTC (permalink / raw)


Ted Dennison <dennison@telepath.com> wrote:
 
: That was "hello world", I believe. I think he actually posted that example at
: one point many years back. It sort of cheated, in that it pragma-interface'd to
: C for stuff like the IO routines. But then again, there's nothing stopping you
: from doing that too if you really want to. :-)
: 


For fun I've tried to check this several times myself; here is one
program in C and Ada, without optimization, that shows essentially
no difference. Differences have usually vanished when I had asked
for optimisation. OTOH, if you follow the assembly output below,
they aren't that significant anyway. The programs have been compiled
with gcc -S and gcc -S -gnatp respectively.

function Silly return Integer is

   Result: Integer:= 0;

begin
   for K in 1..1000 loop
      Result:= Result + 1;
   end loop;

   return Result;
end Silly;


int silly()
{
  int result = 0, k;

  for (k = 1; k <= 1000; k++)
    {
      result++;
    }

  return result;
}


Here is side by side output:

        .file   "silly.adb"             .file   "silly.c"
gcc2_compiled.:                    gcc2_compiled.:
___gnu_compiled_ada:               ___gnu_compiled_c:
.text                              .text
        .align 4                        .align 4
.globl __ada_silly                 .globl _silly
__ada_silly:                       _silly:
        pushl %ebp                      pushl %ebp
        movl %esp,%ebp                  movl %esp,%ebp
        subl $8,%esp                    subl $8,%esp
        movl $0,-4(%ebp)                movl $0,-4(%ebp)
        movl $1,-8(%ebp)                movl $1,-8(%ebp)
L2:                                L2:
        cmpl $1000,-8(%ebp)             cmpl $1000,-8(%ebp)
        jle L5                          jle L5
        jmp L3                          jmp L3
        .align 2,0x90                   .align 2,0x90
L5:                                L5:
        incl -4(%ebp)                   incl -4(%ebp)
        jmp L4                     L4:
        .align 2,0x90                   incl -8(%ebp)
        jmp L3                          jmp L2
        .align 2,0x90                   .align 2,0x90
L6:                                L3:
L4:                                     movl -4(%ebp),%edx
        incl -8(%ebp)                   movl %edx,%eax
        jmp L2                          jmp L1
        .align 2,0x90                   .align 2,0x90
L3:                                L1:
        movl -4(%ebp),%edx              movl %ebp,%esp
        movl %edx,%eax                  popl %ebp
        jmp L1                          ret
        .align 2,0x90
L1:
        movl %ebp,%esp
        popl %ebp
        ret

The optimiser's output is also quite interesting :-)

Georg



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 20:56       ` Georg Bauhaus
@ 2001-12-03 21:17         ` Preben Randhol
  2001-12-03 21:20           ` Preben Randhol
  2001-12-04 23:02           ` Florian Weimer
  2001-12-04  2:35         ` Jeffrey Carter
  2001-12-04 22:37         ` Pascal Obry
  2 siblings, 2 replies; 74+ messages in thread
From: Preben Randhol @ 2001-12-03 21:17 UTC (permalink / raw)


On Mon, 3 Dec 2001 20:56:12 +0000 (UTC), Georg Bauhaus wrote:
> 
> Here is side by side output:
> 
>         .file   "silly.adb"             .file   "silly.c"
> gcc2_compiled.:                    gcc2_compiled.:
> ___gnu_compiled_ada:               ___gnu_compiled_c:
> .text                              .text
>         .align 4                        .align 4
> .globl __ada_silly                 .globl _silly
> __ada_silly:                       _silly:
>         pushl %ebp                      pushl %ebp
>         movl %esp,%ebp                  movl %esp,%ebp
>         subl $8,%esp                    subl $8,%esp
>         movl $0,-4(%ebp)                movl $0,-4(%ebp)
>         movl $1,-8(%ebp)                movl $1,-8(%ebp)
> L2:                                L2:
>         cmpl $1000,-8(%ebp)             cmpl $1000,-8(%ebp)
>         jle L5                          jle L5
>         jmp L3                          jmp L3
>         .align 2,0x90                   .align 2,0x90
> L5:                                L5:
>         incl -4(%ebp)                   incl -4(%ebp)
>         jmp L4                     
>         .align 2,0x90              
>         jmp L3                     
>         .align 2,0x90              
> L6:                                

What happens here? I'm not fluent in assembly any more. Why is there a
jmp L4 etc in the Ada code and not in the C. Is it range checks ?

> L4:                                L4:
>         incl -8(%ebp)                   incl -8(%ebp)
>         jmp L2                          jmp L2
>         .align 2,0x90                   .align 2,0x90
> L3:                                L3:
>         movl -4(%ebp),%edx              movl -4(%ebp),%edx
>         movl %edx,%eax                  movl %edx,%eax
>         jmp L1                          jmp L1
>         .align 2,0x90                   .align 2,0x90
> L1:                                L1:
>         movl %ebp,%esp                  movl %ebp,%esp
>         popl %ebp                       popl %ebp
>         ret                             ret                

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 21:17         ` Preben Randhol
@ 2001-12-03 21:20           ` Preben Randhol
  2001-12-04 23:02           ` Florian Weimer
  1 sibling, 0 replies; 74+ messages in thread
From: Preben Randhol @ 2001-12-03 21:20 UTC (permalink / raw)


On Mon, 3 Dec 2001 21:17:22 +0000 (UTC), Preben Randhol wrote:
> On Mon, 3 Dec 2001 20:56:12 +0000 (UTC), Georg Bauhaus wrote:
>> 
>> Here is side by side output:
>> 
>>         .file   "silly.adb"             .file   "silly.c"
>> gcc2_compiled.:                    gcc2_compiled.:
>> ___gnu_compiled_ada:               ___gnu_compiled_c:
>> .text                              .text
>>         .align 4                        .align 4
>> .globl __ada_silly                 .globl _silly
>> __ada_silly:                       _silly:
>>         pushl %ebp                      pushl %ebp
>>         movl %esp,%ebp                  movl %esp,%ebp
>>         subl $8,%esp                    subl $8,%esp
>>         movl $0,-4(%ebp)                movl $0,-4(%ebp)
>>         movl $1,-8(%ebp)                movl $1,-8(%ebp)
>> L2:                                L2:
>>         cmpl $1000,-8(%ebp)             cmpl $1000,-8(%ebp)
>>         jle L5                          jle L5
>>         jmp L3                          jmp L3
>>         .align 2,0x90                   .align 2,0x90
>> L5:                                L5:
>>         incl -4(%ebp)                   incl -4(%ebp)
>>         jmp L4                     
>>         .align 2,0x90              
>>         jmp L3                     
>>         .align 2,0x90              
>> L6:                                
> 
> What happens here? I'm not fluent in assembly any more. Why is there a
> jmp L4 etc in the Ada code and not in the C. Is it range checks ?

oops I see I missed the point that the ada source was compiled with -gnatp.


-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 20:56       ` Georg Bauhaus
  2001-12-03 21:17         ` Preben Randhol
@ 2001-12-04  2:35         ` Jeffrey Carter
  2001-12-04  6:54           ` Steven Deller
  2001-12-04 22:37         ` Pascal Obry
  2 siblings, 1 reply; 74+ messages in thread
From: Jeffrey Carter @ 2001-12-04  2:35 UTC (permalink / raw)


If you write equivalent loops (a C for loop is a while loop preceded by
an assignment and with an increment added as the last statement of the
loop) by using a while loop rather than an Ada for loop, the results are
even more similar.

-- 
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail



^ permalink raw reply	[flat|nested] 74+ messages in thread

* RE: What is faster Ada or C?
  2001-12-04  2:35         ` Jeffrey Carter
@ 2001-12-04  6:54           ` Steven Deller
  2001-12-04 22:05             ` Bertrand Augereau
  0 siblings, 1 reply; 74+ messages in thread
From: Steven Deller @ 2001-12-04  6:54 UTC (permalink / raw)
  To: comp.lang.ada

Ada.  If written right with a reasonable compiler.

I have had many cases where Ada was faster, both at the macro level and
the micro level.

One macro example -- old UNIX without threads.  50 Ada tasks sharing
SIGIO with 50 open TCP-IP connections versus a single C program doing
the same thing with a "hand coded" routine to check for I/O completions
on SIGIO (actually doing less processing than the Ada version).  The Ada
version achieved 20% better throughput.

In the above, polling was first used in the Ada program.  Because the
Ada was slow, the customer wrote a C framework that did none of the
processing done in the Ada program, but got twice the throughput of the
unmodified data.  The customer wanted to abandon Ada "because Ada
tasking is too slow" and asked for their money back on the compiler.  

We went in, analyzed the problem using RMA, showed them the problem,
provided a "SIGIO distributor" package, changed 10 lines of their
application code to eliminate polling and use SIGIO, and got 140%
speedup from the original Ada, resulting in 20% more throughput than the
simple C program.  I could even explain why the Ada version *should* be
faster, but that was about 10 years ago.

One micro example -- SQRT.  Using Apex and
Numerics.Generic_Elementary_Functions the SQRT function is faster in Ada
than in C on any target system with hardware SQRT.  This is because C
uses a library call to get to the function, while with Ada it is
possible to use Machine_Code and inlining to just "use" the machine
instruction.  Further, for single-precision SQRT, C must promote the
single-precision to double-precision, do the SQRT, and then demote the
result.  In Ada, the single-precision SQRT machine instruction is all
that appears in the code listing.

Regards,
Steve Deller
deller@smsail.com





^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-02  4:49     ` Jeffrey Carter
  2001-12-02 10:44       ` Pascal Obry
@ 2001-12-04 11:43       ` john mann
  2001-12-04 14:25         ` Ted Dennison
  1 sibling, 1 reply; 74+ messages in thread
From: john mann @ 2001-12-04 11:43 UTC (permalink / raw)


I've used the aonix compiler in the past, and for non-numeric types of
operations (playing about with dispatching ops etc), the run time
checks added nothing at all. For number crunching, I worked on about
10-15% difference.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04 11:43       ` john mann
@ 2001-12-04 14:25         ` Ted Dennison
  2001-12-05  9:46           ` John McCabe
  0 siblings, 1 reply; 74+ messages in thread
From: Ted Dennison @ 2001-12-04 14:25 UTC (permalink / raw)


In article <27331d9e.0112040343.76f6f16f@posting.google.com>, john mann says...
>
>I've used the aonix compiler in the past, and for non-numeric types of
>operations (playing about with dispatching ops etc), the run time
>checks added nothing at all. For number crunching, I worked on about
>10-15% difference.

If this is the ObjectAda compiler you are talking about, then it should be noted
that it has no user-settable optimization options (at least not last I checked),
and is really targetted to general Windows developers, not number crunchers. I
think its great for Ada that such a compiler exists, but its not the one to
choose as an Ada representative for number-crunching speed (unless you *want* to
make Ada look bad).

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04  6:54           ` Steven Deller
@ 2001-12-04 22:05             ` Bertrand Augereau
  2001-12-06  4:25               ` Richard Riehle
  0 siblings, 1 reply; 74+ messages in thread
From: Bertrand Augereau @ 2001-12-04 22:05 UTC (permalink / raw)


> One micro example -- SQRT.  Using Apex and
> Numerics.Generic_Elementary_Functions the SQRT function is faster in Ada
> than in C on any target system with hardware SQRT.  This is because C
> uses a library call to get to the function, while with Ada it is
> possible to use Machine_Code and inlining to just "use" the machine
> instruction.  Further, for single-precision SQRT, C must promote the
> single-precision to double-precision, do the SQRT, and then demote the
> result.  In Ada, the single-precision SQRT machine instruction is all
> that appears in the code listing.

Practically, I've never used a C++ compiler where you couldn't declare an
inline assembly function (g++, intel c++, vc++, mwcw)
Moreover, you have float sqrtf(float) which allows you not to use double
sqrt(double) (it sometimes can be costly, ie PSX2)

But I suppose those have been there since longer in Ada.








^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 20:56       ` Georg Bauhaus
  2001-12-03 21:17         ` Preben Randhol
  2001-12-04  2:35         ` Jeffrey Carter
@ 2001-12-04 22:37         ` Pascal Obry
  2001-12-05 15:57           ` Georg Bauhaus
  2 siblings, 1 reply; 74+ messages in thread
From: Pascal Obry @ 2001-12-04 22:37 UTC (permalink / raw)



Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:

> 
> Here is side by side output:
> 
>         .file   "silly.adb"             .file   "silly.c"
> gcc2_compiled.:                    gcc2_compiled.:
> ___gnu_compiled_ada:               ___gnu_compiled_c:
> .text                              .text
>         .align 4                        .align 4
> .globl __ada_silly                 .globl _silly
> __ada_silly:                       _silly:
>         pushl %ebp                      pushl %ebp
>         movl %esp,%ebp                  movl %esp,%ebp
>         subl $8,%esp                    subl $8,%esp
>         movl $0,-4(%ebp)                movl $0,-4(%ebp)
>         movl $1,-8(%ebp)                movl $1,-8(%ebp)
> L2:                                L2:
>         cmpl $1000,-8(%ebp)             cmpl $1000,-8(%ebp)
>         jle L5                          jle L5
>         jmp L3                          jmp L3
>         .align 2,0x90                   .align 2,0x90
> L5:                                L5:
>         incl -4(%ebp)                   incl -4(%ebp)
>         jmp L4                     L4:
>         .align 2,0x90                   incl -8(%ebp)
>         jmp L3                          jmp L2
>         .align 2,0x90                   .align 2,0x90
> L6:                                L3:
> L4:                                     movl -4(%ebp),%edx
>         incl -8(%ebp)                   movl %edx,%eax
>         jmp L2                          jmp L1
>         .align 2,0x90                   .align 2,0x90
> L3:                                L1:
>         movl -4(%ebp),%edx              movl %ebp,%esp
>         movl %edx,%eax                  popl %ebp
>         jmp L1                          ret
>         .align 2,0x90
> L1:
>         movl %ebp,%esp
>         popl %ebp
>         ret
> 

Here is the GNAT 5 output: "-S -gnatp"

	.file	"silly.adb"
	.text
	.align 2
.globl __ada_silly
	.def	__ada_silly;	.scl	2;	.type	32;	.endef
__ada_silly:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	movl	$0, -4(%ebp)
	movl	$1, -8(%ebp)
L2:
	cmpl	$1000, -8(%ebp)
	jle	L5
	jmp	L3
L5:
	leal	-4(%ebp), %eax
	incl	(%eax)
	leal	-8(%ebp), %eax
	incl	(%eax)
	jmp	L2
L3:
	movl	-4(%ebp), %eax
	leave
	ret

And with "-S -gnatp -O2"

	.file	"silly.adb"
	.text
	.align 2
	.p2align 4,,15
.globl __ada_silly
	.def	__ada_silly;	.scl	2;	.type	32;	.endef
__ada_silly:
	pushl	%ebp
	movl	$999, %eax
	movl	%esp, %ebp
	.p2align 4,,7
L8:
	decl	%eax
	jns	L8
	movl	$1000, %eax
	popl	%ebp
	ret

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03  8:49   ` John McCabe
@ 2001-12-04 23:00     ` Florian Weimer
  2001-12-05 15:53       ` Ted Dennison
  0 siblings, 1 reply; 74+ messages in thread
From: Florian Weimer @ 2001-12-04 23:00 UTC (permalink / raw)


john.mccabe@emrad.com.nospam (John McCabe) writes:

>>(Also, I would imagine that with Ada's strong typing, the compiler can
>>do better optimizations than an average C compiler. However, I don't
>>have any evidence for this...)
>
> It's been mentioned before on a couple of occasions, but Tartan (as
> was) wrote a paper identifying why their Ada compiler produced faster
> code than assembler.

This is pure marketing, of course.  Hand-tuned assembler code will
always be as fast as or outperform code generated by compilers because
a human programmer can always take the code generated by a compiler if
he cannot do any better, while the compiler hasn't got this option.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 21:17         ` Preben Randhol
  2001-12-03 21:20           ` Preben Randhol
@ 2001-12-04 23:02           ` Florian Weimer
  2001-12-05 16:05             ` Georg Bauhaus
  1 sibling, 1 reply; 74+ messages in thread
From: Florian Weimer @ 2001-12-04 23:02 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> writes:

> What happens here? I'm not fluent in assembly any more. Why is there a
> jmp L4 etc in the Ada code and not in the C. Is it range checks ?

One of the jumps is unreachable, so I think this is some kind of
compiler bug (if this happens when optimization is turned on).



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04 14:25         ` Ted Dennison
@ 2001-12-05  9:46           ` John McCabe
  0 siblings, 0 replies; 74+ messages in thread
From: John McCabe @ 2001-12-05  9:46 UTC (permalink / raw)


On Tue, 04 Dec 2001 14:25:55 GMT, Ted Dennison<dennison@telepath.com>
wrote:

>In article <27331d9e.0112040343.76f6f16f@posting.google.com>, john mann says...
>>
>>I've used the aonix compiler in the past, and for non-numeric types of
>>operations (playing about with dispatching ops etc), the run time
>>checks added nothing at all. For number crunching, I worked on about
>>10-15% difference.
>
>If this is the ObjectAda compiler you are talking about, then it should be noted
>that it has no user-settable optimization options (at least not last I checked),
>and is really targetted to general Windows developers, not number crunchers.

Mr Mann is more than likely referring to ObjectAda Embedded/Real-Time
using PharLap's ETS rather than the vanilla Windows version. Whether
this makes a difference or not to the optimisation options is not
something I could find on Aonix's website :-)





^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04 23:00     ` Florian Weimer
@ 2001-12-05 15:53       ` Ted Dennison
  2001-12-06  0:17         ` Jeffrey Carter
  0 siblings, 1 reply; 74+ messages in thread
From: Ted Dennison @ 2001-12-05 15:53 UTC (permalink / raw)


In article <871yia7fr2.fsf@deneb.enyo.de>, Florian Weimer says...
>
>john.mccabe@emrad.com.nospam (John McCabe) writes:
>> It's been mentioned before on a couple of occasions, but Tartan (as
>> was) wrote a paper identifying why their Ada compiler produced faster
>> code than assembler.
>
>This is pure marketing, of course.  Hand-tuned assembler code will
>always be as fast as or outperform code generated by compilers because
>a human programmer can always take the code generated by a compiler if
>he cannot do any better, while the compiler hasn't got this option.

In the Tartan case they were talking about assembler written from scratch in
assembler. They weren't talking about hand-optimizing compiler output vs. not
doing that.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04 22:37         ` Pascal Obry
@ 2001-12-05 15:57           ` Georg Bauhaus
  2001-12-05 17:12             ` Larry Kilgallen
  0 siblings, 1 reply; 74+ messages in thread
From: Georg Bauhaus @ 2001-12-05 15:57 UTC (permalink / raw)


Pascal Obry <p.obry@wanadoo.fr> wrote:
 
: Here is the GNAT 5 output: "-S -gnatp"
: 
:        .text
	...
: L2:
:        cmpl    $1000, -8(%ebp)
:        jle     L5
:        jmp     L3
: L5:
:        leal    -4(%ebp), %eax
:        incl    (%eax)
:        leal    -8(%ebp), %eax
:        incl    (%eax)
:        jmp     L2
: L3:
	...

So now even assembler output is more reader friendly.
Must be Ada influence :-) :-)


Georg



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04 23:02           ` Florian Weimer
@ 2001-12-05 16:05             ` Georg Bauhaus
  2001-12-06 23:33               ` Florian Weimer
  0 siblings, 1 reply; 74+ messages in thread
From: Georg Bauhaus @ 2001-12-05 16:05 UTC (permalink / raw)


Florian Weimer <fw@deneb.enyo.de> wrote:
 
: One of the jumps is unreachable, so I think this is some kind of
: compiler bug (if this happens when optimization is turned on).

Why?  (An uninformed wild speculation on my side makes me play with
the thought that this need not in general be true. E.g. if a jump is
a cheap operation and no nop was available, and the processor is as
weird as I want it to be...  O.K., back to the book shelf. :-)



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-05 15:57           ` Georg Bauhaus
@ 2001-12-05 17:12             ` Larry Kilgallen
  0 siblings, 0 replies; 74+ messages in thread
From: Larry Kilgallen @ 2001-12-05 17:12 UTC (permalink / raw)


In article <9ulg5q$cj0$1@a1-hrz.uni-duisburg.de>, Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:
> Pascal Obry <p.obry@wanadoo.fr> wrote:
>  
> : Here is the GNAT 5 output: "-S -gnatp"
> : 
> :        .text
> 	...
> : L2:
> :        cmpl    $1000, -8(%ebp)
> :        jle     L5
> :        jmp     L3
> : L5:
> :        leal    -4(%ebp), %eax
> :        incl    (%eax)
> :        leal    -8(%ebp), %eax
> :        incl    (%eax)
> :        jmp     L2
> : L3:
> 	...
> 
> So now even assembler output is more reader friendly.
> Must be Ada influence :-) :-)

Perhaps the program was optimized for speed or size rather than
for reader friendliness.  I don't know that instruction set,
but there are various issues in some instruction sets regarding
branch prediction and register usage that mean the most optimized
code is likely to be the least obvious.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-05 15:53       ` Ted Dennison
@ 2001-12-06  0:17         ` Jeffrey Carter
  0 siblings, 0 replies; 74+ messages in thread
From: Jeffrey Carter @ 2001-12-06  0:17 UTC (permalink / raw)


Ted Dennison wrote:
> 
> In article <871yia7fr2.fsf@deneb.enyo.de>, Florian Weimer says...
> >
> >john.mccabe@emrad.com.nospam (John McCabe) writes:
> >> It's been mentioned before on a couple of occasions, but Tartan (as
> >> was) wrote a paper identifying why their Ada compiler produced faster
> >> code than assembler.
> >
> >This is pure marketing, of course.  Hand-tuned assembler code will
> >always be as fast as or outperform code generated by compilers because
> >a human programmer can always take the code generated by a compiler if
> >he cannot do any better, while the compiler hasn't got this option.
> 
> In the Tartan case they were talking about assembler written from scratch in
> assembler. They weren't talking about hand-optimizing compiler output vs. not
> doing that.

Their assembler comparison was with human-written code for a specific
project. While interesting, I found it more impressive that their Ada
compiler produced faster code than their C compiler, which they marketed
based on its excellent optimization.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-04 22:05             ` Bertrand Augereau
@ 2001-12-06  4:25               ` Richard Riehle
  2001-12-07 20:02                 ` Hyman Rosen
  0 siblings, 1 reply; 74+ messages in thread
From: Richard Riehle @ 2001-12-06  4:25 UTC (permalink / raw)


Bertrand Augereau wrote:

> Practically, I've never used a C++ compiler where you couldn't declare an
> inline assembly function (g++, intel c++, vc++, mwcw)
> Moreover, you have float sqrtf(float) which allows you not to use double
> sqrt(double) (it sometimes can be costly, ie PSX2)

Practically,  C++ inline functions are a bit of a nuisance since, in a class
definition, one must fully code the implementation when in-lining.  That
is, C++ inline requires one to trade off the practical benefits of separate
compilation for the practical benefits of in-lined code.

Richard Riehle




^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-05 16:05             ` Georg Bauhaus
@ 2001-12-06 23:33               ` Florian Weimer
  0 siblings, 0 replies; 74+ messages in thread
From: Florian Weimer @ 2001-12-06 23:33 UTC (permalink / raw)


Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:

> Florian Weimer <fw@deneb.enyo.de> wrote:
>  
> : One of the jumps is unreachable, so I think this is some kind of
> : compiler bug (if this happens when optimization is turned on).
>
> Why?  (An uninformed wild speculation on my side makes me play with
> the thought that this need not in general be true. E.g. if a jump is
> a cheap operation and no nop was available,

GCC doesn't know much about exact instruction widths, so it cannot
insert explicit NOPs to improve alignment. ;-)



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-03 16:19   ` Jeffrey Carter
  2001-12-03 19:04     ` Ted Dennison
@ 2001-12-07 13:21     ` Jacob Sparre Andersen
  2001-12-07 15:16       ` Aaro Koskinen
                         ` (6 more replies)
  1 sibling, 7 replies; 74+ messages in thread
From: Jacob Sparre Andersen @ 2001-12-07 13:21 UTC (permalink / raw)


Jeffrey Carter wrote:

> Robert Dewar has stated here on several occasions that he has some
> equivalent Ada and C programs that produce identical object code when
> compiled with gcc.

Yes.

Related to that, I have two simple, apparantly equivalent
programs written in respectively Ada and C++, where the GNU
Ada and C++ compilers find it difficult to produce even
roughly equivalent binary code or processing speed.

 * Why are the two programs below not equivalent?
 * How can I get the Ada program to run as fast as the C++
program?

Ada:

Compilation...: gnatmake sqrt_timer -O3 -gnatn
Execution time: 3460 ms
Source code:

with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO;
with Interfaces.C;

procedure Sqrt_Timer is

   type Scalar is new Interfaces.C.Double;

   package Math is new
Ada.Numerics.Generic_Elementary_Functions (Scalar);

   function Sqrt (Item : in Scalar) return Scalar renames
Math.Sqrt;
   pragma Inline (Sqrt);

   X : Scalar := 2.0;

begin  --  Sqrt_Timer
   for i in 1 .. 10_000_000 loop
      X := Sqrt (1.0 + X);
   end loop;

   Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
end Sqrt_Timer;


C++
===

Compilation...: g++ sqrt_timer.cpp -O3
Execution time: 1460 ms
Source code:

#include <math.h>
#include <iostream.h>

int main (int argl,char* argv[]) {

   double x=2.0;

   for(int i=0;i<10000000;i++){
      x=sqrt(1.0+x);
   };

   cout << x << endl;
};


Jacob
-- 
SSLUG's julekalender - fra den 1. til den 24. december p�:
                           http://www.sslug.dk/julekalender/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
@ 2001-12-07 15:16       ` Aaro Koskinen
  2001-12-07 16:50         ` Preben Randhol
  2001-12-07 16:16       ` Preben Randhol
                         ` (5 subsequent siblings)
  6 siblings, 1 reply; 74+ messages in thread
From: Aaro Koskinen @ 2001-12-07 15:16 UTC (permalink / raw)


Jacob Sparre Andersen <sparre@nbi.dk> writes:
>  * Why are the two programs below not equivalent?
>  * How can I get the Ada program to run as fast as the C++ program?
[..]
> Compilation...: gnatmake sqrt_timer -O3 -gnatn
[..]
>    for i in 1 .. 10_000_000 loop
>       X := Sqrt (1.0 + X);
>    end loop;

Did you try with -gnatp?

A.

-- 
Aaro Koskinen, aaro@iki.fi, http://www.iki.fi/aaro



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
  2001-12-07 15:16       ` Aaro Koskinen
@ 2001-12-07 16:16       ` Preben Randhol
  2001-12-07 17:04         ` Jacob Sparre Andersen
  2001-12-07 16:26       ` Ted Dennison
                         ` (4 subsequent siblings)
  6 siblings, 1 reply; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 16:16 UTC (permalink / raw)


On Fri, 07 Dec 2001 14:21:47 +0100, Jacob Sparre Andersen wrote:
> 
> Related to that, I have two simple, apparantly equivalent
> programs written in respectively Ada and C++, where the GNU
> Ada and C++ compilers find it difficult to produce even
> roughly equivalent binary code or processing speed.
> 
>  * Why are the two programs below not equivalent?
>  * How can I get the Ada program to run as fast as the C++
> program?

Did you use the same gcc compiler?

-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
  2001-12-07 15:16       ` Aaro Koskinen
  2001-12-07 16:16       ` Preben Randhol
@ 2001-12-07 16:26       ` Ted Dennison
  2001-12-07 17:08         ` Jacob Sparre Andersen
  2001-12-07 16:45       ` Georg Bauhaus
                         ` (3 subsequent siblings)
  6 siblings, 1 reply; 74+ messages in thread
From: Ted Dennison @ 2001-12-07 16:26 UTC (permalink / raw)


In article <3C10C26B.AA451459@nbi.dk>, Jacob Sparre Andersen says...
>
>Related to that, I have two simple, apparantly equivalent
>programs written in respectively Ada and C++, where the GNU
>Ada and C++ compilers find it difficult to produce even
>roughly equivalent binary code or processing speed.
.
>   Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
..
>   cout << x << endl;

Is that including these lines? These are two *very* different IO systems. I
think in his example Robert used C's printf in both programs.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
                         ` (2 preceding siblings ...)
  2001-12-07 16:26       ` Ted Dennison
@ 2001-12-07 16:45       ` Georg Bauhaus
  2001-12-07 17:02         ` Preben Randhol
  2001-12-07 17:10         ` Jacob Sparre Andersen
  2001-12-07 18:12       ` Pascal Obry
                         ` (2 subsequent siblings)
  6 siblings, 2 replies; 74+ messages in thread
From: Georg Bauhaus @ 2001-12-07 16:45 UTC (permalink / raw)


Jacob Sparre Andersen <sparre@nbi.dk> wrote:
 
: * Why are the two programs below not equivalent?
: * How can I get the Ada program to run as fast as the C++
: program?
 
: with Ada.Numerics.Generic_Elementary_Functions;
: #include <math.h>

do the two sqrts in effect refer to the same routines?

:   Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
 
:   cout << x << endl;

have you tried with redirection to a null device,
or with no output? (terminal I/O might really slow thing
down.)


Georg



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 15:16       ` Aaro Koskinen
@ 2001-12-07 16:50         ` Preben Randhol
  2001-12-07 17:03           ` Jacob Sparre Andersen
  2001-12-07 17:11           ` Ted Dennison
  0 siblings, 2 replies; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 16:50 UTC (permalink / raw)


On 07 Dec 2001 17:16:18 +0200, Aaro Koskinen wrote:
> Jacob Sparre Andersen <sparre@nbi.dk> writes:
>>  * Why are the two programs below not equivalent?
>>  * How can I get the Ada program to run as fast as the C++ program?
> [..]
>> Compilation...: gnatmake sqrt_timer -O3 -gnatn
> [..]
>>    for i in 1 .. 10_000_000 loop
>>       X := Sqrt (1.0 + X);
>>    end loop;
> 
> Did you try with -gnatp?

I tried to add the -gnatp switch. I compiled the Ada programs twice with
the -O3 and -S switches. Whether I add the -gnatp switch or not I get
the exact same assambler source. Is this correct? 

I think the difference between the Ada and C++ program is the Sqrt
function. The assembler source for the ada program is about 2000 lines
while the C++ source is around 100. 

Note that the gcc compiler Ada (GNAT) uses is 2.8.1 while the g++ I
have is 2.95 and 3.0 (unfortunately not 2.8.1).

The execution time are 615ms for the 2.95 while 1041ms for 3.0.
So the gcc compiler also plays a role.

I simplified the two programs by removing sqrt (and using Float in Ada)
and then both programs run at the same speed, 66ms.

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 16:45       ` Georg Bauhaus
@ 2001-12-07 17:02         ` Preben Randhol
  2001-12-07 17:10         ` Jacob Sparre Andersen
  1 sibling, 0 replies; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 17:02 UTC (permalink / raw)


On Fri, 7 Dec 2001 16:45:36 +0000 (UTC), Georg Bauhaus wrote:
> Jacob Sparre Andersen <sparre@nbi.dk> wrote:
>  
>: * Why are the two programs below not equivalent?
>: * How can I get the Ada program to run as fast as the C++
>: program?
>  
>: with Ada.Numerics.Generic_Elementary_Functions;
>: #include <math.h>
> 
> do the two sqrts in effect refer to the same routines?

No. This is the problem.

>:   Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
>  
>:   cout << x << endl;
> 
> have you tried with redirection to a null device,
> or with no output? (terminal I/O might really slow thing
> down.)

I tried this too. It reduces the executiuon time with about 6% for C++
and 14% for the Ada program.

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 16:50         ` Preben Randhol
@ 2001-12-07 17:03           ` Jacob Sparre Andersen
  2001-12-07 17:26             ` Aaro Koskinen
  2001-12-07 17:11           ` Ted Dennison
  1 sibling, 1 reply; 74+ messages in thread
From: Jacob Sparre Andersen @ 2001-12-07 17:03 UTC (permalink / raw)


Preben Randhol wrote:

> On 07 Dec 2001 17:16:18 +0200, Aaro Koskinen wrote:
> > Jacob Sparre Andersen <sparre@nbi.dk> writes:
> >>  * Why are the two programs below not equivalent?
> >>  * How can I get the Ada program to run as fast as the C++ program?
> > [..]
> >> Compilation...: gnatmake sqrt_timer -O3 -gnatn
> > [..]
> >>    for i in 1 .. 10_000_000 loop
> >>       X := Sqrt (1.0 + X);
> >>    end loop;
> >
> > Did you try with -gnatp?

I have tried both "-gnatp", "-funroll-loops" and other flags
without any significant change in the timing results.

> I tried to add the -gnatp switch. I compiled the Ada programs twice with
> the -O3 and -S switches. Whether I add the -gnatp switch or not I get
> the exact same assambler source. Is this correct?

That's very likely. There is no need for range checks on the
counter, and I seem to remember that the floating point
operations (in x86 processors) can check for exceptions
without extra code.

> I think the difference between the Ada and C++ program is the Sqrt
> function.

Certainly. (On ix86 processors) GNU C++ inlines the sqrt
operation built into the processor, while GNU Ada makes
calls to a Sqrt function.

> I simplified the two programs by removing sqrt (and using Float in Ada)
> and then both programs run at the same speed, 66ms.

Of course. Then there is no function call to inline.

Jacob
-- 
SSLUG's julekalender - fra den 1. til den 24. december p�:
                           http://www.sslug.dk/julekalender/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 16:16       ` Preben Randhol
@ 2001-12-07 17:04         ` Jacob Sparre Andersen
  0 siblings, 0 replies; 74+ messages in thread
From: Jacob Sparre Andersen @ 2001-12-07 17:04 UTC (permalink / raw)


Preben Randhol wrote:

> On Fri, 07 Dec 2001 14:21:47 +0100, Jacob Sparre Andersen wrote:
> >
> > Related to that, I have two simple, apparantly equivalent
> > programs written in respectively Ada and C++, where the GNU
> > Ada and C++ compilers find it difficult to produce even
> > roughly equivalent binary code or processing speed.
> >
> >  * Why are the two programs below not equivalent?
> >  * How can I get the Ada program to run as fast as the C++
> > program?
> 
> Did you use the same gcc compiler?

No. The problem is that GNU Ada does not inline the Sqrt
function, while GNU C++ inlines the sqrt function.

Jacob
-- 
SSLUG's julekalender - fra den 1. til den 24. december p�:
                           http://www.sslug.dk/julekalender/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 16:26       ` Ted Dennison
@ 2001-12-07 17:08         ` Jacob Sparre Andersen
  2001-12-09 12:27           ` Robert Dewar
  0 siblings, 1 reply; 74+ messages in thread
From: Jacob Sparre Andersen @ 2001-12-07 17:08 UTC (permalink / raw)


Ted Dennison wrote:

> >   Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
> ..
> >   cout << x << endl;
> 
> Is that including these lines? These are two *very* different IO systems. I
> think in his example Robert used C's printf in both programs.

It includes those lines, but I can assure you that the
results are similar without those lines. I just print the
results, to make sure that clever compilers don't remove the
loop completely.

When I look at the corresponding assembler code (gnatgcc
-S/g++ -S) I can see that GNU C++ inlines the square root
function, while GNU Ada doesn't.

Jacob
-- 
SSLUG's julekalender - fra den 1. til den 24. december p�:
                           http://www.sslug.dk/julekalender/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 16:45       ` Georg Bauhaus
  2001-12-07 17:02         ` Preben Randhol
@ 2001-12-07 17:10         ` Jacob Sparre Andersen
  1 sibling, 0 replies; 74+ messages in thread
From: Jacob Sparre Andersen @ 2001-12-07 17:10 UTC (permalink / raw)


Georg Bauhaus wrote:

> Jacob Sparre Andersen <sparre@nbi.dk> wrote:
> 
> : * Why are the two programs below not equivalent?
> : * How can I get the Ada program to run as fast as the C++
> : program?
> 
> : with Ada.Numerics.Generic_Elementary_Functions;
> : #include <math.h>
> 
> do the two sqrts in effect refer to the same routines?

I can not see why they shouldn't.

> :   Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
> 
> :   cout << x << endl;
> 
> have you tried with redirection to a null device,
> or with no output? (terminal I/O might really slow thing
> down.)

I have tried with 100_000_000 iterations, and found about
ten times as long execution times, as with 10_000_000
iterations.

Jacob
-- 
SSLUG's julekalender - fra den 1. til den 24. december p�:
                           http://www.sslug.dk/julekalender/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 16:50         ` Preben Randhol
  2001-12-07 17:03           ` Jacob Sparre Andersen
@ 2001-12-07 17:11           ` Ted Dennison
  2001-12-07 18:47             ` Preben Randhol
  1 sibling, 1 reply; 74+ messages in thread
From: Ted Dennison @ 2001-12-07 17:11 UTC (permalink / raw)


In article <slrna11smo.h4g.randhol+abuse@kiuk0156.chembio.ntnu.no>, Preben
Randhol says...
>
>Note that the gcc compiler Ada (GNAT) uses is 2.8.1 while the g++ I
>have is 2.95 and 3.0 (unfortunately not 2.8.1).

Whoa! So we are really talking about two completely different back ends here.

I'd suggest C-izing it (not too tough, just change the IO I think), and
compiling it with gnat's gcc. Either that, or take the latest GCC with Gnat and
g++ from the CVS tree and try that.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 17:03           ` Jacob Sparre Andersen
@ 2001-12-07 17:26             ` Aaro Koskinen
  2001-12-07 18:32               ` Preben Randhol
  2001-12-07 20:23               ` Wes Groleau
  0 siblings, 2 replies; 74+ messages in thread
From: Aaro Koskinen @ 2001-12-07 17:26 UTC (permalink / raw)


Jacob Sparre Andersen <sparre@nbi.dk> writes:
> Certainly. (On ix86 processors) GNU C++ inlines the sqrt
> operation built into the processor, while GNU Ada makes
> calls to a Sqrt function.

I thought GNAT could do this as well, there's the following comment in
Numerics.Aux:
--  This package provides the basic computational interface for the generic
--  elementary functions. The C library version interfaces with the routines
--  in the C mathematical library, and is thus quite portable, although it may
--  not necessarily meet the requirements for accuracy in the numerics annex.
--  One advantage of using this package is that it will interface directly to
--  hardware instructions, such as the those provided on the Intel 80x87.
[...]
   function Sqrt (X : Double) return Double;
   pragma Import (C, Sqrt, "sqrt");

A.

-- 
Aaro Koskinen, aaro@iki.fi, http://www.iki.fi/aaro



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
                         ` (3 preceding siblings ...)
  2001-12-07 16:45       ` Georg Bauhaus
@ 2001-12-07 18:12       ` Pascal Obry
  2001-12-07 18:50         ` Preben Randhol
  2001-12-07 18:19       ` Jeffrey Carter
  2001-12-10  9:59       ` Ole-Hjalmar Kristensen
  6 siblings, 1 reply; 74+ messages in thread
From: Pascal Obry @ 2001-12-07 18:12 UTC (permalink / raw)



Jacob Sparre Andersen <sparre@nbi.dk> writes:

> Yes.
> 
> Related to that, I have two simple, apparantly equivalent
> programs written in respectively Ada and C++, where the GNU
> Ada and C++ compilers find it difficult to produce even
> roughly equivalent binary code or processing speed.
> 
>  * Why are the two programs below not equivalent?
>  * How can I get the Ada program to run as fast as the C++
> program?
> 
> Ada:
> 
> Compilation...: gnatmake sqrt_timer -O3 -gnatn
> Execution time: 3460 ms
> Source code:
> 
> 
> Compilation...: g++ sqrt_timer.cpp -O3
> Execution time: 1460 ms
> Source code:

You certainly want to add -gnatp to have at least two programs close enough to
compare. Note that I have the following results:

- GCC 2.95.2

   > time tsqr
   1.61803

   real  0m 0.86s
   user  0m 0.80s
   sys   0m 0.01s

- GNAT 3.x

   > time sqrt_timer
   X =  1.61803398874989E+00

   real  0m 1.38s
   user  0m 1.38s
   sys   0m 0.01s

- GNAT 5.0


   > time sqrt_timer
   X =  1.61803398874989E+00

   real  0m 1.11s
   user  0m 1.10s
   sys   0m 0.01s

I'm not an expert here but I think most of the difference between the C++ and
Ada version is in the way Sqrt is implemented. Ada put some constraints on the
Sqrt accuracy.

Anyway here the difference is not as big as what you have reported.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
                         ` (4 preceding siblings ...)
  2001-12-07 18:12       ` Pascal Obry
@ 2001-12-07 18:19       ` Jeffrey Carter
  2001-12-10  9:59       ` Ole-Hjalmar Kristensen
  6 siblings, 0 replies; 74+ messages in thread
From: Jeffrey Carter @ 2001-12-07 18:19 UTC (permalink / raw)


Jacob Sparre Andersen wrote:
>  * Why are the two programs below not equivalent?
>  * How can I get the Ada program to run as fast as the C++
> program?
> 
> Ada:
> 
> Compilation...: gnatmake sqrt_timer -O3 -gnatn
> Execution time: 3460 ms
> Source code:
> 
> with Ada.Numerics.Generic_Elementary_Functions;
> with Ada.Text_IO;
> with Interfaces.C;
> 
> procedure Sqrt_Timer is
> 
>    type Scalar is new Interfaces.C.Double;
> 
>    package Math is new
> Ada.Numerics.Generic_Elementary_Functions (Scalar);
> 
>    function Sqrt (Item : in Scalar) return Scalar renames
> Math.Sqrt;
>    pragma Inline (Sqrt);
> 
>    X : Scalar := 2.0;
> 
> begin  --  Sqrt_Timer
>    for i in 1 .. 10_000_000 loop
>       X := Sqrt (1.0 + X);
>    end loop;
> 
>    Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
> end Sqrt_Timer;
> 
> C++
> ===
> 
> Compilation...: g++ sqrt_timer.cpp -O3
> Execution time: 1460 ms
> Source code:
> 
> #include <math.h>
> #include <iostream.h>
> 
> int main (int argl,char* argv[]) {
> 
>    double x=2.0;
> 
>    for(int i=0;i<10000000;i++){
>       x=sqrt(1.0+x);
>    };
> 
>    cout << x << endl;
> };

Turn off runtime checks in Ada, or add them to the C++.

Ada's Sqrt is pickier than C/++'s; use the C sqrt from Ada.

C++'s for is really a while preceded by an assignment with an increment
added at the end; use the same structure in Ada.

Make C++ output "X = ", too.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 17:26             ` Aaro Koskinen
@ 2001-12-07 18:32               ` Preben Randhol
  2001-12-07 20:23               ` Wes Groleau
  1 sibling, 0 replies; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 18:32 UTC (permalink / raw)


On 07 Dec 2001 19:26:00 +0200, Aaro Koskinen wrote:
> Jacob Sparre Andersen <sparre@nbi.dk> writes:
>> Certainly. (On ix86 processors) GNU C++ inlines the sqrt
>> operation built into the processor, while GNU Ada makes
>> calls to a Sqrt function.
> 
> I thought GNAT could do this as well, there's the following comment in
> Numerics.Aux:
> --  This package provides the basic computational interface for the generic
> --  elementary functions. The C library version interfaces with the routines
> --  in the C mathematical library, and is thus quite portable, although it may
> --  not necessarily meet the requirements for accuracy in the numerics annex.
> --  One advantage of using this package is that it will interface directly to
> --  hardware instructions, such as the those provided on the Intel 80x87.
> [...]
>    function Sqrt (X : Double) return Double;
>    pragma Import (C, Sqrt, "sqrt");

Using Ada.Numerics.Aux result in the same execution time roughly. But
now if I remove the Put_Line statement and use -O3 the whole loop is
removed by the optimiser :-)

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 17:11           ` Ted Dennison
@ 2001-12-07 18:47             ` Preben Randhol
  0 siblings, 0 replies; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 18:47 UTC (permalink / raw)


On Fri, 07 Dec 2001 17:11:15 GMT, Ted Dennison wrote:
> In article <slrna11smo.h4g.randhol+abuse@kiuk0156.chembio.ntnu.no>, Preben
> Randhol says...
>>
>>Note that the gcc compiler Ada (GNAT) uses is 2.8.1 while the g++ I
>>have is 2.95 and 3.0 (unfortunately not 2.8.1).
> 
> Whoa! So we are really talking about two completely different back ends here.
> 
> I'd suggest C-izing it (not too tough, just change the IO I think), and
> compiling it with gnat's gcc. Either that, or take the latest GCC with Gnat and
> g++ from the CVS tree and try that.

I changed it to C and used gnatgcc and got 544ms while the Ada program
with Ada.Numeric.Aux uses 2794ms with -gnatp.

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 18:12       ` Pascal Obry
@ 2001-12-07 18:50         ` Preben Randhol
  2001-12-07 18:54           ` Pascal Obry
  0 siblings, 1 reply; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 18:50 UTC (permalink / raw)


On 07 Dec 2001 19:12:02 +0100, Pascal Obry wrote:
> - GNAT 5.0

Is this the cvs version of Gnat with gcc 3.0?

> 
> I'm not an expert here but I think most of the difference between the C++ and
> Ada version is in the way Sqrt is implemented. Ada put some constraints on the
> Sqrt accuracy.
> 
> Anyway here the difference is not as big as what you have reported.

Well that depends on the gcc version of GNAT 5.0

-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 18:50         ` Preben Randhol
@ 2001-12-07 18:54           ` Pascal Obry
  2001-12-07 20:40             ` Preben Randhol
  0 siblings, 1 reply; 74+ messages in thread
From: Pascal Obry @ 2001-12-07 18:54 UTC (permalink / raw)



Preben Randhol <randhol+abuse@pvv.org> writes:

> On 07 Dec 2001 19:12:02 +0100, Pascal Obry wrote:
> > - GNAT 5.0
> 
> Is this the cvs version of Gnat with gcc 3.0?

It is using a 3 weeks old GCC 3.0 cvs tree.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-06  4:25               ` Richard Riehle
@ 2001-12-07 20:02                 ` Hyman Rosen
  2001-12-09 19:32                   ` Richard Riehle
  0 siblings, 1 reply; 74+ messages in thread
From: Hyman Rosen @ 2001-12-07 20:02 UTC (permalink / raw)


Richard Riehle <richard@adaworks.com> wrote in message news:<3C0EF345.47BCC09@adaworks.com>...
> Practically,  C++ inline functions are a bit of a nuisance since, in a class
> definition, one must fully code the implementation when in-lining.  That
> is, C++ inline requires one to trade off the practical benefits of separate
> compilation for the practical benefits of in-lined code.

In C++ it is perfectly legal to separate the declaration of a function
from its implementation, even when it's inline:

    struct a { int twice(int x); };
    inline int a::twice(int x) { return 2 * x; }

Any code which wants to call the function must arrange to see the definition,
which is usually done through an #include. In Ada, the compiler can manage to
find the definition on its own, because of the library system, but that's not
exactly "separate compilation".



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 17:26             ` Aaro Koskinen
  2001-12-07 18:32               ` Preben Randhol
@ 2001-12-07 20:23               ` Wes Groleau
  1 sibling, 0 replies; 74+ messages in thread
From: Wes Groleau @ 2001-12-07 20:23 UTC (permalink / raw)




Aaro Koskinen wrote:
> --  elementary functions. The C library version interfaces with the routines
> --  in the C mathematical library, and is thus quite portable, although it may
> --  not necessarily meet the requirements for accuracy in the numerics annex.

On Solaris, it does not meet those requirements.

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 18:54           ` Pascal Obry
@ 2001-12-07 20:40             ` Preben Randhol
  2001-12-07 22:01               ` Pascal Obry
  0 siblings, 1 reply; 74+ messages in thread
From: Preben Randhol @ 2001-12-07 20:40 UTC (permalink / raw)


On 07 Dec 2001 19:54:20 +0100, Pascal Obry wrote:
> 
> Preben Randhol <randhol+abuse@pvv.org> writes:
> 
>> On 07 Dec 2001 19:12:02 +0100, Pascal Obry wrote:
>> > - GNAT 5.0
>> 
>> Is this the cvs version of Gnat with gcc 3.0?
> 
> It is using a 3 weeks old GCC 3.0 cvs tree.

:-) Nice. Is it much hassel to compile on linux?

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 20:40             ` Preben Randhol
@ 2001-12-07 22:01               ` Pascal Obry
  0 siblings, 0 replies; 74+ messages in thread
From: Pascal Obry @ 2001-12-07 22:01 UTC (permalink / raw)



Preben Randhol <randhol+abuse@pvv.org> writes:

> :-) Nice. Is it much hassel to compile on linux?

I don't know, I have never built it on Linux but I would expect this not to be
that difficult. The main problem is that the GCC cvs tree is changing a lot
and sometimes even the C compiler does not build fine. Try to build one day
and if it does not work, try next day and if it does not...

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 17:08         ` Jacob Sparre Andersen
@ 2001-12-09 12:27           ` Robert Dewar
  2001-12-10 16:51             ` Jacob Sparre Andersen
  0 siblings, 1 reply; 74+ messages in thread
From: Robert Dewar @ 2001-12-09 12:27 UTC (permalink / raw)


Jacob Sparre Andersen <sparre@nbi.dk> wrote in message news:<3C10F77E.6BDD9A3B@nbi.dk>...
> When I look at the corresponding assembler code (gnatgcc
> -S/g++ -S) I can see that GNU C++ inlines the square root
> function, while GNU Ada doesn't.


You seem to be assuming that the function called square root in C++
and the function called square root in Ada
are the same function, presumably because their names
are similar, and both are usable in your context, but they
are not at all the same routine. The Ada routine has additional
semantics not present in the C++ routine (e.g.
the handling of -0.0 which is required to return -0.0).
Is this just a theoretical issue? Not at all. Look at the
coding for Sqrt in a-ngelfu.adb:

   function Sqrt (X : Float_Type'Base) return 
                                     Float_Type'Base is
   begin
      if X < 0.0 then
         raise Argument_Error;

      --  Special case Sqrt (0.0) to preserve possible 
      --  minus sign per IEEE

      elsif X = 0.0 then
         return X;

      end if;

      return Float_Type'Base (Aux.Sqrt (Double (X)));
   end Sqrt;

Those extra tests take significant time. Now one can sit
back and say "Ada is a junk language, it insists on testing
for errors at runtime, and in giving accurate IEEE results,
and I don't need either", but that's not a very reasonable
position given that if you like you can easily call the
C routine directly, since Ada, unlike other languages,
carefully defines the syntax and semantics of calling routines written
in other languages :-)



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-02 10:07     ` Mark Lundquist
  2001-12-03 14:43       ` Ted Dennison
@ 2001-12-09 12:31       ` Robert Dewar
  1 sibling, 0 replies; 74+ messages in thread
From: Robert Dewar @ 2001-12-09 12:31 UTC (permalink / raw)


"Mark Lundquist" <mlundquist2@attbi.com> wrote in message news:<S3nO7.2430$KY6.1181@rwcrnsc53>...
> You also might consider using gnatprep to conditionalize 
> these pragmas so
> that you only turn them on when doing the "production" 
> build of the program.

I find that a bit of a junky approach. I think you will
do better simply to have different build options using
-gnatp for selected units if necessary for performance.
This is particularly convenient if you are using the
new project management facilities in GNAT Pro.

P.S. Everyone surely agrees that it is a good idea to have
checks on while testing, but it is not so clear that it is
always better to have checks on for deployment. Remember 
that an unhandled exception can be a much worse disease
than an incorrect non-critical result (the Ariane folks
know that well).



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 20:02                 ` Hyman Rosen
@ 2001-12-09 19:32                   ` Richard Riehle
  2001-12-11 16:14                     ` Hyman Rosen
  0 siblings, 1 reply; 74+ messages in thread
From: Richard Riehle @ 2001-12-09 19:32 UTC (permalink / raw)


Hyman Rosen wrote:

> In C++ it is perfectly legal to separate the declaration of a function
> from its implementation, even when it's inline:
>
>     struct a { int twice(int x); };
>     inline int a::twice(int x) { return 2 * x; }

Unless something has changed, C++ requires the full definition of the
inlined function at the place where it is declared.   Stroustrup does make
a little exception for this in his note about the "absence of unusually
clever compilation and linking facilities" (The C++ Programming
Language, Third Edition, page 144).    At present, the most compilers
require full definition in the header file.

> Any code which wants to call the function must arrange to see the definition,
> which is usually done through an #include. In Ada, the compiler can manage to
> find the definition on its own, because of the library system, but that's not
> exactly "separate compilation".

Well, actually, it is separate compilation.  Of course, if one chooses to use
some new definition of separate compilation, so be it.


Ada permits the designer to specify a declaration in the package specification
as inlined:

      package Not_C_Plus_Plus is
           procedure Friendly_Inline;
           pragma Inline(Friendly_Inline); -- no full definition required or permitted
      end Not_C_Plus_Plus;

This specification is compiled independently of its implementation.  If we really
want to defer the implementation to another separate compilation, we could,


    package body Not_C_Plus_Plus is
           procedure Friendly_Inline is separate;
      end Not_C_Plus_Plus;

thereby separating the compilation of the [definition of] the implementing
code to yet another separate subunit.

    separate (Not_C_Plus_Plus)
    procedure Friendly_Inline is
    begin
        -- algorithmic implementation
    end Friendly_Inline;

The library unit model of Ada, along with its many facilities for separate
compilation are one of the useful features of the language.    In fact, Ada's
separate compilation  helps maintain consistency across multiple library
units when development is being performed by multiple programmers.
The need for a #include, along with associated compiler directives in C++
is not as robust a model for preserving unit integrity as the Ada model,
even though the C++ model does have some offsetting advantages under
some circumstances.

Richard Riehle









^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-07 13:21     ` Jacob Sparre Andersen
                         ` (5 preceding siblings ...)
  2001-12-07 18:19       ` Jeffrey Carter
@ 2001-12-10  9:59       ` Ole-Hjalmar Kristensen
  6 siblings, 0 replies; 74+ messages in thread
From: Ole-Hjalmar Kristensen @ 2001-12-10  9:59 UTC (permalink / raw)


Jacob Sparre Andersen <sparre@nbi.dk> writes:

> Jeffrey Carter wrote:
> 
> > Robert Dewar has stated here on several occasions that he has some
> > equivalent Ada and C programs that produce identical object code when
> > compiled with gcc.
> 
> Yes.
> 
> Related to that, I have two simple, apparantly equivalent
> programs written in respectively Ada and C++, where the GNU
> Ada and C++ compilers find it difficult to produce even
> roughly equivalent binary code or processing speed.
> 
>  * Why are the two programs below not equivalent?
>  * How can I get the Ada program to run as fast as the C++
> program?

It's probably not a good idea to include IO in testts like this. The
buffer strategy used by the different IO libraries may give very
different results.

> 
> Ada:
> 
> Compilation...: gnatmake sqrt_timer -O3 -gnatn
> Execution time: 3460 ms
> Source code:
> 
> with Ada.Numerics.Generic_Elementary_Functions;
> with Ada.Text_IO;
> with Interfaces.C;
> 
> procedure Sqrt_Timer is
> 
>    type Scalar is new Interfaces.C.Double;
> 
>    package Math is new
> Ada.Numerics.Generic_Elementary_Functions (Scalar);
> 
>    function Sqrt (Item : in Scalar) return Scalar renames
> Math.Sqrt;
>    pragma Inline (Sqrt);
> 
>    X : Scalar := 2.0;
> 
> begin  --  Sqrt_Timer
>    for i in 1 .. 10_000_000 loop
>       X := Sqrt (1.0 + X);
>    end loop;
> 
>    Ada.Text_IO.Put_Line ("X = " & Scalar'Image (X));
> end Sqrt_Timer;
> 
> 
> C++
> ===
> 
> Compilation...: g++ sqrt_timer.cpp -O3
> Execution time: 1460 ms
> Source code:
> 
> #include <math.h>
> #include <iostream.h>
> 
> int main (int argl,char* argv[]) {
> 
>    double x=2.0;
> 
>    for(int i=0;i<10000000;i++){
>       x=sqrt(1.0+x);
>    };
> 
>    cout << x << endl;
> };
> 
> 
> Jacob
> -- 
> SSLUG's julekalender - fra den 1. til den 24. december p�:
>                            http://www.sslug.dk/julekalender/

-- 
Kabelsalat ist gesund.

Ole-Hj. Kristensen



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-01  1:43 ` Aaro Koskinen
  2001-12-03  8:49   ` John McCabe
@ 2001-12-10 15:18   ` Dale Pontius
  2001-12-10 17:44     ` Pascal Obry
  1 sibling, 1 reply; 74+ messages in thread
From: Dale Pontius @ 2001-12-10 15:18 UTC (permalink / raw)


In article <pdxu1vb67fq.fsf@sirppi.helsinki.fi>,
        aaro@iki.fi (Aaro Koskinen) writes:
...
> (Also, I would imagine that with Ada's strong typing, the compiler can
> do better optimizations than an average C compiler. However, I don't
> have any evidence for this...)

I've always heard and felt this, too. However I wonder if theory and
practice unfortunately differ here, due to the overwhelming popularity
of C and its ilk.

Take gnat as an example. It's a front-end for gcc, which is itself
developed primarily in C. So granting that strong typing allows better
optimization, is the back-end smart enough to use the extra information?
The primary role for the gcc back-end is for C and C++ front-ends, and
most likely C doesn't give extra type-enabled optimization information.
Does C++ send such information to the back-end?

In other words, I suspect only a custom/dedicated/tuned Ada compiler
will (not can, but will) optimize better than a C compiler, simply due
to marketplace forces.

Dale Pontius
NOT speaking for IBM



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-09 12:27           ` Robert Dewar
@ 2001-12-10 16:51             ` Jacob Sparre Andersen
  2001-12-10 17:33               ` Jeff Creem
  0 siblings, 1 reply; 74+ messages in thread
From: Jacob Sparre Andersen @ 2001-12-10 16:51 UTC (permalink / raw)


Robert Dewar wrote:

> Jacob Sparre Andersen <sparre@nbi.dk> wrote in message news:<3C10F77E.6BDD9A3B@nbi.dk>...
> > When I look at the corresponding assembler code (gnatgcc
> > -S/g++ -S) I can see that GNU C++ inlines the square root
> > function, while GNU Ada doesn't.
> 
> You seem to be assuming that the function called square root in C++
> and the function called square root in Ada
> are the same function,

Correct.

> presumably because their names
> are similar, and both are usable in your context, but they
> are not at all the same routine. The Ada routine has additional
> semantics not present in the C++ routine (e.g.
> the handling of -0.0 which is required to return -0.0).

I had forgotten (or had not noticed) this.

> Those extra tests take significant time. Now one can sit
> back and say "Ada is a junk language, it insists on testing
> for errors at runtime, and in giving accurate IEEE results,
> and I don't need either",

I happen to need accurate results, and I appreciate being
able to specify things like the number of significant digits
in my floating point types. But I am (as a physicist) not
used to -0.0 being different from +0.0, nor to being unable
to calculate the square root of -0.0, as your explanations
seem to indicate that IEEE floating point processors are.

> but that's not a very reasonable
> position given that if you like you can easily call the
> C routine directly, since Ada, unlike other languages,
> carefully defines the syntax and semantics of calling routines written
> in other languages :-)

Since I - in the example program - know that the values will
never get close to zero, I suppose that I can use the C
function "sqrt".

Jacob
-- 
I teorien lyver folk ikke i retten.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-10 16:51             ` Jacob Sparre Andersen
@ 2001-12-10 17:33               ` Jeff Creem
  0 siblings, 0 replies; 74+ messages in thread
From: Jeff Creem @ 2001-12-10 17:33 UTC (permalink / raw)


Note that if you are really interested in the performance difference of
the two discussed square roots you may want to look for a few minutes
at the instruction set of your computer and your problem domain since
there is sometimes an instruction that calculates the 1/sqrt(x) which can
then be used in places where you had code like  Y := B / SQRT(X) which
can now be  Y := B * my_sqrt_recip(X).   If your processor has and
instruction like
this it can save a few cycles.   I use this as an example but there may be
other cases where
things like this can be found.

A small package machine_code coded special purpose math library can
sometimes really
help in tight loops. (And of course it can be a fun waste of time in not so
tight loops :)





"Jacob Sparre Andersen" <sparre@nbi.dk> wrote in message
news:3C14E817.8A2E798E@nbi.dk...
> Robert Dewar wrote:
>
> > Jacob Sparre Andersen <sparre@nbi.dk> wrote in message
news:<3C10F77E.6BDD9A3B@nbi.dk>...
> > > When I look at the corresponding assembler code (gnatgcc
> > > -S/g++ -S) I can see that GNU C++ inlines the square root
> > > function, while GNU Ada doesn't.
> >
> > You seem to be assuming that the function called square root in C++
> > and the function called square root in Ada
> > are the same function,
>
> Correct.
>
> > presumably because their names
> > are similar, and both are usable in your context, but they
> > are not at all the same routine. The Ada routine has additional
> > semantics not present in the C++ routine (e.g.
> > the handling of -0.0 which is required to return -0.0).
>
> I had forgotten (or had not noticed) this.
>
> > Those extra tests take significant time. Now one can sit
> > back and say "Ada is a junk language, it insists on testing
> > for errors at runtime, and in giving accurate IEEE results,
> > and I don't need either",
>
> I happen to need accurate results, and I appreciate being
> able to specify things like the number of significant digits
> in my floating point types. But I am (as a physicist) not
> used to -0.0 being different from +0.0, nor to being unable
> to calculate the square root of -0.0, as your explanations
> seem to indicate that IEEE floating point processors are.
>
> > but that's not a very reasonable
> > position given that if you like you can easily call the
> > C routine directly, since Ada, unlike other languages,
> > carefully defines the syntax and semantics of calling routines written
> > in other languages :-)
>
> Since I - in the example program - know that the values will
> never get close to zero, I suppose that I can use the C
> function "sqrt".
>
> Jacob
> --
> I teorien lyver folk ikke i retten.





^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-10 15:18   ` Dale Pontius
@ 2001-12-10 17:44     ` Pascal Obry
  0 siblings, 0 replies; 74+ messages in thread
From: Pascal Obry @ 2001-12-10 17:44 UTC (permalink / raw)



pontius@btv.MBI.com.invalid (Dale Pontius) writes:

> In article <pdxu1vb67fq.fsf@sirppi.helsinki.fi>,
>         aaro@iki.fi (Aaro Koskinen) writes:
> ...
> > (Also, I would imagine that with Ada's strong typing, the compiler can
> > do better optimizations than an average C compiler. However, I don't
> > have any evidence for this...)
> 
> I've always heard and felt this, too. However I wonder if theory and
> practice unfortunately differ here, due to the overwhelming popularity
> of C and its ilk.
> 
> Take gnat as an example. It's a front-end for gcc, which is itself
> developed primarily in C. So granting that strong typing allows better
> optimization, is the back-end smart enough to use the extra information?

Well GNAT backend is GCC backend heavily patched!

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|         http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-09 19:32                   ` Richard Riehle
@ 2001-12-11 16:14                     ` Hyman Rosen
  2001-12-14  0:36                       ` Will
  2001-12-17 17:37                       ` Richard Riehle
  0 siblings, 2 replies; 74+ messages in thread
From: Hyman Rosen @ 2001-12-11 16:14 UTC (permalink / raw)


Richard Riehle <richard@adaworks.com> wrote in message news:<3C13BC4A.1C1EBE8B@adaworks.com>...
> Well, actually, it is separate compilation.  Of course, if one chooses to use
> some new definition of separate compilation, so be it.

If you look at 10.1.4/7, you will see that Ada allows an implementation
to force the recompilation of any compilation unit which calls an inlined
subprogram whenever the body of that subprogram changes.

The normal definition of separate compilation is exactly the opposite of
this - making changes to a subprogram, as long as you don't change its
interface, never requires recompiling the callers.

Notice that this is not a criticism of Ada. Ada, just like C++, very
reasonably allows compilers to require access to the body of an inlined
subprogram when compiling its callers. C++, not having Ada's library
system, just forces the function definition to be in scope at a call.

> Unless something has changed, C++ requires the full definition of the
> inlined function at the place where it is declared.

That simply is not true. Just as I posted, the definition of an inline
function may be separate from its declaration.



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-11 16:14                     ` Hyman Rosen
@ 2001-12-14  0:36                       ` Will
  2001-12-19 22:23                         ` Hyman Rosen
  2001-12-17 17:37                       ` Richard Riehle
  1 sibling, 1 reply; 74+ messages in thread
From: Will @ 2001-12-14  0:36 UTC (permalink / raw)


hyrosen@mail.com (Hyman Rosen) wrote in message news:<568ede3c.0112110814.1c31fd91@posting.google.com>...
> > Unless something has changed, C++ requires the full definition of the
> > inlined function at the place where it is declared.
> 
> That simply is not true. Just as I posted, the definition of an inline
> function may be separate from its declaration.

actually,
main.cpp:

inline int callme();
main()
{
	callme();
}

test.cpp:

inline int callme()
{
return 0;
}

will not compile. Tested with g++ and Visual C++



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-11 16:14                     ` Hyman Rosen
  2001-12-14  0:36                       ` Will
@ 2001-12-17 17:37                       ` Richard Riehle
  2001-12-20 23:02                         ` Hyman Rosen
  1 sibling, 1 reply; 74+ messages in thread
From: Richard Riehle @ 2001-12-17 17:37 UTC (permalink / raw)


Hyman Rosen wrote:

> Richard Riehle <richard@adaworks.com> wrote in message news:<3C13BC4A.1C1EBE8B@adaworks.com>...
> > Well, actually, it is separate compilation.  Of course, if one chooses to use
> > some new definition of separate compilation, so be it.
>
> If you look at 10.1.4/7, you will see that Ada allows an implementation
> to force the recompilation of any compilation unit which calls an inlined
> subprogram whenever the body of that subprogram changes.

This is not an unreasonable permission given the meaning of term "inline."

> The normal definition of separate compilation is exactly the opposite of
> this - making changes to a subprogram, as long as you don't change its
> interface, never requires recompiling the callers.

With the exception of "inline" this is exactly what Ada does.   Therefore,
I would continue to call it separate compilation.


> > Unless something has changed, C++ requires the full definition of the
> > inlined function at the place where it is declared.
>
> That simply is not true. Just as I posted, the definition of an inline
> function may be separate from its declaration.

I mentioned earlier that Stroustrup's advice is to put the full definition
at the point of declaration unless you have a very clever development
environment.    Every other C++ authority I can find also recommends
putting the definition in the header.    This is the typical design of a
C++ inlined member function.   When I first started using C++, it was
necessary.    Perhaps that has changed.    Ada never required this, and
does not even permit it.    Under most circumstances, a change to an
implementation in Ada requires only relinking not recompilation.

Richard Riehle







^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-14  0:36                       ` Will
@ 2001-12-19 22:23                         ` Hyman Rosen
  0 siblings, 0 replies; 74+ messages in thread
From: Hyman Rosen @ 2001-12-19 22:23 UTC (permalink / raw)


"Will" <wv9557@yahoo.com> wrote in message
news:4a885870.0112131636.227e2521@posting.google.com...
> main.cpp:
> inline int callme();
> main() { callme(); }
> test.cpp:
> inline int callme() { return 0; }
> will not compile. Tested with g++ and Visual C++

Yes, I know. As I have said, C++ requires that the definition
(i.e., the body) of an inline function must be in scope when it
is called. But you may still have a declaration separate from a
definition, which (apparently) Richard Riehle assumed was not
the case. This means that you can write your classes without
defining the inline methods, and define them separately.

This is legal:
struct a { int f(); };
inline int a::f() { return 0; }
main() { a an_a; an_a.f(); }






^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-17 17:37                       ` Richard Riehle
@ 2001-12-20 23:02                         ` Hyman Rosen
  2001-12-23  4:12                           ` Will
  0 siblings, 1 reply; 74+ messages in thread
From: Hyman Rosen @ 2001-12-20 23:02 UTC (permalink / raw)


"Richard Riehle" <richard@adaworks.com>
wrote in message news:3C1E2D52.7499E107@adaworks.com...
> With the exception of "inline" this is exactly what Ada does.   Therefore,
> I would continue to call it separate compilation.

I am tempted to quote Abraham Lincoln: "If you call a tail a leg,
it still doesn't make it a leg".

We are talking about inline! You claimed that C++ traded off the
benefits of separate compilation against the benefits of inlined code.
I hope I have demonstrated to you that C++ and Ada behave in
exactly the same way with regard to this trade-off, except that Ada
can manage to locate the body of the procedure "by itself" (that is,
Ada programming systems know where to look for a piece of code
once its name is given) and C++ requires the programmer to have
placed the body in scope at the call site.





^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-20 23:02                         ` Hyman Rosen
@ 2001-12-23  4:12                           ` Will
  2001-12-23  6:41                             ` James Rogers
  0 siblings, 1 reply; 74+ messages in thread
From: Will @ 2001-12-23  4:12 UTC (permalink / raw)


"Hyman Rosen" <hyrosen@mail.com> wrote in message news:<1008889302.72075@master.nyc.kbcfp.com>...
> "Richard Riehle" <richard@adaworks.com>
> wrote in message news:3C1E2D52.7499E107@adaworks.com...
> > With the exception of "inline" this is exactly what Ada does.   Therefore,
> > I would continue to call it separate compilation.
> 
> I am tempted to quote Abraham Lincoln: "If you call a tail a leg,
> it still doesn't make it a leg".
> 
> We are talking about inline! You claimed that C++ traded off the
> benefits of separate compilation against the benefits of inlined code.
> I hope I have demonstrated to you that C++ and Ada behave in
> exactly the same way with regard to this trade-off, except that Ada
> can manage to locate the body of the procedure "by itself" (that is,
> Ada programming systems know where to look for a piece of code
> once its name is given) and C++ requires the programmer to have
> placed the body in scope at the call site.

Mr Stroustrup said having 2 inline function with the same name but
defined different is illegal. However both g++ and vc++ are pretty
happy with
having 2 identical inline functions in different files. I 'd think its
not
mandatory for C++ compilers to detect this kind of conflicts. I wonder
how its
resolved in Ada. Search every single file to search for the inline
definition
and scream if two inline functions (of the same name ) are found? Or
be happy with the first inline found? Try guessing by looking at
comments? :)



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
  2001-12-23  4:12                           ` Will
@ 2001-12-23  6:41                             ` James Rogers
  0 siblings, 0 replies; 74+ messages in thread
From: James Rogers @ 2001-12-23  6:41 UTC (permalink / raw)


Will wrote:
> 
> Mr Stroustrup said having 2 inline function with the same name but
> defined different is illegal. However both g++ and vc++ are pretty
> happy with
> having 2 identical inline functions in different files. I 'd think its
> not
> mandatory for C++ compilers to detect this kind of conflicts. I wonder
> how its
> resolved in Ada. Search every single file to search for the inline
> definition
> and scream if two inline functions (of the same name ) are found? Or
> be happy with the first inline found? Try guessing by looking at
> comments? :)

The result will depend upon how the code is written. If the inline
functions with the same name are placed in two different packages,
then no problem arises, since the packages provide a name space for
the functions. If they are defined as stand-alone compilation
units the Ada compiler will either complain about ambiguity or
take the first one found, depending upon the compiler's compilation
model.

Jim Rogers
Colorado Springs, Colorado USA



^ permalink raw reply	[flat|nested] 74+ messages in thread

* Re: What is faster Ada or C?
@ 2001-12-23 10:33 Gautier Write-only-address
  0 siblings, 0 replies; 74+ messages in thread
From: Gautier Write-only-address @ 2001-12-23 10:33 UTC (permalink / raw)
  To: comp.lang.ada

Will:
...
>mandatory for C++ compilers to detect this kind of conflicts.
>I wonder how its resolved in Ada. Search every single file
>to search for the inline definition
>and scream if two inline functions (of the same name ) are found? Or
>be happy with the first inline found? Try guessing by looking at
>comments? :)

My compiler searches source files throughout the hard disk,
then on the Web using http://www.adavista.com/ to find any
conflict.

HTH
________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: Do not answer to sender address, visit the Web site!



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




^ permalink raw reply	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2001-12-23 10:33 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-01  1:22 What is faster Ada or C? Heiko Hamann
2001-12-01  1:43 ` Aaro Koskinen
2001-12-03  8:49   ` John McCabe
2001-12-04 23:00     ` Florian Weimer
2001-12-05 15:53       ` Ted Dennison
2001-12-06  0:17         ` Jeffrey Carter
2001-12-10 15:18   ` Dale Pontius
2001-12-10 17:44     ` Pascal Obry
2001-12-01  3:44 ` Nick Roberts
2001-12-01 20:09   ` Heiko Hamann
2001-12-02  4:49     ` Jeffrey Carter
2001-12-02 10:44       ` Pascal Obry
2001-12-04 11:43       ` john mann
2001-12-04 14:25         ` Ted Dennison
2001-12-05  9:46           ` John McCabe
2001-12-02 10:07     ` Mark Lundquist
2001-12-03 14:43       ` Ted Dennison
2001-12-09 12:31       ` Robert Dewar
2001-12-01  9:26 ` Gisle Sælensminde
2001-12-01 10:13 ` Pascal Obry
2001-12-02 17:49   ` Bertrand Augereau
2001-12-03 14:39 ` Ted Dennison
2001-12-03 16:19   ` Jeffrey Carter
2001-12-03 19:04     ` Ted Dennison
2001-12-03 20:56       ` Georg Bauhaus
2001-12-03 21:17         ` Preben Randhol
2001-12-03 21:20           ` Preben Randhol
2001-12-04 23:02           ` Florian Weimer
2001-12-05 16:05             ` Georg Bauhaus
2001-12-06 23:33               ` Florian Weimer
2001-12-04  2:35         ` Jeffrey Carter
2001-12-04  6:54           ` Steven Deller
2001-12-04 22:05             ` Bertrand Augereau
2001-12-06  4:25               ` Richard Riehle
2001-12-07 20:02                 ` Hyman Rosen
2001-12-09 19:32                   ` Richard Riehle
2001-12-11 16:14                     ` Hyman Rosen
2001-12-14  0:36                       ` Will
2001-12-19 22:23                         ` Hyman Rosen
2001-12-17 17:37                       ` Richard Riehle
2001-12-20 23:02                         ` Hyman Rosen
2001-12-23  4:12                           ` Will
2001-12-23  6:41                             ` James Rogers
2001-12-04 22:37         ` Pascal Obry
2001-12-05 15:57           ` Georg Bauhaus
2001-12-05 17:12             ` Larry Kilgallen
2001-12-07 13:21     ` Jacob Sparre Andersen
2001-12-07 15:16       ` Aaro Koskinen
2001-12-07 16:50         ` Preben Randhol
2001-12-07 17:03           ` Jacob Sparre Andersen
2001-12-07 17:26             ` Aaro Koskinen
2001-12-07 18:32               ` Preben Randhol
2001-12-07 20:23               ` Wes Groleau
2001-12-07 17:11           ` Ted Dennison
2001-12-07 18:47             ` Preben Randhol
2001-12-07 16:16       ` Preben Randhol
2001-12-07 17:04         ` Jacob Sparre Andersen
2001-12-07 16:26       ` Ted Dennison
2001-12-07 17:08         ` Jacob Sparre Andersen
2001-12-09 12:27           ` Robert Dewar
2001-12-10 16:51             ` Jacob Sparre Andersen
2001-12-10 17:33               ` Jeff Creem
2001-12-07 16:45       ` Georg Bauhaus
2001-12-07 17:02         ` Preben Randhol
2001-12-07 17:10         ` Jacob Sparre Andersen
2001-12-07 18:12       ` Pascal Obry
2001-12-07 18:50         ` Preben Randhol
2001-12-07 18:54           ` Pascal Obry
2001-12-07 20:40             ` Preben Randhol
2001-12-07 22:01               ` Pascal Obry
2001-12-07 18:19       ` Jeffrey Carter
2001-12-10  9:59       ` Ole-Hjalmar Kristensen
  -- strict thread matches above, loose matches on Subject: below --
2001-12-02 19:37 Gautier Write-only-address
2001-12-23 10:33 Gautier Write-only-address

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox