comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: A couple of quick questions
Date: Sat, 29 Dec 2012 00:27:03 +0100
Date: 2012-12-29T00:27:04+01:00	[thread overview]
Message-ID: <50de2ac7$0$6576$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <0387724a-7fd2-4317-ba16-d3322dd0fdec@googlegroups.com>

On 28.12.12 21:28, Dufr wrote:
> Is the efficiency of the compiled code by penalized in any way by the putative bloat of the language?

No, usually, the language's features do not adversely affect
performance. This might be expected from a language that was required
to be suitable for hard real-time processing (hence cannot require
huge amounts of memory or processing power). One might instead
argue that its features contribute information useful to
optimizing compilers. (C's restrict keyword was added to C to
allow programmers to provide such information. OTOH, note that
Ada has always required that aliased objects be declared aliased.)

One noteworthy exception is overflow checking for arithmetical
operations. Its absence from C programs is a typical cause of
vulnerabilities every other week, which see. But these checks
are expensive and could therefore be turned on for sections of
an Ada program as needed. (I should hope they do that.)

For an example of a program that uses many of Ada's features,
yet is really fast (possibly because it does!), see
http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=chameneosredux

IIRC the wikibook on Ada Programming has examples of executable file
sizes in typical Unix installations; they are about the same as file
sizes of C programs. Size is a consequence of linking libraries, or
linking a small or large run-time system.

Object code size is typically the same as for other languages in
case optimization is turned on, and even when some checks are on.

Here is an example to demonstrate the effect. The same program is
written in C, and in Ada, compiled by the same GCC, using the same
switches (note that only default checks are on for the Ada program):

$ gcc -c -O2 adaex.adb
$ gnatchop -r -w adaex.ada && gcc -c -O2 adaex.adb

The assembly listings are appended to the source text, to show
the extent of difference, if any.


#include <stdint.h>

typedef int16_t num;

num Cex(num a, const num b, const num eps)
{
   num result = b - a;
    
   while (result > eps) {
     a += result / 2;
     result = b - a;
   }
   return result;
}


package Adaex is
    
    type Num is range -(2**15) .. +(2**15)-1;
    
    function Ex(A, B : Num; Eps: Num) return Num;
    
end Adaex;

package body Adaex is
    
    function Ex(A, B : Num; Eps: Num) return Num is
       Copy : Num := A;
       Result : Num := B - A;
    begin
       while Result > Eps loop
          Copy := Copy + Result / 2;
          Result := B - Copy;
       end loop;
       return Result;
    end Ex;
    
end Adaex;


$ otool -tv cex.o
cex.o:
(__TEXT,__text) section
_Cex:
0000000000000000	movl	%esi,%eax
0000000000000002	movl	%edi,%ecx
0000000000000004	movl	%edx,%r9d
0000000000000007	subl	%edi,%eax
0000000000000009	movl	%esi,%r8d
000000000000000c	cmpw	%dx,%ax
000000000000000f	jle	0x00000038
0000000000000011	nopl	0x00000000(%rax)
0000000000000018	nopl	0x00000000(%rax,%rax)
0000000000000020	movl	%eax,%edx
0000000000000022	shrw	$0x0f,%dx
0000000000000026	addl	%edx,%eax
0000000000000028	sarw	%ax
000000000000002b	addl	%eax,%ecx
000000000000002d	movl	%r8d,%eax
0000000000000030	subl	%ecx,%eax
0000000000000032	cmpw	%eax,%r9d
0000000000000036	jl	0x00000020
0000000000000038	repz/ret
$ otool -tv adaex.o
adaex.o:
(__TEXT,__text) section
_adaex__ex:
0000000000000000	movl	%esi,%eax
0000000000000002	movl	%esi,%ecx
0000000000000004	movl	%edx,%r8d
0000000000000007	subl	%edi,%eax
0000000000000009	cmpw	%dx,%ax
000000000000000c	jle	0x00000027
000000000000000e	nop
0000000000000010	movl	%eax,%edx
0000000000000012	shrw	$0x0f,%dx
0000000000000016	addl	%edx,%eax
0000000000000018	sarw	%ax
000000000000001b	addl	%eax,%edi
000000000000001d	movl	%ecx,%eax
000000000000001f	subl	%edi,%eax
0000000000000021	cmpw	%eax,%r8d
0000000000000025	jl	0x00000010
0000000000000027	ret
$





  reply	other threads:[~2012-12-28 23:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-28 15:02 A couple of quick questions Dufr
2012-12-28 15:43 ` Thomas Løcke
2012-12-28 16:46 ` Georg Bauhaus
2012-12-28 20:28 ` Dufr
2012-12-28 23:27   ` Georg Bauhaus [this message]
2012-12-28 23:36     ` Georg Bauhaus
2012-12-29  0:41   ` Yannick Duchêne (Hibou57)
2012-12-29 10:47   ` Florian Weimer
2012-12-29 16:15     ` Shark8
2012-12-29 16:32       ` Bill Findlay
2012-12-29 17:21       ` Florian Weimer
2012-12-31  8:56 ` Paul Colin Gloster
replies disabled

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