Notiz
Permutation Layer
On this layer we will have a permutated value for any input index. We are given a table of inputs with its input data which we will be solving:

So 64-bit of input is taken by i_data and produces a 64-bit output at the port o_data based on the above mapping of data.
Task 1:
[!Question] Question For the implementation of the permutation layer, add a design file present_perm_layer.vhdl and copy the test bench file present_perm_layer_tb.vhdl as well as the golden reference present_perm_layer_stimuli_results.txt from the folder Exercise7 to your Vivado project. Under sources → design right click on present_perm_layer.vhdl and select Set as Top and under sources → sim right click on present_perm_layer_tb.vhdl and select Set as Top. Implement present_perm_layer until the test bench tests are performed successfully.
entity present_perm_layer is
port (
i_data : in std_ulogic_vector(63 downto 0);
o_data : out std_ulogic_vector(63 downto 0)
);
end entity present_perm_layer;
architecture rtl of present_perm_layer is
begin
gen_permutation : for i in 0 to 63 generate
o_data(16 * (i mod 4) + (i / 4)) <= i_data(i);
end generate gen_permutation;
end architecture rtl;
OR, we can also assign the value one by one for each of those 64 values.
Output of the code is viewed as:

As mentioned, the present_perm_layer_stimuli_results.txt contain the info as:
0111011010111111101011011100110111001011011111011000100010000001 0011111111011110110101111011000011111000011000001011010101110001
0110000101100110010111111101011111000111111011110101000100010110 0000011010110000101111111111100110110101011100010100111101011110
0101000001100101100111110111111010001010010010001101111011011101 0000110111011111101101110010111100100111010001001001111000001011
0111101001100111111100011000010111000111110000010110111111101100 0100101010100111101110011110111111111000010011101001110101010100
1100000010111110000001001111101101100100001111001010011111010010 1011001100011010100101101101011000110011101011010010001100100110
0001111101000101110100100001100111100111010001110000001011110101 0100100110000010011110001111001101000100110101101101101101010011
0000011110011100000000001110101011000101110011011110110110000100 0011001110111110010100101111110101000011000010000110000001010100
0000001100100000000001000011010101001101100011111000000111101011 0000000001111011000001011101001001100010000100110100001101010101
0000001011000111101100010001011011100100000011001001100010100110 0010100010011110001100011101000101011001100000110001111000001000
1010101110000000000010111001110010001011000110001101010110111101 1110011111011011000000010000110111000100010000100100011001101111
0101010110111001001101100000001001000010110011000000101101010111 0011000000110100110001001011001100101101010001011111100000000111
0101000110011000001000001000101011111001100011001000110110111100 0011001111111111100000001001010100001001100000101110000011000110
0110101001001001101100100101110010111000111000100001110111010010 0101100111100110101000110010011011001100101100010001101010001110
0001100100001100010010000011100011110101100101101111000111110110 0101010110101010000110001101101100000010100110111100001011101110
1010111110101110101001101001000011100111110011011110110100110011 1111101010111100010101001111110011111100110010110100001001010111
0100001111101011101000011100000111111011110011001011000111001011 0011101011111011101000101011001001111000110010010101010111001101
0010100110110110110111000110010000000110100001011011000110101100 0110110000101011000111110101000110110010010010100110100000011100
0111010011100110010110110111010110101001000101101111101111100010 0010010011001110111110110001101010110110100111111000111101101100
1011110010000110000010101010101100010011001100111101101000100101 1110011100001100010100000000100110010111011101101000000111111001
1000001101110100111010110111100011000000101000111000001111100010 1000110110101010001110101000001001101110001101110110011000010100
1001011101111000000101001111001110001101100000101100111100000111 1001001011101100011001100100110101100011000101011110101101000101
0111011111010100001001110001010010010111011000000000101101100110 0010000010000100111101010110001111001100011001111110011011000100
1101110001111100101110010000000101111111110010100111000001010111 1101110001110000111100001110101100101000110110011010110111001011
0110000011110010100101000011111011110011000000010000100000111011 0010100110000101101001011000000010110011110000110010101011010011
1011000101001100101001000010010111001110101001001001011000110011 1001100011101000001101011101010010001010011001111100000100001011
0100001111000000110111111010001011001100011011010111110101010000 0010111011010100101011001111111001000111001010000100110000011110
0100101100001110111100111011001101110011101100000000011010010110 0101101000100010100110001000010101011111111001010100111111100010
1100010100111101100001011100010010011101100001110000010111001000 1001101011100011110101110101011000100000000100000111010011010100
1000101111001111001101010111000011100001100010111100101101101000 1111000010111101001101101000101001011010100101100101111001010100
0010100001110010100001110101101101001111000001010001101011000100 0100100101000110001001101101001110110101010001000010011101011000
0011111001111101110100100100111100001110010001100010010011011000 0101100101000011011110110111011011100101010110001011100100000010
1100001110000000111011110000010001001011001001001101110101011011 1010110001001101100011011001111001001100011000010100010001001111
1010110001110000000000001110001100010111001111110010010011111011 1100001000010011011000100101011010100011011110110010000111110011
1101100011100010101001011001010011000100101010101100101001101110 1110101010111101101001011100101100111000001101111000011000000000
1110101111011101111110011111001010011000001010101001110011001100 1111111011011111101110100000011111001011001100000111111010001000
1101100101110100010011001001101000101111000001010000000110001011 1100011101000011101111000101000000100001110000011110001001010101
1000110011000010110011011111101001110110010100110101110100001111 1110111100000101011011101110110100010011110100010000011010111101
0101111110010010011010101000111110001101110110010010101000010001 0110011111110100110010010110000001011101000011001110000101110011
1011110111010000101100000101000110101110110111011011111001001010 1110100011111101011000100111011010001000110011011110101100111000
0111000010000001100110110011100101010110110110000100110100001101 0010110100110101100000001110110110000110010000001001111110100101
0010010110100011011000111100110110101001010111000000000011110010 0010001111010010010010110011001010111100100000110101010101100010
1011110000010101001111100000000111011100111010101111000001000001 1100010011111000010101001110101010001100001110001011100110001001
0011000111001110101110101110001110111001110101111000101111111100 0011111011101111001100100011001110011111100101101100100111110110
0111100010001011011011110000110110100100011111101010110100101010 0111010110011101100011010111010010011100101110111001010100100100
1010001011010111111001000011011011111001101001100010001100100101 1010100011100000001111011001000111011011101111100011001011000101
1000101001010100001110001011110000110110110001001010100010101101 1100011100101111001100010111000101001010110010100010101010000001
0101100011000101111001101110000100001101011100010110010100100011 0110101001000000101111100110110000001110001010111001000101110101
1100010001110111111101000110011101011011011110011110111111010101 1000100001011110111111111010111100111011011011000011100111110111
1011011011000101110100011111100101100011111010011101010011101111 1010101100111011011110101010111111000010111000111001111101011001
1101100111000001011111001111000000101110011111000001010110100100 1110011001010010101011100111010100001010111000101101101000101100
0001000001111011010000000010111011010101101001001101011110110111 0001000110101010001010011101110100110011001001111011000011001111
1110101101001101011000011000100111010010111011011001001111000011 1101001110111010101110001011001011001000011001010101010110011101
1000111101101011111100101011011111101111110010101100011100101110 1101101011111001011010011110110101111111110101110101101101000100
0100011000101101100100110001101110100100111010001010000111101111 0001100110111011110100000110001101100101101010110001111100000101
0101011001111010101101101110110100010100000101000111010010011101 0001101100000011111001110101110101111110000010001010100110101011
0110011001000001110001001111110001011110101100111010111010010100 0000101101101110111011111100010111000010011111000001001010110010
1111000111010010000001101010000100110010001011101000001111000101 1010001000011010101001000001001110010110111101001110000110000101
1000010010000011100000101010101000110100001100111111000100000101 1010101100001000010000000100100100010111101110000001000010111101
0000001010100111010011101001100001000100110010100001100001001000 0010011100110101000111001110001001110100000100000001001000001000
0011110110001111001011010110110101001000011111110101111001100000 0111010101010100010101111011111010011010001101101101010100111000
1110100000001101001010010110010011100001010001111110110001110010 1101010010001100100100111011111010001010100110110001010001010010
1011010000111100100010011111111110011001110000000111111001110000 1001111111100100010100110010111010100011000011101010011111001010
0110111001011110000101110000011111010110101010111100000011001000 0101000010111011111101011100101011010101011100000010110110010000
0011011110101110100101000111010101100111101100010001110111111000 0011100000100111010101111100011011110010111000101100101101111110
1001100100100000001011101001011000011110010001001101100011110110 1100011001001110000001010111101100101101010000111100001010001010
1101010111100101100000011011001000110000001010111000000010110110 1010101000011010111100000000000100100011101100111101011010010010
1011101100110100011001001010001100110111100000111000100101011111 1100001000101101000111000100001111101011110100011110000111010111
1011001110011100101011100110101110010010010111010111010011100111 1011110110010010000101100011111111001111010010111110000110111001
1101101110110111001110001110100000011011011100111110011111110010 1110011101001010100100100010111001111010011111111111100011110110
0110010111100111101110011011100100110100111011010111110011011111 0010111100110111111100000111111110111010101010010101111110011011
1010101101111110001001000011010010110100110110010100010000001100 1101000010110001001101010110110111111010100000000110001010110000
1011110100011110101011100111111001011100111000000110111111111111 1101110101100111010101111110111110011111001011111110001010000111
0100111101011011000101010011010000000001111100000100001011000010 0101000000100010111001010010101001010010001001010111111001100000
1000101000011001101010001001011011100111011010001010000011110110 1101111010011010000000011110001101001001111010110011001001000010
0001110011011100110110011100100001001010110000010011101101001100 0111111101100101011110101010001100000000010011001010110000011100
0111110101011000111100011100101111001010000000001000111111111110 0101101111001111111010101000011110001001010001111110110100000110
1010000000110011000010010100111010101101111011101101001101110100 1000010111111000000000110111101110110001101101100011010001001110
0110011110000011111000011010111110000010010110011101001010011011 0010101110011011110010010010100011011011010001010101010100111011
0110011001101001111010101000011100100000011100011001001110001110 0001111000001011111010010010000111101101101001010001000100111100
1000111001001100100011010101100101001011010010111010101001110110 1101110101011100011101101010001101000000010111110000011101010010
1100011011010110000010110110011110101100010110110111101011011100 1010010011010111111100110110101101010111100111000010010100111010
0011101110111100010011011100001110011011100001101000101101101010 0111011011101101000111100001001011100001010101111110010111000100
1010000000001100110010100110010010011101000000101011100100111001 1001110011001101000110110100000010000110000110100000000011001111
1110101000100110100100001100110110111001110110011000010110110001 1100101111111010100100110010010011110000100000100000100111110111
0010100100101011111110010101111110010101101011110011101010100101 0101110110110110000010110101000110111001001111100101111111011001
1011011000000010100111000101110010100111001100010111000001100011 1000110110000000010001110100101011010000111010111000101001111001
0001110111011010111000001110011011100000111100001110101001111000 0111101010101101011010111010101000011011101011101110000000100010
0111010001001010100100101010111100101111010101101110101001101000 0001101101001101111000010111101010010111110111101000100101100000
1100000000010110001101010000000110001110110110010001110100011010 1000000011110101100101000110010000011000010000010010110100111110
0111100001100100110000000111111001001100101101100010011100011100 0100100101100001101110111101010110100011001111001000001000100110
1100001101000011100101010100110000000101100101011111111001100111 1000100100101100101001110101111101010000000011110101110001111001
0111000100000011100111110100110101111001011000010011011110100110 0000110101000010100001111010010110010100101011111101110111011100
0100010110100010110111001000100001000110101011011111111011011101 0010111100111111110011001101111100110000011011000100100000011011
1101111001001100001100101111110011100101111110110100011000110101 1101001110110000111100111110110101001110101101101000101001110011
0010011010101110100110001110010101110011100000011101010001111111 0011111000101001010100111000111111110010110000110000100111011011
1101011000010111111101011100010111110001110100101011100001101001 1000101010101101110111111010001001011000100110101011110111101001
1010110110111011011000000111001100111100010100111101111000110011 1111000001001100010010100110110010111011100101110111001110111011
0001010101000011101101110000111001001100100100011100100011000011 0000100101101110011001011100101000011101000000011101110000110001
0001000010010011111000010100100011001010010111110111111110010000 0010100111010110000010101011110000011000010111001011010000111110
0101101101011111001100111100011110100110101011001000001111001101 0101001010111011101100110101001101011101111001001111110100000101
Testbench code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
use std.env.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity perm_layer_tb is
end entity perm_layer_tb;
architecture tb of perm_layer_tb is
constant bit_width : integer := 64;
component present_perm_layer is
port(
i_data: in std_ulogic_vector(63 downto 0);
o_data: out std_ulogic_vector(63 downto 0)
);
end component present_perm_layer;
signal perm_layer_in : std_ulogic_vector(bit_width-1 downto 0);
signal perm_layer_out : std_ulogic_vector(bit_width-1 downto 0);
begin
present_perm_layer_inst: present_perm_layer
port map (
i_data => perm_layer_in,
o_data => perm_layer_out
);
present_perm_layer_test : process
variable perm_layer_out_val : std_ulogic_vector (bit_width-1 downto 0);
variable num_input_written : integer;
file in_out_vectors : text;
variable get_line : line;
variable sep_whitespace : character;
variable stimuli_in : std_ulogic_vector(bit_width-1 downto 0);
variable result_out : std_ulogic_vector(bit_width-1 downto 0);
begin
file_open(in_out_vectors, "present_perm_layer_stimuli_results.txt", read_mode);
perm_layer_in <= (others =>'X');
perm_layer_out_val := (others => '0');
wait for 100 ns;
while not endfile(in_out_vectors) loop
readline(in_out_vectors, get_line);
read(get_line, stimuli_in);
read(get_line, sep_whitespace);
read(get_line, result_out);
-- Pass the variable to a signal to allow the ripple-carry to use it
perm_layer_in <= stimuli_in;
perm_layer_out_val := result_out;
wait for 20 ns;
assert perm_layer_out = perm_layer_out_val report "PRESENT Permutation Layer output wrong! Permutation Layer Input: " & to_hstring(to_bitvector(perm_layer_in)) & "h" & " | Expected Output: " & to_hstring(to_bitvector(perm_layer_out_val)) & "h" & " | Actual Output: " & to_hstring(to_bitvector(perm_layer_out)) & "h" severity failure;
end loop;
perm_layer_in <= (others =>'X');
wait for 100 ns;
assert false report "PRESENT Permutation Layer test passed!" severity note;
std.env.finish;
end process present_perm_layer_test;
end architecture tb;
And the testbench performed successfully:
