OpenCores
URL https://opencores.org/ocsvn/mips_16/mips_16/trunk

Subversion Repositories mips_16

[/] [mips_16/] [trunk/] [rtl/] [hazard_detection_unit.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 Doyya
/***************************************************
2
 * Module: hazard_detection_unit
3
 * Project: mips_16
4
 * Author: fzy
5
 * Description:
6
 *    Data Hazard detection. if there is a RAW hazard, it will stall the pipeline.
7
 *
8
 *       *       Method: It compare the source register of the instruction in ID_stage
9
 *                       and it's previous 3 instructions' destination register. If
10
 *                       the source register is equal to any of the three destination regs
11
 *                       and not equals to zero, the Hazard Detction Unit will assert
12
 *                       pipeline_stall signal. That signal will freeze the IF & ID stage,
13
 *                       and insert bubbles into EX stage. When the hazard instruction
14
 *                       was flushed out of the pipeline, pipeline_stall signal will
15
 *                       be canceled.
16
 *
17
 * Revise history:
18
 *
19
 ***************************************************/
20
module hazard_detection_unit
21
(
22
        input           [2:0]            decoding_op_src1,               //ID stage source_1 register number
23
        input           [2:0]            decoding_op_src2,               //ID stage source_2 register number
24
 
25
        input           [2:0]            ex_op_dest,                             //EX stage destinaton register number
26
        input           [2:0]            mem_op_dest,                    //MEM stage destinaton register number
27
        input           [2:0]            wb_op_dest,                             //WB stage destinaton register number
28
 
29
        output  reg                             pipeline_stall_n                // Active low
30
);
31
 
32
        always @ (*) begin
33
                pipeline_stall_n = 1;
34
 
35
                if( decoding_op_src1 != 0 &&
36
                        (
37
                                decoding_op_src1 == ex_op_dest  ||
38
                                decoding_op_src1 == mem_op_dest ||
39
                                decoding_op_src1 == wb_op_dest
40
                        )
41
                )
42
                        pipeline_stall_n = 0;
43
 
44
                if( decoding_op_src2 != 0 &&
45
                        (
46
                                decoding_op_src2 == ex_op_dest  ||
47
                                decoding_op_src2 == mem_op_dest ||
48
                                decoding_op_src2 == wb_op_dest
49
                        )
50
                )
51
                        pipeline_stall_n = 0;
52
 
53
 
54
        end
55
 
56
 
57
 
58
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.