
-- 1: --------------------------------
-- 2: -- Ivan Levashew aka OCTAGRAM --
-- 3: --         Barnaul, 2009-2010 --
-- 4: --------------------------------

-- 5:

-- 6: with System; use System;

-- 7: with Interfaces; use Interfaces;

-- 8: with System.Storage_Elements; use System.Storage_Elements;

-- 9: with Turbo_Private.Bits; use Turbo_Private.Bits;
with turbo_private;
with system;
with system;
use system;
with interfaces;
use interfaces;
with system.system__storage_elements;
use system.system__storage_elements;
with turbo_private.turbo_private__bits;
use turbo_private.turbo_private__bits;
with ada.ada__tags;
with system;
with system.system__storage_elements;
with interfaces;

-- 10:

-- 11: procedure Turbo_Private.Memory.Fill_Byte_Fallback
procedure turbo_private.turbo_private__memory.
  turbo_private__memory__fill_byte_fallback (target : system__address;
  amount : turbo_private__bits__unsigned_addr; item :
  interfaces__unsigned_8) is

-- 12:   (Target : Address; Amount : Unsigned_Addr; Item : Unsigned_8)

-- 13: is

-- 14:    pragma Preelaborate;
   pragma preelaborate;
   buffer_size : constant  := 4096;

-- 15:

-- 16:    Buffer_Size : constant := 4096;

-- 17:    type Buffer_Type is new Storage_Array (0 .. Buffer_Size - 1);
   [type turbo_private__memory__fill_byte_fallback__Tbuffer_typeB is array (
     -16#8000_0000# .. 16#7FFF_FFFF# range <>) of
     system__storage_elements__storage_element]
   subtype turbo_private__memory__fill_byte_fallback__buffer_type is
     turbo_private__memory__fill_byte_fallback__Tbuffer_typeB (0 ..
     4095);

-- 18:

-- 19:    Buffer : Buffer_Type := (others => Storage_Element (Item));
   freeze turbo_private__memory__fill_byte_fallback__Tbuffer_typeB []
   freeze turbo_private__memory__fill_byte_fallback__buffer_type []
   buffer : turbo_private__memory__fill_byte_fallback__buffer_type;
   for J3b in 0 .. 4095 loop
      buffer (J3b) := system__storage_elements__storage_element(item);
   end loop;

-- 20:
-- 21:    -- Amount > 0 !

-- 22:    procedure Mini_Fill (Target : Address; Amount : Storage_Count) is
   procedure turbo_private__memory__fill_byte_fallback__mini_fill (
     target : system__address; amount :
     system__storage_elements__storage_count) is
      target_array :
        turbo_private__memory__fill_byte_fallback__buffer_type;

-- 23:       Target_Array : Buffer_Type;

-- 24:       for Target_Array'Address use Target;
      for target_array'address use target;

-- 25:       pragma Import (C, Target_Array);
      pragma import (c, target_array);
      freeze target_array []
      [program_error when
        system__storage_elements__integer_address!(target) rem
          target_array'alignment /= 0
        "misaligned address value"]

-- 26:    begin
   begin

-- 27:       Target_Array (0 .. Amount - 1) := Buffer (0 .. Amount - 1);
      [constraint_error when
        not (interfaces__unsigned_32!(amount) <= 16#7FFF_FFFF#)
        "invalid data"]
      [constraint_error when
        amount - 1 >= 0 and then (amount - 1 > 4095)
        "range check failed"]
      [constraint_error when
        not (interfaces__unsigned_32!(amount) <= 16#7FFF_FFFF#)
        "invalid data"]
      [constraint_error when
        amount - 1 >= 0 and then (amount - 1 > 4095)
        "range check failed"]
      [constraint_error when
        [subtype
          turbo_private__memory__fill_byte_fallback__mini_fill__T7b is
        [subtype
        [type system__storage_elements__Tstorage_offsetB is new integer]
          turbo_private__memory__fill_byte_fallback__mini_fill__T6b is
          system__storage_elements__Tstorage_offsetB range 0 .. amount -
          1]
          turbo_private__memory__fill_byte_fallback__Tbuffer_typeB (
          turbo_private__memory__fill_byte_fallback__mini_fill__T6b)]
        turbo_private__memory__fill_byte_fallback__mini_fill__T7b'
        [subtype
          turbo_private__memory__fill_byte_fallback__mini_fill__T9b is
        [subtype
          turbo_private__memory__fill_byte_fallback__mini_fill__T8b is
          system__storage_elements__Tstorage_offsetB range 0 .. amount -
          1]
          turbo_private__memory__fill_byte_fallback__Tbuffer_typeB (
          turbo_private__memory__fill_byte_fallback__mini_fill__T8b)]
          length /=
          turbo_private__memory__fill_byte_fallback__mini_fill__T9b'
          length
        "length check failed"]
      target_array (0 .. amount - 1) := buffer (0 .. amount - 1);

-- 28:    end Mini_Fill;
      return;
   end turbo_private__memory__fill_byte_fallback__mini_fill;

   amount_div : constant turbo_private__bits__unsigned_addr := amount /

-- 29:

-- 30:    Amount_Div : constant Unsigned_Addr := Amount / Buffer_Size;
     4096;
   amount_mod : constant turbo_private__bits__unsigned_addr := amount rem

-- 31:    Amount_Mod : constant Unsigned_Addr := Amount mod Buffer_Size;
     4096;
   L_1 : label

-- 32:

-- 33: begin
begin

-- 34:

-- 35:    if Amount <= 0 then
   if amount <= 0 then

-- 36:       return;
      return;

-- 37:    end if;
   end if;

-- 38:

-- 39:    if Amount_Div >= 1 then
   if amount_div >= 1 then
      [type turbo_private__bits__Tunsigned_addrB is  mod
        16#1000_0000_0#]
      S11b : turbo_private__bits__Tunsigned_addrB;

-- 40:       for i in 0 .. Amount_Div - 1 loop
      S11b := amount_div - 1;
      L_1 : for i in 0 .. S11b loop

-- 41:          Mini_Fill (Target + i * Buffer_Size, Buffer_Size);
         turbo_private__memory__fill_byte_fallback__mini_fill (
           turbo_private__bits__Oadd__9 (target, i * 4096), 4096);

-- 42:       end loop;
      end loop L_1;

-- 43:    end if;
   end if;

-- 44:

-- 45:    if Amount_Mod >= 1 then
   if amount_mod >= 1 then

-- 46:       Mini_Fill (Target + Amount_Div * Buffer_Size,

-- 47:                  Storage_Count (Amount_Mod));
      [constraint_error when
        not (amount_mod <= 16#7FFF_FFFF#)
        "range check failed"]
      turbo_private__memory__fill_byte_fallback__mini_fill (
        turbo_private__bits__Oadd__9 (target, amount_div * 4096),
        system__storage_elements__storage_count(amount_mod));

-- 48:    end if;
   end if;

-- 49:

-- 50: end Turbo_Private.Memory.Fill_Byte_Fallback;
   return;
end turbo_private.turbo_private__memory.
  turbo_private__memory__fill_byte_fallback;
