package n_bits_int is subtype bits9 is integer range -2** 8 to 2** 8 -1;
subtype bits17 is integer range -2** 16 to 2** 16 -1; type array_bits17_5 is
array( 0 to 4) of bits17; type state_type is( start, leftshift, sop, rightshift
, done); type op_type is( load, mac, scale, denorm, nop); end n_bits_int;
library work; use work.n_bits_int.ALL; library ieee; use
ieee.std_logic_1164.ALL; use ieee.std_logic_arith.ALL; use
ieee.std_logic_signed.ALL;
--***********************************************************************
-- VHDL obfuncation test V1.0 using sqrt.vhd from the book DSP with FPGAs
-- Author: Dr. Uwe Meyer-Baese EMAIL: Uwe.Meyer-Baese@ieee.org
--***********************************************************************
entity sqrt128 is port( clk, reset: in std_logic; x_in: in bits17; a_o, imm_o, f_o
: out bits17; ind_o: out integer range 0 to 4; count_o: out integer range 0 to 3
; x_o, pre_o, post_o: out bits17; f_out: out bits17); end sqrt128; architecture
fpga of sqrt128 is SIGNAL
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
: state_type; SIGNAL
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
: op_type; SIGNAL
l11ll111lll1111l1lll1l1111l1ll11l1lll1111ll1ll11ll1ll1l1l1lll111l1ll1l111ll1l1lll11l1l1lll1ll11l1lll11111l1l11lllllll1ll11l11lll
: bits17 := 0; SIGNAL
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
,
lll11ll1l1l1l11l1ll1l11lll11ll1l1l1ll1ll11ll111111llll11l11l11l1l1ll111l1lll11l1l1lllll1ll111ll1ll1ll1l1ll11l11l1111ll1l1111111l
,
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
,
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
: bits17 := 0; CONSTANT
lll11l1l111l1l111lll11l11ll11llll1lll1lllll11l111l11l1l1ll1111111l1ll1l1ll11l1111l111ll1lll11ll1l1l1l1l1llll1111ll1lll11ll1lll11
: array_bits17_5 :=( 7563, 42299, -29129, 15813, -3778); SIGNAL
l11111llll1l111lll1ll1l11111l11l11111l1ll1ll11l1l1lll1l111l111ll11111l1l111ll11llll1llll1lll111ll1l1ll1l1l11l11ll1l1ll1ll1l1lll1
,
l11lll1lll11ll1ll1l1111l11l1l1ll1l1lll1l1lll1111111l11llll1l111lllllllllll11l11l111l1lll1ll11l1111l11ll1ll11l11ll11lll1ll1l1111l
: bits17; begin states: process( clk) VARIABLE
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
: integer range -1 to 4 := 0; VARIABLE
l111111ll11l1ll11111lll1ll1l111lll1ll11ll1l1lllll1ll11llll11111l1l11lll11l11l1lll11l1l1l1l11ll111lll11l1l1ll1lllll11l1l1ll1111ll
: integer range 0 to 3; begin if reset= '1' then
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
<= start; elsif rising_edge( clk) then case
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
is when start =>
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
<= leftshift;
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
:= 4;
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
<= x_in;
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= load;
l111111ll11l1ll11111lll1ll1l111lll1ll11ll1l1lllll1ll11llll11111l1l11lll11l11l1lll11l1l1l1l11ll111lll11l1l1ll1lllll11l1l1ll1111ll
:= 0; when leftshift =>
l111111ll11l1ll11111lll1ll1l111lll1ll11ll1l1lllll1ll11llll11111l1l11lll11l11l1lll11l1l1l1l11ll111lll11l1l1ll1lllll11l1l1ll1111ll
:=
l111111ll11l1ll11111lll1ll1l111lll1ll11ll1l1lllll1ll11llll11111l1l11lll11l11l1lll11l1l1l1l11ll111lll11l1l1ll1lllll11l1l1ll1111ll
+ 1;
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
<=
l11111llll1l111lll1ll1l11111l11l11111l1ll1ll11l1l1lll1l111l111ll11111l1l111ll11llll1llll1lll111ll1l1ll1l1l11l11ll1l1ll1ll1l1lll1
;
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= scale;
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
<=
lll11l1l111l1l111lll11l11ll11llll1lll1lllll11l111l11l1l1ll1111111l1ll1l1ll11l1111l111ll1lll11ll1l1l1l1l1llll1111ll1lll11ll1lll11
( 4); if
l111111ll11l1ll11111lll1ll1l111lll1ll11ll1l1lllll1ll11llll11111l1l11lll11l11l1lll11l1l1l1l11ll111lll11l1l1ll1lllll11l1l1ll1111ll
= 3 then
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
<= sop;
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= load;
l11ll111lll1111l1lll1l1111l1ll11l1lll1111ll1ll11ll1ll1l1l1lll111l1ll1l111ll1l1lll11l1l1lll1ll11l1lll11111l1l11lllllll1ll11l11lll
<=
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
; end if; when sop =>
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
:=
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
- 1;
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
<=
l11ll111lll1111l1lll1l1111l1ll11l1lll1111ll1ll11ll1ll1l1l1lll111l1ll1l111ll1l1lll11l1l1lll1ll11l1lll11111l1l11lllllll1ll11l11lll
; if
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
= -1 then
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
<= rightshift;
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= denorm;
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
<=
l11lll1lll11ll1ll1l1111l11l1l1ll1l1lll1l1lll1111111l11llll1l111lllllllllll11l11l111l1lll1ll11l1111l11ll1ll11l11ll11lll1ll1l1111l
; else
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
<=
lll11l1l111l1l111lll11l11ll11llll1lll1lllll11l111l11l1l1ll1111111l1ll1l1ll11l1111l111ll1lll11ll1l1l1l1l1llll1111ll1lll11ll1lll11
(
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
);
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= mac; end if; when rightshift =>
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
<= done;
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= nop; when done => f_out <=
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
;
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
<= nop;
lll111l1llll1lll11111l1lll1l1lll1l111l11l1ll1l1ll1l111l11lll1ll1lll1lll11l1111lllll1ll1lll1lll1l11l1l1ll11l111l1l1ll11l1lll1l1ll
<= start; end case; end if; ind_o <=
l111l11ll1ll1l1l1111l1l1111l11l11llll111l1lll111l1111llll1lll111l1llll11l1ll1l1lll11l1l11lll1llll111ll1l1ll1l111l11ll111l11l1l11
; count_o <=
l111111ll11l1ll11111lll1ll1l111lll1ll11ll1l1lllll1ll11llll11111l1l11lll11l11l1lll11l1l1l1l11ll111lll11l1l1ll1lllll11l1l1ll1111ll
; end process states; alu: process begin wait until clk= '1'; case
lllll1l11lll11llllll111l1lllll111l11111ll11111111111llll1lll1lllll1l11l1ll11111l1111l1111111ll1l1lll11l11l11l1ll1ll1llll11lll1ll
is when load =>
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
<=
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
; when mac =>
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
<=
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
*
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
/ 32768+
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
; when scale =>
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
<=
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
*
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
; when denorm =>
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
<=
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
*
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
/ 32768; when nop =>
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
<=
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
; when others =>
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
<=
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
; end case; end process alu; exp: process( x_in) VARIABLE
ll111111ll11l1111l1l1111l1111l1lll11ll111l1l1l1l1l11l1l1ll111l1l111l1lll11l111l1l11ll1111l111ll11l11l1lllllll111l1ll11lll1l11111
: std_logic_vector( 16 downto 0); VARIABLE
l1l1l1l111ll1l1ll111l111l1l11l111l1ll1l11l1l111l1l11l11lll111ll11l11ll1111111lll1l1l11ll11lll1l1lll1ll11lll1l1l1l1l11l111ll11l1l
,
l1l111111l111ll1l1ll111l1l11ll111ll111111l11l11l11111ll1l11lllll1lll11l111lllll11llll11l11l11l111llllllll11lll1lll1l1l1l1l1lll11
: bits17; begin
ll111111ll11l1111l1l1111l1111l1lll11ll111l1l1l1l1l11l1l1ll111l1l111l1lll11l111l1l11ll1111l111ll11l11l1lllllll111l1ll11lll1l11111
:= conv_std_logic_vector( x_in, 17);
l1l111111l111ll1l1ll111l1l11ll111ll111111l11l11l11111ll1l11lllll1lll11l111lllll11llll11l11l11l111llllllll11lll1lll1l1l1l1l1lll11
:= 2** 14; for k in 0 to 15 loop if
ll111111ll11l1111l1l1111l1111l1lll11ll111l1l1l1l1l11l1l1ll111l1l111l1lll11l111l1l11ll1111l111ll11l11l1lllllll111l1ll11lll1l11111
( k)= '1' then
l11111llll1l111lll1ll1l11111l11l11111l1ll1ll11l1l1lll1l111l111ll11111l1l111ll11llll1llll1lll111ll1l1ll1l1l11l11ll1l1ll1ll1l1lll1
<=
l1l111111l111ll1l1ll111l1l11ll111ll111111l11l11l11111ll1l11lllll1lll11l111lllll11llll11l11l11l111llllllll11lll1lll1l1l1l1l1lll11
; end if;
l1l111111l111ll1l1ll111l1l11ll111ll111111l11l11l11111ll1l11lllll1lll11l111lllll11llll11l11l11l111llllllll11lll1lll1l1l1l1l1lll11
:=
l1l111111l111ll1l1ll111l1l11ll111ll111111l11l11l11111ll1l11lllll1lll11l111lllll11llll11l11l11l111llllllll11lll1lll1l1l1l1l1lll11
/ 2; end loop;
l1l1l1l111ll1l1ll111l111l1l11l111l1ll1l11l1l111l1l11l11lll111ll11l11ll1111111lll1l1l11ll11lll1l1lll1ll11lll1l1l1l1l11l111ll11l1l
:= 1; for k in 0 to 7 loop if
ll111111ll11l1111l1l1111l1111l1lll11ll111l1l1l1l1l11l1l1ll111l1l111l1lll11l111l1l11ll1111l111ll11l11l1lllllll111l1ll11lll1l11111
( 2* k)= '1' then
l1l1l1l111ll1l1ll111l111l1l11l111l1ll1l11l1l111l1l11l11lll111ll11l11ll1111111lll1l1l11ll11lll1l1lll1ll11lll1l1l1l1l11l111ll11l1l
:= 256* 2** k; end if; if
ll111111ll11l1111l1l1111l1111l1lll11ll111l1l1l1l1l11l1l1ll111l1l111l1lll11l111l1l11ll1111l111ll11l11l1lllllll111l1ll11lll1l11111
( 2* k +1)= '1' then
l1l1l1l111ll1l1ll111l111l1l11l111l1ll1l11l1l111l1l11l11lll111ll11l11ll1111111lll1l1l11ll11lll1l1lll1ll11lll1l1l1l1l11l111ll11l1l
:= 2**( k +9) -2**( k +7) -2**( k +5) +2**( k +3) +2**( k +1) +2** k/ 32; end
if;
l11lll1lll11ll1ll1l1111l11l1l1ll1l1lll1l1lll1111111l11llll1l111lllllllllll11l11l111l1lll1ll11l1111l11ll1ll11l11ll11lll1ll1l1111l
<=
l1l1l1l111ll1l1ll111l111l1l11l111l1ll1l11l1l111l1l11l11lll111ll11l11ll1111111lll1l1l11ll11lll1l1lll1ll11lll1l1l1l1l11l111ll11l1l
; end loop; end process exp; a_o <=
lllll1111ll1llll11ll1l11lll111lll1l111l1lll11ll11l1ll11lll1111111111l1l11ll1l111llllll1lll111111l1l1111ll1lll1ll11lll1111111llll
; imm_o <=
lll11l1l1ll1l1lll1l111ll1lll1l1ll111l111l11llll1l1l11ll111l111ll1lll1llll1ll1llll11ll1ll11l1llllll1l1l11l11lllll1ll111l1111ll111
; f_o <=
l1l11ll1111l11111l1ll1lll1lll11lll1l111111ll1l11l11ll1ll1111lll1l1111l11lll1lll11l1l11l111l1lll11ll1l111111l1l1l1111111llll111l1
; pre_o <=
l11111llll1l111lll1ll1l11111l11l11111l1ll1ll11l1l1lll1l111l111ll11111l1l111ll11llll1llll1lll111ll1l1ll1l1l11l11ll1l1ll1ll1l1lll1
; post_o <=
l11lll1lll11ll1ll1l1111l11l1l1ll1l1lll1l1lll1111111l11llll1l111lllllllllll11l11l111l1lll1ll11l1111l11ll1ll11l11ll11lll1ll1l1111l
; x_o <=
l11ll111lll1111l1lll1l1111l1ll11l1lll1111ll1ll11ll1ll1l1l1lll111l1ll1l111ll1l1lll11l1l1lll1ll11l1lll11111l1l11lllllll1ll11l11lll
; -- No Warranty! What so ever ! copyright 2011 Uwe Meyer-Baese
end fpga;