What does the Alignment clause in Ada do? -


i'm not clear alignment clause in ada does. see example below. have 40 bit sized record, , i'm not sure happens when use clause.

    type knots_status_record       record         value  : knots;         status : statuses;       end record;      knots_status_record use       record         value  @ 0 range  0 .. 31; -- 32         status @ 0 range 32 .. 39; -- 8       end record;      knots_status_record'alignment use 1; 

attribute alignment

alignment of x ensure address divisible x

data'aligment = x <=> data'address mod x = 0

implication

  • some processors requires data address aligned specific alignment.
  • some processors accesses data faster if data address aligned specific alignment.

example address behavior

with ada.integer_text_io; use ada.integer_text_io; ada.text_io; use ada.text_io; system.storage_elements; use system.storage_elements; ada.assertions; use ada.assertions; ada.command_line; use ada.command_line;  procedure main     function get_argument_1 return natural    begin       return natural'value (argument (1));    exception       when others => raise program_error "missing natural argument(1)";    end;     -- change size see happens every address aligment under 64.    float_array_size : natural := get_argument_1;    type float_array array (integer range 1 .. float_array_size) of float;     f4 : float_array;    f4'alignment use 4;    f8 : float_array;    f8'alignment use 8;    f16 : float_array;    f16'alignment use 16;    f32 : float_array;    f32'alignment use 32;    f64 : float_array;    f64'alignment use 64;  begin     -- check if 4 aligned address 64 aligned.    put (integer(to_integer(f4'address) mod 64));    -- is, not, depends partly of float_array_size.    new_line;    put (integer(to_integer(f8'address) mod 64));    new_line;    put (integer(to_integer(f16'address) mod 64));    new_line;    put (integer(to_integer(f32'address) mod 64));    new_line;    put (integer(to_integer(f64'address) mod 64));     -- lets see if address aligned 64 storage units.    assert (integer(to_integer(f64'address) mod 64) = 0);  end; 

external resources

http://www.adaic.org/resources/add_content/standards/05rm/html/rm-13-3.html http://www.adaic.org/resources/add_content/standards/05rm/html/rm-k.html

the value of attribute of type universal_integer, , nonnegative; 0 means object not aligned on storage element boundary. if x'alignment not zero, x aligned on storage unit boundary , x'address integral multiple of x'alignment (that is, address modulo alignment zero).

https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/representation_clauses_and_pragmas.html https://gcc.gnu.org/onlinedocs/gnat_rm/alignment-clauses.html

gnat requires alignment clauses specify power of 2, , default alignments power of 2. default alignment values follows:

https://en.wikibooks.org/wiki/ada_programming/attributes/'alignment

x'alignment ada attribute x memory-allocated object or type. attribute controls address values used objects. alignment must non-negative. value of 0 means object need not allocated @ boundary of storage units. otherwise address multiple of x's alignment. alignment of object may set.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -