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

Subversion Repositories m1_core

[/] [m1_core/] [trunk/] [hdl/] [rtl/] [m1_core/] [m1_alu.v] - Blame information for rev 33

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 fafa1971
/*
2
 * Simply RISC M1 Arithmetic-Logic Unit
3
 *
4
 * Simple RTL-level ALU with Alternating Bit Protocol (ABP) interface.
5
 */
6
 
7
`include "m1_defs.vh"
8
 
9
// Combinational ALU with 32-bit operands
10
module m1_alu(
11
    input[31:0] a_i,             // Operands A
12
    input[31:0] b_i,             // Operands B
13
    input[4:0] func_i,           // Function to be performed
14
    input signed_i,              // Operation is signed
15
    output reg[31:0] result_o,   // Result
16
    output carry_o               // Carry bit
17
  );
18
 
19
  // Carry is currently unused
20
  assign carry_o = 0;
21
 
22
  // ALU Logic
23
  always @(a_i or b_i or func_i or signed_i) begin
24
    case(func_i)
25
      `ALU_OP_SLL: result_o = a_i << b_i[4:0];
26
      `ALU_OP_SRL: result_o = a_i >> b_i[4:0];
27
      `ALU_OP_SRA: result_o = {{32{a_i[31]}}, a_i } >> b_i[4:0];
28
      `ALU_OP_ADD: result_o = a_i + b_i;
29
      `ALU_OP_SUB: result_o = a_i - b_i;
30
      `ALU_OP_AND: result_o = a_i & b_i;
31
      `ALU_OP_OR:  result_o = a_i | b_i;
32
      `ALU_OP_XOR: result_o = a_i ^ b_i;
33
      `ALU_OP_NOR: result_o = ~(a_i | b_i);
34
      `ALU_OP_SEQ: result_o = (a_i == b_i) ? 32'b1 : 32'b0;
35
      `ALU_OP_SNE: result_o = (a_i != b_i) ? 32'b1 : 32'b0;
36
      `ALU_OP_SLT: if(signed_i) result_o = ({~a_i[31],a_i[30:0]} < {~b_i[31],b_i[30:0]}) ? 32'b1 : 32'b0;
37
                   else result_o = a_i < b_i;
38
      `ALU_OP_SLE: if ((a_i[31] == 1'b1) || (a_i == 32'b0)) result_o = 32'b1;
39
                   else result_o = 32'b0;
40
      `ALU_OP_SGT: if ((a_i[31] == 1'b0) && (a_i != 32'b0)) result_o = 32'b1;
41
                   else result_o = 32'b0;
42
      `ALU_OP_SGE: if(signed_i) result_o = ({~a_i[31],a_i[30:0]} >= {~b_i[31],b_i[30:0]}) ? 32'b1 : 32'b0;
43
                   else result_o = a_i >= b_i;
44
      default: result_o = 32'b0;
45
    endcase
46
  end
47
 
48
endmodule
49
 

powered by: WebSVN 2.1.0

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