utils/conv_gen.py: generate a single file

Instead of generating every convolutional code into a separate
file (such as conv_xcch_gen.c, conv_cs3_gen.c), it is better to
have a single file, containing all definitions, because as many
convolutional codes we add, as many entries we will have to add
into 'src/gsm/Makefile.am'. This approach increases readability
of the Makefile.am, and also makes us able to share some data
between some convolutional code definitions.

For example: xCCH, RACH, SCH, TCH/F, both CS2 and CS3 may use
the same *_state[][2] and *_output[][2] arrays within a single
file. This optimization is currently WIP.

Change-Id: Ib4e4ee5fdde38429e68e3b2fa50ec03a18f59daa
This commit is contained in:
Vadim Yanitskiy 2016-09-07 22:18:10 +07:00 committed by Harald Welte
parent 694f72d148
commit d2d9760c08
3 changed files with 310 additions and 315 deletions

2
.gitignore vendored
View File

@ -110,7 +110,7 @@ doc/html.tar
doc/*.tag
src/crc*gen.c
src/gsm/conv*gen.c
src/gsm/gsm0503_conv.c
include/osmocom/core/crc*gen.h
include/osmocom/core/bit*gen.h

View File

@ -18,16 +18,11 @@ libgsmint_la_SOURCES = a5.c rxlev_stat.c tlv_parser.c comp128.c comp128v23.c \
gprs_cipher_core.c gprs_rlc.c gsm0480.c abis_nm.c gsm0502.c \
gsm0411_utils.c gsm0411_smc.c gsm0411_smr.c \
lapd_core.c lapdm.c kasumi.c gsm_04_08_gprs.c \
conv_cs2_gen.c conv_cs3_gen.c conv_xcch_gen.c \
conv_tch_afs_12_2_gen.c conv_tch_afs_10_2_gen.c \
conv_tch_afs_7_95_gen.c conv_tch_afs_7_4_gen.c \
conv_tch_afs_6_7_gen.c conv_tch_afs_5_9_gen.c \
conv_tch_afs_5_15_gen.c conv_tch_afs_4_75_gen.c \
auth_core.c auth_comp128v1.c auth_comp128v23.c \
auth_milenage.c milenage/aes-encblock.c gea.c \
milenage/aes-internal.c milenage/aes-internal-enc.c \
milenage/milenage.c gan.c ipa.c gsm0341.c apn.c \
gsup.c gprs_gea.c
gsup.c gprs_gea.c gsm0503_conv.c
libgsmint_la_LDFLAGS = -no-undefined
libgsmint_la_LIBADD = $(top_builddir)/src/libosmocore.la
@ -37,5 +32,8 @@ libosmogsm_la_LIBADD = libgsmint.la
EXTRA_DIST = libosmogsm.map
conv%gen.c: $(top_srcdir)/utils/conv_gen.py
# Convolutional codes generation
gsm0503_conv.c:
$(AM_V_GEN)python2 $(top_srcdir)/utils/conv_gen.py
CLEANFILES = gsm0503_conv.c

View File

@ -222,8 +222,9 @@ CCH_poly = [
( G1, 1 ),
]
# xCCH definition
xCCH = ConvolutionalCode(
conv_codes = [
# xCCH definition
ConvolutionalCode(
224,
CCH_poly,
name = "xcch",
@ -233,10 +234,10 @@ xCCH = ConvolutionalCode(
"G0 = 1 + D3 + D4",
"G1 = 1 + D + D3 + D4",
]
)
),
# CS2 definition
CS2 = ConvolutionalCode(
# CS2 definition
ConvolutionalCode(
290,
CCH_poly,
puncture = [
@ -257,10 +258,10 @@ CS2 = ConvolutionalCode(
"G0 = 1 + D3 + D4",
"G1 = 1 + D + D3 + D4",
]
)
),
# CS3 definition
CS3 = ConvolutionalCode(
# CS3 definition
ConvolutionalCode(
334,
CCH_poly,
puncture = [
@ -287,10 +288,10 @@ CS3 = ConvolutionalCode(
"G0 = 1 + D3 + D4",
"G1 = 1 + D + D3 + D4",
]
)
),
# TCH_AFS_12_2 definition
TCH_AFS_12_2 = ConvolutionalCode(
# TCH_AFS_12_2 definition
ConvolutionalCode(
250,
[
( 1, 1 ),
@ -311,10 +312,10 @@ TCH_AFS_12_2 = ConvolutionalCode(
"G0/G0 = 1",
"G1/G0 = 1 + D + D3 + D4 / 1 + D3 + D4",
]
)
),
# TCH_AFS_10_2 definition
TCH_AFS_10_2 = ConvolutionalCode(
# TCH_AFS_10_2 definition
ConvolutionalCode(
210,
[
( G1, G3 ),
@ -347,10 +348,10 @@ TCH_AFS_10_2 = ConvolutionalCode(
"G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4",
"G3/G3 = 1",
]
)
),
# TCH_AFS_7_95 definition
TCH_AFS_7_95 = ConvolutionalCode(
# TCH_AFS_7_95 definition
ConvolutionalCode(
165,
[
( 1, 1 ),
@ -372,10 +373,10 @@ TCH_AFS_7_95 = ConvolutionalCode(
"G5/G4 = 1 + D + D4 + D6 / 1 + D2 + D3 + D5 + D6",
"G6/G4 = 1 + D + D2 + D3 + D4 + D6 / 1 + D2 + D3 + D5 + D6",
]
)
),
# TCH_AFS_7_4 definition
TCH_AFS_7_4 = ConvolutionalCode(
# TCH_AFS_7_4 definition
ConvolutionalCode(
154,
[
( G1, G3 ),
@ -394,10 +395,10 @@ TCH_AFS_7_4 = ConvolutionalCode(
"G2/G3 = 1 + D2 + D4 / 1 + D + D2 + D3 + D4",
"G3/G3 = 1",
]
)
),
# TCH_AFS_6_7 definition
TCH_AFS_6_7 = ConvolutionalCode(
# TCH_AFS_6_7 definition
ConvolutionalCode(
140,
[
( G1, G3 ),
@ -426,10 +427,10 @@ TCH_AFS_6_7 = ConvolutionalCode(
"G3/G3 = 1",
"G3/G3 = 1",
]
)
),
# TCH_AFS_5_9 definition
TCH_AFS_5_9 = ConvolutionalCode(
# TCH_AFS_5_9 definition
ConvolutionalCode(
124,
[
( G4, G6 ),
@ -455,10 +456,10 @@ TCH_AFS_5_9 = ConvolutionalCode(
"G6/G6 = 1",
"G6/G6 = 1",
]
)
),
# TCH_AFS_5_15 definition
TCH_AFS_5_15 = ConvolutionalCode(
# TCH_AFS_5_15 definition
ConvolutionalCode(
109,
[
( G1, G3 ),
@ -488,10 +489,10 @@ TCH_AFS_5_15 = ConvolutionalCode(
"G3/G3 = 1",
"G3/G3 = 1",
]
)
),
# TCH_AFS_4_75 definition
TCH_AFS_4_75 = ConvolutionalCode(
# TCH_AFS_4_75 definition
ConvolutionalCode(
101,
[
( G4, G6 ),
@ -519,28 +520,24 @@ TCH_AFS_4_75 = ConvolutionalCode(
"G6/G6 = 1",
"G6/G6 = 1",
]
)
)
]
def gen_c(dest, pref, code):
f = open(os.path.join(dest, 'conv_' + code.name + '_gen.c'), 'w')
if __name__ == '__main__':
path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
prefix = "gsm0503"
print >>sys.stderr, "Generating convolutional codes..."
# Open a new file for writing
f = open(os.path.join(path, "gsm0503_conv.c"), 'w')
print >>f, mod_license
print >>f, "#include <stdint.h>"
print >>f, "#include <osmocom/core/conv.h>"
code.gen_tables(pref, f)
if __name__ == '__main__':
print >>sys.stderr, "Generating convolutional codes..."
prefix = "gsm0503"
path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
gen_c(path, prefix, xCCH)
gen_c(path, prefix, CS2)
gen_c(path, prefix, CS3)
gen_c(path, prefix, TCH_AFS_12_2)
gen_c(path, prefix, TCH_AFS_10_2)
gen_c(path, prefix, TCH_AFS_7_95)
gen_c(path, prefix, TCH_AFS_7_4)
gen_c(path, prefix, TCH_AFS_6_7)
gen_c(path, prefix, TCH_AFS_5_9)
gen_c(path, prefix, TCH_AFS_5_15)
gen_c(path, prefix, TCH_AFS_4_75)
print >>sys.stderr, "\tdone."
# Generate the tables one by one
for code in conv_codes:
print >>sys.stderr, "Generate '%s' definition" % code.name
code.gen_tables(prefix, f)
print >>sys.stderr, "Generation complete."