Skip to content

Commit 6dc6e2c

Browse files
Update DSP saturation logic
Signed-off-by: Robert Szczepanski <[email protected]>
1 parent a63e552 commit 6dc6e2c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

ql-qlf-plugin/qlf_k6n10f/dsp_sim.v

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ module dsp_t1_sim_cfg_ports # (
10921092
wire rnd = register_inputs_i ? r_rnd : round_i;
10931093

10941094
wire sat_d1 = register_inputs_i ? r_sat_d1 : saturate_enable_i;
1095-
wire sat_d2 = output_select_i[1] ? sat_d1 : r_sat_d2;
1095+
wire sat_d2 = output_select_i[1] ? r_sat_d1 : r_sat_d2;
10961096

10971097
wire rnd_d1 = register_inputs_i ? r_rnd_d1 : round_i;
10981098
wire rnd_d2 = output_select_i[1] ? rnd_d1 : r_rnd_d2;
@@ -1138,8 +1138,8 @@ module dsp_t1_sim_cfg_ports # (
11381138
wire [NBITS_ACC-1:0] add_a = (subtract) ? (~mult_xtnd + 1) : mult_xtnd;
11391139
wire [NBITS_ACC-1:0] add_b = (feedback == 3'h0) ? acc :
11401140
(feedback == 3'h1) ? {{NBITS_ACC}{1'b0}} :
1141-
(acc_fir < 6'd44 ? acc_fir_int << acc_fir :
1142-
acc_fir_int << 6'd44);
1141+
(acc_fir < 6'd44 ? acc_fir_int << acc_fir :
1142+
acc_fir_int << 6'd44);
11431143

11441144
wire [NBITS_ACC-1:0] add_o = add_a + add_b;
11451145

@@ -1159,20 +1159,20 @@ module dsp_t1_sim_cfg_ports # (
11591159
wire [NBITS_ACC-1:0] acc_out = (output_select_i[1]) ? add_o : acc;
11601160

11611161
// Round, shift, saturate
1162-
wire [NBITS_ACC-1:0] acc_rnd = (rnd_d2 && (shift_right_i != 0)) ? (acc_out + ({{(NBITS_ACC-1){1'b0}}, 1'b1} << (shift_right_i - 1))) :
1162+
wire [NBITS_ACC-1:0] acc_rnd = (rnd_d2 && (shift_d2 != 0)) ? (acc_out + ({{(NBITS_ACC-1){1'b0}}, 1'b1} << (shift_d2 - 1))) :
11631163
acc_out;
11641164

1165-
wire [NBITS_ACC-1:0] acc_shr = (unsigned_mode) ? (acc_rnd >> shift_right_i) :
1166-
(acc_rnd >>> shift_right_i);
1165+
wire [NBITS_ACC-1:0] acc_shr = acc_rnd >>> shift_d2;
11671166

1168-
wire [NBITS_ACC-1:0] acc_sat_u = (acc_shr[NBITS_ACC-1:NBITS_Z] != 0) ? {{(NBITS_ACC-NBITS_Z){1'b0}},{NBITS_Z{1'b1}}} :
1169-
{{(NBITS_ACC-NBITS_Z){1'b0}},{acc_shr[NBITS_Z-1:0]}};
1167+
wire [NBITS_ACC-1:0] acc_sat_u = (&acc_shr[NBITS_ACC-1:NBITS_Z-1] == 1'b1) ? {NBITS_ACC{1'b0}} :
1168+
(|acc_shr[NBITS_ACC-1:NBITS_Z-1] == 1'b0 ? {{(NBITS_ACC-NBITS_Z){1'b0}},{acc_shr[NBITS_Z-1:0]}}:
1169+
{{(NBITS_ACC-NBITS_Z){1'b0}},{NBITS_Z{1'b1}}});
11701170

11711171
wire [NBITS_ACC-1:0] acc_sat_s = ((|acc_shr[NBITS_ACC-1:NBITS_Z-1] == 1'b0) ||
11721172
(&acc_shr[NBITS_ACC-1:NBITS_Z-1] == 1'b1)) ? {{(NBITS_ACC-NBITS_Z){1'b0}},{acc_shr[NBITS_Z-1:0]}} :
11731173
{{(NBITS_ACC-NBITS_Z){1'b0}},{acc_shr[NBITS_ACC-1],{NBITS_Z-1{~acc_shr[NBITS_ACC-1]}}}};
11741174

1175-
wire [NBITS_ACC-1:0] acc_sat = (sat_d2) ? ((unsigned_mode) ? acc_sat_u : acc_sat_s) : acc_shr;
1175+
wire [NBITS_ACC-1:0] acc_sat = sat_d2 ? (unsigned_mode ? acc_sat_u : acc_sat_s) : acc_shr;
11761176

11771177
// Output signals
11781178
wire [NBITS_ACC-1:0] z0;

0 commit comments

Comments
 (0)