From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: efficient vector/matrix operations in Fortran, was Re: ... in Ada
Date: Tue, 14 Aug 2001 10:37:42 +0000 (UTC)
Date: 2001-08-14T10:37:42+00:00 [thread overview]
Message-ID: <slrn9nhvrk.ht.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: mailman.997783946.25649.comp.lang.ada@ada.eu.org
* Gautier Write-only-address wrote:
>and return the variable. Maybe a pragma Inline and a strong
>optimization can do the job on some compilers. It would be
>interesting to see if at least one is able to suppress the
>local variable in an inlined call. If not, there is no chance
>that a user-defined "+" is as efficient as a user-defined "+=".
GNAT does a pretty bad job on this subject. Using the "+=" Procedure is
works considerably better. Please play around with compiler flags.
OTOH it is possible to enhance the Kernel Interface vastly if you are
switching to direct syscalls (using System.Machine_Code). Inlining does a
pretty good job on this subject:
\f
with Kernel.Calls;
use Kernel.Calls;
procedure test_kernel is
res : long := sys_kill (0, 0);
begin
null;
end test_kernel;
\f
_ada_test_kernel:
movb $37,%al
xorl %ebx,%ebx
movl %ebx,%ecx
int $0x80
ret
\f
with Ada.Text_IO;
procedure t is
type Vector is array (Positive range <>) of Integer;
function "+" (a, b : Vector) return Vector is
c : Vector(a'Range);
begin
for i in a'Range loop
c(i) := a(i) + b(i);
end loop;
return c;
end "+";
procedure Add_To (a : in out Vector; b : in Vector) is
begin
for i in a'Range loop
a(i) := a(i) + b(i);
end loop;
end Add_To;
pragma Inline("+", Add_To);
procedure Print (a : in Vector) is
package IIO is new Ada.Text_IO.Integer_IO (Integer);
use IIO, Ada.Text_IO;
begin
for i in a'Range loop
Put (i);
Put (a (i));
end loop;
New_Line;
end Print;
a : Vector(1..3) := (others => 3);
b : Vector(1..3) := (1, 2, 3);
c : Vector(1..3) := (4, 5, 6);
d : Vector(1..3);
begin
d := a + b + c;
Print(d);
d := a; Add_To (d, b); Add_To (d, c);
Print(d);
end t;
next prev parent reply other threads:[~2001-08-14 10:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-14 10:11 efficient vector/matrix operations in Fortran, was Re: ... in Ada Gautier Write-only-address
2001-08-14 10:37 ` Lutz Donnerhacke [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-08-14 4:56 efficient vector/matrix operations " Russ
2001-08-14 7:32 ` efficient vector/matrix operations in Fortran, was Re: ... " tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox