File: ../../Sources/A19_run_interruption_error.vhd
0: ----------------------------------------------------------------------------------
1: -- Engineer: Vitor Mendes Camilo
2: --
3: -- Module Name: A19_run_interruption_error - Behavioral
4: -- Description: Code segment A.19 — error computation for run-interruption
5: -- sample (lossless only).
6: --
7: -- With NEAR=0, the T.87 Quantize() step is identity and
8: -- Rx = Ix, so no reconstruction is produced here. Only:
9: -- - sign flip when RItype=0 and Ra > Rb
10: -- - modulo reduction (A.9 inlined)
11: ----------------------------------------------------------------------------------
12:
13: library ieee;
14: use ieee.std_logic_1164.all;
15: use ieee.numeric_std.all;
16: use work.openjls_pkg.all;
17:
18: entity a19_run_interruption_error is
19: generic (
20: BITNESS : natural range 8 to 16 := CO_BITNESS_STD;
21: RANGE_P : natural := CO_RANGE_STD
22: );
23: port (
24: iErrval : in signed (BITNESS downto 0);
25: iRItype : in std_logic;
26: iRa : in unsigned (BITNESS - 1 downto 0);
27: iRb : in unsigned (BITNESS - 1 downto 0);
28: oErrval : out signed (BITNESS downto 0);
29: oSign : out std_logic
30: );
31: end entity a19_run_interruption_error;
32:
33: architecture behavioral of a19_run_interruption_error is
34:
35: begin
36:
37: p_ri_error : process (iErrval, iRItype, iRa, iRb) is
38:
39: variable vErr : integer;
40: variable vErrAdj : integer;
41:
42: begin
43:
44: -- Sign adjustment: RItype=0 and Ra > Rb → negate error
45: if (iRItype = '0' and iRa > iRb) then
46: vErr := - to_integer(iErrval);
47: oSign <= CO_SIGN_NEG;
48: else
49: vErr := to_integer(iErrval);
50: oSign <= CO_SIGN_POS;
51: end if;
52:
53: -- Modulo reduction (A.9 inline)
54: vErrAdj := vErr;
55:
56: if (vErrAdj < 0) then
57: vErrAdj := vErrAdj + RANGE_P;
58: end if;
59:
60: if (vErrAdj >= (RANGE_P + 1) / 2) then
61: vErrAdj := vErrAdj - RANGE_P;
62: end if;
63:
64: oErrval <= to_signed(vErrAdj, oErrval'length);
65:
66: end process p_ri_error;
67:
68: end architecture behavioral;