1 |
2 |
bsa |
/*******************************************************************************************/
|
2 |
|
|
/** **/
|
3 |
|
|
/** COPYRIGHT (C) 2011, SYSTEMYDE INTERNATIONAL CORPORATION, ALL RIGHTS RESERVED **/
|
4 |
|
|
/** **/
|
5 |
|
|
/** alu math module Rev 0.0 07/29/2011 **/
|
6 |
|
|
/** **/
|
7 |
|
|
/*******************************************************************************************/
|
8 |
|
|
module alu_math (adder_c, adder_hc, adder_out, adder_ov, alua_in, alub_in, aluop_reg,
|
9 |
|
|
carry_bit, carry_daa, daa_op, word_op);
|
10 |
|
|
|
11 |
|
|
input carry_bit; /* carry flag */
|
12 |
|
|
input carry_daa; /* carry for daa */
|
13 |
|
|
input daa_op; /* daa operation */
|
14 |
|
|
input word_op; /* word operation */
|
15 |
|
|
input [15:0] alua_in; /* alu a input */
|
16 |
|
|
input [15:0] alub_in; /* alu b input */
|
17 |
|
|
input [`AOP_IDX:0] aluop_reg; /* alu operation control subset */
|
18 |
|
|
output adder_c; /* alu math carry result */
|
19 |
|
|
output adder_hc; /* alu math half-carry result */
|
20 |
|
|
output adder_ov; /* alu math overflow result */
|
21 |
|
|
output [15:0] adder_out; /* alu math result */
|
22 |
|
|
|
23 |
|
|
/*****************************************************************************************/
|
24 |
|
|
/* */
|
25 |
|
|
/* signal declarations */
|
26 |
|
|
/* */
|
27 |
|
|
/*****************************************************************************************/
|
28 |
|
|
wire adder_c; /* alu math carry out */
|
29 |
|
|
wire adder_hc; /* alu math half-carry out */
|
30 |
|
|
wire [15:8] bsign_ext; /* alu b sign extend */
|
31 |
|
|
wire [15:0] adder_out; /* alu math out */
|
32 |
|
|
|
33 |
|
|
reg alu_cin; /* alu math carry in */
|
34 |
|
|
reg adder_ov; /* alu math overflow out */
|
35 |
|
|
reg [4:0] alu0_out; /* alu math nibble 0 */
|
36 |
|
|
reg [4:0] alu1_out; /* alu math nibble 1 */
|
37 |
|
|
reg [4:0] alu2_out; /* alu math nibble 2 */
|
38 |
|
|
reg [4:0] alu3_out; /* alu math nibble 3 */
|
39 |
|
|
|
40 |
|
|
/*****************************************************************************************/
|
41 |
|
|
/* */
|
42 |
|
|
/* alu math carry input, sign extend */
|
43 |
|
|
/* */
|
44 |
|
|
/*****************************************************************************************/
|
45 |
|
|
always @ (aluop_reg or carry_bit) begin
|
46 |
|
|
casex (aluop_reg) //synopsys parallel_case
|
47 |
|
|
`AOP_ADC,
|
48 |
|
|
`AOP_BADC,
|
49 |
|
|
`AOP_SBC,
|
50 |
|
|
`AOP_BSBC: alu_cin = carry_bit;
|
51 |
|
|
default: alu_cin = 1'b0;
|
52 |
|
|
endcase
|
53 |
|
|
end
|
54 |
|
|
|
55 |
|
|
assign bsign_ext = {alub_in[7], alub_in[7], alub_in[7], alub_in[7],
|
56 |
|
|
alub_in[7], alub_in[7], alub_in[7], alub_in[7]};
|
57 |
|
|
|
58 |
|
|
/*****************************************************************************************/
|
59 |
|
|
/* */
|
60 |
|
|
/* alu math function unit */
|
61 |
|
|
/* */
|
62 |
|
|
/*****************************************************************************************/
|
63 |
|
|
always @ (aluop_reg or alua_in or alub_in or alu_cin) begin
|
64 |
|
|
casex (aluop_reg) //synopsys parallel_case
|
65 |
|
|
`AOP_SUB,
|
66 |
|
|
`AOP_BSUB,
|
67 |
|
|
`AOP_SBC,
|
68 |
|
|
`AOP_BSBC: alu0_out = alua_in[3:0] - alub_in[3:0] - alu_cin;
|
69 |
|
|
default: alu0_out = alua_in[3:0] + alub_in[3:0] + alu_cin;
|
70 |
|
|
endcase
|
71 |
|
|
end
|
72 |
|
|
|
73 |
|
|
always @ (aluop_reg or alua_in or alub_in or alu0_out) begin
|
74 |
|
|
casex (aluop_reg) //synopsys parallel_case
|
75 |
|
|
`AOP_SUB,
|
76 |
|
|
`AOP_BSUB,
|
77 |
|
|
`AOP_SBC,
|
78 |
|
|
`AOP_BSBC: alu1_out = alua_in[7:4] - alub_in[7:4] - alu0_out[4];
|
79 |
|
|
default: alu1_out = alua_in[7:4] + alub_in[7:4] + alu0_out[4];
|
80 |
|
|
endcase
|
81 |
|
|
end
|
82 |
|
|
|
83 |
|
|
always @ (aluop_reg or alua_in or alub_in or alu1_out or bsign_ext) begin
|
84 |
|
|
casex (aluop_reg) //synopsys parallel_case
|
85 |
|
|
`AOP_ADS: alu2_out = alua_in[11:8] + bsign_ext[11:8] + alu1_out[4];
|
86 |
|
|
`AOP_SUB,
|
87 |
|
|
`AOP_BSUB,
|
88 |
|
|
`AOP_SBC,
|
89 |
|
|
`AOP_BSBC: alu2_out = alua_in[11:8] - alub_in[11:8] - alu1_out[4];
|
90 |
|
|
default: alu2_out = alua_in[11:8] + alub_in[11:8] + alu1_out[4];
|
91 |
|
|
endcase
|
92 |
|
|
end
|
93 |
|
|
|
94 |
|
|
always @ (aluop_reg or alua_in or alub_in or alu2_out or bsign_ext) begin
|
95 |
|
|
casex (aluop_reg) //synopsys parallel_case
|
96 |
|
|
`AOP_ADS: alu3_out = alua_in[15:12] + bsign_ext[15:12] + alu2_out[4];
|
97 |
|
|
`AOP_SUB,
|
98 |
|
|
`AOP_BSUB,
|
99 |
|
|
`AOP_SBC,
|
100 |
|
|
`AOP_BSBC: alu3_out = alua_in[15:12] - alub_in[15:12] - alu2_out[4];
|
101 |
|
|
default: alu3_out = alua_in[15:12] + alub_in[15:12] + alu2_out[4];
|
102 |
|
|
endcase
|
103 |
|
|
end
|
104 |
|
|
|
105 |
|
|
assign adder_out = {alu3_out[3:0], alu2_out[3:0], alu1_out[3:0], alu0_out[3:0]};
|
106 |
|
|
|
107 |
|
|
/*****************************************************************************************/
|
108 |
|
|
/* */
|
109 |
|
|
/* alu math flag generation */
|
110 |
|
|
/* */
|
111 |
|
|
/*****************************************************************************************/
|
112 |
|
|
assign adder_c = (word_op) ? alu3_out[4] :
|
113 |
|
|
(daa_op) ? carry_daa : alu1_out[4];
|
114 |
|
|
assign adder_hc = (word_op) ? alu2_out[4] : alu0_out[4];
|
115 |
|
|
|
116 |
|
|
always @ (aluop_reg or alua_in or alub_in or alu3_out or alu1_out or bsign_ext) begin
|
117 |
|
|
casex (aluop_reg) //synopsys parallel_case
|
118 |
|
|
`AOP_ADC,
|
119 |
|
|
`AOP_ADD: adder_ov = (!alu3_out[3] && alua_in[15] && alub_in[15]) ||
|
120 |
|
|
( alu3_out[3] && !alua_in[15] && !alub_in[15]);
|
121 |
|
|
`AOP_BADC,
|
122 |
|
|
`AOP_BADD,
|
123 |
|
|
`AOP_BDEC: adder_ov = (!alu1_out[3] && alua_in[7] && alub_in[7]) ||
|
124 |
|
|
( alu1_out[3] && !alua_in[7] && !alub_in[7]);
|
125 |
|
|
`AOP_SBC,
|
126 |
|
|
`AOP_SUB: adder_ov = (!alu3_out[3] && alua_in[15] && !alub_in[15]) ||
|
127 |
|
|
( alu3_out[3] && !alua_in[15] && alub_in[15]);
|
128 |
|
|
`AOP_BSBC,
|
129 |
|
|
`AOP_BSUB: adder_ov = (!alu1_out[3] && alua_in[7] && !alub_in[7]) ||
|
130 |
|
|
( alu1_out[3] && !alua_in[7] && alub_in[7]);
|
131 |
|
|
default: adder_ov = 1'b0;
|
132 |
|
|
endcase
|
133 |
|
|
end
|
134 |
|
|
|
135 |
|
|
endmodule
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
|
141 |
|
|
|