1 |
2 |
madsilicon |
-----------------------------------------------------------------
|
2 |
|
|
-- --
|
3 |
|
|
-----------------------------------------------------------------
|
4 |
|
|
-- --
|
5 |
|
|
-- Copyright (C) 2015 Stefano Tonello --
|
6 |
|
|
-- --
|
7 |
|
|
-- This source file may be used and distributed without --
|
8 |
|
|
-- restriction provided that this copyright statement is not --
|
9 |
|
|
-- removed from the file and that any derivative work contains --
|
10 |
|
|
-- the original copyright notice and the associated disclaimer.--
|
11 |
|
|
-- --
|
12 |
|
|
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY --
|
13 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED --
|
14 |
|
|
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS --
|
15 |
|
|
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR --
|
16 |
|
|
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, --
|
17 |
|
|
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES --
|
18 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE --
|
19 |
|
|
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR --
|
20 |
|
|
-- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
|
21 |
|
|
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
|
22 |
|
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT --
|
23 |
|
|
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE --
|
24 |
|
|
-- POSSIBILITY OF SUCH DAMAGE. --
|
25 |
|
|
-- --
|
26 |
|
|
-----------------------------------------------------------------
|
27 |
|
|
|
28 |
|
|
---------------------------------------------------------------
|
29 |
|
|
-- RV01 division support logic
|
30 |
|
|
---------------------------------------------------------------
|
31 |
|
|
|
32 |
|
|
library IEEE;
|
33 |
|
|
use IEEE.std_logic_1164.all;
|
34 |
|
|
use IEEE.numeric_std.all;
|
35 |
|
|
|
36 |
|
|
library WORK;
|
37 |
|
|
use WORK.RV01_CONSTS_PKG.all;
|
38 |
|
|
use WORK.RV01_TYPES_PKG.all;
|
39 |
|
|
use WORK.RV01_ARITH_PKG.all;
|
40 |
|
|
use work.RV01_IDEC_PKG.all;
|
41 |
|
|
use work.RV01_OP_PKG.all;
|
42 |
|
|
|
43 |
|
|
entity RV01_DIVLOG is
|
44 |
|
|
port(
|
45 |
|
|
V_i : in std_logic;
|
46 |
|
|
INSTR_i : in DEC_INSTR_T;
|
47 |
|
|
DIV_V_i : in std_logic;
|
48 |
|
|
|
49 |
|
|
DIV_STRT_o : out std_logic;
|
50 |
|
|
DIV_QS_o : out std_logic;
|
51 |
|
|
DIV_CLRV_o : out std_logic
|
52 |
|
|
);
|
53 |
|
|
end RV01_DIVLOG;
|
54 |
|
|
|
55 |
|
|
architecture ARC of RV01_DIVLOG is
|
56 |
|
|
|
57 |
|
|
begin
|
58 |
|
|
|
59 |
|
|
-- Division start flag: a new division can start
|
60 |
|
|
-- if current instruction is valid, is of
|
61 |
|
|
-- division/reminder type and there's no result
|
62 |
|
|
-- ready (if there's a result ready, instruction
|
63 |
|
|
-- has been already re-fetched and therefore there
|
64 |
|
|
-- is no need to re-execute it).
|
65 |
|
|
|
66 |
|
|
DIV_STRT_o <= (V_i and not(DIV_V_i)) when (
|
67 |
|
|
INSTR_i.ALU_OP = ALU_DIV or
|
68 |
|
|
INSTR_i.ALU_OP = ALU_REM
|
69 |
|
|
) else '0';
|
70 |
|
|
|
71 |
|
|
-- Division Quotient/Reminder result selection flag
|
72 |
|
|
|
73 |
|
|
DIV_QS_o <= '1' when (
|
74 |
|
|
INSTR_i.ALU_OP = ALU_DIV
|
75 |
|
|
) else '0';
|
76 |
|
|
|
77 |
|
|
-- Clear division result valid flag: if current
|
78 |
|
|
-- instruction is valid, is of division/reminder
|
79 |
|
|
-- type and there's a result ready, result valid
|
80 |
|
|
-- flag can be cleared.
|
81 |
|
|
|
82 |
|
|
DIV_CLRV_o <= (V_i and DIV_V_i) when (
|
83 |
|
|
INSTR_i.ALU_OP = ALU_DIV or
|
84 |
|
|
INSTR_i.ALU_OP = ALU_REM
|
85 |
|
|
) else '0';
|
86 |
|
|
|
87 |
|
|
end ARC;
|