ParaNut SystemC Model
A SystemC Model of the ParaNut architecture
mextension.h
Go to the documentation of this file.
1 /*************************************************************************
2 
3  This file is part of the ParaNut project.
4 
5  Copyright (C) 2019 Alexander Bahle <alexander.bahle@hs-augsburg.de>
6  Hochschule Augsburg, University of Applied Sciences
7 
8  Description:
9  This is a SystemC model of the the hardware multiplier/divider
10  embedded in the execution unit (EXU) of the ParaNut.
11  It is only necessary if the RISC-V M extension is enabled (paranut-config.h).
12 
13  Redistribution and use in source and binary forms, with or without modification,
14  are permitted provided that the following conditions are met:
15 
16  1. Redistributions of source code must retain the above copyright notice, this
17  list of conditions and the following disclaimer.
18 
19  2. Redistributions in binary form must reproduce the above copyright notice,
20  this list of conditions and the following disclaimer in the documentation and/or
21  other materials provided with the distribution.
22 
23  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34  *************************************************************************/
35 
36 #ifndef MEXTENSION_H
37 #define MEXTENSION_H
38 
39 #ifndef __SYNTHESIS__
40 // Vivado HLS 2017.2 throws weird errors if the same header is included in more than one file
41 #include "base.h"
42 #endif
43 #include <systemc.h>
44 
45 // **************** MExtension Function Codes *************
46 typedef enum {
47  // MExtension
49  afDiv = 0,
51  afDivu = 1,
53  afRem = 2,
55  afRemu = 3,
56 } EMExtFunc;
57 
58 
59 // **************** MMExtension ************************
60 
61 class MMExtension : ::sc_core::sc_module {
62 public:
63  // Ports ...
64  sc_in<bool> clk, reset;
65 
66  sc_in<bool> m_enable, d_enable;
67  sc_in<sc_uint<2> > md_func;
68  sc_in<sc_uint<32> > op_a, op_b;
69 
70  sc_out<bool> m_valid, d_valid;
71  sc_out<sc_uint<32> > m_result, d_result;
72 
73  // Constructor ...
74  SC_HAS_PROCESS (MMExtension);
75  MMExtension (sc_module_name name) : sc_module (name) {
76  SC_METHOD (MulMethod);
77  sensitive << op_a << op_b << m_enable << md_func;
78  SC_METHOD (MulAddMethod);
79  sensitive << a1b1_reg << a1b2_reg << a2b1_reg << a2b2_reg << md_func;
80  SC_METHOD (DivTransitionMethod);
81  sensitive << clk.pos ();
82  SC_METHOD (DivCombMethod);
83  sensitive << op_a << op_b << d_enable << md_func << remd_reg << quot_reg << state;
84  }
85 
86  // Functions ...
87  void Trace (sc_trace_file * tf, int levels = 1);
88 
89  // Processes ...
90  void MulMethod ();
91  void MulAddMethod ();
92  void DivCombMethod ();
93  void DivTransitionMethod ();
94 
95 protected:
96  // MUL signals & registers...
97  sc_signal<sc_uint<32> > a1b1, a1b2, a2b1, a2b2, a1b1_reg, a1b2_reg, a2b1_reg, a2b2_reg;
98  sc_signal<bool> sign;
99 
100  // DIV/REM signals & registers ...
101  sc_signal<sc_uint<32> > remd, quot, remd_reg, quot_reg;
102  sc_signal<sc_uint<33> > state;
103 };
104 
105 #endif // MEXTENSION_H
Helpers, Makros and performance measuring Classes used in most ParaNut files.
Definition: mextension.h:61
sc_in< sc_uint< 2 > > md_func
Definition: mextension.h:67
sc_out< sc_uint< 32 > > d_result
Definition: mextension.h:71
sc_signal< sc_uint< 32 > > a1b1_reg
Definition: mextension.h:97
sc_out< bool > d_valid
Definition: mextension.h:70
void MulMethod()
Definition: mextension.cpp:67
void Trace(sc_trace_file *tf, int levels=1)
Definition: mextension.cpp:36
sc_out< bool > m_valid
Definition: mextension.h:70
sc_signal< sc_uint< 33 > > state
Definition: mextension.h:102
sc_signal< sc_uint< 32 > > a1b1
Definition: mextension.h:97
sc_signal< sc_uint< 32 > > a2b1_reg
Definition: mextension.h:97
sc_out< sc_uint< 32 > > m_result
Definition: mextension.h:71
sc_signal< sc_uint< 32 > > a2b2_reg
Definition: mextension.h:97
sc_in< bool > reset
Definition: mextension.h:64
sc_signal< sc_uint< 32 > > a2b2
Definition: mextension.h:97
sc_in< sc_uint< 32 > > op_a
Definition: mextension.h:68
void DivCombMethod()
Definition: mextension.cpp:164
sc_signal< sc_uint< 32 > > quot_reg
Definition: mextension.h:101
sc_in< bool > m_enable
Definition: mextension.h:66
sc_signal< sc_uint< 32 > > remd_reg
Definition: mextension.h:101
sc_in< bool > d_enable
Definition: mextension.h:66
sc_signal< bool > sign
Definition: mextension.h:98
void DivTransitionMethod()
Definition: mextension.cpp:131
sc_in< sc_uint< 32 > > op_b
Definition: mextension.h:68
sc_signal< sc_uint< 32 > > a1b2_reg
Definition: mextension.h:97
sc_signal< sc_uint< 32 > > a1b2
Definition: mextension.h:97
sc_signal< sc_uint< 32 > > remd
Definition: mextension.h:101
sc_in< bool > clk
Definition: mextension.h:64
MMExtension(sc_module_name name)
Definition: mextension.h:75
sc_signal< sc_uint< 32 > > a2b1
Definition: mextension.h:97
void MulAddMethod()
Definition: mextension.cpp:106
sc_signal< sc_uint< 32 > > quot
Definition: mextension.h:101
EMExtFunc
Definition: mextension.h:46
@ afRem
Definition: mextension.h:53
@ afMulh
Definition: mextension.h:50
@ afRemu
Definition: mextension.h:55
@ afMul
Definition: mextension.h:48
@ afMulhsu
Definition: mextension.h:52
@ afDivu
Definition: mextension.h:51
@ afMulhu
Definition: mextension.h:54
@ afDiv
Definition: mextension.h:49
sc_trace_file * tf
Definition: tlb_tb.cpp:94