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

Subversion Repositories v586

[/] [v586/] [trunk/] [core_rtl/] [arithbox.v] - Blame information for rev 123

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

Line No. Rev Author Line
1 121 ultro
/* verilator lint_off WIDTH */
2
/* verilator lint_off UNUSED */
3
/* verilator lint_off COMBDLY */
4
 
5
module arithbox (arithop,calc_sz,ci,co,af,ai,sa,sb,opa,opb,resa,cmp);
6
 
7
input       [3:0] arithop;
8
input       [3:0] calc_sz;
9
input      [31:0] opa,opb;
10
output reg [31:0] resa;
11
input         ci,ai;
12
output reg    co,af,sa,sb,cmp;
13
 
14
wire        [4:0] af2,af3,af4,af5;
15
 
16
assign af2 = opa[3:0]+opb[3:0];
17
assign af3 = opa[3:0]+opb[3:0]+ci;
18
assign af4 = opa[3:0]-opb[3:0];
19
assign af5 = opa[3:0]-opb[3:0]-ci;
20
 
21
always @(*)
22
      case (arithop)
23
         4'b0000 : if (calc_sz==4) begin {co,resa[31:0]} <= opa[31:0] + opb[31:0]; sa<=opa[31]; sb<=opb[31]; af <= af2[4];                            cmp <=0; end else
24
                   if (calc_sz==2) begin {co,resa[15:0]} <= opa[15:0] + opb[15:0]; sa<=opa[15]; sb<=opb[15]; af <= af2[4]; resa[31:16] <= opa[31:16]; cmp <=0; end else
25
                                   begin {co,resa[ 7:0]} <= opa[ 7:0] + opb[ 7:0]; sa<=opa[ 7]; sb<=opb[ 7]; af <= af2[4]; resa[31: 8] <= opa[31: 8]; cmp <=0; end // add
26
 
27
         4'b0001 :                 begin     resa[31:0]  <= opa[31:0] | opb[31:0]; sa<=     1 ; sb<= 0     ; af <= ai    ; co <= 0;   cmp <=0; end // or
28
 
29
         4'b0010 : if (calc_sz==4) begin {co,resa[31:0]} <= opa[31:0] + opb[31:0] + ci; sa<=opa[31]; sb<=opb[31]; af <= af3[4];                       cmp <=0; end else
30
                   if (calc_sz==2) begin {co,resa[15:0]} <= opa[15:0] + opb[15:0] + ci; sa<=opa[15]; sb<=opb[15]; af <= af3[4]; resa[31:16] <= opa[31:16]; cmp <=0; end else
31
                                   begin {co,resa[ 7:0]} <= opa[ 7:0] + opb[ 7:0] + ci; sa<=opa[ 7]; sb<=opb[ 7]; af <= af3[4]; resa[31: 8] <= opa[31: 8]; cmp <=0; end // adc
32
 
33
         4'b0011 : if (calc_sz==4) begin {co,resa[31:0]} <= opa[31:0] - opb[31:0] - ci; sa<=opa[31]; sb<=~opb[31];af <= af5[4];                       cmp <=0; end else
34
                   if (calc_sz==2) begin {co,resa[15:0]} <= opa[15:0] - opb[15:0] - ci; sa<=opa[15]; sb<=~opb[15];af <= af5[4]; resa[31:16] <= opa[31:16]; cmp <=0; end else
35
                                   begin {co,resa[ 7:0]} <= opa[ 7:0] - opb[ 7:0] - ci; sa<=opa[ 7]; sb<=~opb[ 7];af <= af5[4]; resa[31: 8] <= opa[31: 8]; cmp <=0; end // sbc & cmp
36
 
37
         4'b0100 :                 begin     resa[31:0]  <= opa[31:0] & opb[31:0]; sa<=1      ; sb<= 0      ; af <= ai    ; co <= 0; cmp <= 0; end // and
38
 
39
         4'b0111 : begin
40
                   if (calc_sz==4) begin {co,resa[31:0]} <= opa[31:0] - opb[31:0]; sa<=opa[31]; sb<=~opb[31]; af <= af4[4]; cmp <=1;                            end else
41
                   if (calc_sz==2) begin {co,resa[15:0]} <= opa[15:0] - opb[15:0]; sa<=opa[15]; sb<=~opb[15]; af <= af4[4]; cmp <=1; resa[31:16] <= opa[31:16]; end else
42
                                   begin {co,resa[ 7:0]} <= opa[ 7:0] - opb[ 7:0]; sa<=opa[ 7]; sb<=~opb[ 7]; af <= af4[4]; cmp <=1; resa[31: 8] <= opa[31: 8]; end // sub
43
                   end
44
 
45
         4'b0101 : if (calc_sz==4) begin {co,resa[31:0]} <= opa[31:0] - opb[31:0]; sa<=opa[31]; sb<=~opb[31]; af <= af4[4]; cmp <=0;                                end else
46
                   if (calc_sz==2) begin {co,resa[15:0]} <= opa[15:0] - opb[15:0]; sa<=opa[15]; sb<=~opb[15]; af <= af4[4]; cmp <=0; resa[31:16] <= opa[31:16]; end else
47
                                   begin {co,resa[ 7:0]} <= opa[ 7:0] - opb[ 7:0]; sa<=opa[ 7]; sb<=~opb[ 7]; af <= af4[4]; cmp <=0; resa[31: 8] <= opa[31: 8]; end // sub
48
 
49
         4'b0110 :                 begin     resa[31:0]  <= opa[31:0] ^ opb[31:0]; sa<=     1 ; sb<=    0   ; af <= ai; co <= 0;  cmp <=0; end // xor
50
         default :                 begin     resa[31:0]  <= opa[31:0]            ; sa <=    0 ; sb<=    0   ; af <= ai; co <= ci; cmp <=1; end
51
      endcase
52
 
53
 
54
endmodule

powered by: WebSVN 2.1.0

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