-- PERFORMANCE MEASUREMENT : operations on boolean arrays
--                           arrays are packed
--                           operations on entire array structure
--                           XOR  NOT  OR  NOT  AND

with Remote_Global;
use Remote_Global; -- control optimization
with Iteration;                         -- obtain stable measurement
with Piwg_Io;                           -- output results

procedure H000001 is  -- main procedure to execute

    Cpu_Time : Duration;           -- CPU time for one feature execution
    Wall_Time : Duration;          -- WALL time for one feature execution
    Check_Times : constant := 100; -- inside loop count and check
    Iteration_Count : Integer;     -- set and varied by ITERATION package
    Stable : Boolean;              -- true when measurement stable
--
-- Boolean array declarations
--
    type Packed_Bit_Array is array (Natural range <>) of Boolean;
    pragma Pack (Packed_Bit_Array);

    Bit_Value_1 : Boolean := Global > 0;
    Bit_Value_2 : Boolean := Global rem 2 = 0;
    Bit_Value_3 : Boolean := Global <= 1;

    subtype Packed_16 is Packed_Bit_Array (0 .. 15);

    Packed_1 : Packed_16 := Packed_16'(0 | 3 | 6 | 9 | 12 | 15 => Bit_Value_1,
                                       1 | 5 | 7 | 11 | 13 => Bit_Value_2,
                                       others => Bit_Value_3);
    Packed_2 : Packed_16 := Packed_16'(0 .. 3 => Bit_Value_1,
                                       4 .. 12 => Bit_Value_2,
                                       others => Bit_Value_3);

begin  -- procedure H000001

    Iteration.Start_Control;  -- dummy to bring in pages on some machines

    delay 0.5;  -- wait for stable enviornment on some machines

    Iteration.Initialize (Iteration_Count);

    loop  -- until stable measurement, ITERATION_COUNT increases each time
--
-- Control loop
--
        Iteration.Start_Control;
        for J in 1 .. Iteration_Count loop
            Global := 0;
            for Inside_Loop in 1 .. Check_Times loop
                Global := Global + A_One;
                Remote;  
            end loop;
        end loop;
        Iteration.Stop_Control (Global, Check_Times);
--
-- Test loop
--
        Iteration.Start_Test;
        for J in 1 .. Iteration_Count loop
            Global := 0;
            for Inside_Loop in 1 .. Check_Times loop
                Global := Global + A_One;
                Packed_1 := Packed_2 xor not Packed_1;
                Packed_2 := Packed_1 or Packed_2;
                Packed_1 := not (Packed_1 and Packed_2);
                Remote;
            end loop;
        end loop;
        Iteration.Stop_Test (Global, Check_Times);
--
-- Be sure PACKED_1 has been computed
--
        if Packed_1 (Global rem 16) then
            Global := A_One;
            Remote;
        end if;

        Iteration.Test_Stable (Iteration_Count, Stable);
        exit when Stable;
    end loop;

    Iteration.Feature_Times (Cpu_Time, Wall_Time);
--
-- Printout
--
    Piwg_Io.Piwg_Output
       ("H000001", "Chapter 13", Cpu_Time, Wall_Time, Iteration_Count,
        " Time to perform standard boolean operations on arrays of booleans.",
        " For this test the arrays are PACKED with the pragma 'PACK.'",
        " For this test the operations are performed on the entire arrays.");

end H000001;