* boolean array
@ 2002-01-25 0:33 Keith
2002-01-25 13:51 ` Sandro Binetti
0 siblings, 1 reply; 4+ messages in thread
From: Keith @ 2002-01-25 0:33 UTC (permalink / raw)
Hello,
I want to know if there is any false element(s) in an array of booleans.
Currently I am looping through the array and looking at each value until
I find a false element.
x := true;
for i in foo'range loop -- foo'range < 8
x := foo (i);
exit when not x;
end loop;
if x then .....
Is there a faster/preferred way of accomplishing this?
I am compiling Ada 95 with Green Hills AdaMULTI for VxWorks running on x86.
Thank you,
Keith
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: boolean array
@ 2002-01-25 5:55 Christoph Grein
2002-01-25 20:37 ` Robert Dewar
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Grein @ 2002-01-25 5:55 UTC (permalink / raw)
Foo : array (some_range) of Boolean;
...
Any_False_Present : constant Boolean := Foo /= (some_range => True);
But faster/preferred ??
> Hello,
>
> I want to know if there is any false element(s) in an array of booleans.
>
> Currently I am looping through the array and looking at each value until
> I find a false element.
>
> x := true;
> for i in foo'range loop -- foo'range < 8
> x := foo (i);
> exit when not x;
> end loop;
>
> if x then .....
>
> Is there a faster/preferred way of accomplishing this?
> I am compiling Ada 95 with Green Hills AdaMULTI for VxWorks running on x86.
>
> Thank you,
> Keith
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: boolean array
2002-01-25 0:33 Keith
@ 2002-01-25 13:51 ` Sandro Binetti
0 siblings, 0 replies; 4+ messages in thread
From: Sandro Binetti @ 2002-01-25 13:51 UTC (permalink / raw)
yokwad@yahoo.com (Keith) wrote in message news:<b28112f8.0201241633.7baa1010@posting.google.com>...
> Hello,
>
> I want to know if there is any false element(s) in an array of booleans.
>
> Currently I am looping through the array and looking at each value until
> I find a false element.
>
> x := true;
> for i in foo'range loop -- foo'range < 8
> x := foo (i);
> exit when not x;
> end loop;
>
if foo/=(foo'range=>TRUE) then ...
Bye, Sandro.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: boolean array
2002-01-25 5:55 boolean array Christoph Grein
@ 2002-01-25 20:37 ` Robert Dewar
0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 2002-01-25 20:37 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-01-25 20:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-25 5:55 boolean array Christoph Grein
2002-01-25 20:37 ` Robert Dewar
-- strict thread matches above, loose matches on Subject: below --
2002-01-25 0:33 Keith
2002-01-25 13:51 ` Sandro Binetti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox