From: dewar@gnat.com (Robert Dewar)
Subject: Re: boolean array
Date: 25 Jan 2002 12:37:10 -0800
Date: 2002-01-25T20:37:10+00:00 [thread overview]
Message-ID: <5ee5b646.0201251237.766bac75@posting.google.com> (raw)
In-Reply-To: mailman.1011938222.12962.comp.lang.ada@ada.eu.org
Christoph Grein <christoph.grein@eurocopter.com> wrote in message news:<mailman.1011938222.12962.comp.lang.ada@ada.eu.org>...
> Foo : array (some_range) of Boolean;
> ...
> Any_False_Present : constant Boolean := Foo /= (some_range => True);
>
> But faster/preferred ??
If the array is packed, this should be fast. Here using the
latest version of GNAT, is a source program:
procedure K is
type Rng is range 1 .. 8;
type a is array (Rng) of Boolean;
pragma Pack (a);
va : a := (1 => False, others => True);
begin
if va = (Rng => True) then
null;
end if;
end;
And here is the expanded source program:
procedure k is
type k__rng is range 1 .. 8;
type k__a is array (1 .. 8) of boolean;
pragma pack (k__a);
va : k__a := k__T6b!(16#FE#);
begin
if va = k__T10b!(16#FF#) then
null;
end if;
return;
end k;
The ! here is unchecked conversion, and the implementation
type of va is an 8 bit unsigned number, so as you can see
this reduces the cost to a single comparison instruction.
For those who need to see the asm to be convinced, here
it is:
.file "k.adb"
gcc2_compiled.:
___gnu_compiled_ada:
.text
.align 2
.globl __ada_k
__ada_k:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
movb $254,-1(%ebp)
cmpb $255,-1(%ebp)
jne L2
L2:
jmp L1
.align 2,0x90
L1:
leave
ret
next prev parent reply other threads:[~2002-01-25 20:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-25 5:55 boolean array Christoph Grein
2002-01-25 20:37 ` Robert Dewar [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-01-25 0:33 Keith
2002-01-25 13:51 ` Sandro Binetti
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox