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

Subversion Repositories edge

[/] [edge/] [trunk/] [HW/] [Verilog/] [alu_decoder.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 heshamelma
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  ALU decoder for Edge core                                   //
4
//                                                              //
5
//  This file is part of the Edge project                       //
6
//  http://www.opencores.org/project,edge                       //
7
//                                                              //
8
//  Description                                                 //
9
//  ALU decoder decodes functions encoded in MIPS instruction   //
10
//  and sends out the appropriate command to ALU unit.          //
11
//                                                              //
12
//  Author(s):                                                  //
13
//      - Hesham AL-Matary, heshamelmatary@gmail.com            //
14
//                                                              //
15
//////////////////////////////////////////////////////////////////
16
//                                                              //
17
// Copyright (C) 2014 Authors and OPENCORES.ORG                 //
18
//                                                              //
19
// This source file may be used and distributed without         //
20
// restriction provided that this copyright statement is not    //
21
// removed from the file and that any derivative work contains  //
22
// the original copyright notice and the associated disclaimer. //
23
//                                                              //
24
// This source file is free software; you can redistribute it   //
25
// and/or modify it under the terms of the GNU Lesser General   //
26
// Public License as published by the Free Software Foundation; //
27
// either version 2.1 of the License, or (at your option) any   //
28
// later version.                                               //
29
//                                                              //
30
// This source is distributed in the hope that it will be       //
31
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
32
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
33
// PURPOSE.  See the GNU Lesser General Public License for more //
34
// details.                                                     //
35
//                                                              //
36
// You should have received a copy of the GNU Lesser General    //
37
// Public License along with this source; if not, download it   //
38
// from http://www.opencores.org/lgpl.shtml                     //
39
//                                                              //
40
//////////////////////////////////////////////////////////////////
41
 
42
`define ADD_ALUOP   4'b0000
43
`define SUB_ALUOP   4'b0001
44
`define LOOK_FUNCT  4'b0010
45
`define INVAL       4'b0011
46
`define SLTI_ALUOP  4'b0100
47
`define ANDI_ALUOP  4'b0101
48
`define ORI_ALUOP   4'b0110
49
`define XORI_ALUOP  4'b0111
50
`define MUL_ALUOP   4'b1000
51
 
52
/* ALUControl output defines */
53
`define ADD_ALUCTRL   4'b0010
54
`define SUB_ALUCTRL   4'b0110
55
`define AND_ALUCTRL   4'b0000
56
`define OR_ALUCTRL    4'b0001
57
`define SLT_ALUCTRL   4'b0111
58
`define XOR_ALUCTRL   4'b0011
59
`define NOR_ALUCTRL   4'b0100
60
`define MUL_ALUCTRL   4'b1000
61
 
62
/* FUNCT defines INST[5:0] */
63
`define SLL_FUNCT   6'b000000 // 0 
64
`define SRL_FUNCT   6'b000010 // 2
65
`define SRA_FUNCT   6'b000011 // 3
66
`define SLLV_FUNCT  6'b000100 // 4
67
`define SRLV_FUNCT  6'b000110 // 6
68
`define SRAV_FUNCT  6'b000111 // 7
69
`define ADD_FUNCT   6'b100000 // 32
70
`define ADDU_FUNCT  6'b100001 // 33
71
`define SUB_FUNCT   6'b100010 // 34
72
`define SUBU_FUNCT  6'b100011 // 35
73
`define AND_FUNCT   6'b100100 // 36
74
`define OR_FUNCT    6'b100101 // 37
75
`define XOR_FUNCT   6'b100110 // 38
76
`define NOR_FUNCT   6'b100111 // 39
77
`define SLT_FUNCT   6'b101010 // 42
78
`define SLTU_FUNCT  6'b101011 // 43
79
 
80
module alu_decoder
81
(
82
  input[3:0] ALUop,
83
  input[5:0] Funct,
84
  output reg[3:0] ALUControl
85
);
86
 
87
always @*
88
begin
89
 
90
  case(ALUop)
91
    `ADD_ALUOP :  ALUControl <= `ADD_ALUCTRL;
92
    `SUB_ALUOP :  ALUControl <= `SUB_ALUCTRL;
93
    `SLTI_ALUOP:  ALUControl <= `SLT_ALUCTRL;
94
    `ANDI_ALUOP:  ALUControl <= `AND_ALUCTRL;
95
    `ORI_ALUOP :  ALUControl <= `OR_ALUCTRL;
96
    `XORI_ALUOP:  ALUControl <= `XOR_ALUCTRL;
97
    `MUL_ALUOP :  ALUControl <= `MUL_ALUCTRL;
98
    `LOOK_FUNCT:  ALUControl <= funct_decode(Funct);
99
    `INVAL     :  ALUControl <= 3'b000; /* (nop) Mapped to be add operation */
100
    default    :  ALUControl <= `ADD_ALUCTRL;
101
  endcase
102
end
103
 
104
function[3:0] funct_decode (input[5:0] funct);
105
  case (funct)
106
    `ADD_FUNCT,
107
    `ADDU_FUNCT:
108
      funct_decode = `ADD_ALUCTRL;
109
    `SUB_FUNCT,
110
    `SUBU_FUNCT:
111
      funct_decode = `SUB_ALUCTRL;
112
    `NOR_FUNCT,
113
    `OR_FUNCT:
114
      funct_decode = `OR_ALUCTRL;
115
    `XOR_FUNCT:
116
      funct_decode = `XOR_ALUCTRL;
117
    `SLT_FUNCT, `SLTU_FUNCT:
118
      funct_decode = `SLT_ALUCTRL;
119
    default:
120
      funct_decode = 5'b00000;
121
  endcase
122
 
123
endfunction
124
 
125
endmodule

powered by: WebSVN 2.1.0

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