comp.lang.ada
 help / color / mirror / Atom feed
* Re: 'Size (novice question)
       [not found] <38ACA68D.CEA7E03F@interact.net.au>
@ 2000-02-18  0:00 ` Jeff Carter
       [not found] ` <wccsnyqof2a.fsf@world.std.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff Carter @ 2000-02-18  0:00 UTC (permalink / raw)


G wrote:
> Type Byte is mod 2**8;
> for Byte'Size use 8;
> 
> why is the 'Size postfix used to set the size to
> 8 bits when I would have thought that mod 2**8
> did the same thing.

In most cases you would probably be right. BUT ...

It is perfectly OK for the compiler to use more bits than necessary.
Perhaps the architecture is such that loading a 32-bit word into a
register is faster than loading an 8-bit byte. The type definition only
defines the number of values that objects of the type can have (256, in
this case. A 'Size definition instructs the compiler to use a specific
number of bits.

Note that this works both ways:

type Half_Word is mod 2 ** 8;
for Half_Word'Size use 16;

Here we want to use one byte out of a (16-bit) word. The range of values
can be stored in 8 bits, but we are requiring that objects of this type
occupy 16 bits.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail




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

* Re: 'Size (novice question)
       [not found]     ` <87aekxlz33.fsf@deneb.cygnus.argh.org>
@ 2000-02-22  0:00       ` Lutz Donnerhacke
  2000-02-22  0:00         ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Lutz Donnerhacke @ 2000-02-22  0:00 UTC (permalink / raw)


* Florian Weimer wrote:
>   Put ("Boolean'Size (type):     "); Put (Boolean'Size); New_Line;
>   Put ("Boolean'Size (variable): "); Put (X'Size); New_Line;
>
>Almost no compiler will print 1 twice because on most architectures,
>access to individual bits is expensive in both time and space when
>compared to word or even octet access.

But the following code can not use compressed variables:

with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
procedure Size_Difference is
   X1, X2 : Boolean;
   A1, A2 : array (1..8) of Boolean;
   pragma Pack (X2,A2);  -- I know, that a named array subtype is packable.
begin
   Put ("Boolean'Size (type): "); Put (Boolean'Size); New_Line;
   Put ("Boolean'Size (X1):   "); Put (X1'Size); New_Line;
   Put ("Boolean'Size (X2):   "); Put (X2'Size); New_Line;
   Put ("Boolean'Size (A1):   "); Put (A1'Size); New_Line;
   Put ("Boolean'Size (A2):   "); Put (A2'Size); New_Line;
end;





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

* Re: 'Size (novice question)
       [not found]   ` <slrn8aqgfn.15u.lutz@taranis.iks-jena.de>
@ 2000-02-22  0:00     ` Vladimir Olensky
  2000-02-22  0:00       ` Robert Dewar
       [not found]     ` <87aekxlz33.fsf@deneb.cygnus.argh.org>
  1 sibling, 1 reply; 6+ messages in thread
From: Vladimir Olensky @ 2000-02-22  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2554 bytes --]


Lutz Donnerhacke wrote in message ...
>* Robert A Duff wrote:
>>The important thing to remember is that if you say:
>>
>>    X: Byte;
>>
>>then (surprise!) X'Size might be 8, or might be 32, whether or not the
>>above Size clause is there.  The language rules just say X'Size >=
>>Byte'Size.
>>The compiler should choose whatever is most efficient.  If

>>you really want X to be 8 bits, say "for X'Size use 8;".  Likewise, if
>
>Funny.

Though what is said above is generally true I see no reason to worry
about that much.

According  to LRM 13.3 (50) compiler should use the same size for
object as the size of it's type provided that this size provides
independent addressability :

=====================================================
Implementation Advice:

50  If the Size of a subtype is specified, and allows for efficient
independent addressability (see 9.10) on the target architecture,
then the Size of the following objects of the subtype should equal
the Size of the subtype:

51 � Aliased objects (including components).
52 � Unaliased components, unless the Size of the component is
     determined by a component_clause or Component_Size clause.
....
54 The recommended level of support for the Size attribute of
      subtypes is:

55 � The Size (if not specified) of a static discrete or fixed point
subtype should be the number of bits needed to represent each
value belonging to the subtype using an unbiased representation,
leaving space for a sign bit only if the subtype contains negative
values. If such a subtype is a first subtype, then an implementation
should support a specified Size for it that reflects this representation.


============================================

As I understand efficient  independent addressability  means
that the X'Size should be multiple of storage_units.
It would be strange to hear that separate storage unit could
not be addressed efficiently.

So if  X_Type'Size is multiple of storage_unit than
X'Size should be the same.

At least on IA32 platform storage_unit is equal one byte.

So if you  have :

  type  Byte_type is mod 2**8;
  type  Bits5_type is mod 2**5;
  type  Bits10_type is mod 2**10;

   A : byte_type;
   B : Bits5_type;
   C:  Bits10_type;

then according to 13.3 (55):

   Byte_Type'Size = 8;
   Bits5_type'Size = 5;
   Bits10_type'Size =10;

if  ( storage_unit = 8)  then

    A'Size = 8;
    B'Size = 8;
    C'Size =16;

end if;

 if  ( storage_unit = 32)  then

    A'Size = 32;
    B'Size = 32;
    C'Size = 32;

 end if;


Regards,
Vladimir Olensky










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

* Re: 'Size (novice question)
  2000-02-22  0:00     ` Vladimir Olensky
@ 2000-02-22  0:00       ` Robert Dewar
  0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 2000-02-22  0:00 UTC (permalink / raw)


In article <sb58e0h1r2a31@corp.supernews.com>,
  "Vladimir Olensky" <vladimir_olensky@yahoo.com> wrote:

> As I understand efficient  independent addressability  means
> that the X'Size should be multiple of storage_units.
> It would be strange to hear that separate storage unit could
> not be addressed efficiently.

What you find strange depends on your knowledge :-)

But in fact architectures that are byte addressable but do not
allow efficient access to individual storage bytes are not
uncommon. Examples are the AMD 29K, and most earlier models
of the Digital Alpha chip. There are other examples.

On the Alpha for example, GNAT will always allocate 32 bits
to a stand alone Character or Boolean variable, in accordance
with the implementation advice quoted. There is a switch for
GNAT that tells it that you have a late model Alpha where
this is not required.


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: 'Size (novice question)
  2000-02-22  0:00       ` Lutz Donnerhacke
@ 2000-02-22  0:00         ` Florian Weimer
  2000-02-23  0:00           ` Lutz Donnerhacke
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2000-02-22  0:00 UTC (permalink / raw)


lutz@iks-jena.de (Lutz Donnerhacke) writes:

> * Florian Weimer wrote:
> >   Put ("Boolean'Size (type):     "); Put (Boolean'Size); New_Line;
> >   Put ("Boolean'Size (variable): "); Put (X'Size); New_Line;
> >
> >Almost no compiler will print 1 twice because on most architectures,
> >access to individual bits is expensive in both time and space when
> >compared to word or even octet access.
> 
> But the following code can not use compressed variables:

Yes, that's correct.  But, in my eyes, your example is pretty
pointless. ;)  Would you mind posting another one?




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

* Re: 'Size (novice question)
  2000-02-22  0:00         ` Florian Weimer
@ 2000-02-23  0:00           ` Lutz Donnerhacke
  0 siblings, 0 replies; 6+ messages in thread
From: Lutz Donnerhacke @ 2000-02-23  0:00 UTC (permalink / raw)


* Florian Weimer wrote:
>Yes, that's correct.  But, in my eyes, your example is pretty
>pointless. ;)  Would you mind posting another one?

No. I'm working on not so silly subjects ;-)
\f
de.org.ccc for more examples.




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

end of thread, other threads:[~2000-02-23  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <38ACA68D.CEA7E03F@interact.net.au>
2000-02-18  0:00 ` 'Size (novice question) Jeff Carter
     [not found] ` <wccsnyqof2a.fsf@world.std.com>
     [not found]   ` <slrn8aqgfn.15u.lutz@taranis.iks-jena.de>
2000-02-22  0:00     ` Vladimir Olensky
2000-02-22  0:00       ` Robert Dewar
     [not found]     ` <87aekxlz33.fsf@deneb.cygnus.argh.org>
2000-02-22  0:00       ` Lutz Donnerhacke
2000-02-22  0:00         ` Florian Weimer
2000-02-23  0:00           ` Lutz Donnerhacke

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