1 |
7 |
dbrochart |
######################################################################
|
2 |
|
|
#### ####
|
3 |
|
|
#### select.py ####
|
4 |
|
|
#### ####
|
5 |
|
|
#### This file is part of the turbo decoder IP core project ####
|
6 |
|
|
#### http://www.opencores.org/projects/turbocodes/ ####
|
7 |
|
|
#### ####
|
8 |
|
|
#### Author(s): ####
|
9 |
|
|
#### - David Brochart(dbrochart@opencores.org) ####
|
10 |
|
|
#### ####
|
11 |
|
|
#### All additional information is available in the README.txt ####
|
12 |
|
|
#### file. ####
|
13 |
|
|
#### ####
|
14 |
|
|
######################################################################
|
15 |
|
|
#### ####
|
16 |
|
|
#### Copyright (C) 2005 Authors ####
|
17 |
|
|
#### ####
|
18 |
|
|
#### This source file may be used and distributed without ####
|
19 |
|
|
#### restriction provided that this copyright statement is not ####
|
20 |
|
|
#### removed from the file and that any derivative work contains ####
|
21 |
|
|
#### the original copyright notice and the associated disclaimer. ####
|
22 |
|
|
#### ####
|
23 |
|
|
#### This source file is free software; you can redistribute it ####
|
24 |
|
|
#### and/or modify it under the terms of the GNU Lesser General ####
|
25 |
|
|
#### Public License as published by the Free Software Foundation; ####
|
26 |
|
|
#### either version 2.1 of the License, or (at your option) any ####
|
27 |
|
|
#### later version. ####
|
28 |
|
|
#### ####
|
29 |
|
|
#### This source is distributed in the hope that it will be ####
|
30 |
|
|
#### useful, but WITHOUT ANY WARRANTY; without even the implied ####
|
31 |
|
|
#### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ####
|
32 |
|
|
#### PURPOSE. See the GNU Lesser General Public License for more ####
|
33 |
|
|
#### details. ####
|
34 |
|
|
#### ####
|
35 |
|
|
#### You should have received a copy of the GNU Lesser General ####
|
36 |
|
|
#### Public License along with this source; if not, download it ####
|
37 |
|
|
#### from http://www.opencores.org/lgpl.shtml ####
|
38 |
|
|
#### ####
|
39 |
|
|
######################################################################
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
from misc import min4, cod2, mux4, min8, cod3
|
44 |
|
|
from myhdl import Signal, instances
|
45 |
|
|
|
46 |
|
|
def accDistSel(accDist, accDistCod, accDistOut, q = 8):
|
47 |
|
|
""" Accumulated distance selection (one out of four, per state)
|
48 |
|
|
|
49 |
|
|
accDist -- in : array of 32 (q+1)-bit accumulated distances
|
50 |
|
|
accDistCod -- out : array of 8 2-bit selection signals
|
51 |
|
|
accDistOut -- out : array of 8 (q+1)-bit selected accumulated distances
|
52 |
|
|
|
53 |
|
|
"""
|
54 |
|
|
min4_i = [None for i in range(8)]
|
55 |
|
|
cod2_i = [None for i in range(8)]
|
56 |
|
|
mux4_i = [None for i in range(8)]
|
57 |
|
|
comp = [Signal(bool(0)) for i in range(24)]
|
58 |
|
|
from2to = [0, 25, 6, 31, 8, 17, 14, 23, 20, 13, 18, 11, 28, 5, 26, 3, 4, 29, 2, 27, 12, 21, 10, 19, 16, 9, 22, 15, 24, 1, 30, 7]
|
59 |
|
|
for i in range(8):
|
60 |
|
|
min4_i[i] = min4(accDist[from2to[4*i]], accDist[from2to[4*i+1]], accDist[from2to[4*i+2]], accDist[from2to[4*i+3]], comp[3*i], comp[3*i+1], comp[3*i+2], q)
|
61 |
|
|
for i in range(8):
|
62 |
|
|
cod2_i[i] = cod2(comp[3*i], comp[3*i+1], comp[3*i+2], accDistCod[i])
|
63 |
|
|
for i in range(8):
|
64 |
|
|
mux4_i[i] = mux4(accDist[from2to[4*i]], accDist[from2to[4*i+1]], accDist[from2to[4*i+2]], accDist[from2to[4*i+3]], accDistCod[i], accDistOut[i])
|
65 |
|
|
|
66 |
|
|
return min4_i, cod2_i, mux4_i
|
67 |
|
|
|
68 |
|
|
def stateSel(stateDist, selState, q = 8):
|
69 |
|
|
""" State selection (one out of eight).
|
70 |
|
|
|
71 |
|
|
q -- accumulated distance width
|
72 |
|
|
stateDist -- in : state accumulated distance
|
73 |
|
|
selState -- out : selected state code
|
74 |
|
|
|
75 |
|
|
"""
|
76 |
|
|
tmp = [Signal(bool(0)) for i in range(7)]
|
77 |
|
|
min8_i0 = min8(stateDist, tmp, q)
|
78 |
|
|
cod3_i0 = cod3(tmp, selState)
|
79 |
|
|
|
80 |
|
|
return min8_i0, cod3_i0
|