comp.lang.ada
 help / color / mirror / Atom feed
From: Lucas Redding <lucas.redding@gmail.com>
Subject: Re: Addressing in Object Ada v/s GNAT (2013) showing Vast Differences
Date: Mon, 21 Sep 2015 06:22:47 -0700 (PDT)
Date: 2015-09-21T06:22:47-07:00	[thread overview]
Message-ID: <2c064071-2e40-4267-81f6-3196d7ae35ab@googlegroups.com> (raw)
In-Reply-To: <871tds56jw.fsf@adaheads.sparre-andersen.dk>

On Monday, September 21, 2015 at 12:57:09 PM UTC+1, Jacob Sparre Andersen wrote:
> Lucas Redding wrote:
> 
> Your examples don't compile.  Please show us the actual code.
> 
> Greetings,
> 
> Jacob
> -- 
> "Very small. Go to sleep" - monster (not drooling)

Hi Jacob

thanks for that. I am avoiding having to flood this with tons of code. So here is a compiled example.

package interface_p
is

   type sixteen_bits is range 0..(2**16)-1 ; 
   type fourteen_bits is range 0..(2**14)-1; 
   type ten_bits is range 0..(2**10)-1; 
   type padding_bits is range 0..(2**8)-1 ; 

   type rec is record 
      a: fourteen_bits ; 
      b: ten_bits ; 
      padding : padding_bits ;
   end record ; 

   for rec use 
   record
      a at 0 range 0..13 ; 
      b at 0 range 14..23 ; 
      padding at 0 range 24..31;
   end record ; 
   for rec'size use 32; 
   for rec'alignment use 1; 

   subtype local_fourteen_bits is sixteen_bits range 0 .. (2 ** 14)-1;
   subtype local_ten_bits is sixteen_bits range 0 .. (2 ** 10)-1; 
   type local_rec is record
      a : local_fourteen_bits ; 
      b : local_ten_bits ; 
   end record; 

   for local_rec use 
   record
      a at 0 range 0 .. 13 ; 
      b at 2 range 0 .. 9 ; 
   end record; 

   for local_rec'size use 32 ; 
   for local_rec'Alignment use 1 ; 
 
   VAR_REC : rec := (a => 1, b => 2, padding => 0 ) ; 
   
   -- I explicitly assign here but in actual application it maps onto a 32 bit 
   -- record in memory. I have deliberately changed in order to avoid adding 
   -- tons of irrelevant code.
   
   
   function READ_RECORD
   return local_rec ;

end interface_p ;

package body INTERFACE_P
is
   function READ_RECORD
   return local_rec 
   is
      VAR_LOCAL_REC : local_rec ; 
   begin 
   
      -- We would like to copy the information once to a byte aligned 
      -- record to hopefully speed up 
      -- access to this item because it is accessed internally a large 
      -- number of times. 

      VAR_LOCAL_REC.a := local_fourteen_bits(VAR_REC.a) ;
      VAR_LOCAL_REC.b := local_ten_bits(VAR_REC.b) ;
      
      -- The problem is when I copy each record component to the local copies 
      -- (including the typecast) 
      -- my var_local_rec.a takes on a 16 bit value and thus includes the bit values 
      -- from var_rec.b ;       
      
      -- So if var_rec.a is 1 and var_rec.b is 2 I end up with the following in 
      -- var_local_rec in GNAT Ada : 

      -- var_local_rec.a = 32769 ; 
      -- var_local_rec.b = 2 ; 

      -- Clearly this is wrong. And although I have set all checks in the compiler I 
      -- don't get an overflow error which is what I would expect. 

      --      In Object Ada I get : 

      --      var_local_rec.a = 1 ; 
      --      var_local_rec.b = 2; 
      return VAR_LOCAl_REC ;
      
   end READ_RECORD ;

end INTERFACE_P ;

  reply	other threads:[~2015-09-21 13:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-07 11:39 Addressing in Object Ada v/s GNAT (2013) showing Vast Differences Lucas Redding
2015-09-07 11:54 ` Lucas Redding
2015-09-07 14:04   ` G.B.
2015-09-07 16:02     ` Lucas Redding
2015-09-07 16:28       ` Anh Vo
2015-09-08  7:30         ` Lucas Redding
2015-09-08 15:11           ` Anh Vo
2015-09-08 17:20           ` Jeffrey R. Carter
2015-09-07 17:20   ` Pascal Obry
2015-09-07 17:21   ` Pascal Obry
2015-09-08  7:04     ` Lucas Redding
2015-09-07 21:02   ` Niklas Holsti
2015-09-08  8:00     ` Lucas Redding
2015-09-07 15:48 ` Jeffrey R. Carter
2015-09-08  7:27   ` Lucas Redding
2015-09-08  7:12 ` Markus Schöpflin
2015-09-08  8:05   ` Lucas Redding
2015-09-10 10:47 ` Lucas Redding
2015-09-10 12:34   ` G.B.
2015-09-21 11:12     ` Lucas Redding
2015-09-21 11:57       ` Jacob Sparre Andersen
2015-09-21 13:22         ` Lucas Redding [this message]
2015-09-21 13:47           ` Jacob Sparre Andersen
2015-09-21 13:52           ` Georg Bauhaus
2015-09-21 15:54             ` Lucas Redding
2015-09-22 17:49               ` Jacob Sparre Andersen
2015-09-22 18:45               ` Jacob Sparre Andersen
2015-10-01  6:50                 ` Lucas Redding
2015-09-21 16:48       ` Dmitry A. Kazakov
2015-10-01  7:25         ` Lucas Redding
2015-10-01 20:04           ` Randy Brukardt
replies disabled

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