Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
spbro
OpenXG-RAN
Commits
ab2b868b
Commit
ab2b868b
authored
Apr 23, 2024
by
Laurent THOMAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve polar init and polar readability
parent
8a3c329e
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
420 additions
and
636 deletions
+420
-636
CMakeLists.txt
CMakeLists.txt
+0
-1
doc/Doxyfile
doc/Doxyfile
+0
-1
openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
+17
-17
openair1/PHY/CODING/nrPolar_tools/nr_polar_crc.c
openair1/PHY/CODING/nrPolar_tools/nr_polar_crc.c
+0
-46
openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
+100
-87
openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
+42
-47
openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
+21
-52
openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
+141
-171
openair1/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
.../PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
+21
-25
openair1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
...air1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
+14
-43
openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c
openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c
+37
-67
openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c
openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c
+20
-40
openair1/PHY/CODING/nr_polar_init.c
openair1/PHY/CODING/nr_polar_init.c
+7
-39
No files found.
CMakeLists.txt
View file @
ab2b868b
...
...
@@ -801,7 +801,6 @@ set(PHY_POLARSRC
${
OPENAIR1_DIR
}
/PHY/CODING/nr_polar_init.c
${
OPENAIR1_DIR
}
/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
${
OPENAIR1_DIR
}
/PHY/CODING/nrPolar_tools/nr_crc_byte.c
${
OPENAIR1_DIR
}
/PHY/CODING/nrPolar_tools/nr_polar_crc.c
${
OPENAIR1_DIR
}
/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
${
OPENAIR1_DIR
}
/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
${
OPENAIR1_DIR
}
/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
...
...
doc/Doxyfile
View file @
ab2b868b
...
...
@@ -2217,7 +2217,6 @@ INPUT = \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrLDPC_encoder/ldpc_BG2_Zc352_byte_128.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrPolar_tools/nr_polar_crc.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c \
...
...
openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c
View file @
ab2b868b
...
...
@@ -33,25 +33,25 @@
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
void
nr_bit2byte_uint32_8
(
uint32_t
*
in
,
uint16_t
arraySize
,
uint8_t
*
out
)
{
uint8_
t
arrayInd
=
ceil
(
arraySize
/
32
.
0
);
for
(
int
i
=
0
;
i
<
(
arrayInd
-
1
);
i
++
)
{
for
(
int
j
=
0
;
j
<
32
;
j
++
)
{
out
[
j
+
(
i
*
32
)]
=
(
in
[
i
]
>>
j
)
&
1
;
}
}
const
uin
t
arrayInd
=
ceil
(
arraySize
/
32
.
0
);
for
(
int
i
=
0
;
i
<
(
arrayInd
-
1
);
i
++
)
{
for
(
int
j
=
0
;
j
<
32
;
j
++
)
{
out
[
j
+
(
i
*
32
)]
=
(
in
[
i
]
>>
j
)
&
1
;
}
}
for
(
int
j
=
0
;
j
<
arraySize
-
((
arrayInd
-
1
)
*
32
);
j
++
)
out
[
j
+
((
arrayInd
-
1
)
*
32
)]
=
(
in
[(
arrayInd
-
1
)]
>>
j
)
&
1
;
for
(
int
j
=
0
;
j
<
arraySize
-
((
arrayInd
-
1
)
*
32
);
j
++
)
out
[
j
+
((
arrayInd
-
1
)
*
32
)]
=
(
in
[(
arrayInd
-
1
)]
>>
j
)
&
1
;
}
void
nr_byte2bit_uint8_32
(
uint8_t
*
in
,
uint16_t
arraySize
,
uint32_t
*
out
)
{
uint8_
t
arrayInd
=
ceil
(
arraySize
/
32
.
0
);
for
(
int
i
=
0
;
i
<
arrayInd
;
i
++
)
{
out
[
i
]
=
0
;
for
(
int
j
=
31
;
j
>
0
;
j
--
)
{
out
[
i
]
|=
in
[(
i
*
32
)
+
j
];
out
[
i
]
<<=
1
;
}
out
[
i
]
|=
in
[(
i
*
32
)];
}
const
uin
t
arrayInd
=
ceil
(
arraySize
/
32
.
0
);
for
(
int
i
=
0
;
i
<
arrayInd
;
i
++
)
{
out
[
i
]
=
0
;
for
(
int
j
=
31
;
j
>
0
;
j
--
)
{
out
[
i
]
|=
in
[(
i
*
32
)
+
j
];
out
[
i
]
<<=
1
;
}
out
[
i
]
|=
in
[(
i
*
32
)];
}
}
openair1/PHY/CODING/nrPolar_tools/nr_polar_crc.c
deleted
100644 → 0
View file @
8a3c329e
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
void
nr_polar_crc
(
uint8_t
*
a
,
uint8_t
A
,
uint8_t
P
,
uint8_t
**
G_P
,
uint8_t
**
b
)
{
int
i
,
j
;
int
*
temp_b
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
P
);
if
(
temp_b
==
NULL
)
{
fprintf
(
stderr
,
"malloc failed
\n
"
);
exit
(
-
1
);
}
printf
(
"temp = "
);
for
(
i
=
0
;
i
<
P
;
i
++
)
{
temp_b
[
i
]
=
0
;
for
(
j
=
0
;
j
<
A
;
j
++
)
{
temp_b
[
i
]
=
temp_b
[
i
]
+
a
[
j
]
*
G_P
[
j
][
i
];
}
temp_b
[
i
]
=
temp_b
[
i
]
%
2
;
printf
(
"%i "
,
temp_b
[
i
]);
}
*
b
=
(
uint8_t
*
)
malloc
(
sizeof
(
uint8_t
)
*
(
A
+
P
));
if
(
*
b
==
NULL
)
{
fprintf
(
stderr
,
"malloc failed
\n
"
);
exit
(
-
1
);
}
printf
(
"
\n
b = "
);
for
(
i
=
0
;
i
<
A
;
i
++
)
{
(
*
b
)[
i
]
=
a
[
i
];
printf
(
"%i"
,
(
*
b
)[
i
]);
}
for
(
i
=
A
;
i
<
A
+
P
;
i
++
)
{
(
*
b
)[
i
]
=
temp_b
[
i
-
A
];
printf
(
"%i"
,
(
*
b
)[
i
]);
}
free
(
temp_b
);
}
openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c
View file @
ab2b868b
...
...
@@ -51,9 +51,9 @@ static inline void updateCrcChecksum2(int xlen,
uint32_t
i2
,
uint8_t
len
)
{
for
(
uint
8_t
i
=
0
;
i
<
listSize
;
i
++
)
{
for
(
uint
8_t
j
=
0
;
j
<
len
;
j
++
)
{
crcChecksum
[
j
][
i
+
listSize
]
=
(
(
crcChecksum
[
j
][
i
]
+
crcGen
[
i2
][
j
])
%
2
)
;
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
{
for
(
uint
j
=
0
;
j
<
len
;
j
++
)
{
crcChecksum
[
j
][
i
+
listSize
]
=
(
crcChecksum
[
j
][
i
]
+
crcGen
[
i2
][
j
])
%
2
;
}
}
}
...
...
@@ -87,7 +87,7 @@ int8_t polar_decoder(double *input,
for
(
int
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
{
llrUpdated
[
i
][
polarParams
->
n
]
=
1
;
bitUpdated
[
i
][
0
]
=
((
polarParams
->
information_bit_pattern
[
i
]
+
1
)
%
2
)
;
bitUpdated
[
i
][
0
]
=
(
polarParams
->
information_bit_pattern
[
i
]
+
1
)
%
2
;
}
uint8_t
extended_crc_generator_matrix
[
polarParams
->
K
][
polarParams
->
crcParityBits
];
//G_P3
...
...
@@ -101,11 +101,7 @@ int8_t polar_decoder(double *input,
for
(
int
i
=
polarParams
->
payloadBits
;
i
<
polarParams
->
K
;
i
++
)
{
for
(
int
j
=
0
;
j
<
polarParams
->
crcParityBits
;
j
++
)
{
if
(
(
i
-
polarParams
->
payloadBits
)
==
j
)
{
tempECGM
[
i
][
j
]
=
1
;
}
else
{
tempECGM
[
i
][
j
]
=
0
;
}
tempECGM
[
i
][
j
]
=
(
i
-
polarParams
->
payloadBits
)
==
j
;
}
}
...
...
@@ -121,7 +117,8 @@ int8_t polar_decoder(double *input,
for
(
int
j
=
0
;
j
<
polarParams
->
crcParityBits
;
j
++
)
{
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
{
if
(
extended_crc_generator_matrix
[
i
][
j
]
==
1
)
last1ind
[
j
]
=
i
;
if
(
extended_crc_generator_matrix
[
i
][
j
]
==
1
)
last1ind
[
j
]
=
i
;
}
}
...
...
@@ -135,12 +132,12 @@ int8_t polar_decoder(double *input,
* SCL polar decoder.
*/
uint32_t
nonFrozenBit
=
0
;
uint
8_t
currentListSize
=
1
;
uint
8_t
decoderIterationCheck
=
0
;
int
16_t
checkCrcBits
=
-
1
;
uint
currentListSize
=
1
;
uint
decoderIterationCheck
=
0
;
int
checkCrcBits
=
-
1
;
uint8_t
listIndex
[
2
*
listSize
],
copyIndex
;
for
(
uint
16_t
currentBit
=
0
;
currentBit
<
polarParams
->
N
;
currentBit
++
)
{
for
(
uint
currentBit
=
0
;
currentBit
<
polarParams
->
N
;
currentBit
++
)
{
updateLLR
(
currentListSize
,
currentBit
,
0
,
polarParams
->
N
,
polarParams
->
n
+
1
,
2
*
listSize
,
llr
,
llrUpdated
,
bit
,
bitUpdated
);
if
(
polarParams
->
information_bit_pattern
[
currentBit
]
==
0
)
{
//Frozen bit.
...
...
@@ -179,19 +176,18 @@ int8_t polar_decoder(double *input,
// Keep only the best "listSize" number of entries.
if
(
currentListSize
>
listSize
)
{
for
(
uint
8_t
i
=
0
;
i
<
2
*
listSize
;
i
++
)
for
(
uint
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
nr_sort_asc_double_1D_array_ind
(
pathMetric
,
listIndex
,
currentListSize
);
// sort listIndex[listSize, ..., 2*listSize-1] in descending order.
uint8_t
swaps
,
tempInd
;
for
(
uint
8_t
i
=
0
;
i
<
listSize
;
i
++
)
{
swaps
=
0
;
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
{
int
swaps
=
0
;
for
(
uint
8_t
j
=
listSize
;
j
<
(
2
*
listSize
-
i
)
-
1
;
j
++
)
{
for
(
uint
j
=
listSize
;
j
<
(
2
*
listSize
-
i
)
-
1
;
j
++
)
{
if
(
listIndex
[
j
+
1
]
>
listIndex
[
j
])
{
tempInd
=
listIndex
[
j
];
int
tempInd
=
listIndex
[
j
];
listIndex
[
j
]
=
listIndex
[
j
+
1
];
listIndex
[
j
+
1
]
=
tempInd
;
swaps
++
;
...
...
@@ -218,7 +214,8 @@ int8_t polar_decoder(double *input,
}
}
for
(
int
k
=
(
listSize
-
1
);
k
>
0
;
k
--
)
crcState
[
listIndex
[(
2
*
listSize
-
1
)
-
k
]]
=
crcState
[
listIndex
[
k
]];
for
(
int
k
=
(
listSize
-
1
);
k
>
0
;
k
--
)
crcState
[
listIndex
[(
2
*
listSize
-
1
)
-
k
]]
=
crcState
[
listIndex
[
k
]];
//Copy the best "listSize" number of entries to the first indices.
for
(
int
k
=
0
;
k
<
listSize
;
k
++
)
{
...
...
@@ -269,18 +266,20 @@ int8_t polar_decoder(double *input,
}
if
(
checkCrcBits
>
(
-
1
)
)
{
for
(
uint
8_t
i
=
0
;
i
<
currentListSize
;
i
++
)
{
for
(
uint
i
=
0
;
i
<
currentListSize
;
i
++
)
{
if
(
crcChecksum
[
checkCrcBits
][
i
]
==
1
)
{
crcState
[
i
]
=
0
;
//0=False, 1=True
}
}
}
for
(
uint8_t
i
=
0
;
i
<
currentListSize
;
i
++
)
decoderIterationCheck
+=
crcState
[
i
];
for
(
uint
i
=
0
;
i
<
currentListSize
;
i
++
)
decoderIterationCheck
+=
crcState
[
i
];
if
(
decoderIterationCheck
==
0
)
{
//perror("[SCL polar decoder] All list entries have failed the CRC checks.");
polarReturn
(
-
1
);
polarReturn
(
polarParams
);
return
-
1
;
}
nonFrozenBit
++
;
...
...
@@ -289,22 +288,26 @@ int8_t polar_decoder(double *input,
}
}
for
(
uint8_t
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
for
(
uint
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
nr_sort_asc_double_1D_array_ind
(
pathMetric
,
listIndex
,
currentListSize
);
for
(
uint
8_t
i
=
0
;
i
<
fmin
(
listSize
,
(
pow
(
2
,
polarParams
->
crcCorrectionBits
))
);
i
++
)
{
uint8_t
nr_polar_A
[
polarParams
->
payloadBits
];
for
(
uint
i
=
0
;
i
<
fmin
(
listSize
,
(
pow
(
2
,
polarParams
->
crcCorrectionBits
))
);
i
++
)
{
if
(
crcState
[
listIndex
[
i
]]
==
1
)
{
uint8_t
nr_polar_U
[
polarParams
->
N
];
for
(
int
j
=
0
;
j
<
polarParams
->
N
;
j
++
)
polarParams
->
nr_polar_U
[
j
]
=
bit
[
j
][
0
][
listIndex
[
i
]];
nr_polar_U
[
j
]
=
bit
[
j
][
0
][
listIndex
[
i
]];
//Extract the information bits (û to ĉ)
nr_polar_info_bit_extraction
(
polarParams
->
nr_polar_U
,
polarParams
->
nr_polar_CPrime
,
polarParams
->
information_bit_pattern
,
polarParams
->
N
);
uint8_t
nr_polar_CPrime
[
polarParams
->
N
];
nr_polar_info_bit_extraction
(
nr_polar_U
,
nr_polar_CPrime
,
polarParams
->
information_bit_pattern
,
polarParams
->
N
);
//Deinterleaving (ĉ to b)
nr_polar_deinterleaver
(
polarParams
->
nr_polar_CPrime
,
polarParams
->
nr_polar_B
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
uint8_t
nr_polar_B
[
polarParams
->
K
];
nr_polar_deinterleaver
(
nr_polar_CPrime
,
nr_polar_B
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
//Remove the CRC (â)
for
(
int
j
=
0
;
j
<
polarParams
->
payloadBits
;
j
++
)
polarParams
->
nr_polar_A
[
j
]
=
polarParams
->
nr_polar_B
[
j
]
;
memcpy
(
nr_polar_A
,
nr_polar_B
,
polarParams
->
payloadBits
)
;
break
;
}
...
...
@@ -313,9 +316,10 @@ int8_t polar_decoder(double *input,
/*
* Return bits.
*/
nr_byte2bit_uint8_32
(
polarParams
->
nr_polar_A
,
polarParams
->
payloadBits
,
out
);
nr_byte2bit_uint8_32
(
nr_polar_A
,
polarParams
->
payloadBits
,
out
);
polarReturn
0
;
polarReturn
(
polarParams
);
return
0
;
}
int8_t
polar_decoder_dci
(
double
*
input
,
...
...
@@ -347,7 +351,7 @@ int8_t polar_decoder_dci(double *input,
for
(
int
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
{
llrUpdated
[
i
][
polarParams
->
n
]
=
1
;
bitUpdated
[
i
][
0
]
=
((
polarParams
->
information_bit_pattern
[
i
]
+
1
)
%
2
)
;
bitUpdated
[
i
][
0
]
=
(
polarParams
->
information_bit_pattern
[
i
]
+
1
)
%
2
;
}
uint8_t
extended_crc_generator_matrix
[
polarParams
->
K
][
polarParams
->
crcParityBits
];
//G_P3: K-by-P
...
...
@@ -361,11 +365,7 @@ int8_t polar_decoder_dci(double *input,
for
(
int
i
=
polarParams
->
payloadBits
;
i
<
polarParams
->
K
;
i
++
)
{
for
(
int
j
=
0
;
j
<
polarParams
->
crcParityBits
;
j
++
)
{
if
(
(
i
-
polarParams
->
payloadBits
)
==
j
)
{
tempECGM
[
i
][
j
]
=
1
;
}
else
{
tempECGM
[
i
][
j
]
=
0
;
}
tempECGM
[
i
][
j
]
=
(
i
-
polarParams
->
payloadBits
)
==
j
;
}
}
...
...
@@ -384,7 +384,8 @@ int8_t polar_decoder_dci(double *input,
}
}
for
(
int
i
=
0
;
i
<
8
;
i
++
)
extended_crc_scrambling_pattern
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
extended_crc_scrambling_pattern
[
i
]
=
0
;
for
(
int
i
=
8
;
i
<
polarParams
->
crcParityBits
;
i
++
)
{
extended_crc_scrambling_pattern
[
i
]
=
(
n_RNTI
>>
(
23
-
i
))
&
1
;
...
...
@@ -408,12 +409,12 @@ int8_t polar_decoder_dci(double *input,
}
uint32_t
nonFrozenBit
=
0
;
uint
8_t
currentListSize
=
1
;
uint
8_t
decoderIterationCheck
=
0
;
int
16_t
checkCrcBits
=
-
1
;
uint
currentListSize
=
1
;
uint
decoderIterationCheck
=
0
;
int
checkCrcBits
=
-
1
;
uint8_t
listIndex
[
2
*
listSize
],
copyIndex
;
for
(
uint
16_t
currentBit
=
0
;
currentBit
<
polarParams
->
N
;
currentBit
++
)
{
for
(
uint
currentBit
=
0
;
currentBit
<
polarParams
->
N
;
currentBit
++
)
{
updateLLR
(
currentListSize
,
currentBit
,
0
,
polarParams
->
N
,
polarParams
->
n
+
1
,
2
*
listSize
,
llr
,
llrUpdated
,
bit
,
bitUpdated
);
if
(
polarParams
->
information_bit_pattern
[
currentBit
]
==
0
)
{
//Frozen bit.
...
...
@@ -445,18 +446,18 @@ int8_t polar_decoder_dci(double *input,
//Keep only the best "listSize" number of entries.
if
(
currentListSize
>
listSize
)
{
for
(
uint8_t
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
for
(
uint
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
nr_sort_asc_double_1D_array_ind
(
pathMetric
,
listIndex
,
currentListSize
);
//sort listIndex[listSize, ..., 2*listSize-1] in descending order.
uint8_t
swaps
,
tempInd
;
// sort listIndex[listSize, ..., 2*listSize-1] in descending order.
for
(
uint
8_t
i
=
0
;
i
<
listSize
;
i
++
)
{
swaps
=
0
;
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
{
int
swaps
=
0
;
for
(
uint
8_t
j
=
listSize
;
j
<
(
2
*
listSize
-
i
)
-
1
;
j
++
)
{
for
(
uint
j
=
listSize
;
j
<
(
2
*
listSize
-
i
)
-
1
;
j
++
)
{
if
(
listIndex
[
j
+
1
]
>
listIndex
[
j
])
{
tempInd
=
listIndex
[
j
];
int
tempInd
=
listIndex
[
j
];
listIndex
[
j
]
=
listIndex
[
j
+
1
];
listIndex
[
j
+
1
]
=
tempInd
;
swaps
++
;
...
...
@@ -483,7 +484,8 @@ int8_t polar_decoder_dci(double *input,
}
}
for
(
int
k
=
(
listSize
-
1
);
k
>
0
;
k
--
)
crcState
[
listIndex
[(
2
*
listSize
-
1
)
-
k
]]
=
crcState
[
listIndex
[
k
]];
for
(
int
k
=
(
listSize
-
1
);
k
>
0
;
k
--
)
crcState
[
listIndex
[(
2
*
listSize
-
1
)
-
k
]]
=
crcState
[
listIndex
[
k
]];
//Copy the best "listSize" number of entries to the first indices.
for
(
int
k
=
0
;
k
<
listSize
;
k
++
)
{
...
...
@@ -534,19 +536,20 @@ int8_t polar_decoder_dci(double *input,
}
if
(
checkCrcBits
>
(
-
1
)
)
{
for
(
uint
8_t
i
=
0
;
i
<
currentListSize
;
i
++
)
{
for
(
uint
i
=
0
;
i
<
currentListSize
;
i
++
)
{
if
(
crcChecksum
[
checkCrcBits
][
i
]
!=
extended_crc_scrambling_pattern
[
checkCrcBits
])
{
crcState
[
i
]
=
0
;
//0=False, 1=True
}
}
}
for
(
uint
8_t
i
=
0
;
i
<
currentListSize
;
i
++
)
decoderIterationCheck
+=
crcState
[
i
];
for
(
uint
i
=
0
;
i
<
currentListSize
;
i
++
)
decoderIterationCheck
+=
crcState
[
i
];
if
(
decoderIterationCheck
==
0
)
{
//perror("[SCL polar decoder] All list entries have failed the CRC checks.");
polarReturn
-
1
;
polarReturn
(
polarParams
);
return
-
1
;
}
nonFrozenBit
++
;
...
...
@@ -555,22 +558,27 @@ int8_t polar_decoder_dci(double *input,
}
}
for
(
uint8_t
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
for
(
uint
i
=
0
;
i
<
2
*
listSize
;
i
++
)
listIndex
[
i
]
=
i
;
nr_sort_asc_double_1D_array_ind
(
pathMetric
,
listIndex
,
currentListSize
);
uint8_t
nr_polar_A
[
polarParams
->
payloadBits
];
for
(
uint
8_t
i
=
0
;
i
<
fmin
(
listSize
,
(
pow
(
2
,
polarParams
->
crcCorrectionBits
))
);
i
++
)
{
for
(
uint
i
=
0
;
i
<
fmin
(
listSize
,
(
pow
(
2
,
polarParams
->
crcCorrectionBits
))
);
i
++
)
{
if
(
crcState
[
listIndex
[
i
]]
==
1
)
{
for
(
int
j
=
0
;
j
<
polarParams
->
N
;
j
++
)
polarParams
->
nr_polar_U
[
j
]
=
bit
[
j
][
0
][
listIndex
[
i
]];
uint8_t
nr_polar_U
[
polarParams
->
N
];
for
(
int
j
=
0
;
j
<
polarParams
->
N
;
j
++
)
nr_polar_U
[
j
]
=
bit
[
j
][
0
][
listIndex
[
i
]];
//Extract the information bits (û to ĉ)
nr_polar_info_bit_extraction
(
polarParams
->
nr_polar_U
,
polarParams
->
nr_polar_CPrime
,
polarParams
->
information_bit_pattern
,
polarParams
->
N
);
uint8_t
nr_polar_CPrime
[
polarParams
->
N
];
nr_polar_info_bit_extraction
(
nr_polar_U
,
nr_polar_CPrime
,
polarParams
->
information_bit_pattern
,
polarParams
->
N
);
//Deinterleaving (ĉ to b)
nr_polar_deinterleaver
(
polarParams
->
nr_polar_CPrime
,
polarParams
->
nr_polar_B
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
uint8_t
nr_polar_B
[
polarParams
->
K
];
nr_polar_deinterleaver
(
nr_polar_CPrime
,
nr_polar_B
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
//Remove the CRC (â)
for
(
int
j
=
0
;
j
<
polarParams
->
payloadBits
;
j
++
)
polarParams
->
nr_polar_A
[
j
]
=
polarParams
->
nr_polar_B
[
j
];
memcpy
(
nr_polar_A
,
nr_polar_B
,
polarParams
->
payloadBits
);
break
;
}
}
...
...
@@ -578,9 +586,10 @@ int8_t polar_decoder_dci(double *input,
/*
* Return bits.
*/
nr_byte2bit_uint8_32
(
polarParams
->
nr_polar_A
,
polarParams
->
payloadBits
,
out
);
nr_byte2bit_uint8_32
(
nr_polar_A
,
polarParams
->
payloadBits
,
out
);
polarReturn
0
;
polarReturn
(
polarParams
);
return
0
;
}
void
init_polar_deinterleaver_table
(
t_nrPolar_params
*
polarParams
)
{
...
...
@@ -588,29 +597,27 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams) {
AssertFatal
(
polarParams
->
K
<
129
,
"K = %d > 128, is not supported yet
\n
"
,
polarParams
->
K
);
int
bit_i
,
ip
,
ipmod64
;
int
numbytes
=
polarParams
->
K
>>
3
;
int
residue
=
polarParams
->
K
&
7
;
int
numbits
;
int
residue
=
polarParams
->
K
&
7
;
if
(
residue
>
0
)
numbytes
++
;
if
(
residue
>
0
)
numbytes
++
;
for
(
int
byte
=
0
;
byte
<
numbytes
;
byte
++
)
{
if
(
byte
<
(
polarParams
->
K
>>
3
))
numbits
=
8
;
else
numbits
=
residue
;
int
numbits
=
byte
<
(
polarParams
->
K
>>
3
)
?
8
:
residue
;
for
(
int
i
=
0
;
i
<
numbits
;
i
++
)
{
// flip bit endian for B
ip
=
polarParams
->
K
-
1
-
polarParams
->
interleaving_pattern
[(
8
*
byte
)
+
i
];
#if 0
printf("byte %d, i %d => ip %d\n",byte,i,ip);
#endif
ip
=
polarParams
->
K
-
1
-
polarParams
->
interleaving_pattern
[(
8
*
byte
)
+
i
];
ipmod64
=
ip
&
63
;
AssertFatal
(
ip
<
128
,
"ip = %d
\n
"
,
ip
);
for
(
int
val
=
0
;
val
<
256
;
val
++
)
{
bit_i
=
(
val
>>
i
)
&
1
;
if
(
ip
<
64
)
polarParams
->
B_tab0
[
byte
][
val
]
|=
(((
uint64_t
)
bit_i
)
<<
ipmod64
);
else
polarParams
->
B_tab1
[
byte
][
val
]
|=
(((
uint64_t
)
bit_i
)
<<
ipmod64
);
if
(
ip
<
64
)
polarParams
->
B_tab0
[
byte
][
val
]
|=
((
uint64_t
)
bit_i
)
<<
ipmod64
;
else
polarParams
->
B_tab1
[
byte
][
val
]
|=
((
uint64_t
)
bit_i
)
<<
ipmod64
;
}
}
}
...
...
@@ -641,8 +648,10 @@ uint32_t polar_decoder_int16(int16_t *input,
nr_polar_rate_matching_int16
(
input
,
d_tilde
,
polarParams
->
rate_matching_pattern
,
polarParams
->
K
,
polarParams
->
N
,
polarParams
->
encoderLength
,
polarParams
->
i_bil
);
for
(
int
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
{
if
(
d_tilde
[
i
]
<-
128
)
d_tilde
[
i
]
=-
128
;
else
if
(
d_tilde
[
i
]
>
127
)
d_tilde
[
i
]
=
128
;
if
(
d_tilde
[
i
]
<
-
128
)
d_tilde
[
i
]
=
-
128
;
else
if
(
d_tilde
[
i
]
>
127
)
d_tilde
[
i
]
=
128
;
}
#ifdef POLAR_CODING_DEBUG
...
...
@@ -656,9 +665,10 @@ uint32_t polar_decoder_int16(int16_t *input,
printf
(
"
\n
"
);
#endif
memcpy
((
void
*
)
&
polarParams
->
tree
.
root
->
alpha
[
0
],
(
void
*
)
&
d_tilde
[
0
],
sizeof
(
int16_t
)
*
polarParams
->
N
);
memset
(
polarParams
->
nr_polar_U
,
0
,
polarParams
->
N
*
sizeof
(
uint8_t
));
generic_polar_decoder
(
polarParams
,
polarParams
->
tree
.
root
);
memcpy
(
polarParams
->
tree
.
root
->
alpha
,
d_tilde
,
sizeof
(
d_tilde
));
uint8_t
nr_polar_U
[
polarParams
->
N
];
memset
(
nr_polar_U
,
0
,
sizeof
(
nr_polar_U
));
generic_polar_decoder
(
polarParams
,
polarParams
->
tree
.
root
,
nr_polar_U
);
#ifdef POLAR_CODING_DEBUG
printf
(
"u: "
);
...
...
@@ -666,7 +676,7 @@ uint32_t polar_decoder_int16(int16_t *input,
if
(
i
%
4
==
0
)
{
printf
(
" "
);
}
printf
(
"%i"
,
polarParams
->
nr_polar_U
[
i
]);
printf
(
"%i"
,
nr_polar_U
[
i
]);
}
printf
(
"
\n
"
);
#endif
...
...
@@ -674,7 +684,7 @@ uint32_t polar_decoder_int16(int16_t *input,
// Extract the information bits (û to ĉ)
uint64_t
Cprime
[
4
]
=
{
0
};
nr_polar_info_extraction_from_u
(
Cprime
,
polarParams
->
nr_polar_U
,
nr_polar_U
,
polarParams
->
information_bit_pattern
,
polarParams
->
parity_check_bit_pattern
,
polarParams
->
N
,
...
...
@@ -704,7 +714,8 @@ uint32_t polar_decoder_int16(int16_t *input,
}
else
if
(
polarParams
->
K
<
129
)
{
int
len
=
polarParams
->
K
/
8
;
if
((
polarParams
->
K
&
7
)
>
0
)
len
++
;
if
((
polarParams
->
K
&
7
)
>
0
)
len
++
;
for
(
int
k
=
0
;
k
<
len
;
k
++
)
{
B
[
0
]
|=
polarParams
->
B_tab0
[
k
][
Cprimebyte
[
k
]];
...
...
@@ -737,7 +748,8 @@ uint32_t polar_decoder_int16(int16_t *input,
// appending 24 ones before a0 for DCI as stated in 38.212 7.3.2
uint8_t
offset
=
0
;
if
(
ones_flag
)
offset
=
3
;
if
(
ones_flag
)
offset
=
3
;
if
(
len
<=
32
)
{
Ar
=
(
uint32_t
)(
B
[
0
]
>>
crclen
);
...
...
@@ -756,7 +768,7 @@ uint32_t polar_decoder_int16(int16_t *input,
else
if
(
crclen
==
11
)
crc
=
(
uint64_t
)((
crc11
(
A32_flip
,
8
*
offset
+
len
)
>>
21
)
&
0x7ff
);
else
if
(
crclen
==
6
)
crc
=
(
uint64_t
)((
crc6
(
A32_flip
,
8
*
offset
+
len
)
>>
26
)
&
0x3f
);
}
else
if
(
len
<=
64
)
{
Ar
=
(
B
[
0
]
>>
crclen
)
|
(
B
[
1
]
<<
(
64
-
crclen
));
;
Ar
=
(
B
[
0
]
>>
crclen
)
|
(
B
[
1
]
<<
(
64
-
crclen
))
;
uint8_t
A64_flip
[
8
+
offset
];
if
(
ones_flag
)
{
A64_flip
[
0
]
=
0xff
;
...
...
@@ -800,5 +812,6 @@ uint32_t polar_decoder_int16(int16_t *input,
#endif
out
[
0
]
=
Ar
;
polarReturn
crc
^
rxcrc
;
polarReturn
(
polarParams
);
return
crc
^
rxcrc
;
}
openair1/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c
View file @
ab2b868b
...
...
@@ -45,9 +45,9 @@ static inline void updateBit(uint8_t listSize,
uint8_t
bit
[
xlen
][
ylen
][
zlen
],
uint8_t
bitU
[
xlen
][
ylen
])
{
uint16_
t
offset
=
(
xlen
/
(
pow
(
2
,
(
ylen
-
col
))));
const
uin
t
offset
=
(
xlen
/
(
pow
(
2
,
(
ylen
-
col
))));
for
(
uint
8_t
i
=
0
;
i
<
listSize
;
i
++
)
{
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
{
if
(((
row
)
%
(
2
*
offset
))
>=
offset
)
{
if
(
bitU
[
row
][
col
-
1
]
==
0
)
updateBit
(
listSize
,
row
,
(
col
-
1
),
xlen
,
ylen
,
zlen
,
bit
,
bitU
);
...
...
@@ -89,8 +89,8 @@ void updateLLR(uint8_t listSize,
uint8_t
bit
[
xlen
][
ylen
][
zlen
],
uint8_t
bitU
[
xlen
][
ylen
])
{
uint16_
t
offset
=
(
xlen
/
(
pow
(
2
,
(
ylen
-
col
-
1
))));
for
(
uint
8_t
i
=
0
;
i
<
listSize
;
i
++
)
{
const
uin
t
offset
=
(
xlen
/
(
pow
(
2
,
(
ylen
-
col
-
1
))));
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
{
if
((
row
%
(
2
*
offset
))
>=
offset
)
{
if
(
bitU
[
row
-
offset
][
col
]
==
0
)
updateBit
(
listSize
,
(
row
-
offset
),
col
,
xlen
,
ylen
,
zlen
,
bit
,
bitU
);
...
...
@@ -122,10 +122,9 @@ void updatePathMetric(double *pathMetric,
double
llr
[
xlen
][
ylen
][
zlen
]
)
{
int8_t
multiplier
=
(
2
*
bitValue
)
-
1
;
for
(
uint8_t
i
=
0
;
i
<
listSize
;
i
++
)
pathMetric
[
i
]
+=
log
(
1
+
exp
(
multiplier
*
llr
[
row
][
0
][
i
])
)
;
//eq. (11b)
const
int
multiplier
=
(
2
*
bitValue
)
-
1
;
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
pathMetric
[
i
]
+=
log
(
1
+
exp
(
multiplier
*
llr
[
row
][
0
][
i
]));
// eq. (11b)
}
void
updatePathMetric2
(
double
*
pathMetric
,
...
...
@@ -136,19 +135,18 @@ void updatePathMetric2(double *pathMetric,
int
zlen
,
double
llr
[
xlen
][
ylen
][
zlen
])
{
double
tempPM
[
listSize
];
memcpy
(
tempPM
,
pathMetric
,
(
sizeof
(
double
)
*
listSize
));
uint8_t
bitValue
=
0
;
int8_t
multiplier
=
(
2
*
bitValue
)
-
1
;
for
(
uint8_t
i
=
0
;
i
<
listSize
;
i
++
)
pathMetric
[
i
]
+=
log
(
1
+
exp
(
multiplier
*
llr
[
row
][
0
][
i
]));
//eq. (11b)
bitValue
=
1
;
multiplier
=
(
2
*
bitValue
)
-
1
;
for
(
uint8_t
i
=
listSize
;
i
<
2
*
listSize
;
i
++
)
pathMetric
[
i
]
=
tempPM
[(
i
-
listSize
)]
+
log
(
1
+
exp
(
multiplier
*
llr
[
row
][
0
][(
i
-
listSize
)]));
//eq. (11b)
double
tempPM
[
listSize
];
memcpy
(
tempPM
,
pathMetric
,
(
sizeof
(
double
)
*
listSize
));
uint
bitValue
=
0
;
int
multiplier
=
(
2
*
bitValue
)
-
1
;
for
(
uint
i
=
0
;
i
<
listSize
;
i
++
)
pathMetric
[
i
]
+=
log
(
1
+
exp
(
multiplier
*
llr
[
row
][
0
][
i
]));
// eq. (11b)
bitValue
=
1
;
multiplier
=
(
2
*
bitValue
)
-
1
;
for
(
uint
i
=
listSize
;
i
<
2
*
listSize
;
i
++
)
pathMetric
[
i
]
=
tempPM
[(
i
-
listSize
)]
+
log
(
1
+
exp
(
multiplier
*
llr
[
row
][
0
][(
i
-
listSize
)]));
// eq. (11b)
}
decoder_node_t
*
new_decoder_node
(
int
first_leaf_index
,
int
level
)
{
...
...
@@ -189,13 +187,13 @@ decoder_node_t *add_nodes(int level, int first_leaf_index, t_nrPolar_params *pol
for
(
int
i
=
0
;
i
<
Nv
;
i
++
)
{
if
(
polarParams
->
information_bit_pattern
[
i
+
first_leaf_index
]
>
0
)
{
all_frozen_below
=
0
;
break
;
all_frozen_below
=
0
;
break
;
}
}
if
(
all_frozen_below
==
0
)
new_node
->
left
=
add_nodes
(
level
-
1
,
first_leaf_index
,
polarParams
);
new_node
->
left
=
add_nodes
(
level
-
1
,
first_leaf_index
,
polarParams
);
else
{
#ifdef DEBUG_NEW_IMPL
printf
(
"aggregating frozen bits %d ... %d at level %d (%s)
\n
"
,
first_leaf_index
,
first_leaf_index
+
Nv
-
1
,
level
,((
first_leaf_index
/
Nv
)
&
1
)
==
0
?
"left"
:
"right"
);
...
...
@@ -204,7 +202,7 @@ decoder_node_t *add_nodes(int level, int first_leaf_index, t_nrPolar_params *pol
new_node
->
all_frozen
=
1
;
}
if
(
all_frozen_below
==
0
)
new_node
->
right
=
add_nodes
(
level
-
1
,
first_leaf_index
+
(
Nv
/
2
),
polarParams
);
new_node
->
right
=
add_nodes
(
level
-
1
,
first_leaf_index
+
(
Nv
/
2
),
polarParams
);
#ifdef DEBUG_NEW_IMPL
printf
(
"new_node (%d): first_leaf_index %d, left %p, right %p
\n
"
,
Nv
,
first_leaf_index
,
new_node
->
left
,
new_node
->
right
);
...
...
@@ -239,7 +237,8 @@ void build_decoder_tree(t_nrPolar_params *polarParams)
#endif
}
void
applyFtoleft
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
)
{
static
void
applyFtoleft
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
,
uint8_t
*
output
)
{
int16_t
*
alpha_v
=
node
->
alpha
;
int16_t
*
alpha_l
=
node
->
left
->
alpha
;
int16_t
*
betal
=
node
->
left
->
beta
;
...
...
@@ -248,12 +247,10 @@ void applyFtoleft(const t_nrPolar_params *pp, decoder_node_t *node) {
#ifdef DEBUG_NEW_IMPL
printf
(
"applyFtoleft %d, Nv %d (level %d,node->left (leaf %d, AF %d))
\n
"
,
node
->
first_leaf_index
,
node
->
Nv
,
node
->
level
,
node
->
left
->
leaf
,
node
->
left
->
all_frozen
);
for
(
int
i
=
0
;
i
<
node
->
Nv
;
i
++
)
printf
(
"i%d (frozen %d): alpha_v[i] = %d
\n
"
,
i
,
1
-
pp
->
information_bit_pattern
[
node
->
first_leaf_index
+
i
],
alpha_v
[
i
]);
for
(
int
i
=
0
;
i
<
node
->
Nv
;
i
++
)
printf
(
"i%d (frozen %d): alpha_v[i] = %d
\n
"
,
i
,
1
-
pp
->
information_bit_pattern
[
node
->
first_leaf_index
+
i
],
alpha_v
[
i
]);
#endif
if
(
node
->
left
->
all_frozen
==
0
)
{
int
avx2mod
=
(
node
->
Nv
/
2
)
&
15
;
if
(
avx2mod
==
0
)
{
...
...
@@ -307,7 +304,7 @@ void applyFtoleft(const t_nrPolar_params *pp, decoder_node_t *node) {
#ifdef DEBUG_NEW_IMPL
printf
(
"betal[0] %d (%p)
\n
"
,
betal
[
0
],
&
betal
[
0
]);
#endif
pp
->
nr_polar_U
[
node
->
first_leaf_index
]
=
(
1
+
betal
[
0
])
>>
1
;
output
[
node
->
first_leaf_index
]
=
(
1
+
betal
[
0
])
>>
1
;
#ifdef DEBUG_NEW_IMPL
printf
(
"Setting bit %d to %d (LLR %d)
\n
"
,
node
->
first_leaf_index
,(
betal
[
0
]
+
1
)
>>
1
,
alpha_l
[
0
]);
#endif
...
...
@@ -315,8 +312,8 @@ void applyFtoleft(const t_nrPolar_params *pp, decoder_node_t *node) {
}
}
void
applyGtoright
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
)
{
static
void
applyGtoright
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
,
uint8_t
*
output
)
{
int16_t
*
alpha_v
=
node
->
alpha
;
int16_t
*
alpha_r
=
node
->
right
->
alpha
;
int16_t
*
betal
=
node
->
left
->
beta
;
...
...
@@ -332,10 +329,9 @@ void applyGtoright(const t_nrPolar_params *pp,decoder_node_t *node) {
int
avx2len
=
node
->
Nv
/
2
/
16
;
for
(
int
i
=
0
;
i
<
avx2len
;
i
++
)
{
((
simde__m256i
*
)
alpha_r
)[
i
]
=
simde_mm256_subs_epi16
(((
simde__m256i
*
)
alpha_v
)[
i
+
avx2len
],
simde_mm256_sign_epi16
(((
simde__m256i
*
)
alpha_v
)[
i
],
((
simde__m256i
*
)
betal
)[
i
]));
((
simde__m256i
*
)
alpha_r
)[
i
]
=
simde_mm256_subs_epi16
(((
simde__m256i
*
)
alpha_v
)[
i
+
avx2len
],
simde_mm256_sign_epi16
(((
simde__m256i
*
)
alpha_v
)[
i
],
((
simde__m256i
*
)
betal
)[
i
]));
}
}
else
if
(
avx2mod
==
8
)
{
...
...
@@ -360,7 +356,7 @@ void applyGtoright(const t_nrPolar_params *pp,decoder_node_t *node) {
}
if
(
node
->
Nv
==
2
)
{
// apply hard decision on right node
betar
[
0
]
=
(
alpha_r
[
0
]
>
0
)
?
-
1
:
1
;
pp
->
nr_polar_U
[
node
->
first_leaf_index
+
1
]
=
(
1
+
betar
[
0
])
>>
1
;
output
[
node
->
first_leaf_index
+
1
]
=
(
1
+
betar
[
0
])
>>
1
;
#ifdef DEBUG_NEW_IMPL
printf
(
"Setting bit %d to %d (LLR %d)
\n
"
,
node
->
first_leaf_index
+
1
,(
betar
[
0
]
+
1
)
>>
1
,
alpha_r
[
0
]);
#endif
...
...
@@ -407,18 +403,17 @@ void computeBeta(const t_nrPolar_params *pp,decoder_node_t *node) {
memcpy
((
void
*
)
&
betav
[
node
->
Nv
/
2
],
betar
,(
node
->
Nv
/
2
)
*
sizeof
(
int16_t
));
}
void
generic_polar_decoder
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
)
{
void
generic_polar_decoder
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
,
uint8_t
*
nr_polar_U
)
{
// Apply F to left
applyFtoleft
(
pp
,
node
);
applyFtoleft
(
pp
,
node
,
nr_polar_U
);
// if left is not a leaf recurse down to the left
if
(
node
->
left
->
leaf
==
0
)
generic_polar_decoder
(
pp
,
node
->
left
);
generic_polar_decoder
(
pp
,
node
->
left
,
nr_polar_U
);
applyGtoright
(
pp
,
node
);
if
(
node
->
right
->
leaf
==
0
)
generic_polar_decoder
(
pp
,
node
->
right
);
applyGtoright
(
pp
,
node
,
nr_polar_U
);
if
(
node
->
right
->
leaf
==
0
)
generic_polar_decoder
(
pp
,
node
->
right
,
nr_polar_U
);
computeBeta
(
pp
,
node
);
}
}
openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h
View file @
ab2b868b
...
...
@@ -77,7 +77,7 @@ typedef struct decoder_tree_t_s {
int
num_nodes
;
}
decoder_tree_t
;
struct
nrPolar_params
{
typedef
struct
nrPolar_params
{
//messageType: 0=PBCH, 1=DCI, -1=UCI
struct
nrPolar_params
*
nextPtr
__attribute__
((
aligned
(
16
)));
...
...
@@ -99,7 +99,6 @@ struct nrPolar_params {
uint32_t
crcBit
;
uint16_t
*
interleaving_pattern
;
uint16_t
*
deinterleaving_pattern
;
uint16_t
*
rate_matching_pattern
;
const
uint16_t
*
Q_0_Nminus1
;
int16_t
*
Q_I_N
;
...
...
@@ -107,36 +106,18 @@ struct nrPolar_params {
int16_t
*
Q_PC_N
;
uint8_t
*
information_bit_pattern
;
uint8_t
*
parity_check_bit_pattern
;
uint16_t
*
channel_interleaver_pattern
;
//uint32_t crc_polynomial;
const
uint8_t
**
crc_generator_matrix
;
// G_P
const
uint8_t
**
G_N
;
fourDimArray_t
*
G_N_tab
;
int
groupsize
;
int
*
rm_tab
;
uint64_t
cprime_tab0
[
32
][
256
];
uint64_t
cprime_tab1
[
32
][
256
];
uint64_t
B_tab0
[
32
][
256
];
uint64_t
B_tab1
[
32
][
256
];
uint8_t
**
extended_crc_generator_matrix
;
//lowercase: bits, Uppercase: Bits stored in bytes
//polar_encoder vectors
uint8_t
*
nr_polar_crc
;
uint8_t
*
nr_polar_aPrime
;
uint8_t
*
nr_polar_APrime
;
uint8_t
*
nr_polar_D
;
uint8_t
*
nr_polar_E
;
//Polar Coding vectors
uint8_t
*
nr_polar_A
;
uint8_t
*
nr_polar_CPrime
;
uint8_t
*
nr_polar_B
;
uint8_t
*
nr_polar_U
;
// lowercase: bits, Uppercase: Bits stored in bytes
// polar_encoder vectors
decoder_tree_t
tree
;
}
__attribute__
((
__packed__
));
typedef
struct
nrPolar_params
t_nrPolar_params
;
}
t_nrPolar_params
;
void
polar_encoder
(
uint32_t
*
input
,
uint32_t
*
output
,
...
...
@@ -181,14 +162,7 @@ int8_t polar_decoder_dci(double *input,
uint16_t
messageLength
,
uint8_t
aggregation_level
);
void
generic_polar_decoder
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
);
void
applyFtoleft
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
);
void
applyGtoright
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
);
void
generic_polar_decoder
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
,
uint8_t
*
nr_polar_U
);
void
computeBeta
(
const
t_nrPolar_params
*
pp
,
decoder_node_t
*
node
);
...
...
@@ -219,8 +193,6 @@ uint32_t nr_polar_output_length(uint16_t K,
uint16_t
E
,
uint8_t
n_max
);
void
nr_polar_channel_interleaver_pattern
(
uint16_t
*
cip
,
const
uint8_t
I_BIL
,
const
uint16_t
E
);
void
nr_polar_rate_matching_pattern
(
uint16_t
*
rmp
,
uint16_t
*
J
,
const
uint8_t
*
P_i_
,
...
...
@@ -254,11 +226,11 @@ void nr_polar_info_bit_pattern(uint8_t *ibp,
int16_t
*
Q_PC_N
,
const
uint16_t
*
J
,
const
uint16_t
*
Q_0_Nminus1
,
uint16_t
K
,
uint16_t
N
,
const
uint16_t
K
,
const
uint16_t
N
,
const
uint16_t
E
,
uint8_t
n_PC
,
uint8_t
n_pc_wm
);
const
uint8_t
n_PC
,
const
uint8_t
n_pc_wm
);
void
nr_polar_info_bit_extraction
(
uint8_t
*
input
,
uint8_t
*
output
,
...
...
@@ -309,10 +281,6 @@ void nr_sort_asc_double_1D_array_ind(double *matrix,
uint8_t
*
ind
,
uint8_t
len
);
void
nr_sort_asc_int16_1D_array_ind
(
int32_t
*
matrix
,
int
*
ind
,
int
len
);
void
nr_free_double_2D_array
(
double
**
input
,
uint16_t
xlen
);
#ifndef __cplusplus
...
...
@@ -350,23 +318,24 @@ static inline void nr_polar_interleaver(uint8_t *input,
uint16_t
*
pattern
,
uint16_t
size
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
)
output
[
i
]
=
input
[
pattern
[
i
]];
for
(
int
i
=
0
;
i
<
size
;
i
++
)
output
[
i
]
=
input
[
pattern
[
i
]];
}
static
inline
void
nr_polar_deinterleaver
(
uint8_t
*
input
,
uint8_t
*
output
,
uint16_t
*
pattern
,
uint16_t
size
)
static
inline
void
nr_polar_deinterleaver
(
uint8_t
*
input
,
uint8_t
*
output
,
uint16_t
*
pattern
,
uint16_t
size
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
)
output
[
pattern
[
i
]]
=
input
[
i
];
for
(
int
i
=
0
;
i
<
size
;
i
++
)
output
[
pattern
[
i
]]
=
input
[
i
];
}
void
delete_decoder_tree
(
t_nrPolar_params
*
);
extern
pthread_mutex_t
PolarListMutex
;
#define polarReturn \
pthread_mutex_lock(&PolarListMutex); \
polarParams->busy=false; \
pthread_mutex_unlock(&PolarListMutex); \
return
static
inline
void
polarReturn
(
t_nrPolar_params
*
polarParams
)
{
pthread_mutex_lock
(
&
PolarListMutex
);
polarParams
->
busy
=
false
;
pthread_mutex_unlock
(
&
PolarListMutex
);
}
#endif
openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c
View file @
ab2b868b
...
...
@@ -48,115 +48,96 @@ void polar_encoder(uint32_t *in,
uint16_t
messageLength
,
uint8_t
aggregation_level
)
{
t_nrPolar_params
*
polarParams
=
nr_polar_params
(
messageType
,
messageLength
,
aggregation_level
,
false
);
if
(
1
)
{
//polarParams->idx == 0 || polarParams->idx == 1) { //PBCH or PDCCH
/*
uint64_t B = (((uint64_t)*in)&((((uint64_t)1)<<32)-1)) | (((uint64_t)crc24c((uint8_t*)in,polarParams->payloadBits)>>8)<<polarParams->payloadBits);
#ifdef DEBUG_POLAR_ENCODER
printf("polar_B %llx (crc %x)\n",B,crc24c((uint8_t*)in,polarParams->payloadBits)>>8);
#endif
nr_bit2byte_uint32_8_t((uint32_t*)&B, polarParams->K, polarParams->nr_polar_B);*/
nr_bit2byte_uint32_8
(
in
,
polarParams
->
payloadBits
,
polarParams
->
nr_polar_A
);
/*
* Bytewise operations
*/
//Calculate CRC.
nr_matrix_multiplication_uint8_1D_uint8_2D
(
polarParams
->
nr_polar_A
,
polarParams
->
crc_generator_matrix
,
polarParams
->
nr_polar_crc
,
polarParams
->
payloadBits
,
polarParams
->
crcParityBits
);
for
(
uint8_t
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
polarParams
->
nr_polar_crc
[
i
]
=
(
polarParams
->
nr_polar_crc
[
i
]
%
2
);
//Attach CRC to the Transport Block. (a to b)
for
(
uint16_t
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
polarParams
->
nr_polar_B
[
i
]
=
polarParams
->
nr_polar_A
[
i
];
for
(
uint16_t
i
=
polarParams
->
payloadBits
;
i
<
polarParams
->
K
;
i
++
)
polarParams
->
nr_polar_B
[
i
]
=
polarParams
->
nr_polar_crc
[
i
-
(
polarParams
->
payloadBits
)];
uint8_t
nr_polar_A
[
polarParams
->
payloadBits
];
nr_bit2byte_uint32_8
(
in
,
polarParams
->
payloadBits
,
nr_polar_A
);
/*
* Bytewise operations
*/
// Calculate CRC.
uint8_t
nr_polar_crc
[
polarParams
->
crcParityBits
];
nr_matrix_multiplication_uint8_1D_uint8_2D
(
nr_polar_A
,
polarParams
->
crc_generator_matrix
,
nr_polar_crc
,
polarParams
->
payloadBits
,
polarParams
->
crcParityBits
);
for
(
uint
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
nr_polar_crc
[
i
]
%=
2
;
uint8_t
nr_polar_B
[
polarParams
->
K
];
// Attach CRC to the Transport Block. (a to b)
memcpy
(
nr_polar_B
,
nr_polar_A
,
polarParams
->
payloadBits
);
for
(
uint
i
=
polarParams
->
payloadBits
;
i
<
polarParams
->
K
;
i
++
)
nr_polar_B
[
i
]
=
nr_polar_crc
[
i
-
(
polarParams
->
payloadBits
)];
#ifdef DEBUG_POLAR_ENCODER
uint64_t
B2
=
0
;
uint64_t
B2
=
0
;
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
B2
=
B2
|
((
uint64_t
)
polarParams
->
nr_polar_B
[
i
]
<<
i
);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
B2
|=
((
uint64_t
)
nr_polar_B
[
i
]
<<
i
);
printf
(
"polar_B %lx
\n
"
,
B2
);
for
(
int
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
printf
(
"a[%d]=%d
\n
"
,
i
,
polarParams
->
nr_polar_A
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
printf
(
"b[%d]=%d
\n
"
,
i
,
polarParams
->
nr_polar_B
[
i
]);
printf
(
"polar_B %lx
\n
"
,
B2
);
for
(
int
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
printf
(
"a[%d]=%d
\n
"
,
i
,
nr_polar_A
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
printf
(
"b[%d]=%d
\n
"
,
i
,
nr_polar_B
[
i
]);
#endif
/* for (int j=0;j<polarParams->crcParityBits;j++) {
for (int i=0;i<polarParams->payloadBits;i++)
printf("%1d.%1d+",polarParams->crc_generator_matrix[i][j],polarParams->nr_polar_A[i]);
printf(" => %d\n",polarParams->nr_polar_crc[j]);
}*/
}
else
{
//UCI
}
//Interleaving (c to c')
nr_polar_interleaver
(
polarParams
->
nr_polar_B
,
polarParams
->
nr_polar_CPrime
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
uint8_t
nr_polar_CPrime
[
polarParams
->
K
];
nr_polar_interleaver
(
nr_polar_B
,
nr_polar_CPrime
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
#ifdef DEBUG_POLAR_ENCODER
uint64_t
Cprime
=
0
;
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
{
Cprime
=
Cprime
|
((
uint64_t
)
polarParams
->
nr_polar_CPrime
[
i
]
<<
i
);
if
(
polarParams
->
nr_polar_CPrime
[
i
]
==
1
)
printf
(
"pos %d : %lx
\n
"
,
i
,
Cprime
);
Cprime
=
Cprime
|
((
uint64_t
)
nr_polar_CPrime
[
i
]
<<
i
);
if
(
nr_polar_CPrime
[
i
]
==
1
)
printf
(
"pos %d : %lx
\n
"
,
i
,
Cprime
);
}
printf
(
"polar_Cprime %lx
\n
"
,
Cprime
);
#endif
//Bit insertion (c' to u)
nr_polar_bit_insertion
(
polarParams
->
nr_polar_CPrime
,
polarParams
->
nr_polar_U
,
uint8_t
nr_polar_U
[
polarParams
->
N
];
nr_polar_bit_insertion
(
nr_polar_CPrime
,
nr_polar_U
,
polarParams
->
N
,
polarParams
->
K
,
polarParams
->
Q_I_N
,
polarParams
->
Q_PC_N
,
polarParams
->
n_pc
);
//Encoding (u to d)
/* memset(polarParams->nr_polar_U,0,polarParams->N);
polarParams->nr_polar_U[247]=1;
polarParams->nr_polar_U[253]=1;*/
nr_matrix_multiplication_uint8_1D_uint8_2D
(
polarParams
->
nr_polar_U
,
polarParams
->
G_N
,
polarParams
->
nr_polar_D
,
polarParams
->
N
,
polarParams
->
N
);
for
(
uint16_t
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
polarParams
->
nr_polar_D
[
i
]
=
(
polarParams
->
nr_polar_D
[
i
]
%
2
);
uint8_t
nr_polar_D
[
polarParams
->
N
];
nr_matrix_multiplication_uint8_1D_uint8_2D
(
nr_polar_U
,
polarParams
->
G_N
,
nr_polar_D
,
polarParams
->
N
,
polarParams
->
N
);
for
(
uint
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
nr_polar_D
[
i
]
%=
2
;
uint64_t
D
[
8
];
memset
(
(
void
*
)
D
,
0
,
8
*
sizeof
(
int64_t
));
memset
(
D
,
0
,
sizeof
(
D
));
#ifdef DEBUG_POLAR_ENCODER
for
(
int
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
D
[
i
/
64
]
|=
((
uint64_t
)
polarParams
->
nr_polar_D
[
i
])
<<
(
i
&
63
);
for
(
int
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
D
[
i
/
64
]
|=
((
uint64_t
)
nr_polar_D
[
i
])
<<
(
i
&
63
);
printf
(
"D %llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx
\n
"
,
D
[
0
],
D
[
1
],
D
[
2
],
D
[
3
],
D
[
4
],
D
[
5
],
D
[
6
],
D
[
7
]);
#endif
//Rate matching
//Sub-block interleaving (d to y) and Bit selection (y to e)
nr_polar_interleaver
(
polarParams
->
nr_polar_D
,
polarParams
->
nr_polar_E
,
polarParams
->
rate_matching_pattern
,
polarParams
->
encoderLength
);
uint8_t
nr_polar_E
[
polarParams
->
encoderLength
];
nr_polar_interleaver
(
nr_polar_D
,
nr_polar_E
,
polarParams
->
rate_matching_pattern
,
polarParams
->
encoderLength
);
/*
* Return bits.
*/
#ifdef DEBUG_POLAR_ENCODER
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
;
i
++
)
printf
(
"f[%d]=%d
\n
"
,
i
,
polarParams
->
nr_polar_E
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
;
i
++
)
printf
(
"f[%d]=%d
\n
"
,
i
,
nr_polar_E
[
i
]);
#endif
nr_byte2bit_uint8_32
(
polarParams
->
nr_polar_E
,
polarParams
->
encoderLength
,
out
);
polarReturn
;
nr_byte2bit_uint8_32
(
nr_polar_E
,
polarParams
->
encoderLength
,
out
);
polarReturn
(
polarParams
);
}
void
polar_encoder_dci
(
uint32_t
*
in
,
...
...
@@ -174,19 +155,24 @@ void polar_encoder_dci(uint32_t *in,
* Bytewise operations
*/
//(a to a')
nr_bit2byte_uint32_8
(
in
,
polarParams
->
payloadBits
,
polarParams
->
nr_polar_A
);
for
(
int
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
polarParams
->
nr_polar_APrime
[
i
]
=
1
;
for
(
int
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
polarParams
->
nr_polar_APrime
[
i
+
(
polarParams
->
crcParityBits
)]
=
polarParams
->
nr_polar_A
[
i
];
uint8_t
nr_polar_A
[
polarParams
->
payloadBits
];
nr_bit2byte_uint32_8
(
in
,
polarParams
->
payloadBits
,
nr_polar_A
);
uint8_t
nr_polar_APrime
[
polarParams
->
K
];
for
(
int
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
nr_polar_APrime
[
i
]
=
1
;
const
int
end
=
polarParams
->
crcParityBits
+
polarParams
->
payloadBits
;
for
(
int
i
=
polarParams
->
crcParityBits
;
i
<
end
;
i
++
)
nr_polar_APrime
[
i
]
=
nr_polar_A
[
i
];
#ifdef DEBUG_POLAR_ENCODER_DCI
printf
(
"[polar_encoder_dci] A: "
);
for
(
int
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
printf
(
"%d-"
,
polarParams
->
nr_polar_A
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
printf
(
"%d-"
,
nr_polar_A
[
i
]);
printf
(
"
\n
"
);
printf
(
"[polar_encoder_dci] APrime: "
);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
printf
(
"%d-"
,
polarParams
->
nr_polar_APrime
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
printf
(
"%d-"
,
nr_polar_APrime
[
i
]);
printf
(
"
\n
"
);
printf
(
"[polar_encoder_dci] GP: "
);
...
...
@@ -194,73 +180,76 @@ void polar_encoder_dci(uint32_t *in,
printf
(
"
\n
"
);
#endif
//Calculate CRC.
nr_matrix_multiplication_uint8_1D_uint8_2D
(
polarParams
->
nr_polar_APrime
,
polarParams
->
crc_generator_matrix
,
polarParams
->
nr_polar_crc
,
polarParams
->
K
,
polarParams
->
crcParityBits
);
uint8_t
nr_polar_crc
[
polarParams
->
crcParityBits
];
nr_matrix_multiplication_uint8_1D_uint8_2D
(
nr_polar_APrime
,
polarParams
->
crc_generator_matrix
,
nr_polar_crc
,
polarParams
->
K
,
polarParams
->
crcParityBits
);
for
(
uint8_t
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
polarParams
->
nr_polar_crc
[
i
]
=
(
polarParams
->
nr_polar_crc
[
i
]
%
2
);
for
(
uint
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
nr_polar_crc
[
i
]
%=
2
;
#ifdef DEBUG_POLAR_ENCODER_DCI
printf
(
"[polar_encoder_dci] CRC: "
);
for
(
int
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
printf
(
"%d-"
,
polarParams
->
nr_polar_crc
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
crcParityBits
;
i
++
)
printf
(
"%d-"
,
nr_polar_crc
[
i
]);
printf
(
"
\n
"
);
#endif
uint8_t
nr_polar_B
[
polarParams
->
payloadBits
+
8
+
16
];
//Attach CRC to the Transport Block. (a to b)
for
(
uint16_t
i
=
0
;
i
<
polarParams
->
payloadBits
;
i
++
)
polarParams
->
nr_polar_B
[
i
]
=
polarParams
->
nr_polar_A
[
i
];
memcpy
(
nr_polar_B
,
nr_polar_A
,
polarParams
->
payloadBits
);
for
(
uint
16_t
i
=
polarParams
->
payloadBits
;
i
<
polarParams
->
K
;
i
++
)
polarParams
->
nr_polar_B
[
i
]
=
polarParams
->
nr_polar_crc
[
i
-
(
polarParams
->
payloadBits
)
];
for
(
uint
i
=
polarParams
->
payloadBits
;
i
<
polarParams
->
K
;
i
++
)
nr_polar_B
[
i
]
=
nr_polar_crc
[
i
-
polarParams
->
payloadBits
];
//Scrambling (b to c)
for
(
int
i
=
0
;
i
<
16
;
i
++
)
polarParams
->
nr_polar_B
[
polarParams
->
payloadBits
+
8
+
i
]
=
(
polarParams
->
nr_polar_B
[
polarParams
->
payloadBits
+
8
+
i
]
+
((
n_RNTI
>>
(
15
-
i
))
&
1
)
)
%
2
;
nr_polar_B
[
polarParams
->
payloadBits
+
8
+
i
]
=
(
nr_polar_B
[
polarParams
->
payloadBits
+
8
+
i
]
+
((
n_RNTI
>>
(
15
-
i
))
&
1
)
)
%
2
;
#ifdef DEBUG_POLAR_ENCODER_DCI
printf
(
"[polar_encoder_dci] B: "
);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
printf
(
"%d-"
,
polarParams
->
nr_polar_B
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
printf
(
"%d-"
,
nr_polar_B
[
i
]);
printf
(
"
\n
"
);
#endif
//Interleaving (c to c')
nr_polar_interleaver
(
polarParams
->
nr_polar_B
,
polarParams
->
nr_polar_CPrime
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
uint8_t
nr_polar_CPrime
[
polarParams
->
K
];
nr_polar_interleaver
(
nr_polar_B
,
nr_polar_CPrime
,
polarParams
->
interleaving_pattern
,
polarParams
->
K
);
//Bit insertion (c' to u)
nr_polar_bit_insertion
(
polarParams
->
nr_polar_CPrime
,
polarParams
->
nr_polar_U
,
uint8_t
nr_polar_U
[
polarParams
->
N
];
nr_polar_bit_insertion
(
nr_polar_CPrime
,
nr_polar_U
,
polarParams
->
N
,
polarParams
->
K
,
polarParams
->
Q_I_N
,
polarParams
->
Q_PC_N
,
polarParams
->
n_pc
);
//Encoding (u to d)
nr_matrix_multiplication_uint8_1D_uint8_2D
(
polarParams
->
nr_polar_U
,
polarParams
->
G_N
,
polarParams
->
nr_polar_D
,
polarParams
->
N
,
polarParams
->
N
);
for
(
uint16_t
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
polarParams
->
nr_polar_D
[
i
]
=
(
polarParams
->
nr_polar_D
[
i
]
%
2
);
uint8_t
nr_polar_D
[
polarParams
->
N
];
nr_matrix_multiplication_uint8_1D_uint8_2D
(
nr_polar_U
,
polarParams
->
G_N
,
nr_polar_D
,
polarParams
->
N
,
polarParams
->
N
);
for
(
uint
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
nr_polar_D
[
i
]
%=
2
;
//Rate matching
//Sub-block interleaving (d to y) and Bit selection (y to e)
nr_polar_interleaver
(
polarParams
->
nr_polar_D
,
polarParams
->
nr_polar_E
,
polarParams
->
rate_matching_pattern
,
polarParams
->
encoderLength
);
uint8_t
nr_polar_E
[
polarParams
->
encoderLength
];
nr_polar_interleaver
(
nr_polar_D
,
nr_polar_E
,
polarParams
->
rate_matching_pattern
,
polarParams
->
encoderLength
);
/*
* Return bits.
*/
nr_byte2bit_uint8_32
(
polarParams
->
nr_polar_E
,
polarParams
->
encoderLength
,
out
);
nr_byte2bit_uint8_32
(
nr_polar_E
,
polarParams
->
encoderLength
,
out
);
#ifdef DEBUG_POLAR_ENCODER_DCI
printf
(
"[polar_encoder_dci] E: "
);
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
;
i
++
)
printf
(
"%d-"
,
polarParams
->
nr_polar_E
[
i
]);
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
;
i
++
)
printf
(
"%d-"
,
nr_polar_E
[
i
]);
uint8_t
outputInd
=
ceil
(
polarParams
->
encoderLength
/
32
.
0
);
printf
(
"
\n
[polar_encoder_dci] out: "
);
for
(
int
i
=
0
;
i
<
outputInd
;
i
++
)
printf
(
"[%d]->0x%08x
\t
"
,
i
,
out
[
i
]);
for
(
int
i
=
0
;
i
<
outputInd
;
i
++
)
printf
(
"[%d]->0x%08x
\t
"
,
i
,
out
[
i
]);
#endif
polarReturn
;
polarReturn
(
polarParams
)
;
}
/*
...
...
@@ -301,10 +290,8 @@ void nr_polar_rm_interleaving_cb(void *in, void *out, uint16_t E)
}
}
static
inline
void
polar_rate_matching
(
const
t_nrPolar_params
*
polarParams
,
void
*
in
,
void
*
out
)
__attribute__
((
always_inline
));
static
inline
void
polar_rate_matching
(
const
t_nrPolar_params
*
polarParams
,
void
*
in
,
void
*
out
)
{
__attribute__
((
always_inline
))
static
inline
void
polar_rate_matching
(
const
t_nrPolar_params
*
polarParams
,
void
*
in
,
void
*
out
)
{
// handle rate matching with a single 128 bit word using bit shuffling
// can be done with SIMD intrisics if needed
if
(
polarParams
->
groupsize
<
8
)
{
...
...
@@ -312,8 +299,7 @@ static inline void polar_rate_matching(const t_nrPolar_params *polarParams,void
uint128_t
*
out128
=
(
uint128_t
*
)
out
;
uint128_t
*
in128
=
(
uint128_t
*
)
in
;
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
>>
7
;
i
++
)
out128
[
i
]
=
0
;
uint128_t
tmp0
;
out128
[
i
]
=
0
;
#ifdef DEBUG_POLAR_ENCODER
uint128_t
tmp1
;
#endif
...
...
@@ -326,9 +312,8 @@ static inline void polar_rate_matching(const t_nrPolar_params *polarParams,void
uint8_t
pimod128
=
pi
&
127
;
uint8_t
imod128
=
i
&
127
;
uint8_t
i7
=
i
>>
7
;
tmp0
=
(
in128
[
pi7
]
&
(((
uint128_t
)
1
)
<<
(
pimod128
)));
uint128_t
tmp0
=
(
in128
[
pi7
]
&
(((
uint128_t
)
1
)
<<
(
pimod128
)));
if
(
tmp0
!=
0
)
{
out128
[
i7
]
=
out128
[
i7
]
|
((
uint128_t
)
1
)
<<
imod128
;
#ifdef DEBUG_POLAR_ENCODER
...
...
@@ -343,7 +328,8 @@ static inline void polar_rate_matching(const t_nrPolar_params *polarParams,void
}
// These are based on LUTs for byte and short word groups
else
if
(
polarParams
->
groupsize
==
8
)
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
>>
3
;
i
++
)
((
uint8_t
*
)
out
)[
i
]
=
((
uint8_t
*
)
in
)[
polarParams
->
rm_tab
[
i
]];
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
>>
3
;
i
++
)
((
uint8_t
*
)
out
)[
i
]
=
((
uint8_t
*
)
in
)[
polarParams
->
rm_tab
[
i
]];
else
// groupsize==16
for
(
int
i
=
0
;
i
<
polarParams
->
encoderLength
>>
4
;
i
++
)
{
((
uint16_t
*
)
out
)[
i
]
=
((
uint16_t
*
)
in
)[
polarParams
->
rm_tab
[
i
]];
...
...
@@ -357,59 +343,37 @@ static inline void polar_rate_matching(const t_nrPolar_params *polarParams,void
void
build_polar_tables
(
t_nrPolar_params
*
polarParams
)
{
// build table b -> c'
AssertFatal
(
polarParams
->
K
>
17
,
"K = %d < 18, is not possible
\n
"
,
polarParams
->
K
);
AssertFatal
(
polarParams
->
K
<
129
,
"K = %d > 128, is not supported yet
\n
"
,
polarParams
->
K
);
int
bit_i
,
ip
;
AssertFatal
(
polarParams
->
K
<
129
,
"K = %d > 128, is not supported yet
\n
"
,
polarParams
->
K
);
const
int
numbytes
=
(
polarParams
->
K
+
7
)
/
8
;
const
int
residue
=
polarParams
->
K
&
7
;
uint
deinterleaving_pattern
[
polarParams
->
K
];
for
(
int
i
=
0
;
i
<
polarParams
->
K
;
i
++
)
deinterleaving_pattern
[
polarParams
->
interleaving_pattern
[
i
]]
=
i
;
for
(
int
byte
=
0
;
byte
<
numbytes
;
byte
++
)
{
int
numbits
=
byte
<
(
polarParams
->
K
>>
3
)
?
8
:
residue
;
for
(
int
val
=
0
;
val
<
256
;
val
++
)
{
polarParams
->
cprime_tab0
[
byte
][
val
]
=
0
;
polarParams
->
cprime_tab1
[
byte
][
val
]
=
0
;
for
(
uint64_t
val
=
0
;
val
<
256LU
;
val
++
)
{
// uint16_t * tmp=polarParams->deinterleaving_pattern+polarParams->K - 1 - 8 * byte;
union
{
uint128_t
full
;
uint64_t
pieces
[
2
];
}
tab
=
{
0
};
uint
*
tmp
=
deinterleaving_pattern
+
polarParams
->
K
-
8
*
byte
-
1
;
for
(
int
i
=
0
;
i
<
numbits
;
i
++
)
{
// flip bit endian of B bitstring
ip
=
polarParams
->
deinterleaving_pattern
[
polarParams
->
K
-
1
-
((
8
*
byte
)
+
i
)]
;
const
int
ip
=
*
tmp
--
;
AssertFatal
(
ip
<
128
,
"ip = %d
\n
"
,
ip
);
bit_i
=
(
val
>>
i
)
&
1
;
if
(
ip
<
64
)
polarParams
->
cprime_tab0
[
byte
][
val
]
|=
(((
uint64_t
)
bit_i
)
<<
ip
);
else
polarParams
->
cprime_tab1
[
byte
][
val
]
|=
(((
uint64_t
)
bit_i
)
<<
(
ip
&
63
));
const
uint128_t
bit_i
=
(
val
>>
i
)
&
1
;
tab
.
full
|=
bit_i
<<
ip
;
}
polarParams
->
cprime_tab0
[
byte
][
val
]
=
tab
.
pieces
[
0
];
polarParams
->
cprime_tab1
[
byte
][
val
]
=
tab
.
pieces
[
1
];
}
}
AssertFatal
(
polarParams
->
N
==
512
||
polarParams
->
N
==
256
||
polarParams
->
N
==
128
||
polarParams
->
N
==
64
,
"N = %d, not done yet
\n
"
,
polarParams
->
N
);
// build G bit vectors for information bit positions and convert the bit as bytes tables in nr_polar_kronecker_power_matrices.c to
// 64 bit packed vectors.
// Truncates id N%64 != 0
allocCast2D
(
pp
,
uint64_t
,
polarParams
->
G_N_tab
,
polarParams
->
N
,
polarParams
->
N
/
64
,
false
);
simde__m256i
zeros
=
simde_mm256_setzero_si256
();
// this code packs the one bit per byte of G_N into a packed bits G_N_tab
for
(
int
i
=
0
;
i
<
polarParams
->
N
;
i
++
)
{
for
(
int
j
=
0
;
j
<
polarParams
->
N
;
j
+=
64
)
{
const
simde__m256i
tmp1
=
simde_mm256_cmpgt_epi8
(
simde_mm256_loadu_si256
((
simde__m256i
*
)
&
polarParams
->
G_N
[
i
][
j
]),
zeros
);
const
simde__m256i
tmp2
=
simde_mm256_cmpgt_epi8
(
simde_mm256_loadu_si256
((
simde__m256i
*
)
&
polarParams
->
G_N
[
i
][
j
+
32
]),
zeros
);
// cast directly to uint64_t from int32_t propagates the sign bit (in gcc)
const
uint32_t
part1
=
simde_mm256_movemask_epi8
(
tmp1
);
const
uint32_t
part2
=
simde_mm256_movemask_epi8
(
tmp2
);
pp
[
i
][
j
/
64
]
=
((
uint64_t
)
part2
<<
32
)
|
part1
;
}
#ifdef DEBUG_POLAR_ENCODER
printf
(
"Bit %d Selecting row %d of G : "
,
i
,
i
);
for
(
int
j
=
0
;
j
<
polarParams
->
N
;
j
+=
4
)
printf
(
"%1x"
,
polarParams
->
G_N
[
i
][
j
]
+
(
polarParams
->
G_N
[
i
][
j
+
1
]
*
2
)
+
(
polarParams
->
G_N
[
i
][
j
+
2
]
*
4
)
+
(
polarParams
->
G_N
[
i
][
j
+
3
]
*
8
));
printf
(
"
\n
"
);
#endif
}
// rate matching table
int
iplast
=
polarParams
->
rate_matching_pattern
[
0
];
int
ccnt
=
0
;
...
...
@@ -422,11 +386,12 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
// compute minimum group size of rate-matching pattern
for
(
int
outpos
=
1
;
outpos
<
polarParams
->
encoderLength
;
outpos
++
)
{
i
p
=
polarParams
->
rate_matching_pattern
[
outpos
];
i
nt
ip
=
polarParams
->
rate_matching_pattern
[
outpos
];
#ifdef DEBUG_POLAR_ENCODER
printf
(
"rm: outpos %d, inpos %d
\n
"
,
outpos
,
ip
);
#endif
if
((
ip
-
iplast
)
==
1
)
ccnt
++
;
if
((
ip
-
iplast
)
==
1
)
ccnt
++
;
else
{
#ifdef DEBUG_POLAR_ENCODER
groupcnt
++
;
...
...
@@ -435,7 +400,8 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
firstingroup_out
,
firstingroup_out
+
ccnt
);
#endif
if
((
ccnt
+
1
)
<
mingroupsize
)
mingroupsize
=
ccnt
+
1
;
if
((
ccnt
+
1
)
<
mingroupsize
)
mingroupsize
=
ccnt
+
1
;
ccnt
=
0
;
#ifdef DEBUG_POLAR_ENCODER
...
...
@@ -448,12 +414,16 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
}
#ifdef DEBUG_POLAR_ENCODER
groupcnt
++
;
#endif
#endif
if
((
ccnt
+
1
)
<
mingroupsize
)
mingroupsize
=
ccnt
+
1
;
#ifdef DEBUG_POLAR_ENCODER
printf
(
"group %d (size %d): (%d:%d) => (%d:%d)
\n
"
,
groupcnt
,
ccnt
+
1
,
firstingroup_in
,
firstingroup_in
+
ccnt
,
firstingroup_out
,
firstingroup_out
+
ccnt
);
printf
(
"group %d (size %d): (%d:%d) => (%d:%d)
\n
"
,
groupcnt
,
ccnt
+
1
,
firstingroup_in
,
firstingroup_in
+
ccnt
,
firstingroup_out
,
firstingroup_out
+
ccnt
);
#endif
polarParams
->
groupsize
=
mingroupsize
;
...
...
@@ -473,15 +443,14 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
shift
=
4
;
break
;
default:
AssertFatal
(
1
==
0
,
"mingroupsize = %i is not supported
\n
"
,
mingroupsize
);
AssertFatal
(
false
,
"mingroupsize = %i is not supported
\n
"
,
mingroupsize
);
break
;
}
polarParams
->
rm_tab
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
(
polarParams
->
encoderLength
>>
shift
));
polarParams
->
rm_tab
=
malloc
(
sizeof
(
*
polarParams
->
rm_tab
)
*
(
polarParams
->
encoderLength
>>
shift
));
// rerun again to create groups
int
tcnt
=
0
;
for
(
int
outpos
=
0
;
outpos
<
polarParams
->
encoderLength
;
outpos
+=
mingroupsize
,
tcnt
++
)
for
(
int
outpos
=
0
,
tcnt
=
0
;
outpos
<
polarParams
->
encoderLength
;
outpos
+=
mingroupsize
,
tcnt
++
)
polarParams
->
rm_tab
[
tcnt
]
=
polarParams
->
rate_matching_pattern
[
outpos
]
>>
shift
;
}
...
...
@@ -532,10 +501,11 @@ void polar_encoder_fast(uint64_t *A,
#endif
uint64_t
tcrc
=
0
;
uint
8_t
offset
=
0
;
uint
offset
=
0
;
// appending 24 ones before a0 for DCI as stated in 38.212 7.3.2
if
(
ones_flag
)
offset
=
3
;
if
(
ones_flag
)
offset
=
3
;
// A bit string should be stored as 0, 0, ..., 0, a'_0, a'_1, ..., a'_A-1,
//???a'_{N-1} a'_{N-2} ... a'_{N-A} 0 .... 0, where N=64,128,192,..., N is smallest multiple of 64 greater than or equal to A
...
...
@@ -722,5 +692,5 @@ void polar_encoder_fast(uint64_t *A,
printf
(
"
\n
"
);
#endif
polarReturn
;
polarReturn
(
polarParams
)
;
}
openair1/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c
View file @
ab2b868b
...
...
@@ -33,29 +33,25 @@
#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h"
void
nr_polar_interleaving_pattern
(
uint16_t
K
,
uint8_t
I_IL
,
uint16_t
*
PI_k_
){
uint8_t
K_IL_max
=
164
,
k
=
0
;
uint8_t
interleaving_pattern_table
[
164
]
=
{
0
,
2
,
4
,
7
,
9
,
14
,
19
,
20
,
24
,
25
,
26
,
28
,
31
,
34
,
42
,
45
,
49
,
50
,
51
,
53
,
54
,
56
,
58
,
59
,
61
,
62
,
65
,
66
,
67
,
69
,
70
,
71
,
72
,
76
,
77
,
81
,
82
,
83
,
87
,
88
,
89
,
91
,
93
,
95
,
98
,
101
,
104
,
106
,
108
,
110
,
111
,
113
,
115
,
118
,
119
,
120
,
122
,
123
,
126
,
127
,
129
,
132
,
134
,
138
,
139
,
140
,
1
,
3
,
5
,
8
,
10
,
15
,
21
,
27
,
29
,
32
,
35
,
43
,
46
,
52
,
55
,
57
,
60
,
63
,
68
,
73
,
78
,
84
,
90
,
92
,
94
,
96
,
99
,
102
,
105
,
107
,
109
,
112
,
114
,
116
,
121
,
124
,
128
,
130
,
133
,
135
,
141
,
6
,
11
,
16
,
22
,
30
,
33
,
36
,
44
,
47
,
64
,
74
,
79
,
85
,
97
,
100
,
103
,
117
,
125
,
131
,
136
,
142
,
12
,
17
,
23
,
37
,
48
,
75
,
80
,
86
,
137
,
143
,
13
,
18
,
38
,
144
,
39
,
145
,
40
,
146
,
41
,
147
,
148
,
149
,
150
,
151
,
152
,
153
,
154
,
155
,
156
,
157
,
158
,
159
,
160
,
161
,
162
,
163
};
if
(
I_IL
==
0
){
for
(;
k
<=
K
-
1
;
k
++
)
PI_k_
[
k
]
=
k
;
}
else
{
for
(
int
m
=
0
;
m
<=
(
K_IL_max
-
1
);
m
++
){
if
(
interleaving_pattern_table
[
m
]
>=
(
K_IL_max
-
K
))
{
PI_k_
[
k
]
=
interleaving_pattern_table
[
m
]
-
(
K_IL_max
-
K
);
k
++
;
}
}
}
uint
K_IL_max
=
164
,
k
=
0
;
uint8_t
interleaving_pattern_table
[
164
]
=
{
0
,
2
,
4
,
7
,
9
,
14
,
19
,
20
,
24
,
25
,
26
,
28
,
31
,
34
,
42
,
45
,
49
,
50
,
51
,
53
,
54
,
56
,
58
,
59
,
61
,
62
,
65
,
66
,
67
,
69
,
70
,
71
,
72
,
76
,
77
,
81
,
82
,
83
,
87
,
88
,
89
,
91
,
93
,
95
,
98
,
101
,
104
,
106
,
108
,
110
,
111
,
113
,
115
,
118
,
119
,
120
,
122
,
123
,
126
,
127
,
129
,
132
,
134
,
138
,
139
,
140
,
1
,
3
,
5
,
8
,
10
,
15
,
21
,
27
,
29
,
32
,
35
,
43
,
46
,
52
,
55
,
57
,
60
,
63
,
68
,
73
,
78
,
84
,
90
,
92
,
94
,
96
,
99
,
102
,
105
,
107
,
109
,
112
,
114
,
116
,
121
,
124
,
128
,
130
,
133
,
135
,
141
,
6
,
11
,
16
,
22
,
30
,
33
,
36
,
44
,
47
,
64
,
74
,
79
,
85
,
97
,
100
,
103
,
117
,
125
,
131
,
136
,
142
,
12
,
17
,
23
,
37
,
48
,
75
,
80
,
86
,
137
,
143
,
13
,
18
,
38
,
144
,
39
,
145
,
40
,
146
,
41
,
147
,
148
,
149
,
150
,
151
,
152
,
153
,
154
,
155
,
156
,
157
,
158
,
159
,
160
,
161
,
162
,
163
};
if
(
I_IL
==
0
)
{
for
(;
k
<=
K
-
1
;
k
++
)
PI_k_
[
k
]
=
k
;
}
else
{
for
(
int
m
=
0
;
m
<=
(
K_IL_max
-
1
);
m
++
)
{
if
(
interleaving_pattern_table
[
m
]
>=
(
K_IL_max
-
K
))
{
PI_k_
[
k
]
=
interleaving_pattern_table
[
m
]
-
(
K_IL_max
-
K
);
k
++
;
}
}
}
}
openair1/PHY/CODING/nrPolar_tools/nr_polar_matrix_and_array.c
View file @
ab2b868b
...
...
@@ -38,58 +38,29 @@ void nr_matrix_multiplication_uint8_1D_uint8_2D(const uint8_t *matrix1,
uint16_t
row
,
uint16_t
col
)
{
for
(
uint
16_t
i
=
0
;
i
<
col
;
i
++
)
{
for
(
uint
i
=
0
;
i
<
col
;
i
++
)
{
output
[
i
]
=
0
;
for
(
uint
16_t
j
=
0
;
j
<
row
;
j
++
)
{
output
[
i
]
+=
matrix1
[
j
]
*
matrix2
[
j
][
i
];
}
for
(
uint
j
=
0
;
j
<
row
;
j
++
)
{
output
[
i
]
+=
matrix1
[
j
]
*
matrix2
[
j
][
i
];
}
}
}
// Modified Bubble Sort.
void
nr_sort_asc_double_1D_array_ind
(
double
*
matrix
,
uint8_t
*
ind
,
uint8_t
len
)
{
int
swaps
;
double
temp
;
int
tempInd
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
swaps
=
0
;
for
(
int
j
=
0
;
j
<
(
len
-
i
)
-
1
;
j
++
)
{
if
(
matrix
[
j
]
>
matrix
[
j
+
1
])
{
temp
=
matrix
[
j
];
matrix
[
j
]
=
matrix
[
j
+
1
];
matrix
[
j
+
1
]
=
temp
;
tempInd
=
ind
[
j
];
ind
[
j
]
=
ind
[
j
+
1
];
ind
[
j
+
1
]
=
tempInd
;
swaps
++
;
}
}
if
(
swaps
==
0
)
break
;
}
}
void
nr_sort_asc_int16_1D_array_ind
(
int32_t
*
matrix
,
int
*
ind
,
int
len
)
{
int
swaps
;
int16_t
temp
;
int
tempInd
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
swaps
=
0
;
int
swaps
=
0
;
for
(
int
j
=
0
;
j
<
(
len
-
i
)
-
1
;
j
++
)
{
if
(
matrix
[
j
]
>
matrix
[
j
+
1
])
{
temp
=
matrix
[
j
];
matrix
[
j
]
=
matrix
[
j
+
1
];
matrix
[
j
+
1
]
=
temp
;
tempInd
=
ind
[
j
];
ind
[
j
]
=
ind
[
j
+
1
];
ind
[
j
+
1
]
=
tempInd
;
swaps
++
;
double
temp
=
matrix
[
j
];
matrix
[
j
]
=
matrix
[
j
+
1
];
matrix
[
j
+
1
]
=
temp
;
int
tempInd
=
ind
[
j
];
ind
[
j
]
=
ind
[
j
+
1
];
ind
[
j
+
1
]
=
tempInd
;
swaps
++
;
}
}
if
(
swaps
==
0
)
...
...
openair1/PHY/CODING/nrPolar_tools/nr_polar_procedures.c
View file @
ab2b868b
...
...
@@ -232,9 +232,12 @@ uint32_t nr_polar_output_length(uint16_t K,
n_2
=
ceil
(
log2
(
K
/
R_min
));
int
n
=
n_max
;
if
(
n
>
n_1
)
n
=
n_1
;
if
(
n
>
n_2
)
n
=
n_2
;
if
(
n
<
n_min
)
n
=
n_min
;
if
(
n
>
n_1
)
n
=
n_1
;
if
(
n
>
n_2
)
n
=
n_2
;
if
(
n
<
n_min
)
n
=
n_min
;
/*printf("nr_polar_output_length: K %d, E %d, n %d (n_max %d,n_min %d, n_1 %d,n_2 %d)\n",
K,E,n,n_max,n_min,n_1,n_2);
...
...
@@ -242,39 +245,6 @@ uint32_t nr_polar_output_length(uint16_t K,
return
((
uint32_t
)
pow
(
2
.
0
,
n
));
//=polar_code_output_length
}
void
nr_polar_channel_interleaver_pattern
(
uint16_t
*
cip
,
const
uint8_t
I_BIL
,
const
uint16_t
E
)
{
if
(
I_BIL
==
1
)
{
int
T
=
E
;
while
(
((
T
/
2
)
*
(
T
+
1
))
<
E
)
T
++
;
int16_t
v
[
T
][
T
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<=
T
-
1
;
i
++
)
{
for
(
int
j
=
0
;
j
<=
(
T
-
1
)
-
i
;
j
++
)
{
if
(
k
<
E
)
{
v
[
i
][
j
]
=
k
;
}
else
{
v
[
i
][
j
]
=
(
-
1
);
}
k
++
;
}
}
k
=
0
;
for
(
int
j
=
0
;
j
<=
T
-
1
;
j
++
)
{
for
(
int
i
=
0
;
i
<=
(
T
-
1
)
-
j
;
i
++
)
{
if
(
v
[
i
][
j
]
!=
(
-
1
)
)
{
cip
[
k
]
=
v
[
i
][
j
];
k
++
;
}
}
}
}
else
{
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
)
cip
[
i
]
=
i
;
}
}
void
nr_polar_info_bit_pattern
(
uint8_t
*
ibp
,
uint8_t
*
pcbp
,
int16_t
*
Q_I_N
,
...
...
@@ -282,43 +252,41 @@ void nr_polar_info_bit_pattern(uint8_t *ibp,
int16_t
*
Q_PC_N
,
const
uint16_t
*
J
,
const
uint16_t
*
Q_0_Nminus1
,
uint16_t
K
,
uint16_t
N
,
const
uint16_t
K
,
const
uint16_t
N
,
const
uint16_t
E
,
uint8_t
n_PC
,
uint8_t
n_pc_wm
)
const
uint8_t
n_PC
,
const
uint8_t
n_pc_wm
)
{
int
Q_Ftmp_N
[
N
+
1
];
// Last element shows the final
int
Q_Itmp_N
[
N
+
1
];
// array index assigned a value.
for
(
int
i
=
0
;
i
<=
N
;
i
++
)
{
Q_Ftmp_N
[
i
]
=
-
1
;
// Empty array.
Q_Itmp_N
[
i
]
=
-
1
;
}
int
limit
;
if
(
E
<
N
)
{
if
((
K
/
(
double
)
E
)
<=
(
7
.
0
/
16
))
{
// puncturing
for
(
int
n
=
0
;
n
<=
N
-
E
-
1
;
n
++
)
{
int
ind
=
Q_Ftmp_N
[
N
]
+
1
;
Q_Ftmp_N
[
ind
]
=
J
[
n
];
Q_Ftmp_N
[
N
]
=
Q_Ftmp_N
[
N
]
+
1
;
int
ind
=
Q_Ftmp_N
[
N
]
+
1
;
Q_Ftmp_N
[
ind
]
=
J
[
n
];
Q_Ftmp_N
[
N
]
=
Q_Ftmp_N
[
N
]
+
1
;
}
if
((
E
/
(
double
)
N
)
>=
(
3
.
0
/
4
))
{
limit
=
ceil
((
double
)(
3
*
N
-
2
*
E
)
/
4
);
int
limit
=
ceil
((
double
)(
3
*
N
-
2
*
E
)
/
4
);
for
(
int
n
=
0
;
n
<=
limit
-
1
;
n
++
)
{
int
ind
=
Q_Ftmp_N
[
N
]
+
1
;
Q_Ftmp_N
[
ind
]
=
n
;
Q_Ftmp_N
[
N
]
=
Q_Ftmp_N
[
N
]
+
1
;
int
ind
=
Q_Ftmp_N
[
N
]
+
1
;
Q_Ftmp_N
[
ind
]
=
n
;
Q_Ftmp_N
[
N
]
=
Q_Ftmp_N
[
N
]
+
1
;
}
}
else
{
limit
=
ceil
((
double
)(
9
*
N
-
4
*
E
)
/
16
);
int
limit
=
ceil
((
double
)(
9
*
N
-
4
*
E
)
/
16
);
for
(
int
n
=
0
;
n
<=
limit
-
1
;
n
++
)
{
int
ind
=
Q_Ftmp_N
[
N
]
+
1
;
Q_Ftmp_N
[
ind
]
=
n
;
Q_Ftmp_N
[
N
]
=
Q_Ftmp_N
[
N
]
+
1
;
int
ind
=
Q_Ftmp_N
[
N
]
+
1
;
Q_Ftmp_N
[
ind
]
=
n
;
Q_Ftmp_N
[
N
]
=
Q_Ftmp_N
[
N
]
+
1
;
}
}
}
else
{
// shortening
...
...
@@ -332,15 +300,15 @@ void nr_polar_info_bit_pattern(uint8_t *ibp,
// Q_I,tmp_N = Q_0_N-1 \ Q_F,tmp_N
for
(
int
n
=
0
;
n
<=
N
-
1
;
n
++
)
{
bool
flag
=
true
;
for
(
int
m
=
0
;
m
<=
Q_Ftmp_N
[
N
];
m
++
){
const
int
end
=
Q_Ftmp_N
[
N
];
int
m
;
for
(
m
=
0
;
m
<=
end
;
m
++
)
{
AssertFatal
(
m
<
N
+
1
,
"Buffer boundary overflow"
);
if
(
Q_0_Nminus1
[
n
]
==
Q_Ftmp_N
[
m
])
{
flag
=
false
;
break
;
}
}
if
(
flag
)
{
if
(
m
>
end
)
{
Q_Itmp_N
[
Q_Itmp_N
[
N
]
+
1
]
=
Q_0_Nminus1
[
n
];
Q_Itmp_N
[
N
]
++
;
}
...
...
@@ -361,14 +329,14 @@ void nr_polar_info_bit_pattern(uint8_t *ibp,
// Q_F_N = Q_0_N-1 \ Q_I_N
for
(
int
n
=
0
;
n
<=
N
-
1
;
n
++
)
{
bool
flag
=
true
;
for
(
int
m
=
0
;
m
<=
(
K
+
n_PC
)
-
1
;
m
++
)
if
(
Q_0_Nminus1
[
n
]
==
Q_I_N
[
m
])
{
flag
=
false
;
const
int
sz
=
(
K
+
n_PC
)
-
1
;
const
int
toCmp
=
Q_0_Nminus1
[
n
];
int
m
;
for
(
m
=
0
;
m
<=
sz
;
m
++
)
if
(
toCmp
==
Q_I_N
[
m
])
break
;
}
if
(
flag
)
{
Q_F_N
[
Q_F_N
[
N
]
+
1
]
=
Q_0_Nminus1
[
n
];
if
(
m
>
sz
)
{
Q_F_N
[
Q_F_N
[
N
]
+
1
]
=
toCmp
;
Q_F_N
[
N
]
++
;
}
}
...
...
@@ -462,9 +430,11 @@ void nr_polar_rate_matching(double *input,
}
}
else
{
if
(
(
K
/
(
double
)
E
)
<=
(
7
.
0
/
16
)
)
{
//puncturing
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
}
else
{
//shortening
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
INFINITY
;
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
INFINITY
;
}
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
){
...
...
openair1/PHY/CODING/nrPolar_tools/nr_polar_rate_match.c
View file @
ab2b868b
...
...
@@ -31,13 +31,13 @@ void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, const uint8_t *P
for
(
int
m
=
0
;
m
<=
N
-
1
;
m
++
)
{
i
=
floor
((
32
*
m
)
/
N
);
J
[
m
]
=
(
P_i_
[
i
]
*
(
N
/
32
))
+
(
m
%
(
N
/
32
)
);
J
[
m
]
=
P_i_
[
i
]
*
(
N
/
32
))
+
(
m
%
(
N
/
32
);
y
[
m
]
=
d
[
J
[
m
]];
}
if
(
E
>=
N
)
{
// repetition
for
(
int
k
=
0
;
k
<=
E
-
1
;
k
++
)
{
ind
=
(
k
%
N
)
;
ind
=
k
%
N
;
rmp
[
k
]
=
y
[
ind
];
}
}
else
{
...
...
@@ -55,43 +55,23 @@ void nr_polar_rate_matching_pattern(uint16_t *rmp, uint16_t *J, const uint8_t *P
void
nr_polar_rate_matching
(
double
*
input
,
double
*
output
,
uint16_t
*
rmp
,
uint16_t
K
,
uint16_t
N
,
uint16_t
E
){
if
(
E
>=
N
)
{
// repetition
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
)
{
output
[
rmp
[
i
]]
+=
input
[
i
];
}
}
else
{
if
((
K
/
(
double
)
E
)
<=
(
7
.
0
/
16
))
{
// puncturing
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
}
else
{
// shortening
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
INFINITY
;
}
if
(
E
>=
N
)
{
//repetition
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
){
output
[
rmp
[
i
]]
+=
input
[
i
];
}
}
else
{
if
(
(
K
/
(
double
)
E
)
<=
(
7
.
0
/
16
)
)
{
//puncturing
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
}
else
{
//shortening
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
INFINITY
;
}
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
){
output
[
rmp
[
i
]]
=
input
[
i
];
}
}
}
void
nr_polar_rate_matching_int8
(
int16_t
*
input
,
int16_t
*
output
,
uint16_t
*
rmp
,
uint16_t
K
,
uint16_t
N
,
uint16_t
E
){
if
(
E
>=
N
)
{
//repetition
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
){
output
[
rmp
[
i
]]
+=
input
[
i
];
}
}
else
{
if
(
(
K
/
(
double
)
E
)
<=
(
7
.
0
/
16
)
)
{
//puncturing
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
0
;
}
else
{
//shortening
for
(
int
i
=
0
;
i
<=
N
-
1
;
i
++
)
output
[
i
]
=
INFINITY
;
}
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
){
output
[
rmp
[
i
]]
=
input
[
i
];
}
}
for
(
int
i
=
0
;
i
<=
E
-
1
;
i
++
)
{
output
[
rmp
[
i
]]
=
input
[
i
];
}
}
}
openair1/PHY/CODING/nr_polar_init.c
View file @
ab2b868b
...
...
@@ -50,30 +50,17 @@ static void nr_polar_delete_list(t_nrPolar_params * polarParams) {
delete_decoder_tree
(
polarParams
);
// From build_polar_tables()
free
(
polarParams
->
G_N_tab
);
free
(
polarParams
->
rm_tab
);
if
(
polarParams
->
crc_generator_matrix
)
free
(
polarParams
->
crc_generator_matrix
);
//polar_encoder vectors:
free
(
polarParams
->
nr_polar_crc
);
free
(
polarParams
->
nr_polar_aPrime
);
free
(
polarParams
->
nr_polar_APrime
);
free
(
polarParams
->
nr_polar_D
);
free
(
polarParams
->
nr_polar_E
);
//Polar Coding vectors
free
(
polarParams
->
nr_polar_U
);
free
(
polarParams
->
nr_polar_CPrime
);
free
(
polarParams
->
nr_polar_B
);
free
(
polarParams
->
nr_polar_A
);
// Polar Coding vectors
free
(
polarParams
->
interleaving_pattern
);
free
(
polarParams
->
deinterleaving_pattern
);
free
(
polarParams
->
rate_matching_pattern
);
free
(
polarParams
->
information_bit_pattern
);
free
(
polarParams
->
parity_check_bit_pattern
);
free
(
polarParams
->
Q_I_N
);
free
(
polarParams
->
Q_F_N
);
free
(
polarParams
->
Q_PC_N
);
free
(
polarParams
->
channel_interleaver_pattern
);
free
(
polarParams
);
}
...
...
@@ -113,11 +100,12 @@ t_nrPolar_params *nr_polar_params(int8_t messageType, uint16_t messageLength, ui
t_nrPolar_params
*
newPolarInitNode
=
calloc
(
sizeof
(
t_nrPolar_params
),
1
);
AssertFatal
(
newPolarInitNode
,
"[nr_polar_init] New t_nrPolar_params * could not be created"
);
newPolarInitNode
->
busy
=
true
;
newPolarInitNode
->
nextPtr
=
NULL
;
newPolarInitNode
->
nextPtr
=
PolarList
;
PolarList
=
newPolarInitNode
;
pthread_mutex_unlock
(
&
PolarListMutex
);
// LOG_D(PHY,"Setting new polarParams index %d, messageType %d, messageLength %d, aggregation_prime %d\n",(messageType * messageLength * aggregation_prime),messageType,messageLength,aggregation_prime);
newPolarInitNode
->
idx
=
PolarKey
;
newPolarInitNode
->
nextPtr
=
NULL
;
//printf("newPolarInitNode->idx %d, (%d,%d,%d:%d)\n",newPolarInitNode->idx,messageType,messageLength,aggregation_prime,aggregation_level);
if
(
messageType
==
NR_POLAR_PBCH_MESSAGE_TYPE
)
{
...
...
@@ -217,26 +205,12 @@ t_nrPolar_params *nr_polar_params(int8_t messageType, uint16_t messageLength, ui
newPolarInitNode
->
n_max
);
newPolarInitNode
->
n
=
log2
(
newPolarInitNode
->
N
);
newPolarInitNode
->
G_N
=
nr_polar_kronecker_power_matrices
(
newPolarInitNode
->
n
);
//polar_encoder vectors:
newPolarInitNode
->
nr_polar_crc
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
crcParityBits
);
newPolarInitNode
->
nr_polar_aPrime
=
malloc
(
sizeof
(
uint8_t
)
*
((
ceil
((
newPolarInitNode
->
payloadBits
)
/
32
.
0
)
*
4
)
+
3
));
newPolarInitNode
->
nr_polar_APrime
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
K
);
newPolarInitNode
->
nr_polar_D
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
N
);
newPolarInitNode
->
nr_polar_E
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
encoderLength
);
//Polar Coding vectors
newPolarInitNode
->
nr_polar_U
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
N
);
//Decoder: nr_polar_uHat
newPolarInitNode
->
nr_polar_CPrime
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
K
);
//Decoder: nr_polar_cHat
newPolarInitNode
->
nr_polar_B
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
K
);
//Decoder: nr_polar_bHat
newPolarInitNode
->
nr_polar_A
=
malloc
(
sizeof
(
uint8_t
)
*
newPolarInitNode
->
payloadBits
);
//Decoder: nr_polar_aHat
// polar_encoder vectors:
newPolarInitNode
->
Q_0_Nminus1
=
nr_polar_sequence_pattern
(
newPolarInitNode
->
n
);
newPolarInitNode
->
interleaving_pattern
=
malloc
(
sizeof
(
uint16_t
)
*
newPolarInitNode
->
K
);
nr_polar_interleaving_pattern
(
newPolarInitNode
->
K
,
newPolarInitNode
->
i_il
,
newPolarInitNode
->
interleaving_pattern
);
newPolarInitNode
->
deinterleaving_pattern
=
malloc
(
sizeof
(
uint16_t
)
*
newPolarInitNode
->
K
);
for
(
int
i
=
0
;
i
<
newPolarInitNode
->
K
;
i
++
)
newPolarInitNode
->
deinterleaving_pattern
[
newPolarInitNode
->
interleaving_pattern
[
i
]]
=
i
;
newPolarInitNode
->
rate_matching_pattern
=
malloc
(
sizeof
(
uint16_t
)
*
newPolarInitNode
->
encoderLength
);
uint16_t
J
[
newPolarInitNode
->
N
];
...
...
@@ -270,18 +244,12 @@ t_nrPolar_params *nr_polar_params(int8_t messageType, uint16_t messageLength, ui
// sort the Q_I_N array in ascending order (first K positions)
qsort
((
void
*
)
newPolarInitNode
->
Q_I_N
,
newPolarInitNode
->
K
,
sizeof
(
int16_t
),
intcmp
);
newPolarInitNode
->
channel_interleaver_pattern
=
malloc
(
sizeof
(
uint16_t
)
*
newPolarInitNode
->
encoderLength
);
nr_polar_channel_interleaver_pattern
(
newPolarInitNode
->
channel_interleaver_pattern
,
newPolarInitNode
->
i_bil
,
newPolarInitNode
->
encoderLength
);
if
(
decoder_flag
==
1
)
build_decoder_tree
(
newPolarInitNode
);
build_polar_tables
(
newPolarInitNode
);
init_polar_deinterleaver_table
(
newPolarInitNode
);
//printf("decoder tree nodes %d\n",newPolarInitNode->tree.num_nodes);
newPolarInitNode
->
nextPtr
=
PolarList
;
PolarList
=
newPolarInitNode
;
init_polar_deinterleaver_table
(
newPolarInitNode
);
return
newPolarInitNode
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment