-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdec_vector.vhd
More file actions
521 lines (483 loc) · 16.1 KB
/
Copy pathdec_vector.vhd
File metadata and controls
521 lines (483 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
-- SISO vector decoder for IRA-LDPC codes
--
-- Copyright 2019 Ahmet Inan <inan@aicodix.de>
library ieee;
use ieee.std_logic_1164.all;
use work.ldpc_scalar.all;
use work.ldpc_vector.all;
use work.table_vector.all;
entity dec_vector is
port (
clock : in std_logic;
ready : out boolean := true;
istart : in boolean;
ostart : out boolean := false;
isoft : in soft_scalar;
osoft : out soft_scalar
);
end dec_vector;
architecture rtl of dec_vector is
signal swap_cv : natural range 0 to code_vectors := code_vectors;
signal swap_vs : natural range 0 to vector_scalars := vector_scalars;
signal swap_bv : natural range 0 to block_vectors-1;
subtype vector_index is natural range 0 to vector_scalars-1;
type swap_vs_delays is array (1 to 2) of vector_index;
signal swap_vs_d : swap_vs_delays;
signal prev_vsft : vsft_scalar;
signal var_wren, var_rden : boolean := false;
signal var_wpos, var_rpos : natural range 0 to code_vectors-1;
signal var_isft, var_osft : vsft_vector;
signal bnl_wren, bnl_rden : boolean := false;
signal bnl_wpos, bnl_rpos : vector_location;
signal bnl_isft, bnl_osft : csft_vector;
signal first_wdf : boolean;
signal wdf_wren, wdf_rden : boolean := false;
signal wdf_wpos, wdf_rpos : vector_location;
signal wdf_iwdf, wdf_owdf : boolean;
signal loc_rden : boolean := false;
signal loc_rpos : vector_location;
signal loc_ooff : vector_offset;
signal loc_oshi : vector_shift;
signal cnt_rpos : natural range 0 to vector_parities_max-1;
signal cnt_ocnt : count_scalar;
signal cnp_start : boolean := false;
signal cnp_count : count_scalar;
signal cnp_ready, cnp_valid : boolean;
signal cnp_iseq, cnp_oseq : sequence_scalar;
signal cnp_ivsft, cnp_ovsft : vsft_vector;
signal cnp_icsft, cnp_ocsft : csft_vector;
signal cnp_iwdf, cnp_owdf : boolean;
signal cnp_iloc, cnp_oloc : vector_location;
signal cnp_ioff, cnp_ooff : vector_offset;
signal cnp_ishi, cnp_oshi : vector_shift;
signal ror_shift : natural range 0 to soft_vector'length-1;
signal ror_ivsft, ror_ovsft : vsft_vector;
signal rol_clken : boolean;
signal rol_shift : natural range 0 to soft_vector'length-1;
signal rol_ivsft, rol_ovsft : vsft_vector;
signal sub_clken : boolean;
signal sub_ivsft, sub_ovsft : vsft_vector;
signal sub_icsft, inv_sub_icsft : csft_vector;
signal add_ivsft, add_ovsft : vsft_vector;
signal add_icsft : csft_vector;
signal ptys : vector_parities := init_vector_parities;
signal msgs : vector_messages := CODE_VECTORS - init_vector_parities;
signal inp_pty : natural range 0 to vector_parities_max;
signal prev_start : boolean := false;
type swap_start_delays is array (1 to 2) of boolean;
signal swap_start_d : swap_start_delays := (others => false);
signal inp_seq, out_seq : sequence_scalar;
type inp_stages is array (0 to 8) of boolean;
signal inp_stage : inp_stages := (others => false);
type swap_stages is array (0 to 3) of boolean;
signal swap_stage : swap_stages := (others => false);
type swap_soft_delays is array (1 to 2) of soft_scalar;
signal swap_soft_d : swap_soft_delays;
signal swap_pos, swap_dpos : natural range 0 to code_vectors-1;
subtype num_scalar is natural range 0 to degree_max;
signal inp_num : num_scalar := 0;
signal inp_cnt : count_scalar := degree_max;
signal inp_loc : vector_location;
type out_stages is array (0 to 5) of boolean;
signal out_stage : out_stages := (others => false);
type out_off_delays is array (1 to 4) of vector_offset;
signal out_off_d : out_off_delays;
type out_shi_delays is array (1 to 2) of vector_shift;
signal out_shi_d : out_shi_delays;
type out_wdf_delays is array (1 to 4) of boolean;
signal out_wdf_d : out_wdf_delays;
type inp_num_delays is array (1 to 8) of num_scalar;
signal inp_num_d : inp_num_delays;
type inp_cnt_delays is array (1 to 8) of count_scalar;
signal inp_cnt_d : inp_cnt_delays;
type inp_seq_delays is array (1 to 8) of sequence_scalar;
signal inp_seq_d : inp_seq_delays;
type inp_loc_delays is array (1 to 8) of vector_location;
signal inp_loc_d : inp_loc_delays;
type inp_wdf_delays is array (1 to 6) of boolean;
signal inp_wdf_d : inp_wdf_delays;
type inp_off_delays is array (1 to 6) of vector_offset;
signal inp_off_d : inp_off_delays;
type inp_shi_delays is array (1 to 6) of vector_shift;
signal inp_shi_d : inp_shi_delays;
type inp_bnl_delays is array (1 to 2) of csft_vector;
signal inp_bnl_d : inp_bnl_delays;
function inv (val : csft_vector) return csft_vector is
variable tmp : csft_vector;
begin
for idx in tmp'range loop
tmp(idx) := (not val(idx).sgn, val(idx).mag);
end loop;
return tmp;
end function;
begin
loc_rden <= cnp_ready;
loc_inst : entity work.loc_vector
port map (clock,
loc_rden, loc_rpos,
loc_ooff, loc_oshi);
wdf_rden <= cnp_ready;
wdf_inst : entity work.wdf_vector
port map (clock,
wdf_wren, wdf_rden,
wdf_wpos, wdf_rpos,
wdf_iwdf, wdf_owdf);
var_rden <= cnp_ready;
var_inst : entity work.var_vector
generic map (code_vectors)
port map (clock,
var_wren, var_rden,
var_wpos, var_rpos,
var_isft, var_osft);
cnt_inst : entity work.cnt_vector
port map (clock,
cnt_rpos, cnt_ocnt);
bnl_rden <= cnp_ready;
bnl_inst : entity work.bnl_vector
generic map (vector_locations_max)
port map (clock,
bnl_wren, bnl_rden,
bnl_wpos, bnl_rpos,
bnl_isft, bnl_osft);
out_stage(0) <= cnp_valid;
cnp_inst : entity work.cnp_vector
port map (clock,
cnp_start, cnp_count,
cnp_ready, cnp_valid,
cnp_iseq, cnp_oseq,
cnp_ivsft, cnp_ovsft,
cnp_icsft, cnp_ocsft,
cnp_iwdf, cnp_owdf,
cnp_iloc, cnp_oloc,
cnp_ioff, cnp_ooff,
cnp_ishi, cnp_oshi);
ror_inst : entity work.ror_vector
port map (clock, true,
ror_shift,
ror_ivsft, ror_ovsft);
rol_clken <= cnp_ready;
rol_inst : entity work.rol_vector
port map (clock, rol_clken,
rol_shift,
rol_ivsft, rol_ovsft);
sub_clken <= cnp_ready;
inv_sub_icsft <= inv(sub_icsft);
sub_inst : entity work.add_vector
port map (clock, sub_clken,
sub_ivsft, inv_sub_icsft,
sub_ovsft);
add_inst : entity work.add_vector
port map (clock, true,
add_ivsft, add_icsft,
add_ovsft);
process (clock)
begin
if rising_edge(clock) then
if istart then
swap_cv <= 0;
swap_bv <= 0;
swap_vs <= 0;
swap_start_d(1) <= prev_start;
prev_start <= istart;
swap_stage(0) <= true;
elsif swap_cv < msgs then
swap_start_d(1) <= false;
if swap_bv = block_vectors-1 then
swap_bv <= 0;
if swap_vs = vector_scalars-1 then
swap_vs <= 0;
swap_cv <= swap_cv + block_vectors;
else
swap_vs <= swap_vs + 1;
end if;
else
swap_bv <= swap_bv + 1;
end if;
-- report "MSG" & HT & integer'image(swap_cv) & HT & integer'image(swap_bv) & HT & integer'image(swap_vs);
elsif swap_vs /= vector_scalars then
if swap_cv = code_vectors-block_vectors then
swap_cv <= msgs;
if swap_bv = block_vectors-1 then
swap_bv <= 0;
swap_vs <= swap_vs + 1;
else
swap_bv <= swap_bv + 1;
end if;
else
swap_cv <= swap_cv + block_vectors;
end if;
if swap_cv = code_vectors-2*block_vectors and swap_bv = block_vectors-1 and swap_vs = vector_scalars-1 then
ready <= false;
end if;
if swap_cv = code_vectors-block_vectors and swap_bv = block_vectors-1 and swap_vs = vector_scalars-1 then
swap_stage(0) <= false;
end if;
-- report "PTY" & HT & integer'image(swap_cv) & HT & integer'image(swap_bv) & HT & integer'image(swap_vs);
end if;
if swap_stage(0) then
swap_vs_d(1) <= swap_vs;
swap_start_d(2) <= swap_start_d(1);
swap_soft_d(1) <= isoft;
swap_pos <= swap_cv + swap_bv;
var_rpos <= swap_cv + swap_bv;
end if;
swap_stage(1) <= swap_stage(0);
if swap_stage(1) then
swap_vs_d(2) <= swap_vs_d(1);
ostart <= swap_start_d(2);
swap_soft_d(2) <= swap_soft_d(1);
swap_dpos <= swap_pos;
end if;
swap_stage(2) <= swap_stage(1);
if swap_stage(2) then
osoft <= vsft_to_soft(var_osft(swap_vs_d(2)));
var_wren <= true;
var_wpos <= swap_dpos;
for idx in soft_vector'range loop
if swap_vs_d(2) = idx then
var_isft(idx) <= soft_to_vsft(swap_soft_d(2));
else
var_isft(idx) <= var_osft(idx);
end if;
end loop;
end if;
swap_stage(3) <= swap_stage(2);
if swap_stage(3) and not swap_stage(2) then
var_wren <= false;
inp_stage(0) <= true;
-- ready <= true;
end if;
if inp_stage(0) then
if cnp_ready then
if inp_num = inp_cnt then
inp_num <= 0;
inp_cnt <= cnt_ocnt;
if inp_pty+1 = ptys then
if inp_seq+1 = iterations_max then
inp_stage(0) <= false;
else
inp_seq <= inp_seq + 1;
inp_pty <= 0;
end if;
else
inp_pty <= inp_pty + 1;
end if;
else
inp_num <= inp_num + 1;
end if;
if inp_num = 0 then
if inp_pty = 0 then
inp_loc <= 0;
end if;
elsif inp_loc+1 /= vector_locations_max then
inp_loc <= inp_loc + 1;
end if;
if inp_num = 0 then
if inp_pty+1 = ptys then
cnt_rpos <= 0;
elsif cnt_rpos+1 /= vector_parities_max then
cnt_rpos <= cnt_rpos + 1;
end if;
end if;
end if;
else
cnt_rpos <= 0;
inp_cnt <= cnt_ocnt;
inp_num <= 0;
inp_pty <= 0;
inp_seq <= 0;
inp_loc <= 0;
end if;
-- report boolean'image(inp_stage(0)) & HT & boolean'image(cnp_ready) & HT & integer'image(inp_seq) & HT & integer'image(inp_cnt) & HT & integer'image(inp_num) & HT & integer'image(inp_loc) & HT & integer'image(inp_pty);
if inp_stage(0) and cnp_ready then
loc_rpos <= inp_loc;
wdf_rpos <= inp_loc;
inp_num_d(1) <= inp_num;
inp_cnt_d(1) <= inp_cnt;
inp_seq_d(1) <= inp_seq;
inp_loc_d(1) <= inp_loc;
end if;
inp_stage(1) <= inp_stage(0);
if inp_stage(1) and cnp_ready then
inp_num_d(2) <= inp_num_d(1);
inp_cnt_d(2) <= inp_cnt_d(1);
inp_seq_d(2) <= inp_seq_d(1);
inp_loc_d(2) <= inp_loc_d(1);
end if;
inp_stage(2) <= inp_stage(1);
if inp_stage(2) and cnp_ready then
var_rpos <= loc_ooff;
if inp_seq_d(2) = 0 then
if inp_num_d(2) = 1 then
inp_wdf_d(1) <= false;
else
inp_wdf_d(1) <= inp_off_d(1) = loc_ooff;
end if;
else
inp_wdf_d(1) <= wdf_owdf;
end if;
inp_num_d(3) <= inp_num_d(2);
inp_cnt_d(3) <= inp_cnt_d(2);
inp_seq_d(3) <= inp_seq_d(2);
inp_loc_d(3) <= inp_loc_d(2);
inp_off_d(1) <= loc_ooff;
inp_shi_d(1) <= loc_oshi;
end if;
inp_stage(3) <= inp_stage(2);
if inp_stage(3) and cnp_ready then
if inp_num_d(3) = 1 then
first_wdf <= inp_wdf_d(1);
elsif inp_num_d(3) /= 0 then
wdf_wren <= true;
wdf_wpos <= inp_loc_d(4);
if inp_off_d(2) = inp_off_d(1) then
wdf_iwdf <= inp_wdf_d(1);
else
wdf_iwdf <= first_wdf;
first_wdf <= inp_wdf_d(1);
end if;
end if;
inp_num_d(4) <= inp_num_d(3);
inp_cnt_d(4) <= inp_cnt_d(3);
inp_seq_d(4) <= inp_seq_d(3);
inp_loc_d(4) <= inp_loc_d(3);
inp_wdf_d(2) <= inp_wdf_d(1);
inp_off_d(2) <= inp_off_d(1);
inp_shi_d(2) <= inp_shi_d(1);
end if;
inp_stage(4) <= inp_stage(3);
if inp_stage(4) and cnp_ready then
if inp_num_d(4) = inp_cnt_d(4) then
wdf_wpos <= inp_loc_d(4);
wdf_iwdf <= first_wdf;
end if;
rol_shift <= inp_shi_d(2);
rol_ivsft <= var_osft;
bnl_rpos <= inp_loc_d(4);
inp_num_d(5) <= inp_num_d(4);
inp_cnt_d(5) <= inp_cnt_d(4);
inp_seq_d(5) <= inp_seq_d(4);
inp_loc_d(5) <= inp_loc_d(4);
inp_wdf_d(3) <= inp_wdf_d(2);
inp_off_d(3) <= inp_off_d(2);
inp_shi_d(3) <= inp_shi_d(2);
end if;
inp_stage(5) <= inp_stage(4);
if inp_stage(5) and cnp_ready then
if inp_num_d(5) = inp_cnt_d(5) then
wdf_wren <= false;
end if;
inp_num_d(6) <= inp_num_d(5);
inp_cnt_d(6) <= inp_cnt_d(5);
inp_seq_d(6) <= inp_seq_d(5);
inp_loc_d(6) <= inp_loc_d(5);
inp_wdf_d(4) <= inp_wdf_d(3);
inp_off_d(4) <= inp_off_d(3);
inp_shi_d(4) <= inp_shi_d(3);
end if;
inp_stage(6) <= inp_stage(5);
if inp_stage(6) and cnp_ready then
if inp_off_d(4) = code_vectors-1 and inp_shi_d(4) = vector_scalars-1 then
prev_vsft <= rol_ovsft(vsft_vector'low);
sub_ivsft <= soft_to_vsft(vmag_scalar'high) & rol_ovsft(vsft_vector'low+1 to vsft_vector'high);
else
sub_ivsft <= rol_ovsft;
end if;
if inp_seq_d(6) = 0 then
sub_icsft <= (others => (false, 0));
inp_bnl_d(1) <= (others => (false, 0));
else
sub_icsft <= bnl_osft;
inp_bnl_d(1) <= bnl_osft;
end if;
inp_num_d(7) <= inp_num_d(6);
inp_cnt_d(7) <= inp_cnt_d(6);
inp_seq_d(7) <= inp_seq_d(6);
inp_loc_d(7) <= inp_loc_d(6);
inp_wdf_d(5) <= inp_wdf_d(4);
inp_off_d(5) <= inp_off_d(4);
inp_shi_d(5) <= inp_shi_d(4);
end if;
inp_stage(7) <= inp_stage(6);
if inp_stage(7) and cnp_ready then
inp_num_d(8) <= inp_num_d(7);
inp_cnt_d(8) <= inp_cnt_d(7);
inp_seq_d(8) <= inp_seq_d(7);
inp_loc_d(8) <= inp_loc_d(7);
inp_wdf_d(6) <= inp_wdf_d(5);
inp_off_d(6) <= inp_off_d(5);
inp_shi_d(6) <= inp_shi_d(5);
inp_bnl_d(2) <= inp_bnl_d(1);
end if;
inp_stage(8) <= inp_stage(7);
if inp_stage(8) and cnp_ready then
cnp_start <= inp_num_d(8) = 0;
cnp_count <= inp_cnt_d(8);
cnp_ivsft <= sub_ovsft;
cnp_icsft <= inp_bnl_d(2);
cnp_iseq <= inp_seq_d(8);
cnp_iloc <= inp_loc_d(8);
cnp_iwdf <= inp_wdf_d(6);
cnp_ioff <= inp_off_d(6);
cnp_ishi <= inp_shi_d(6);
end if;
-- report boolean'image(cnp_start) & HT & boolean'image(cnp_ready) & HT & integer'image(cnp_iseq) & HT & integer'image(cnp_iloc) & HT & integer'image(cnp_ioff) & HT & integer'image(cnp_ishi) & HT & boolean'image(cnp_iwdf) & HT & integer'image(cnp_count) & HT &
-- integer'image(vsft_to_soft(cnp_ivsft(0))) & HT & integer'image(vsft_to_soft(cnp_ivsft(1))) & HT & integer'image(vsft_to_soft(cnp_ivsft(2))) & HT & integer'image(vsft_to_soft(cnp_ivsft(3))) & HT & integer'image(vsft_to_soft(cnp_ivsft(4)));
-- report boolean'image(cnp_valid) & HT & boolean'image(cnp_ready) & HT & integer'image(cnp_oseq) & HT & integer'image(cnp_oloc) & HT & integer'image(cnp_ooff) & HT & integer'image(cnp_oshi) & HT & boolean'image(cnp_owdf) & HT &
-- integer'image(vsft_to_soft(cnp_ovsft(0))) & HT & integer'image(vsft_to_soft(cnp_ovsft(1))) & HT & integer'image(vsft_to_soft(cnp_ovsft(2))) & HT & integer'image(vsft_to_soft(cnp_ovsft(3))) & HT & integer'image(vsft_to_soft(cnp_ovsft(4))) & HT &
-- integer'image(csft_to_soft(cnp_ocsft(0))) & HT & integer'image(csft_to_soft(cnp_ocsft(1))) & HT & integer'image(csft_to_soft(cnp_ocsft(2))) & HT & integer'image(csft_to_soft(cnp_ocsft(3))) & HT & integer'image(csft_to_soft(cnp_ocsft(4)));
if out_stage(0) then
add_ivsft <= cnp_ovsft;
add_icsft <= cnp_ocsft;
out_wdf_d(1) <= cnp_owdf;
out_off_d(1) <= cnp_ooff;
out_shi_d(1) <= cnp_oshi;
bnl_wpos <= cnp_oloc;
bnl_wren <= cnp_oseq = 0 or not cnp_owdf;
if not cnp_owdf then
bnl_isft <= cnp_ocsft;
elsif cnp_oseq = 0 then
bnl_isft <= (others => (false, 0));
end if;
else
bnl_wren <= false;
end if;
out_stage(1) <= out_stage(0);
if out_stage(1) then
out_off_d(2) <= out_off_d(1);
out_shi_d(2) <= out_shi_d(1);
out_wdf_d(2) <= out_wdf_d(1);
end if;
out_stage(2) <= out_stage(1);
if out_stage(2) then
ror_shift <= out_shi_d(2);
if out_off_d(2) = code_vectors-1 and out_shi_d(2) = vector_scalars-1 then
ror_ivsft <= prev_vsft & add_ovsft(vsft_vector'low+1 to vsft_vector'high);
else
ror_ivsft <= add_ovsft;
end if;
out_off_d(3) <= out_off_d(2);
out_wdf_d(3) <= out_wdf_d(2);
end if;
out_stage(3) <= out_stage(2);
if out_stage(3) then
out_off_d(4) <= out_off_d(3);
out_wdf_d(4) <= out_wdf_d(3);
end if;
out_stage(4) <= out_stage(3);
if out_stage(4) then
var_isft <= ror_ovsft;
var_wpos <= out_off_d(4);
var_wren <= not out_wdf_d(4);
end if;
out_stage(5) <= out_stage(4);
if out_stage(5) and not out_stage(4) then
var_wren <= false;
if out_stage = (out_stage'low to out_stage'high-1 => false) & true and
not inp_stage(inp_stage'high) and cnp_ready then
ready <= true;
end if;
end if;
end if;
end process;
end rtl;