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

-- 5:
-- 6: -- Turbo_Private.Atomic_Integer_Addr_Package, x86 version

-- 7:

-- 8: with Interfaces, Turbo_Private.Generic_Atomic_32,

-- 9:    Turbo_Private.Bits;

-- 10:

-- 11: use  Interfaces, Turbo_Private.Bits;

-- 12:

-- 13: package Turbo_Private.Atomic_Integer_Addr_Package is
with turbo_private;
with turbo_private;
with turbo_private;
with interfaces;
with turbo_private.turbo_private__generic_atomic_32;
with turbo_private.turbo_private__bits;
use interfaces, turbo_private.turbo_private__bits;
with turbo_private;
with system;
with system.system__machine_code;
with interfaces;
with turbo_private;
with ada;
with ada.ada__characters;
with system;
with system.system__machine_code;
with ada.ada__characters.ada__characters__latin_1;
with interfaces;
with turbo_private.turbo_private__cpuid;
with system;
with system.system__machine_code;
turbo_private__atomic_integer_addr_package_E : boolean := false;
package body turbo_private.turbo_private__atomic_integer_addr_package is
   function turbo_private__atomic_integer_addr_package__get (source :
     in turbo_private__atomic_integer_addr_package__atomic_type_32)
     return turbo_private__atomic_integer_addr_package__type_32 is
      item : turbo_private__atomic_integer_addr_package__type_32;
      for item'address use source.item'address;
      pragma import (ada, item);
      result : turbo_private__atomic_integer_addr_package__type_32;
      freeze item []
   begin
      system__machine_code__asm_insn'(
      asm ("lock xaddl %2, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", item),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=r", result)), inputs => interfaces__unsigned_32'asm_input("1",
        0), volatile => true, clobber => ""););
      null;
      return result;
   end turbo_private__atomic_integer_addr_package__get;
   function turbo_private__atomic_integer_addr_package__get (source : not null
     access turbo_private__atomic_integer_addr_package__atomic_type_32)
     return turbo_private__atomic_integer_addr_package__type_32 is
      result : turbo_private__atomic_integer_addr_package__type_32;
   begin
      system__machine_code__asm_insn'(
      asm ("lock xaddl %2, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", source.all.item),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=r", result)), inputs => interfaces__unsigned_32'asm_input("1",
        0), volatile => true, clobber => ""););
      null;
      return result;
   end turbo_private__atomic_integer_addr_package__get;
   function turbo_private__atomic_integer_addr_package__lazy_get (
     source : in
     turbo_private__atomic_integer_addr_package__atomic_type_32)
     return turbo_private__atomic_integer_addr_package__type_32 is
   begin
      null;
      return source.item;
   end turbo_private__atomic_integer_addr_package__lazy_get;
   function turbo_private__atomic_integer_addr_package__lazy_get (
     source : not null access
     turbo_private__atomic_integer_addr_package__atomic_type_32)
     return turbo_private__atomic_integer_addr_package__type_32 is
   begin
      null;
      return source.all.item;
   end turbo_private__atomic_integer_addr_package__lazy_get;
   procedure turbo_private__atomic_integer_addr_package__set (target : not null
     access turbo_private__atomic_integer_addr_package__atomic_type_32;
     item : turbo_private__atomic_integer_addr_package__type_32) is
      dummy : turbo_private__atomic_integer_addr_package__type_32;
   begin
      null;
      system__machine_code__asm_insn'(
      asm ("lock xchgl %2, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=m", target.all.item),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=r", dummy)), inputs =>
        turbo_private__atomic_integer_addr_package__type_32'asm_input("1",
        item), volatile => true, clobber => ""););
      return;
   end turbo_private__atomic_integer_addr_package__set;
   procedure turbo_private__atomic_integer_addr_package__set (target :
     in out turbo_private__atomic_integer_addr_package__atomic_type_32;
     item : turbo_private__atomic_integer_addr_package__type_32) is
      dummy : turbo_private__atomic_integer_addr_package__type_32;
   begin
      null;
      system__machine_code__asm_insn'(
      asm ("lock xchgl %2, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=m", target.item),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=r", dummy)), inputs =>
        turbo_private__atomic_integer_addr_package__type_32'asm_input("1",
        item), volatile => true, clobber => ""););
      return;
   end turbo_private__atomic_integer_addr_package__set;
   procedure turbo_private__atomic_integer_addr_package__lazy_set (
     target : not null access
     turbo_private__atomic_integer_addr_package__atomic_type_32; item :
     turbo_private__atomic_integer_addr_package__type_32) is
   begin
      null;
      target.all.item := item;
      return;
   end turbo_private__atomic_integer_addr_package__lazy_set;
   procedure turbo_private__atomic_integer_addr_package__lazy_set (
     target : in out
     turbo_private__atomic_integer_addr_package__atomic_type_32; item :
     turbo_private__atomic_integer_addr_package__type_32) is
   begin
      null;
      target.item := item;
      return;
   end turbo_private__atomic_integer_addr_package__lazy_set;
   function turbo_private__atomic_integer_addr_package__create (item :
     turbo_private__atomic_integer_addr_package__type_32) return
     turbo_private__atomic_integer_addr_package__atomic_type_32 is
   begin
      R51b : declare
         [constraint_error when
           createBIPaccess = null
           "access check failed"]
         result___XR_createBIPaccess___XEXA : _renaming_type;
         result :
           turbo_private__atomic_integer_addr_package__atomic_type_32
           renames createBIPaccess.all;
      begin
         B52b : declare
         begin
            null;
            turbo_private__atomic_integer_addr_package__set__2 (result,
              item);
         end B52b;
         return result;
      end R51b;
   end turbo_private__atomic_integer_addr_package__create;
   function turbo_private__atomic_integer_addr_package__lazy_create (
     item : turbo_private__atomic_integer_addr_package__type_32)
     return turbo_private__atomic_integer_addr_package__atomic_type_32 is
   begin
      R56b : declare
         [constraint_error when
           lazy_createBIPaccess = null
           "access check failed"]
         R55b___XR_lazy_createBIPaccess___XEXA : _renaming_type;
         R55b :
           turbo_private__atomic_integer_addr_package__atomic_type_32
           renames lazy_createBIPaccess.all;
         null;
         R55b.item := item;
      begin
         return R55b;
      end R56b;
   end turbo_private__atomic_integer_addr_package__lazy_create;
   function turbo_private__atomic_integer_addr_package__swap (target : not null
     access turbo_private__atomic_integer_addr_package__atomic_type_32;
     item : turbo_private__atomic_integer_addr_package__type_32)
     return turbo_private__atomic_integer_addr_package__type_32 is
      result : turbo_private__atomic_integer_addr_package__type_32;
   begin
      null;
      system__machine_code__asm_insn'(
      asm ("lock xchgl %1, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", target.all.item),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=r", result)), inputs =>
        turbo_private__atomic_integer_addr_package__type_32'asm_input("1",
        item), volatile => true, clobber => ""););
      null;
      return result;
   end turbo_private__atomic_integer_addr_package__swap;
   function turbo_private__atomic_integer_addr_package__compare_swap (
     target : not null access
     turbo_private__atomic_integer_addr_package__atomic_type_32;
     comparand : turbo_private__atomic_integer_addr_package__type_32;
     new_item : turbo_private__atomic_integer_addr_package__type_32)
     return boolean is
      result : boolean;
      dummy : turbo_private__atomic_integer_addr_package__type_32;
   begin
      null;
      null;
      system__machine_code__asm_insn'(
      asm ("lock cmpxchgl %3, %0["0a"]["09"]setzb %1", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", target.all.item), boolean'asm_output("=rm", result),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=a", dummy)), inputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_input("r",
        new_item), turbo_private__atomic_integer_addr_package__type_32'
        asm_input("a", comparand)), volatile => true, clobber => ""););
      [constraint_error when
        not (interfaces__unsigned_32!(result) >=
          interfaces__unsigned_32!(false) and then
          interfaces__unsigned_32!(result) <= interfaces__unsigned_32!(
          true))
        "invalid data"]
      return result;
   end turbo_private__atomic_integer_addr_package__compare_swap;
   function turbo_private__atomic_integer_addr_package__compare_swap (
     target : not null access
     turbo_private__atomic_integer_addr_package__type_32; comparand :
     turbo_private__atomic_integer_addr_package__type_32; new_item :
     turbo_private__atomic_integer_addr_package__type_32) return
     turbo_private__atomic_integer_addr_package__type_32 is
      result : turbo_private__atomic_integer_addr_package__type_32;
   begin
      null;
      null;
      system__machine_code__asm_insn'(
      asm ("lock cmpxchgl %2, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", target.all),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=a", result)), inputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_input("r",
        new_item), turbo_private__atomic_integer_addr_package__type_32'
        asm_input("a", comparand)), volatile => true, clobber => ""););
      null;
      return result;
   end turbo_private__atomic_integer_addr_package__compare_swap;
   function turbo_private__atomic_integer_addr_package__compare_swap (
     target : not null access
     turbo_private__atomic_integer_addr_package__atomic_type_32;
     comparand : turbo_private__atomic_integer_addr_package__type_32;
     new_item : turbo_private__atomic_integer_addr_package__type_32)
     return turbo_private__atomic_integer_addr_package__type_32 is
      result : turbo_private__atomic_integer_addr_package__type_32;
   begin
      null;
      null;
      system__machine_code__asm_insn'(
      asm ("lock cmpxchgl %2, %0", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", target.all.item),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=a", result)), inputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_input("r",
        new_item), turbo_private__atomic_integer_addr_package__type_32'
        asm_input("a", comparand)), volatile => true, clobber => ""););
      null;
      return result;
   end turbo_private__atomic_integer_addr_package__compare_swap;
   function turbo_private__atomic_integer_addr_package__compare_swap (
     target : not null access
     turbo_private__atomic_integer_addr_package__atomic_type_32;
     comparand : turbo_private__atomic_integer_addr_package__type_32;
     new_item : turbo_private__atomic_integer_addr_package__type_32;
     fetched : not null access
     turbo_private__atomic_integer_addr_package__type_32) return
     boolean is
      result : boolean;
   begin
      null;
      null;
      system__machine_code__asm_insn'(
      asm ("lock cmpxchgl %3, %0["0a"]["09"]setzb %1", outputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "+m", target.all.item), boolean'asm_output("=mr", result),
        turbo_private__atomic_integer_addr_package__type_32'asm_output(
        "=a", fetched.all)), inputs => (
        turbo_private__atomic_integer_addr_package__type_32'asm_input("r",
        new_item), turbo_private__atomic_integer_addr_package__type_32'
        asm_input("a", comparand)), volatile => true, clobber => ""););
      [constraint_error when
        not (interfaces__unsigned_32!(result) >=
          interfaces__unsigned_32!(false) and then
          interfaces__unsigned_32!(result) <= interfaces__unsigned_32!(
          true))
        "invalid data"]
      return result;
   end turbo_private__atomic_integer_addr_package__compare_swap;
begin
   null;
end turbo_private.turbo_private__atomic_integer_addr_package;


-- 14:    new Turbo_Private.Generic_Atomic_32 (Integer_Addr);

-- 15:

-- 16: pragma Preelaborate (Turbo_Private.Atomic_Integer_Addr_Package);
pragma preelaborate (turbo_private.
  turbo_private__atomic_integer_addr_package);
