├── .gitignore ├── .gitlab-ci.yml ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── ci ├── analysis-cppcheck.sh ├── build-linux-macos.sh ├── build-windows-gcc.bat ├── build-windows-msvc.bat └── tools │ ├── aff3ct-git-version.bat │ ├── aff3ct-git-version.sh │ ├── threads.bat │ └── threads.sh ├── img ├── polar_tree_(128,64)_(2.5dB)_(r0,r1,rep,spc).svg └── polar_tree_(8,4)_(2.5dB)_(rep,spc).svg ├── scripts ├── convert_dot_to_pdf.sh ├── generate_polar_gpp_decoders.sh └── generate_polar_tta_decoders.sh ├── src ├── Generator │ ├── Generator.hpp │ └── Polar │ │ ├── GPP │ │ ├── Generator_polar_GPP.cpp │ │ ├── Generator_polar_GPP.hpp │ │ ├── SC │ │ │ ├── Generator_polar_GPP_SC_sys.cpp │ │ │ └── Generator_polar_GPP_SC_sys.hpp │ │ └── SCL │ │ │ ├── Generator_polar_GPP_SCL_sys.cpp │ │ │ └── Generator_polar_GPP_SCL_sys.hpp │ │ ├── Generator_polar.cpp │ │ ├── Generator_polar.hpp │ │ └── TTA │ │ ├── Generator_polar_TTA.cpp │ │ ├── Generator_polar_TTA.hpp │ │ ├── SC │ │ ├── Generator_polar_TTA_SC_sys.cpp │ │ └── Generator_polar_TTA_SC_sys.hpp │ │ └── SCAN │ │ ├── Generator_polar_TTA_SCAN_sys.cpp │ │ └── Generator_polar_TTA_SCAN_sys.hpp ├── Tools │ └── Code │ │ └── Polar │ │ └── Patterns │ │ ├── GPP │ │ ├── SC │ │ │ ├── Pattern_polar_SC_r0.hpp │ │ │ ├── Pattern_polar_SC_r0_left.hpp │ │ │ ├── Pattern_polar_SC_r1.hpp │ │ │ ├── Pattern_polar_SC_rep.hpp │ │ │ ├── Pattern_polar_SC_rep_left.hpp │ │ │ ├── Pattern_polar_SC_spc.hpp │ │ │ └── Pattern_polar_SC_std.hpp │ │ └── SCL │ │ │ ├── Pattern_polar_SCL_r0.hpp │ │ │ ├── Pattern_polar_SCL_r0_left.hpp │ │ │ ├── Pattern_polar_SCL_r1.hpp │ │ │ ├── Pattern_polar_SCL_rep.hpp │ │ │ ├── Pattern_polar_SCL_rep_left.hpp │ │ │ ├── Pattern_polar_SCL_spc.hpp │ │ │ └── Pattern_polar_SCL_std.hpp │ │ └── TTA │ │ ├── Pattern_polar_tile.hpp │ │ ├── Pattern_polar_tile_scan.hpp │ │ ├── SC │ │ ├── Pattern_polar_TTA_SC_r0.hpp │ │ ├── Pattern_polar_TTA_SC_r0_left.hpp │ │ ├── Pattern_polar_TTA_SC_r1.hpp │ │ ├── Pattern_polar_TTA_SC_rep.hpp │ │ ├── Pattern_polar_TTA_SC_rep_left.hpp │ │ ├── Pattern_polar_TTA_SC_spc.hpp │ │ └── Pattern_polar_TTA_SC_std.hpp │ │ └── SCAN │ │ ├── Pattern_polar_TTA_SCAN_r0.hpp │ │ ├── Pattern_polar_TTA_SCAN_r0_left.hpp │ │ ├── Pattern_polar_TTA_SCAN_r1.hpp │ │ ├── Pattern_polar_TTA_SCAN_rep.hpp │ │ ├── Pattern_polar_TTA_SCAN_rep_left.hpp │ │ ├── Pattern_polar_TTA_SCAN_spc.hpp │ │ └── Pattern_polar_TTA_SCAN_std.hpp └── main.cpp └── tests ├── refs.zip └── run_tests.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | build*/ 3 | tests/refs/* 4 | cmake*/ -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | variables: 2 | GIT_SUBMODULE_STRATEGY: recursive 3 | 4 | stages: 5 | - analysis 6 | - build 7 | - test 8 | 9 | before_script: 10 | - hostname 11 | - whoami 12 | 13 | analysis-cppcheck: 14 | stage: analysis 15 | variables: 16 | GIT_SUBMODULE_STRATEGY: none 17 | artifacts: 18 | name: analysis-cppcheck-logs 19 | when: always 20 | paths: 21 | - cppcheck/ 22 | tags: 23 | - cppcheck 24 | script: 25 | - ./ci/analysis-cppcheck.sh 26 | 27 | build-linux-gcc: 28 | stage: build 29 | tags: 30 | - linux 31 | - gcc 32 | - cmake 33 | - x86 34 | dependencies: [] 35 | artifacts: 36 | name: build-linux-gcc 37 | when: always 38 | paths: 39 | - ./build_linux_gcc/ 40 | script: 41 | - export CXX="g++" 42 | - export CFLAGS="-Wall -funroll-loops -msse4.2" 43 | - export BUILD="build_linux_gcc" 44 | - source ./ci/tools/threads.sh 45 | - source ./ci/tools/aff3ct-git-version.sh 46 | - ./ci/build-linux-macos.sh 47 | 48 | build-linux-clang: 49 | stage: build 50 | tags: 51 | - linux 52 | - clang 53 | - cmake 54 | - x86 55 | dependencies: [] 56 | artifacts: 57 | name: build-linux-clang 58 | when: always 59 | paths: 60 | - ./build_linux_clang/ 61 | script: 62 | - export CXX="clang++" 63 | - export CFLAGS="-Wall -Wno-overloaded-virtual -funroll-loops -msse4.2" 64 | - export BUILD="build_linux_clang" 65 | - source ./ci/tools/threads.sh 66 | - source ./ci/tools/aff3ct-git-version.sh 67 | - ./ci/build-linux-macos.sh 68 | 69 | build-linux-gcc-4.8: 70 | stage: build 71 | tags: 72 | - linux 73 | - gcc-4.8 74 | - cmake 75 | dependencies: [] 76 | artifacts: 77 | name: build-linux-gcc-4.8 78 | when: always 79 | paths: 80 | - ./build_linux_gcc-4.8/ 81 | script: 82 | - export CXX="g++-4.8" 83 | - export CFLAGS="-Wall -funroll-loops -msse4.2" 84 | - export BUILD="build_linux_gcc-4.8" 85 | - source ./ci/tools/threads.sh 86 | - source ./ci/tools/aff3ct-git-version.sh 87 | - ./ci/build-linux-macos.sh 88 | 89 | build-linux-icpc: 90 | stage: build 91 | tags: 92 | - linux 93 | - icpc 94 | - cmake 95 | - x86 96 | dependencies: [] 97 | artifacts: 98 | name: build-linux-icpc 99 | when: always 100 | paths: 101 | - ./build_linux_icpc/ 102 | script: 103 | - export CXX="icpc" 104 | - export CFLAGS="-Wall -funroll-loops -msse4.2 -std=c++11" 105 | - export BUILD="build_linux_icpc" 106 | - source ./ci/tools/threads.sh 107 | - source ./ci/tools/aff3ct-git-version.sh 108 | - ./ci/build-linux-macos.sh 109 | 110 | build-windows-gcc: 111 | stage: build 112 | tags: 113 | - windows 114 | - gcc 115 | - cmake 116 | dependencies: [] 117 | artifacts: 118 | name: build-windows-gcc 119 | when: always 120 | paths: 121 | - ./build_windows_gcc/ 122 | script: 123 | - set "CFLAGS=-Wall -funroll-loops -mavx" 124 | - set "BUILD=build_windows_gcc" 125 | - call ./ci/tools/threads.bat 126 | - call ./ci/tools/aff3ct-git-version.bat 127 | - ./ci/build-windows-gcc.bat 128 | 129 | build-windows-msvc: 130 | stage: build 131 | tags: 132 | - windows 133 | - msvc 134 | - cmake 135 | dependencies: [] 136 | artifacts: 137 | name: build-windows-msvc 138 | when: always 139 | paths: 140 | - ./build_windows_msvc/ 141 | script: 142 | - set "CFLAGS=-D_CRT_SECURE_NO_DEPRECATE /EHsc /arch:AVX" 143 | - set "BUILD=build_windows_msvc" 144 | - call ./ci/tools/threads.bat 145 | - call ./ci/tools/aff3ct-git-version.bat 146 | - ./ci/build-windows-msvc.bat 147 | 148 | build-macos-clang: 149 | stage: build 150 | tags: 151 | - macos 152 | - apple-clang 153 | - cmake 154 | - x86 155 | dependencies: [] 156 | artifacts: 157 | name: build-macos-clang 158 | when: always 159 | paths: 160 | - ./build_macos_clang/ 161 | script: 162 | - export CXX="clang++" 163 | - export CFLAGS="-Wall -Wno-overloaded-virtual -funroll-loops -msse4.2" 164 | - export BUILD="build_macos_clang" 165 | - source ./ci/tools/threads.sh 166 | - source ./ci/tools/aff3ct-git-version.sh 167 | - ./ci/build-linux-macos.sh 168 | 169 | test-linux-gcc: 170 | stage: test 171 | tags: 172 | - linux 173 | - x86 174 | dependencies: 175 | - build-linux-gcc 176 | script: 177 | - mv build_linux_gcc build 178 | - ./tests/run_tests.sh -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/aff3ct"] 2 | path = lib/aff3ct 3 | url = ../aff3ct 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | cmake_policy(SET CMP0054 NEW) 3 | 4 | project (polar_decoder_gen) 5 | 6 | # Enable C++11 7 | set(CMAKE_CXX_STANDARD 11) 8 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 9 | 10 | # Specify bin path 11 | set (EXECUTABLE_OUTPUT_PATH bin/) 12 | 13 | # Generate the source files list 14 | file (GLOB_RECURSE source_files src/*) 15 | 16 | # Create the executable from sources 17 | add_executable(polar_decoder_gen ${source_files}) 18 | 19 | # Link with the "Threads library (required to link with AFF3CT after) 20 | set(CMAKE_THREAD_PREFER_PTHREAD ON) 21 | set(THREADS_PREFER_PTHREAD_FLAG ON) 22 | find_package(Threads REQUIRED) 23 | 24 | # Link with AFF3CT 25 | set (AFF3CT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") 26 | find_package(AFF3CT CONFIG 2.3.1 REQUIRED) 27 | target_link_libraries(polar_decoder_gen PRIVATE aff3ct::aff3ct-static-lib) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2019 polar_decoder_gen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Decoders generation for Polar codes 2 | 3 | [![pipeline status](https://gitlab.com/aff3ct/polar_decoder_gen/badges/master/pipeline.svg)](https://gitlab.com/aff3ct/polar_decoder_gen/pipelines) 4 | 5 | This project is made to generate **channel coding Polar decoders** (unrolled 6 | decoders): **Successive Cancellation** (SC) and **CRC Aided Successive 7 | Cancellation List** (CA-SCL) algorithms are supported. Given a specific codeword 8 | size and Signal Noise Ratio (Eb/N0) the tree structure of the Polar codes gives 9 | the opportunity to completely replace the recursive function calls by a flat and 10 | **fully unrolled source code**. 11 | 12 | The code is able to **match some simplifications in the Polar trees to reduce 13 | the decoders latency** like ``Rate 0``, ``Rate 1``, ``Repetition`` (rep) and 14 | ``Single Parity Check`` (spc) nodes. It is possible to select which tree cuts to 15 | enable/disable from the command line and see the impact on the generated source 16 | code. For large codewords the size of the generated source code can exceed the 17 | size of the instruction cache of the CPU, this lead to reduced performances. In 18 | this project **a compression algorithm is implemented** to push the codeword 19 | size limit and keep best possible performance. 20 | 21 | Additionally, the code generates ``.dot`` files compatible with 22 | [Graphviz](https://www.graphviz.org/) to visualize the Polar tree with the 23 | simplifications used to generate the source code of the decoder. The following 24 | figure is an example of a generated Polar tree with *N = 128*, *K = 64*, 25 | *Eb/N0 = 2.5 dB* and with ``Rate 0``, ``Rate 1``, ``Repetition`` and ``Single 26 | Parity Check`` tree cut simplifications: 27 | 28 | ![Polar tree](img/polar_tree_(128,64)_(2.5dB)_(r0,r1,rep,spc).svg) 29 | 30 | # Scientific publications 31 | 32 | This code has been used to generate both software and hardware implementations 33 | in the following publications: 34 | 35 | Mathieu Léonardon, Camille Leroux, Pekka Jääskeläinen, Christophe Jégo and Yvon Savaria, 36 | [**Transport Triggered Polar Decoders**](https://doi.org/10.1109/ISTC.2018.8625310), 37 | *The 10th International Symposium on Turbo Codes & Iterative Information Processing (ISTC 2018), December 2018.* 38 | 39 | 40 | Adrien Cassagne, Olivier Aumage, Camille Leroux, Denis Barthou and Bertrand Le Gal, 41 | [**Energy Consumption Analysis of Software Polar Decoders on Low Power Processors**](https://doi.org/10.1109/EUSIPCO.2016.7760327), 42 | *The 24nd European Signal Processing Conference (EUSIPCO 2016), September 2016.* 43 | 44 | 45 | Adrien Cassagne, Bertrand Le Gal, Camille Leroux, Olivier Aumage and Denis Barthou, 46 | [**An Efficient, Portable and Generic Library for Successive Cancellation Decoding of Polar Codes**](https://doi.org/10.1007/978-3-319-29778-1_19), 47 | *The 28th International Workshop on Languages and Compilers for Parallel Computing (LCPC 2015), September 2015.* 48 | 49 | # How to compile this project 50 | 51 | Get the [AFF3CT](https://github.com/aff3ct/aff3ct) library: 52 | 53 | $ git submodule update --init --recursive 54 | 55 | Compile the [AFF3CT](https://github.com/aff3ct/aff3ct) library on Linux/MacOS/MinGW: 56 | 57 | $ cd lib/aff3ct 58 | $ mkdir build 59 | $ cd build 60 | $ cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-funroll-loops -march=native" -DAFF3CT_COMPILE_EXE="OFF" -DAFF3CT_COMPILE_STATIC_LIB="ON" -DAFF3CT_EXT_STRINGS="OFF" -DCMAKE_INSTALL_PREFIX="install" 61 | $ make -j4 62 | $ make install 63 | $ cd ../../../ 64 | 65 | Compile this project: 66 | 67 | $ mkdir cmake && mkdir cmake/Modules 68 | $ cp lib/aff3ct/build/install/lib/cmake/aff3ct-*/* cmake/Modules 69 | $ mkdir build 70 | $ cd build 71 | $ cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-funroll-loops -march=native" 72 | $ make -j4 73 | 74 | The source code of this project is in the `src/` directory. 75 | The compiled binary is in `build/bin/polar_decoder_gen`. 76 | 77 | # Run example 78 | 79 | Generates an Polar SC decoder with a *N = 8*, *K = 4* and optimized for a *Eb/N0 = 2.5 dB*: 80 | 81 | $ ./bin/polar_decoder_gen --dec-type SC -N 8 -K 4 --fbg-noise 2.5 82 | 83 | Expected outpout: 84 | 85 | # ------------------------------------------------- 86 | # ---- POLAR DECODER GENERATOR (with AFF3CT) ---- 87 | # ------------------------------------------------- 88 | # Parameters : 89 | # * Frozen bits generator ------------------------- 90 | # ** Fb gen. method = GA 91 | # ** Fb info. bits (K) = 4 92 | # ** Fb codeword size (N) = 8 93 | # ** Fb sigma = 0.749894 94 | # * Decoder Polar --------------------------------- 95 | # ** Type (D) = SC 96 | # ** Implementation = FAST 97 | # ** Info. bits (K) = 4 98 | # ** Codeword size (N) = 8 99 | # ** Code rate (R) = 0.500000 100 | # ** Systematic = yes 101 | # ** Inter frame level = 1 102 | # ** Polar node types = {R0,R0L,R1,REP,REPL,SPC} 103 | # ** Base path = . 104 | # 105 | General statistics: 106 | ------------------- 107 | Generated decoder file name = ./Decoder_polar_SC_fast_sys_N8_K4_SNR25.hpp 108 | Associate graph file name = ./Decoder_polar_SC_fast_sys_N8_K4_SNR25.dot 109 | Nodes number before pruning = 7 110 | Nodes number after pruning = 3 111 | Terminal nodes (alias pruning rules): 112 | - Rate 0: 0 / 3 113 | - Rate 1: 0 / 3 114 | - Rep: 1 / 3 115 | - SPC: 1 / 3 116 | Non-terminal nodes (alias specialization rules): 117 | - Default: 0 / 3 118 | - Rate 0 left: 0 / 3 119 | - Rep left: 1 / 3 120 | 121 | Per layer (graph depth) statistics: 122 | ----------------------------------- 123 | * Graph depth = 0 124 | Sub-code length = 8 125 | Nodes number before pruning = 1 126 | Nodes number after pruning = 1 127 | Terminal nodes (alias pruning rules) 128 | - Rate 0: 0 / 1 129 | - Rate 1: 0 / 1 130 | - Rep: 0 / 1 131 | - SPC: 0 / 1 132 | Non-terminal nodes (alias specialization rules): 133 | - Default: 0 / 1 134 | - Rate 0 left: 0 / 1 135 | - Rep left: 1 / 1 136 | 137 | * Graph depth = 1 138 | Sub-code length = 4 139 | Nodes number before pruning = 2 140 | Nodes number after pruning = 2 141 | Terminal nodes (alias pruning rules) 142 | - Rate 0: 0 / 2 143 | - Rate 1: 0 / 2 144 | - Rep: 1 / 2 145 | - SPC: 1 / 2 146 | Non-terminal nodes (alias specialization rules): 147 | - Default: 0 / 2 148 | - Rate 0 left: 0 / 2 149 | - Rep left: 0 / 2 150 | 151 | * Graph depth = 2 152 | Sub-code length = 2 153 | Nodes number before pruning = 4 154 | Nodes number after pruning = 0 155 | Terminal nodes (alias pruning rules) 156 | - Rate 0: 0 / 0 157 | - Rate 1: 0 / 0 158 | - Rep: 0 / 0 159 | - SPC: 0 / 0 160 | Non-terminal nodes (alias specialization rules): 161 | - Default: 0 / 0 162 | - Rate 0 left: 0 / 0 163 | - Rep left: 0 / 0 164 | 165 | * Graph depth = 3 166 | Sub-code length = 1 167 | Nodes number before pruning = 8 168 | Nodes number after pruning = 0 169 | Terminal nodes (alias pruning rules) 170 | - Rate 0: 0 / 0 171 | - Rate 1: 0 / 0 172 | - Rep: 0 / 0 173 | - SPC: 0 / 0 174 | Non-terminal nodes (alias specialization rules): 175 | - Default: 0 / 0 176 | - Rate 0 left: 0 / 0 177 | - Rep left: 0 / 0 178 | # 179 | 180 | # Generated Source Code 181 | 182 | The previous command line generates the following Polar tree: 183 | 184 | ![Polar tree](img/polar_tree_(8,4)_(2.5dB)_(rep,spc).svg) 185 | 186 | And the associated source code is: 187 | 188 | ```cpp 189 | // ... 190 | static const std::vector Decoder_polar_SC_fast_sys_fb_8_4_25 = { 191 | 1, 1, 1, 0, 1, 0, 0, 0}; 192 | 193 | template 194 | class Decoder_polar_SC_fast_sys_N8_K4_SNR25 : public Decoder_polar_SC_fast_sys 195 | { 196 | public: 197 | // ... 198 | void _decode() 199 | { 200 | // ... 201 | API_polar::template f <4>( l, 0+ 0, 0+ 4, 0+ 8, 4); 202 | API_polar::template rep<4>(s, l, 8+ 0, 0+ 0, 4); 203 | API_polar::template gr <4>(s, l, 0+ 0, 0+ 4, 0+ 0, 0+ 8, 4); 204 | API_polar::template spc<4>(s, l, 8+ 0, 4+ 0, 4); 205 | API_polar::template xo <4>(s, 0+ 0, 0+ 4, 0+ 0, 4); 206 | } 207 | }; 208 | // ... 209 | ``` 210 | 211 | This is an header only class compatible with the 212 | [AFF3CT](https://github.com/aff3ct/aff3ct) simulator. The frozen bits are 213 | statically declared in the ``Decoder_polar_SC_fast_sys_fb_8_4_25`` vector 214 | and the generated code is in the ``_decode()`` method. ``l`` is the vector of 215 | LLRs from the channel and ``s`` is the partial sums vector. The generated source 216 | code looks like a dedicated Polar decoder instruction set. For instance 217 | ``API_polar::template f<4>(l, 0+0, 0+4, 0+8, 4);`` means that a ``f`` 218 | function is performed four times (``<4>`` from the template parameter and 219 | ``4`` from the last method parameter). The ``f`` function is working on the LLRs 220 | (first ``l`` argument in the method). The second method parameter (``0+0``) 221 | specifies the memory location of the left operands for the ``f`` function, the 222 | third method parameter (``0+4``) specifies the memory location of the right 223 | operands for the ``f`` function and the fourth parameter (``0+8``) specifies 224 | where the results on the ``f`` functions will be stored. The same philosophy is 225 | used for the next Polar decoder instructions. 226 | -------------------------------------------------------------------------------- /ci/analysis-cppcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | 4 | cppcheck --version 5 | 6 | mkdir cppcheck 7 | #cppcheck --suppress=missingIncludeSystem -I./src/ --force --enable=all --std=c++11 -U_MSC_VER ./src/ 2> cppcheck_all.log 8 | find .\/src\/ -type f -follow -print | grep "[.]h$\|[.]hpp$\|[.]hxx$\|[.]cpp$" > src_files.txt 9 | cppcheck --language=c++ --suppress=missingIncludeSystem --force --enable=all --std=c++11 -U_MSC_VER --file-list=src_files.txt 2> cppcheck/cppcheck_all.log 10 | cat cppcheck/cppcheck_all.log | grep "(error)" > cppcheck/cppcheck_error.log 11 | cat cppcheck/cppcheck_all.log | grep "(warning)" > cppcheck/cppcheck_warning.log 12 | cat cppcheck/cppcheck_all.log | grep "(performance)" > cppcheck/cppcheck_performance.log 13 | cat cppcheck/cppcheck_all.log | grep "(style)" > cppcheck/cppcheck_style.log 14 | cat cppcheck/cppcheck_all.log | grep "(portability)" > cppcheck/cppcheck_portability.log 15 | cat cppcheck/cppcheck_all.log | grep "(information)" > cppcheck/cppcheck_information.log 16 | cat cppcheck/cppcheck_all.log | grep "(unusedFunction)" > cppcheck/cppcheck_unusedFunction.log 17 | cat cppcheck/cppcheck_all.log | grep "(missingInclude)" > cppcheck/cppcheck_missingInclude.log 18 | 19 | COUNT=$(wc -l < cppcheck/cppcheck_error.log ) 20 | 21 | if [ $COUNT -gt 0 ]; then 22 | echo "Error count is $COUNT! cppcheck run failed :-(."; 23 | echo "" 24 | echo "Errors list:" 25 | cat cppcheck/cppcheck_error.log 26 | exit 1; 27 | else 28 | echo "There is no error :-)." 29 | fi 30 | 31 | exit 0; 32 | -------------------------------------------------------------------------------- /ci/build-linux-macos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | 4 | if [ -z "$CXX" ] 5 | then 6 | echo "Please define the 'CXX' environment variable." 7 | exit 1 8 | fi 9 | 10 | if [ -z "$AFF3CT_GIT_VERSION" ] 11 | then 12 | echo "Please define the 'AFF3CT_GIT_VERSION' environment variable." 13 | exit 1 14 | fi 15 | 16 | if [ -z "$BUILD" ] 17 | then 18 | echo "The 'BUILD' environment variable is not set, default value = 'build_linux_macos'." 19 | BUILD="build_linux_macos" 20 | fi 21 | 22 | if [ -z "$THREADS" ] 23 | then 24 | echo "The 'THREADS' environment variable is not set, default value = 1." 25 | THREADS=1 26 | fi 27 | 28 | if [[ $CXX == icpc ]]; then 29 | source /opt/intel/vars-intel.sh 30 | fi 31 | 32 | # Compile the AFF3CT library 33 | cd lib/aff3ct 34 | mkdir $BUILD 35 | cd $BUILD 36 | cmake .. -G"Unix Makefiles" -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$CFLAGS" -DAFF3CT_COMPILE_EXE="OFF" -DAFF3CT_COMPILE_STATIC_LIB="ON" 37 | rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi 38 | make -j $THREADS 39 | rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi 40 | # make install > /dev/null 41 | # rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi 42 | cd ../../../ 43 | 44 | mkdir cmake && mkdir cmake/Modules 45 | cp lib/aff3ct/${BUILD}/lib/cmake/aff3ct-$AFF3CT_GIT_VERSION/* cmake/Modules 46 | 47 | mkdir $BUILD 48 | cd $BUILD 49 | cmake .. -G"Unix Makefiles" -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="$CFLAGS" 50 | rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi 51 | make -j $THREADS 52 | rc=$?; if [[ $rc != 0 ]]; then exit $rc; fi 53 | -------------------------------------------------------------------------------- /ci/build-windows-gcc.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | 3 | rem Compile the AFF3CT library 4 | cd lib\aff3ct 5 | mkdir %BUILD% 6 | cd %BUILD% 7 | cmake .. -G"MinGW Makefiles" -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="%CFLAGS%" -DAFF3CT_COMPILE_EXE="OFF" -DAFF3CT_COMPILE_STATIC_LIB="ON" 8 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 9 | mingw32-make -j %THREADS% 10 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 11 | rem mingw32-make install > nul 12 | rem if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 13 | cd ../../../ 14 | 15 | mkdir cmake && mkdir cmake/Modules 16 | xcopy lib\aff3ct\%BUILD%\lib\cmake\aff3ct-%AFF3CT_GIT_VERSION%\* cmake\Modules\ /s /e 17 | 18 | mkdir %BUILD% 19 | cd %BUILD% 20 | cmake .. -G"MinGW Makefiles" -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="%CFLAGS%" 21 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 22 | mingw32-make -j %THREADS% 23 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 24 | exit /B 0 25 | -------------------------------------------------------------------------------- /ci/build-windows-msvc.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | 3 | set "VSCMD_START_DIR=%CD%" 4 | call "%VS_PATH%\VC\Auxiliary\Build\vcvars64.bat" 5 | 6 | rem Compile the AFF3CT library 7 | cd lib\aff3ct 8 | mkdir %BUILD% 9 | cd %BUILD% 10 | cmake .. -G"Visual Studio 15 2017 Win64" -DCMAKE_CXX_FLAGS="%CFLAGS% /MP%THREADS%" -DAFF3CT_COMPILE_EXE="OFF" -DAFF3CT_COMPILE_STATIC_LIB="ON" 11 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 12 | devenv /build Release aff3ct.sln 13 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 14 | rem devenv /build Release aff3ct.sln /project INSTALL > nul 15 | rem if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 16 | cd ../../../ 17 | 18 | mkdir cmake && mkdir cmake/Modules 19 | xcopy lib\aff3ct\%BUILD%\lib\cmake\aff3ct-%AFF3CT_GIT_VERSION%\* cmake\Modules\ /s /e 20 | 21 | mkdir %BUILD% 22 | cd %BUILD% 23 | cmake .. -G"Visual Studio 15 2017 Win64" -DCMAKE_CXX_FLAGS="%CFLAGS% /MP%THREADS%" 24 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 25 | devenv /build Release polar_decoder_gen.sln 26 | if %ERRORLEVEL% neq 0 exit %ERRORLEVEL% 27 | exit /B 0 28 | -------------------------------------------------------------------------------- /ci/tools/aff3ct-git-version.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | cd lib/aff3ct/ 4 | 5 | for /F "tokens=* USEBACKQ" %%F in (`git describe "--abbrev=7"`) do ( 6 | set "AFF3CT_GIT_VERSION=%%F" 7 | ) 8 | set AFF3CT_GIT_VERSION=%AFF3CT_GIT_VERSION:~1% 9 | 10 | cd ../../ 11 | 12 | :End -------------------------------------------------------------------------------- /ci/tools/aff3ct-git-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # set -x 3 | 4 | cd lib/aff3ct/ 5 | 6 | AFF3CT_GIT_VERSION=$(git describe --abbrev=7) 7 | 8 | if [ ! -z "$AFF3CT_GIT_VERSION" ] 9 | then 10 | AFF3CT_GIT_VERSION=$(echo $AFF3CT_GIT_VERSION | cut -d $'v' -f2-) 11 | export AFF3CT_GIT_VERSION 12 | fi 13 | 14 | cd ../../ -------------------------------------------------------------------------------- /ci/tools/threads.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | IF "%THREADS%" NEQ "" goto End 4 | set "THREADS=%NUMBER_OF_PROCESSORS%" 5 | IF "%THREADS%"=="" set "THREADS=1" 6 | 7 | :End -------------------------------------------------------------------------------- /ci/tools/threads.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # set -x 3 | 4 | if [ -z "$THREADS" ]; then 5 | if [ ! -f /proc/cpuinfo ]; then 6 | export THREADS=1 7 | else 8 | THREADS=$(grep -c ^processor /proc/cpuinfo) 9 | export THREADS 10 | fi 11 | fi 12 | -------------------------------------------------------------------------------- /scripts/convert_dot_to_pdf.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | ROOT=src_generated 4 | if [ "$#" -gt "0" ]; 5 | then 6 | ROOT=$1 7 | fi 8 | 9 | # Make sure to have Graphviz installed (http://www.graphviz.org/) 10 | 11 | echo "Generates SC graphs (from *.dot to *.dot.pdf, rate 1/2)..." 12 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K2_SNR25.dot -O 13 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K2_SNR25.dot -O 14 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8_K4_SNR25.dot -O 15 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16_K8_SNR25.dot -O 16 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32_K16_SNR25.dot -O 17 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N64_K32_SNR25.dot -O 18 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N128_K64_SNR25.dot -O 19 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N256_K128_SNR25.dot -O 20 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N512_K256_SNR25.dot -O 21 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1024_K512_SNR25.dot -O 22 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1024_SNR25.dot -O 23 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K2048_SNR25.dot -O 24 | 25 | echo "Generates SC graphs (from *.dot to *.dot.pdf, rate 5/6)..." 26 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K3_SNR40.dot -O 27 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8_K7_SNR40.dot -O 28 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16_K13_SNR40.dot -O 29 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32_K27_SNR40.dot -O 30 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N64_K53_SNR40.dot -O 31 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N128_K107_SNR40.dot -O 32 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N256_K213_SNR40.dot -O 33 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N512_K427_SNR40.dot -O 34 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1024_K853_SNR40.dot -O 35 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1707_SNR40.dot -O 36 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K3413_SNR40.dot -O 37 | 38 | echo "Generates SC short graphs (from *.short.dot to *.short.dot.pdf, rate 1/2)..." 39 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K2_SNR25.short.dot -O 40 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K2_SNR25.short.dot -O 41 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8_K4_SNR25.short.dot -O 42 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16_K8_SNR25.short.dot -O 43 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32_K16_SNR25.short.dot -O 44 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N64_K32_SNR25.short.dot -O 45 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N128_K64_SNR25.short.dot -O 46 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N256_K128_SNR25.short.dot -O 47 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N512_K256_SNR25.short.dot -O 48 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1024_K512_SNR25.short.dot -O 49 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1024_SNR25.short.dot -O 50 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K2048_SNR25.short.dot -O 51 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8192_K4096_SNR25.short.dot -O 52 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16384_K8192_SNR25.short.dot -O 53 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K16384_SNR25.short.dot -O 54 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K16384_SNR18.short.dot -O 55 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N65536_K32768_SNR15.short.dot -O 56 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N65536_K32768_SNR25.short.dot -O 57 | 58 | echo "Generates SC short graphs (from *.short.dot to *.short.dot.pdf, rate 5/6)..." 59 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K3_SNR40.short.dot -O 60 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8_K7_SNR40.short.dot -O 61 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16_K13_SNR40.short.dot -O 62 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32_K27_SNR40.short.dot -O 63 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N64_K53_SNR40.short.dot -O 64 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N128_K107_SNR40.short.dot -O 65 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N256_K213_SNR40.short.dot -O 66 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N512_K427_SNR40.short.dot -O 67 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1024_K853_SNR40.short.dot -O 68 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1707_SNR40.short.dot -O 69 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K3413_SNR40.short.dot -O 70 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8192_K6827_SNR40.short.dot -O 71 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16384_K13653_SNR40.short.dot -O 72 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K27307_SNR40.short.dot -O 73 | dot -Tpdf ./$ROOT/SC/Decoder_polar_SC_fast_sys_N65536_K54613_SNR40.short.dot -O 74 | 75 | echo "Generates SCL graphs (from *.dot to *.dot.pdf, all rates)..." 76 | dot -Tpdf ./$ROOT/SCL/CRC/Decoder_polar_SCL_fast_CA_sys_N4_K2_SNR25.dot -O 77 | dot -Tpdf ./$ROOT/SCL/CRC/Decoder_polar_SCL_fast_CA_sys_N2048_K1755_SNR35.dot -O 78 | dot -Tpdf ./$ROOT/SCL/CRC/Decoder_polar_SCL_fast_CA_sys_N256_K64_SNR30.dot -O 79 | -------------------------------------------------------------------------------- /scripts/generate_polar_gpp_decoders.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | ROOT=src_generated 4 | if [ "$#" -gt "0" ]; 5 | then 6 | ROOT=$1 7 | fi 8 | 9 | mkdir ./$ROOT > /dev/null 2>&1 10 | mkdir ./$ROOT/SC/ > /dev/null 2>&1 11 | mkdir ./$ROOT/SCL/ > /dev/null 2>&1 12 | mkdir ./$ROOT/SCL/CRC/ > /dev/null 2>&1 13 | 14 | # Frozen bits generation method (Gaussian Approximation = "GA", Tal & Vardy = "TV") 15 | GEN="GA" 16 | 17 | echo "Generates GPP SC decoders (rate 1/2)..." 18 | ./build/bin/polar_decoder_gen --dec-type SC -N 4 -K 2 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K2_SNR25.report 2>&1 19 | ./build/bin/polar_decoder_gen --dec-type SC -N 8 -K 4 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8_K4_SNR25.report 2>&1 20 | ./build/bin/polar_decoder_gen --dec-type SC -N 16 -K 8 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16_K8_SNR25.report 2>&1 21 | ./build/bin/polar_decoder_gen --dec-type SC -N 32 -K 16 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32_K16_SNR25.report 2>&1 22 | ./build/bin/polar_decoder_gen --dec-type SC -N 64 -K 32 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N64_K32_SNR25.report 2>&1 23 | ./build/bin/polar_decoder_gen --dec-type SC -N 128 -K 64 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N128_K64_SNR25.report 2>&1 24 | ./build/bin/polar_decoder_gen --dec-type SC -N 256 -K 128 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N256_K128_SNR25.report 2>&1 25 | ./build/bin/polar_decoder_gen --dec-type SC -N 512 -K 256 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N512_K256_SNR25.report 2>&1 26 | ./build/bin/polar_decoder_gen --dec-type SC -N 1024 -K 512 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1024_K512_SNR25.report 2>&1 27 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1024 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1024_SNR25.report 2>&1 28 | ./build/bin/polar_decoder_gen --dec-type SC -N 4096 -K 2048 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K2048_SNR25.report 2>&1 29 | ./build/bin/polar_decoder_gen --dec-type SC -N 4096 -K 2048 --fbg-noise 3.3 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K2048_SNR33.report 2>&1 30 | ./build/bin/polar_decoder_gen --dec-type SC -N 8192 -K 4096 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8192_K4096_SNR25.report 2>&1 31 | ./build/bin/polar_decoder_gen --dec-type SC -N 16384 -K 8192 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16384_K8192_SNR25.report 2>&1 32 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 16384 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K16384_SNR25.report 2>&1 33 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 16384 --fbg-noise 1.8 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K16384_SNR18.report 2>&1 34 | ./build/bin/polar_decoder_gen --dec-type SC -N 65536 -K 32768 --fbg-noise 1.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N65536_K32768_SNR15.report 2>&1 35 | ./build/bin/polar_decoder_gen --dec-type SC -N 65536 -K 32768 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N65536_K32768_SNR25.report 2>&1 36 | ./build/bin/polar_decoder_gen --dec-type SC -N 131072 -K 65536 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N131072_K65536_SNR25.report 2>&1 37 | ./build/bin/polar_decoder_gen --dec-type SC -N 262144 -K 131072 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N262144_K131072_SNR25.report 2>&1 38 | ./build/bin/polar_decoder_gen --dec-type SC -N 524288 -K 262144 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N524288_K262144_SNR25.report 2>&1 39 | ./build/bin/polar_decoder_gen --dec-type SC -N 1048576 -K 524288 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1048576_K524288_SNR25.report 2>&1 40 | 41 | echo "Generates GPP SC decoders (rate 5/6)..." 42 | ./build/bin/polar_decoder_gen --dec-type SC -N 4 -K 3 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4_K3_SNR40.report 2>&1 43 | ./build/bin/polar_decoder_gen --dec-type SC -N 8 -K 7 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8_K7_SNR40.report 2>&1 44 | ./build/bin/polar_decoder_gen --dec-type SC -N 16 -K 13 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16_K13_SNR40.report 2>&1 45 | ./build/bin/polar_decoder_gen --dec-type SC -N 32 -K 27 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32_K27_SNR40.report 2>&1 46 | ./build/bin/polar_decoder_gen --dec-type SC -N 64 -K 53 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N64_K53_SNR40.report 2>&1 47 | ./build/bin/polar_decoder_gen --dec-type SC -N 128 -K 107 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N128_K107_SNR40.report 2>&1 48 | ./build/bin/polar_decoder_gen --dec-type SC -N 256 -K 213 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N256_K213_SNR40.report 2>&1 49 | ./build/bin/polar_decoder_gen --dec-type SC -N 512 -K 427 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N512_K427_SNR40.report 2>&1 50 | ./build/bin/polar_decoder_gen --dec-type SC -N 1024 -K 853 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1024_K853_SNR40.report 2>&1 51 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1707 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1707_SNR40.report 2>&1 52 | ./build/bin/polar_decoder_gen --dec-type SC -N 4096 -K 3413 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N4096_K3413_SNR40.report 2>&1 53 | ./build/bin/polar_decoder_gen --dec-type SC -N 8192 -K 6827 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N8192_K6827_SNR40.report 2>&1 54 | ./build/bin/polar_decoder_gen --dec-type SC -N 16384 -K 13653 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16384_K13653_SNR40.report 2>&1 55 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 27307 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K27307_SNR40.report 2>&1 56 | ./build/bin/polar_decoder_gen --dec-type SC -N 65536 -K 54613 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N65536_K54613_SNR40.report 2>&1 57 | ./build/bin/polar_decoder_gen --dec-type SC -N 131072 -K 109227 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N131072_K109227_SNR40.report 2>&1 58 | ./build/bin/polar_decoder_gen --dec-type SC -N 262144 -K 218453 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N262144_K218453_SNR40.report 2>&1 59 | ./build/bin/polar_decoder_gen --dec-type SC -N 524288 -K 436907 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N524288_K436907_SNR40.report 2>&1 60 | ./build/bin/polar_decoder_gen --dec-type SC -N 1048576 -K 873813 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N1048576_K873813_SNR40.report 2>&1 61 | 62 | echo "Generates GPP SC decoders N = 2048 (rate 1/10, 2/10, ..., 9/10)..." 63 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 205 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K205_SNR25.report 2>&1 64 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 410 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K410_SNR25.report 2>&1 65 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 614 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K614_SNR25.report 2>&1 66 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 819 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K819_SNR25.report 2>&1 67 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1024 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1024_SNR25.report 2>&1 68 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1229 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1229_SNR25.report 2>&1 69 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1434 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1434_SNR25.report 2>&1 70 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1638 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1638_SNR25.report 2>&1 71 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1843 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1843_SNR25.report 2>&1 72 | 73 | echo "Generates GPP SC decoders N = 32768 (rate 1/10, 2/10, ..., 9/10)..." 74 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 3277 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K3277_SNR25.report 2>&1 75 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 6554 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K6554_SNR25.report 2>&1 76 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 9830 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K9830_SNR25.report 2>&1 77 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 13107 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K13107_SNR25.report 2>&1 78 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 16384 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K16384_SNR25.report 2>&1 79 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 19661 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K19661_SNR25.report 2>&1 80 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 22938 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K22938_SNR25.report 2>&1 81 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 26214 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K26214_SNR25.report 2>&1 82 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 29491 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K29491_SNR25.report 2>&1 83 | 84 | echo "Generates GPP SC decoders (other rates)..." 85 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 410 --fbg-noise 2.5 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K410_SNR25.report 2>&1 86 | ./build/bin/polar_decoder_gen --dec-type SC -N 2048 -K 1843 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N2048_K1843_SNR40.report 2>&1 87 | ./build/bin/polar_decoder_gen --dec-type SC -N 16384 -K 14746 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N16384_K14746_SNR40.report 2>&1 88 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 27568 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K27568_SNR40.report 2>&1 89 | ./build/bin/polar_decoder_gen --dec-type SC -N 32768 -K 29492 --fbg-noise 4.0 --fbg-gen-method $GEN --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_polar_SC_fast_sys_N32768_K29492_SNR40.report 2>&1 90 | 91 | echo "Generates GPP SCL decoders (all rates)..." 92 | ./build/bin/polar_decoder_gen --dec-type SCL -N 4 -K 2 --fbg-noise 2.5 --dec-polar-nodes "{R0,R0L,R1,REP,REPL,SPC_4}" --fbg-gen-method $GEN --dec-path ./$ROOT/SCL/CRC > ./$ROOT/SCL/CRC/Decoder_polar_SCL_fast_CA_sys_N4_K2_SNR25.report 2>&1 93 | ./build/bin/polar_decoder_gen --dec-type SCL -N 2048 -K 1755 --fbg-noise 3.5 --dec-polar-nodes "{R0,R0L,R1,REP,REPL,SPC_4}" --fbg-gen-method $GEN --dec-path ./$ROOT/SCL/CRC > ./$ROOT/SCL/CRC/Decoder_polar_SCL_fast_CA_sys_N2048_K1755_SNR35.report 2>&1 94 | ./build/bin/polar_decoder_gen --dec-type SCL -N 256 -K 64 --fbg-noise 3.0 --dec-polar-nodes "{R0,R0L,R1,REP,REPL,SPC_4+}" --fbg-gen-method $GEN --dec-path ./$ROOT/SCL/CRC > ./$ROOT/SCL/CRC/Decoder_polar_SCL_fast_CA_sys_N256_K64_SNR30.report 2>&1 -------------------------------------------------------------------------------- /scripts/generate_polar_tta_decoders.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | ROOT=src_generated 4 | if [ "$#" -gt "0" ]; 5 | then 6 | ROOT=$1 7 | fi 8 | 9 | mkdir ./$ROOT > /dev/null 2>&1 10 | mkdir ./$ROOT/SC/ > /dev/null 2>&1 11 | mkdir ./$ROOT/SCAN/ > /dev/null 2>&1 12 | 13 | echo "Generates TTA SC decoders (rate 1/2)..." 14 | ./build/bin/polar_decoder_gen -D SC -N 1024 -K 512 --fbg-gen-method FILE --fbg-awgn-path lib/aff3ct/conf/cde/awgn_polar_codes/TV/10/N1024_awgn_s0.750.pc --dec-polar-nodes "{R0_8+,R1_8+,R0L_8+}" --fbg-noise 1.0 -a TTA --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_simd_unrolled_N1024_K512.report 2>&1 15 | ./build/bin/polar_decoder_gen -D SC -N 512 -K 256 --fbg-gen-method FILE --fbg-awgn-path lib/aff3ct/conf/cde/awgn_polar_codes/TV/9/N512_awgn_s0.750.pc --dec-polar-nodes "{R0_8+,R1_8+}" --fbg-noise 1.0 -a TTA --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_simd_unrolled_N512_K256.report 2>&1 16 | ./build/bin/polar_decoder_gen -D SC -N 256 -K 128 --fbg-gen-method FILE --fbg-awgn-path lib/aff3ct/conf/cde/awgn_polar_codes/TV/8/N256_awgn_s0.750.pc --dec-polar-nodes "{R0_8+,R1_8+}" --fbg-noise 1.0 -a TTA --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_simd_unrolled_N256_K128.report 2>&1 17 | ./build/bin/polar_decoder_gen -D SC -N 128 -K 64 --fbg-gen-method FILE --fbg-awgn-path lib/aff3ct/conf/cde/awgn_polar_codes/TV/7/N128_awgn_s0.750.pc --dec-polar-nodes "{R0_8+,R1_8+}" --fbg-noise 1.0 -a TTA --dec-path ./$ROOT/SC > ./$ROOT/SC/Decoder_simd_unrolled_N128_K64.report 2>&1 18 | 19 | echo "Generates TTA SCAN decoders (rate 1/2)..." 20 | ./build/bin/polar_decoder_gen -D SCAN -N 1024 -K 512 --fbg-gen-method FILE --fbg-awgn-path lib/aff3ct/conf/cde/awgn_polar_codes/TV/10/N1024_awgn_s0.750.pc --dec-polar-nodes "{}" --fbg-noise 1.0 -a TTA --dec-path ./$ROOT/SCAN > ./$ROOT/SCAN/Decoder_simd_scan_N1024_K512.report 2>&1 21 | -------------------------------------------------------------------------------- /src/Generator/Generator.hpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * \file 3 | * \brief Generates source code. 4 | * 5 | * \section LICENSE 6 | * This file is under MIT license (https://opensource.org/licenses/MIT). 7 | */ 8 | #ifndef GENERATOR_HPP_ 9 | #define GENERATOR_HPP_ 10 | 11 | #include 12 | 13 | namespace aff3ct 14 | { 15 | namespace generator 16 | { 17 | /*! 18 | * \class Generator 19 | * 20 | * \brief Generates source code. 21 | */ 22 | class Generator 23 | { 24 | public: 25 | /*! 26 | * \brief Constructor. 27 | */ 28 | Generator() 29 | { 30 | } 31 | 32 | /*! 33 | * \brief Destructor. 34 | */ 35 | virtual ~Generator() 36 | { 37 | } 38 | 39 | /*! 40 | * \brief Generates the source code. 41 | */ 42 | virtual void generate() = 0; 43 | }; 44 | } 45 | } 46 | 47 | #endif /* GENERATOR_HPP_ */ 48 | -------------------------------------------------------------------------------- /src/Generator/Polar/GPP/Generator_polar_GPP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Generator_polar_GPP.hpp" 9 | 10 | using namespace aff3ct; 11 | using namespace aff3ct::generator; 12 | 13 | Generator_polar_GPP 14 | ::Generator_polar_GPP(const int& K, 15 | const int& N, 16 | const float& snr, 17 | const std::vector& frozen_bits, 18 | const std::vector &patterns, 19 | const int idx_r0, 20 | const int idx_r1, 21 | std::string mother_class_name, 22 | std::string MOTHER_CLASS_NAME, 23 | std::ostream &dec_stream, 24 | std::ostream &short_dec_stream, 25 | std::ostream &graph_stream, 26 | std::ostream &short_graph_stream, 27 | const bool enable_short_decoder) 28 | : Generator_polar(K, 29 | N, 30 | snr, 31 | frozen_bits, 32 | patterns, 33 | idx_r0, 34 | idx_r1, 35 | mother_class_name, 36 | MOTHER_CLASS_NAME, 37 | dec_stream, 38 | short_dec_stream, 39 | graph_stream, 40 | short_graph_stream, 41 | enable_short_decoder) 42 | { 43 | } 44 | 45 | Generator_polar_GPP 46 | ::~Generator_polar_GPP() 47 | { 48 | } 49 | 50 | void Generator_polar_GPP 51 | ::generate_header(const std::string mother_class_name, const std::vector &frozen_bits, 52 | const std::string fbits_name, std::ostream &stream) 53 | { 54 | const auto n_lines = (int)ceil((float)frozen_bits.size() / 32.f); 55 | std::stringstream fbits; 56 | auto i = 0; 57 | for (auto j = 0; j < n_lines; j++) 58 | { 59 | auto k = 0; 60 | while (k < 32 && i < (int)frozen_bits.size()) 61 | { 62 | fbits << frozen_bits[i]; 63 | if (i < (int)frozen_bits.size() -1) fbits << ", "; 64 | i++; k++; 65 | } 66 | if (i < (int)frozen_bits.size()) fbits << std::endl; 67 | } 68 | 69 | std::string pragma_name = MOTHER_CLASS_NAME + "_N" + std::to_string(N) + 70 | "_K" + std::to_string(K) + 71 | "_SNR" + std::to_string((int)(snr*10)) + "_HPP_"; 72 | stream << "#ifndef " << pragma_name << std::endl; 73 | stream << "#define " << pragma_name << std::endl; 74 | stream << std::endl; 75 | stream << "#include " << std::endl; 76 | stream << "#include " << std::endl; 77 | stream << std::endl; 78 | stream << "#include \"../" << mother_class_name << ".hpp\"" << std::endl; 79 | stream << std::endl; 80 | stream << "namespace aff3ct" << std::endl; 81 | stream << "{" << std::endl; 82 | stream << "namespace module" << std::endl; 83 | stream << "{" << std::endl; 84 | stream << "static const std::vector " << fbits_name << " = {" << std::endl; 85 | stream << fbits.str() << "};" << std::endl; 86 | stream << std::endl; 87 | } 88 | 89 | void Generator_polar_GPP 90 | ::generate_footer(std::ostream &stream) 91 | { 92 | stream << "}" << std::endl; 93 | stream << "}" << std::endl; 94 | stream << "#endif" << std::endl; 95 | } -------------------------------------------------------------------------------- /src/Generator/Polar/GPP/Generator_polar_GPP.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_GPP 2 | #define GENERATOR_POLAR_GPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../Generator_polar.hpp" 10 | 11 | namespace aff3ct 12 | { 13 | namespace generator 14 | { 15 | class Generator_polar_GPP : public Generator_polar 16 | { 17 | public: 18 | Generator_polar_GPP(const int& K, 19 | const int& N, 20 | const float& snr, 21 | const std::vector& frozen_bits, 22 | const std::vector &patterns, 23 | const int idx_r0, 24 | const int idx_r1, 25 | std::string mother_class_name, 26 | std::string MOTHER_CLASS_NAME, 27 | std::ostream &dec_stream = std::cout, 28 | std::ostream &short_dec_stream = std::cout, 29 | std::ostream &graph_stream = std::cout, 30 | std::ostream &short_graph_stream = std::cout, 31 | const bool enable_short_decoder = true); 32 | virtual ~Generator_polar_GPP(); 33 | 34 | protected: 35 | void generate_header(const std::string mother_class_name, 36 | const std::vector& frozen_bits, 37 | const std::string fbits_name, 38 | std::ostream &stream); 39 | 40 | virtual void generate_class_header(const std::string class_name, 41 | const std::string fbits_name, 42 | std::ostream &stream1, 43 | std::ostream &stream2) = 0; 44 | 45 | virtual void generate_class_footer(std::ostream &stream) = 0; 46 | void generate_footer (std::ostream &stream); 47 | 48 | virtual void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream) = 0; 49 | virtual void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream) = 0; 50 | }; 51 | } 52 | } 53 | 54 | #endif /* GENERATOR_POLAR_GPP */ 55 | -------------------------------------------------------------------------------- /src/Generator/Polar/GPP/SC/Generator_polar_GPP_SC_sys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Generator_polar_GPP_SC_sys.hpp" 9 | 10 | using namespace aff3ct; 11 | using namespace aff3ct::generator; 12 | 13 | Generator_polar_GPP_SC_sys 14 | ::Generator_polar_GPP_SC_sys(const int& K, 15 | const int& N, 16 | const float& snr, 17 | const std::vector& frozen_bits, 18 | const std::vector &patterns, 19 | const int idx_r0, 20 | const int idx_r1, 21 | std::ostream &dec_stream, 22 | std::ostream &short_dec_stream, 23 | std::ostream &graph_stream, 24 | std::ostream &short_graph_stream) 25 | : Generator_polar_GPP(K, 26 | N, 27 | snr, 28 | frozen_bits, 29 | patterns, 30 | idx_r0, 31 | idx_r1, 32 | "Decoder_polar_SC_fast_sys", 33 | "DECODER_POLAR_SC_FAST_SYS", 34 | dec_stream, 35 | short_dec_stream, 36 | graph_stream, 37 | short_graph_stream) 38 | { 39 | } 40 | 41 | Generator_polar_GPP_SC_sys 42 | ::~Generator_polar_GPP_SC_sys() 43 | { 44 | } 45 | 46 | void Generator_polar_GPP_SC_sys 47 | ::generate_class_header(const std::string class_name, 48 | const std::string fbits_name, 49 | std::ostream &stream1, 50 | std::ostream &stream2) 51 | { 52 | stream1 << "template " << std::endl; 53 | stream1 << "class " << class_name << " : public " << this->mother_class_name << "" << std::endl; 54 | stream1 << "{" << std::endl; 55 | stream1 << "public:" << std::endl; 56 | stream1 << tab << class_name << "(const int& K, const int& N, const int n_frames = 1)" << std::endl; 57 | stream1 << tab << ": Decoder(K, N, n_frames, API_polar::get_n_frames())," << std::endl; 58 | stream1 << tab << " " << this->mother_class_name << "(K, N, " << this->fbits_name 59 | << ")" << std::endl; 60 | stream1 << tab << "{" << std::endl; 61 | stream1 << tab << tab << "const std::string name = \"" + class_name + "\";" << std::endl; 62 | stream1 << tab << tab << "this->set_name(name);" << std::endl; 63 | stream1 << tab << tab << "assert(N == " << N << ");" << std::endl; 64 | stream1 << tab << tab << "assert(K == " << K << ");" << std::endl; 65 | stream1 << tab << "}" << std::endl; 66 | stream1 << std::endl; 67 | stream1 << tab << "virtual ~" << class_name << "()" << std::endl; 68 | stream1 << tab << "{" << std::endl; 69 | stream1 << tab << "}" << std::endl; 70 | stream1 << std::endl; 71 | stream2 << tab << "void _decode()" << std::endl; 72 | stream2 << tab << "{" << std::endl; 73 | stream2 << tab << tab << "using namespace tools;" << std::endl; 74 | stream2 << std::endl; 75 | stream2 << tab << tab << "auto &l = this->l;" << std::endl; 76 | stream2 << tab << tab << "auto &s = this->s;" << std::endl; 77 | stream2 << std::endl; 78 | } 79 | 80 | void Generator_polar_GPP_SC_sys 81 | ::generate_class_footer(std::ostream &stream) 82 | { 83 | stream << tab << "}" << std::endl; 84 | stream << "};" << "" << std::endl; 85 | } 86 | 87 | void Generator_polar_GPP_SC_sys 88 | ::recursive_generate_decoder(const Binary_node* node_curr, std::ostream &stream) 89 | { 90 | n_nodes_before_compression++; 91 | 92 | if (!node_curr->is_leaf()) // stop condition 93 | { 94 | if (!node_curr->get_c()->apply_f().empty()) 95 | stream << tab << tab << node_curr->get_c()->apply_f(); 96 | 97 | this->recursive_generate_decoder(node_curr->get_left(), stream); // recursive call 98 | 99 | if (!node_curr->get_c()->apply_g().empty()) 100 | stream << tab << tab << node_curr->get_c()->apply_g(); 101 | 102 | this->recursive_generate_decoder(node_curr->get_right(), stream); // recursive call 103 | } 104 | 105 | if (!node_curr->get_c()->apply_h().empty()) 106 | stream << tab << tab << node_curr->get_c()->apply_h(); 107 | } 108 | 109 | void Generator_polar_GPP_SC_sys 110 | ::recursive_generate_short_decoder(const Binary_node* node_curr, std::ostream &stream) 111 | { 112 | if (subtree_occurences_cpy[node_curr->get_c()->get_key()] == 1) 113 | { 114 | if (!node_curr->is_leaf()) // stop condition 115 | { 116 | if (!node_curr->get_c()->apply_f().empty()) 117 | stream << tab << tab << node_curr->get_c()->apply_f(); 118 | this->recursive_generate_short_decoder(node_curr->get_left(), stream); // recursive call 119 | if (!node_curr->get_c()->apply_g().empty()) 120 | stream << tab << tab << node_curr->get_c()->apply_g(); 121 | this->recursive_generate_short_decoder(node_curr->get_right(), stream); // recursive call 122 | } 123 | if (!node_curr->get_c()->apply_h().empty()) 124 | stream << tab << tab << node_curr->get_c()->apply_h(); 125 | } 126 | else 127 | { 128 | stream << tab << tab; 129 | stream << node_curr->get_c()->get_key() 130 | << "(" << node_curr->get_c()->get_off_l() << ", " << node_curr->get_c()->get_off_s() << ");" << std::endl; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/Generator/Polar/GPP/SC/Generator_polar_GPP_SC_sys.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_GPP_SC_SYS_ 2 | #define GENERATOR_POLAR_GPP_SC_SYS_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../Generator_polar_GPP.hpp" 10 | 11 | namespace aff3ct 12 | { 13 | namespace generator 14 | { 15 | class Generator_polar_GPP_SC_sys : public Generator_polar_GPP 16 | { 17 | public: 18 | Generator_polar_GPP_SC_sys(const int& K, 19 | const int& N, 20 | const float& snr, 21 | const std::vector& frozen_bits, 22 | const std::vector &patterns, 23 | const int idx_r0, 24 | const int idx_r1, 25 | std::ostream &dec_stream = std::cout, 26 | std::ostream &short_dec_stream = std::cout, 27 | std::ostream &graph_stream = std::cout, 28 | std::ostream &short_graph_stream = std::cout); 29 | virtual ~Generator_polar_GPP_SC_sys(); 30 | 31 | protected: 32 | void generate_class_header(const std::string class_name, 33 | const std::string fbits_name, 34 | std::ostream &stream1, 35 | std::ostream &stream2); 36 | void generate_class_footer( std::ostream &stream); 37 | 38 | void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream); 39 | void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream); 40 | }; 41 | } 42 | } 43 | 44 | #endif /* GENERATOR_POLAR_GPP_SC_SYS_ */ 45 | -------------------------------------------------------------------------------- /src/Generator/Polar/GPP/SCL/Generator_polar_GPP_SCL_sys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Generator_polar_GPP_SCL_sys.hpp" 9 | 10 | using namespace aff3ct; 11 | using namespace aff3ct::generator; 12 | 13 | Generator_polar_GPP_SCL_sys 14 | ::Generator_polar_GPP_SCL_sys(const int& K, 15 | const int& N, 16 | const float& snr, 17 | const std::vector& frozen_bits, 18 | const std::vector &patterns, 19 | const int idx_r0, 20 | const int idx_r1, 21 | std::ostream &dec_stream, 22 | std::ostream &graph_stream) 23 | : Generator_polar_GPP(K, 24 | N, 25 | snr, 26 | frozen_bits, 27 | patterns, 28 | idx_r0, 29 | idx_r1, 30 | "Decoder_polar_SCL_fast_CA_sys", 31 | "DECODER_POLAR_SCL_FAST_SYS_CA", 32 | dec_stream, 33 | dec_stream, 34 | graph_stream, 35 | graph_stream, 36 | false) 37 | { 38 | } 39 | 40 | Generator_polar_GPP_SCL_sys 41 | ::~Generator_polar_GPP_SCL_sys() 42 | { 43 | } 44 | 45 | void Generator_polar_GPP_SCL_sys 46 | ::generate_class_header(const std::string class_name, 47 | const std::string fbits_name, 48 | std::ostream &stream1, 49 | std::ostream &stream2) 50 | { 51 | stream1 << "template " << std::endl; 52 | stream1 << "class " << class_name << " : public " << this->mother_class_name << "" << std::endl; 53 | stream1 << "{" << std::endl; 54 | stream1 << "public:" << std::endl; 55 | stream1 << tab << class_name << "(const int& K, const int& N, const int& L, CRC& crc," 56 | << " const int n_frames = 1)" << std::endl; 57 | stream1 << tab << ": Decoder(K, N, n_frames, API_polar::get_n_frames())," << std::endl; 58 | stream1 << tab << " " << this->mother_class_name << "(K, N, L, " << this->fbits_name 59 | << ", crc)" << std::endl; 60 | stream1 << tab << "{" << std::endl; 61 | stream1 << tab << tab << "const std::string name = \"" + class_name + "\";" << std::endl; 62 | stream1 << tab << tab << "this->set_name(name);" << std::endl; 63 | stream1 << tab << tab << "assert(N == " << N << ");" << std::endl; 64 | stream1 << tab << tab << "assert(K == " << K << ");" << std::endl; 65 | stream1 << tab << "}" << std::endl; 66 | stream1 << std::endl; 67 | stream1 << tab << "virtual ~" << class_name << "()" << std::endl; 68 | stream1 << tab << "{" << std::endl; 69 | stream1 << tab << "}" << std::endl; 70 | stream1 << std::endl; 71 | 72 | stream2 << tab << "void _decode(const R *Y_N)" << std::endl; 73 | stream2 << tab << "{" << std::endl; 74 | stream2 << tab << tab << "using namespace tools;" << std::endl; 75 | stream2 << std::endl; 76 | stream2 << tab << tab << "auto y = Y_N;" << std::endl; 77 | stream2 << tab << tab << "auto &l = this->l;" << std::endl; 78 | stream2 << tab << tab << "auto &s = this->s;" << std::endl; 79 | stream2 << std::endl; 80 | } 81 | 82 | void Generator_polar_GPP_SCL_sys 83 | ::generate_class_footer(std::ostream &stream) 84 | { 85 | stream << tab << "}" << std::endl; 86 | stream << "};" << "" << std::endl; 87 | } 88 | 89 | void Generator_polar_GPP_SCL_sys 90 | ::recursive_generate_decoder(const Binary_node* node_curr, std::ostream &stream) 91 | { 92 | n_nodes_before_compression++; 93 | 94 | if (!node_curr->is_leaf()) // stop condition 95 | { 96 | if (!node_curr->get_c()->apply_f().empty()) 97 | stream << node_curr->get_c()->apply_f(tab + tab); 98 | 99 | this->recursive_generate_decoder(node_curr->get_left(), stream); // recursive call 100 | 101 | if (!node_curr->get_c()->apply_g().empty()) 102 | stream << node_curr->get_c()->apply_g(tab + tab); 103 | 104 | this->recursive_generate_decoder(node_curr->get_right(), stream); // recursive call 105 | } 106 | 107 | if (!node_curr->get_c()->apply_h().empty()) 108 | stream << node_curr->get_c()->apply_h(tab + tab); 109 | } 110 | 111 | void Generator_polar_GPP_SCL_sys 112 | ::recursive_generate_short_decoder(const Binary_node* node_curr, std::ostream &stream) 113 | { 114 | // TODO 115 | } 116 | -------------------------------------------------------------------------------- /src/Generator/Polar/GPP/SCL/Generator_polar_GPP_SCL_sys.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_GPP_SCL_SYS_ 2 | #define GENERATOR_POLAR_GPP_SCL_SYS_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../Generator_polar_GPP.hpp" 10 | 11 | namespace aff3ct 12 | { 13 | namespace generator 14 | { 15 | class Generator_polar_GPP_SCL_sys : public Generator_polar_GPP 16 | { 17 | public: 18 | Generator_polar_GPP_SCL_sys(const int& K, 19 | const int& N, 20 | const float& snr, 21 | const std::vector& frozen_bits, 22 | const std::vector &patterns, 23 | const int idx_r0, 24 | const int idx_r1, 25 | std::ostream &dec_stream = std::cout, 26 | std::ostream &graph_stream = std::cout); 27 | virtual ~Generator_polar_GPP_SCL_sys(); 28 | 29 | protected: 30 | void generate_class_header(const std::string class_name, 31 | const std::string fbits_name, 32 | std::ostream &stream1, 33 | std::ostream &stream2); 34 | void generate_class_footer( std::ostream &stream); 35 | 36 | void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream); 37 | void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream); 38 | }; 39 | } 40 | } 41 | 42 | #endif /* GENERATOR_POLAR_GPP_SCL_SYS_ */ 43 | -------------------------------------------------------------------------------- /src/Generator/Polar/Generator_polar.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | #include "Generator_polar.hpp" 10 | 11 | using namespace aff3ct::generator; 12 | using namespace aff3ct::tools; 13 | 14 | Generator_polar 15 | ::Generator_polar(const int& K, 16 | const int& N, 17 | const float& snr, 18 | const std::vector& frozen_bits, 19 | const std::vector &patterns, 20 | const int idx_r0, 21 | const int idx_r1, 22 | string mother_class_name, 23 | string MOTHER_CLASS_NAME, 24 | ostream &dec_stream, 25 | ostream &short_dec_stream, 26 | ostream &graph_stream, 27 | ostream &short_graph_stream, 28 | const bool enable_short_decoder) 29 | : K (K ), 30 | N (N ), 31 | m ((int)log2(N) ), 32 | snr (snr ), 33 | frozen_bits (frozen_bits ), 34 | patterns (patterns ), 35 | pattern_rate0 (*patterns[idx_r0] ), 36 | pattern_rate1 (*patterns[idx_r1] ), 37 | parser (frozen_bits, patterns, idx_r0, idx_r1), 38 | mother_class_name (mother_class_name ), 39 | MOTHER_CLASS_NAME (MOTHER_CLASS_NAME ), 40 | dec_stream (dec_stream ), 41 | short_dec_stream (short_dec_stream ), 42 | graph_stream (graph_stream ), 43 | short_graph_stream (short_graph_stream ), 44 | tab ("\t" ), 45 | inlining_level (3 ), 46 | stats (m +1 ), 47 | n_nodes_before_compression(0 ), 48 | n_nodes_after_compression (0 ), 49 | enable_short_decoder (enable_short_decoder ) 50 | { 51 | for (unsigned i = 0; i < stats.size(); i++) 52 | stats[i].resize(patterns.size()); 53 | } 54 | 55 | Generator_polar 56 | ::~Generator_polar() 57 | { 58 | } 59 | 60 | std::string Generator_polar 61 | ::get_class_name() 62 | { 63 | return mother_class_name + "_N" + to_string(N) + 64 | "_K" + to_string(K) + 65 | "_SNR" + to_string((int)(snr*10)); 66 | } 67 | 68 | void Generator_polar 69 | ::generate() 70 | { 71 | n_nodes_before_compression = 0; 72 | n_nodes_after_compression = 0; 73 | for (unsigned i = 0; i < stats.size(); i++) 74 | std::fill(stats[i].begin(), stats[i].end(), 0); 75 | 76 | string class_name = get_class_name(); 77 | 78 | fbits_name = mother_class_name + "_fb_" + to_string(N) + 79 | "_" + to_string(K) + 80 | "_" + to_string((int)(snr*10)); 81 | 82 | // decoder generation 83 | stringstream dec_common1, dec_common2, dec_common3, dec, short_dec1, short_dec2; 84 | 85 | this->generate_header (mother_class_name, frozen_bits, fbits_name, dec_common1); 86 | this->generate_class_header (class_name, fbits_name, dec_common1, dec_common2 ); 87 | this->recursive_generate_decoder(parser.get_polar_tree().get_root(), dec ); 88 | this->generate_class_footer (dec_common3 ); 89 | this->generate_footer (dec_common3 ); 90 | 91 | dec_stream << dec_common1.str(); 92 | dec_stream << dec_common2.str(); 93 | dec_stream << dec.str(); 94 | dec_stream << dec_common3.str(); 95 | 96 | // graph generation 97 | stringstream graph, short_graph; 98 | this->recursive_generate_graph(parser.get_polar_tree().get_root(), graph); 99 | this->subtree_occurences_cpy = this->subtree_occurences; 100 | 101 | if (enable_short_decoder) 102 | this->recursive_generate_short_graph(parser.get_polar_tree().get_root(), short_graph); 103 | 104 | stringstream graph_common1; 105 | graph_common1 << "digraph " << class_name << "{" << endl; 106 | graph_common1 << tab << "subgraph cluster_0 {" << endl; 107 | graph_common1 << tab << tab << "label=\"Legend\";" << endl; 108 | graph_common1 << tab << tab << "rankdir=LR;" << endl; 109 | graph_common1 << tab << tab << "rank=same;" << endl; 110 | for (unsigned p = 0; p < patterns.size(); p++) 111 | { 112 | std::string rng = patterns[p]->range().empty() ? "" : std::string("\n") + patterns[p]->range(); 113 | graph_common1 << tab << tab; 114 | graph_common1 << "\"" << patterns[p]->name() << rng << "\"[" 115 | << "style=filled, " 116 | << "fillcolor=\"" << patterns[p]->fill_color() << "\"," 117 | << "fontcolor=\"" << patterns[p]->font_color() << "\"" 118 | << "];" << endl; 119 | } 120 | 121 | for (unsigned p = 0; p < patterns.size() -1; p++) 122 | { 123 | std::string rng0 = patterns[p ]->range().empty() ? "" : std::string("\n") + patterns[p ]->range(); 124 | std::string rng1 = patterns[p +1]->range().empty() ? "" : std::string("\n") + patterns[p +1]->range(); 125 | graph_common1 << tab << tab; 126 | graph_common1 << "\"" << patterns[p ]->name() << rng0 << "\" -> " << "\"" 127 | << patterns[p +1]->name() << rng1 << "\";" << endl; 128 | } 129 | 130 | float compression_rate = 1.f; 131 | if (n_nodes_after_compression != 0) 132 | compression_rate = (float)n_nodes_before_compression / (float)n_nodes_after_compression; 133 | graph_common1 << tab << "}" << endl; 134 | graph_common1 << tab << "subgraph cluster_1 {" << endl; 135 | graph_common1 << tab << tab 136 | << "label=\"Decoder SC systematic - " 137 | << "N=" << N << ", " 138 | << "K=" << K << ", " 139 | << "R=" << std::setprecision(3) << ((float)K / (float)N) << ", " 140 | << "SNR=" << std::setprecision(2) << snr << " - " 141 | << "Compression rate=" << std::setprecision(3) << compression_rate << "\";" << endl; 142 | 143 | stringstream graph_common2; 144 | graph_common2 << tab << "}" << endl; 145 | graph_common2 << "}" << endl; 146 | 147 | graph_stream << graph_common1.str(); 148 | graph_stream << graph.str(); 149 | graph_stream << graph_common2.str(); 150 | 151 | if (enable_short_decoder) 152 | { 153 | short_graph_stream << graph_common1.str(); 154 | short_graph_stream << short_graph.str(); 155 | short_graph_stream << graph_common2.str(); 156 | 157 | // short decoder generation 158 | short_dec_stream << dec_common1.str(); 159 | this->subtree_occurences_cpy = this->subtree_occurences; 160 | this->recursive_generate_short_decoder_funcs(parser.get_polar_tree().get_root(), short_dec1); 161 | short_dec_stream << short_dec1.str(); 162 | short_dec_stream << dec_common2.str(); 163 | this->subtree_occurences_cpy = this->subtree_occurences; 164 | this->recursive_generate_short_decoder(parser.get_polar_tree().get_root(), short_dec2); 165 | short_dec_stream << short_dec2.str(); 166 | short_dec_stream << dec_common3.str(); 167 | } 168 | } 169 | 170 | void Generator_polar 171 | ::recursive_generate_graph(const Binary_node* n_c, ostream &stream) 172 | { 173 | string key = ""; 174 | 175 | string ne_c = string("\n(") + to_string(n_c->get_c()->get_size()) + string(")"); 176 | 177 | // generate graphviz tree 178 | stream << tab << tab; 179 | stream << "\"N" << n_c->get_c()->get_id() << ne_c << "\"[" 180 | << "style=filled," 181 | << "fillcolor=\"" << n_c->get_c()->fill_color() << "\"," 182 | << "fontcolor=\"" << n_c->get_c()->font_color() << "\"" 183 | << "];" << endl; 184 | 185 | if (!n_c->is_leaf()) // stop condition 186 | { 187 | string ne_l = string("\n(") + to_string(n_c->get_left ()->get_c()->get_size()) + string(")"); 188 | string ne_r = string("\n(") + to_string(n_c->get_right()->get_c()->get_size()) + string(")"); 189 | 190 | stream << tab << tab; 191 | stream << "\"N" << n_c ->get_c()->get_id() << ne_c << "\" -> " 192 | << "\"N" << n_c->get_left()->get_c()->get_id() << ne_l << "\"" 193 | << "[label=\"" << n_c->get_c()->f() << ((!n_c->get_c()->f().empty()) ? "()" : "") 194 | << "\"];" << endl; 195 | 196 | this->recursive_generate_graph(n_c->get_left(), stream); // recursive call 197 | key += n_c->get_left()->get_c()->get_key(); 198 | 199 | stream << tab << tab; 200 | stream << "\"N" << n_c ->get_c()->get_id() << ne_c << "\" -> " 201 | << "\"N" << n_c->get_right()->get_c()->get_id() << ne_r << "\"" 202 | << "[label=\"" << n_c->get_c()->g() << ((!n_c->get_c()->g().empty()) ? "()" : "") 203 | << "\"];" << endl; 204 | 205 | this->recursive_generate_graph(n_c->get_right(), stream); // recursive call 206 | key += n_c->get_right()->get_c()->get_key(); 207 | } 208 | else 209 | { 210 | key += n_c->get_c()->short_name() + to_string(n_c->get_depth()); 211 | } 212 | 213 | if (!n_c->get_c()->h().empty()) 214 | { 215 | stream << tab << tab; 216 | stream << "\"N" << n_c->get_c()->get_id() << ne_c << "\" -> " 217 | << "\"N" << n_c->get_c()->get_id() << ne_c << "\"" 218 | << "[label=\"" << n_c->get_c()->h() << "()\"];" << endl; 219 | } 220 | 221 | // statistics 222 | int pattern_id = 0; 223 | Pattern_polar_i* pattern = n_c->get_c(); 224 | for (unsigned i = 0; i < patterns.size(); i++) 225 | { 226 | auto cur_pattern = patterns[i]; 227 | if (typeid(*cur_pattern) == typeid(*pattern)) 228 | { 229 | pattern_id = i; 230 | break; 231 | } 232 | } 233 | stats[n_c->get_depth()][pattern_id]++; 234 | 235 | n_c->get_c()->set_key(key); 236 | if (subtree_occurences.find(key) != subtree_occurences.end()) 237 | subtree_occurences[key]++; 238 | else 239 | subtree_occurences[key] = 1; 240 | } 241 | 242 | void Generator_polar 243 | ::recursive_generate_short_graph(const Binary_node* n_c, ostream &stream) 244 | { 245 | if (subtree_occurences_cpy[n_c->get_c()->get_key()]) 246 | { 247 | string ne_c = string("\n(") + to_string(n_c->get_c()->get_size()) + string(")"); 248 | 249 | n_nodes_after_compression++; 250 | subtree_occurences_cpy[n_c->get_c()->get_key()] = 0; 251 | subtree_nodes [n_c->get_c()->get_key()] = string("\"N") + to_string(n_c->get_c()->get_id()) + ne_c + 252 | string("\""); 253 | 254 | // generate graphviz tree 255 | stream << tab << tab; 256 | stream << "\"N" << n_c->get_c()->get_id() << ne_c << "\"[" 257 | << "style=filled," 258 | << "fillcolor=\"" << n_c->get_c()->fill_color() << "\"," 259 | << "fontcolor=\"" << n_c->get_c()->font_color() << "\"" 260 | << "];" << endl; 261 | 262 | if (!n_c->is_leaf()) // stop condition 263 | { 264 | string ne_l = string("\n(") + to_string(n_c->get_left ()->get_c()->get_size()) + string(")"); 265 | string ne_r = string("\n(") + to_string(n_c->get_right()->get_c()->get_size()) + string(")"); 266 | 267 | auto occurences = subtree_occurences_cpy[n_c->get_left()->get_c()->get_key()]; 268 | if (occurences) 269 | { 270 | stream << tab << tab; 271 | stream << "\"N" << n_c ->get_c()->get_id() << ne_c << "\" -> " 272 | << "\"N" << n_c->get_left()->get_c()->get_id() << ne_l << "\"" 273 | // << "[label=\"" << occurences << "\"];" 274 | << endl; 275 | 276 | this->recursive_generate_short_graph(n_c->get_left(), stream); // recursive call 277 | } 278 | else 279 | { 280 | auto name = subtree_nodes[n_c->get_left()->get_c()->get_key()]; 281 | stream << tab << tab; 282 | stream << "\"N" << n_c->get_c()->get_id() << ne_c << "\" -> " << name << endl; 283 | } 284 | 285 | occurences = subtree_occurences_cpy[n_c->get_right()->get_c()->get_key()]; 286 | if (occurences) 287 | { 288 | stream << tab << tab; 289 | stream << "\"N" << n_c ->get_c()->get_id() << ne_c << "\" -> " 290 | << "\"N" << n_c->get_right()->get_c()->get_id() << ne_r << "\"" 291 | // << "[label=\"" << occurences << "\"];" 292 | << endl; 293 | 294 | this->recursive_generate_short_graph(n_c->get_right(), stream); // recursive call 295 | } 296 | else 297 | { 298 | auto name = subtree_nodes[n_c->get_right()->get_c()->get_key()]; 299 | stream << tab << tab; 300 | stream << "\"N" << n_c->get_c()->get_id() << ne_c << "\" -> " << name << endl; 301 | } 302 | } 303 | } 304 | } 305 | 306 | void Generator_polar 307 | ::recursive_generate_short_decoder_funcs(const Binary_node* node_curr, ostream &stream) 308 | { 309 | if (!node_curr->is_leaf()) // stop condition 310 | { 311 | this->recursive_generate_short_decoder_funcs(node_curr->get_left(), stream); // recursive call 312 | this->recursive_generate_short_decoder_funcs(node_curr->get_right(), stream); // recursive call 313 | } 314 | 315 | if (subtree_occurences_cpy[node_curr->get_c()->get_key()] > 1) 316 | { 317 | stream << tab << "// depth = " << node_curr->get_depth() << ", " 318 | << "reverse depth = " << (this->m - node_curr->get_depth()) << ", " 319 | << "size = " << node_curr->get_c()->get_size() << ", " 320 | << "calls = " << subtree_occurences_cpy[node_curr->get_c()->get_key()] << endl; 321 | if ((this->m - node_curr->get_depth()) <= this->inlining_level) 322 | stream << tab << "__attribute__((always_inline))" << endl; 323 | stream << tab << "inline void " << node_curr->get_c()->get_key() << "(const int off_l, " 324 | << "const int off_s)" << endl; 325 | stream << tab << "{" << endl; 326 | 327 | subtree_occurences_cpy[node_curr->get_c()->get_key()] = 0; 328 | 329 | if (node_curr->is_leaf()) 330 | { 331 | std::string h = node_curr->get_c()->apply_h("", "off_l", "off_s"); 332 | if (!h.empty()) 333 | { 334 | stream << tab << tab << "using namespace tools;" << endl; 335 | stream << endl; 336 | stream << tab << tab << "auto &l = this->l;" << endl; 337 | stream << tab << tab << "auto &s = this->s;" << endl; 338 | stream << endl; 339 | stream << tab << tab << h; 340 | } 341 | } 342 | else 343 | { 344 | stream << tab << tab << "using namespace tools;" << endl; 345 | stream << endl; 346 | stream << tab << tab << "auto &l = this->l;" << endl; 347 | stream << tab << tab << "auto &s = this->s;" << endl; 348 | stream << endl; 349 | 350 | if (!node_curr->get_c()->apply_f("", "off_l", "off_s").empty()) 351 | { 352 | stream << tab << tab << node_curr->get_c()->apply_f("", "off_l", "off_s"); 353 | } 354 | if(node_curr->get_left() != nullptr) 355 | { 356 | stream << tab << tab; 357 | stream << node_curr->get_left()->get_c()->get_key() << "(" 358 | << "off_l" << "+" << node_curr->get_c()->get_size() << ", " 359 | << "off_s" << "+" << 0 << ");" << endl; 360 | } 361 | 362 | if (!node_curr->get_c()->apply_g("", "off_l", "off_s").empty()) 363 | stream << tab << tab << node_curr->get_c()->apply_g("", "off_l", "off_s"); 364 | if(node_curr->get_right() != nullptr) 365 | { 366 | stream << tab << tab; 367 | stream << node_curr->get_right()->get_c()->get_key() << "(" 368 | << "off_l" << "+" << node_curr->get_c()->get_size() << ", " 369 | << "off_s" << "+" << node_curr->get_c()->get_si_2() << ");" << endl; 370 | } 371 | 372 | if (!node_curr->get_c()->apply_h("", "off_l", "off_s").empty()) 373 | stream << tab << tab << node_curr->get_c()->apply_h("", "off_l", "off_s"); 374 | } 375 | stream << tab << "}" << endl << endl; 376 | } 377 | } 378 | 379 | unsigned long Generator_polar 380 | ::get_n_generated_nodes(int graph_depth) const 381 | { 382 | if (graph_depth >= m +1) 383 | { 384 | stringstream message; 385 | message << "'graph_depth' has to be smaller than 'm' +1. ('graph_depth' = " << graph_depth 386 | << ", 'm' = " << m << ")"; 387 | throw aff3ct::tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); 388 | } 389 | 390 | unsigned long sum_nodes = 0; 391 | 392 | if (graph_depth < 0) 393 | for (auto d = 0; d < m +1; d++) 394 | for (unsigned p = 0; p < patterns.size(); p++) 395 | sum_nodes += stats[d][p]; 396 | else 397 | for (unsigned p = 0; p < patterns.size(); p++) 398 | sum_nodes += stats[graph_depth][p]; 399 | 400 | return sum_nodes; 401 | } 402 | 403 | unsigned long Generator_polar 404 | ::get_n_generated_nodes_by_pattern(std::size_t pattern_hash, int graph_depth) const 405 | { 406 | if (graph_depth >= m +1) 407 | { 408 | stringstream message; 409 | message << "'graph_depth' has to be smaller than 'm' +1. ('graph_depth' = " << graph_depth 410 | << ", 'm' = " << m << ")"; 411 | throw aff3ct::tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); 412 | } 413 | 414 | unsigned long sum_nodes = 0; 415 | 416 | if (graph_depth < 0) 417 | for (auto d = 0; d < m +1; d++) 418 | for (unsigned p = 0; p < patterns.size(); p++) 419 | { 420 | auto cur_pattern = patterns[p]; 421 | if (typeid(*cur_pattern).hash_code() == pattern_hash) 422 | { 423 | sum_nodes += stats[d][p]; 424 | break; 425 | } 426 | } 427 | else 428 | for (unsigned p = 0; p < patterns.size(); p++) 429 | { 430 | auto cur_pattern = patterns[p]; 431 | if (typeid(*cur_pattern).hash_code() == pattern_hash) 432 | { 433 | sum_nodes += stats[graph_depth][p]; 434 | break; 435 | } 436 | } 437 | 438 | return sum_nodes; 439 | } 440 | -------------------------------------------------------------------------------- /src/Generator/Polar/Generator_polar.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_SYS_ 2 | #define GENERATOR_POLAR_SYS_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../Generator.hpp" 10 | 11 | namespace aff3ct 12 | { 13 | namespace generator 14 | { 15 | class Generator_polar : public Generator 16 | { 17 | protected: 18 | const int K; // k bits input 19 | const int N; // n bits input 20 | const int m; // graph depth 21 | const float snr; 22 | 23 | const std::vector& frozen_bits; 24 | 25 | const std::vector &patterns; 26 | const tools::Pattern_polar_i &pattern_rate0; 27 | const tools::Pattern_polar_i &pattern_rate1; 28 | 29 | tools::Pattern_polar_parser parser; 30 | 31 | std::string mother_class_name; 32 | std::string MOTHER_CLASS_NAME; 33 | std::string fbits_name; 34 | 35 | std::ostream &dec_stream; 36 | std::ostream &short_dec_stream; 37 | std::ostream &graph_stream; 38 | std::ostream &short_graph_stream; 39 | 40 | std::string tab; 41 | const int inlining_level; 42 | std::vector> stats; 43 | std::map subtree_occurences; 44 | std::map subtree_occurences_cpy; 45 | std::map subtree_nodes; 46 | unsigned n_nodes_before_compression; 47 | unsigned n_nodes_after_compression; 48 | 49 | const bool enable_short_decoder; 50 | 51 | public: 52 | Generator_polar(const int& K, 53 | const int& N, 54 | const float& snr, 55 | const std::vector& frozen_bits, 56 | const std::vector &patterns, 57 | const int idx_r0, 58 | const int idx_r1, 59 | std::string mother_class_name, 60 | std::string MOTHER_CLASS_NAME, 61 | std::ostream &dec_stream = std::cout, 62 | std::ostream &short_dec_stream = std::cout, 63 | std::ostream &graph_stream = std::cout, 64 | std::ostream &short_graph_stream = std::cout, 65 | const bool enable_short_decoder = true); 66 | virtual ~Generator_polar(); 67 | 68 | void generate(); 69 | 70 | std::string get_class_name(); 71 | 72 | unsigned long get_n_generated_nodes ( int graph_depth = -1) const; 73 | unsigned long get_n_generated_nodes_by_pattern(std::size_t pattern_hash, int graph_depth = -1) const; 74 | 75 | protected: 76 | virtual void generate_header(const std::string mother_class_name, 77 | const std::vector &frozen_bits, 78 | const std::string fbits_name, 79 | std::ostream &stream) = 0; 80 | 81 | virtual void generate_class_header(const std::string class_name, 82 | const std::string fbits_name, 83 | std::ostream &stream1, 84 | std::ostream &stream2) = 0; 85 | 86 | virtual void generate_class_footer( std::ostream &stream) = 0; 87 | virtual void generate_footer ( std::ostream &stream) = 0; 88 | 89 | virtual void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream) = 0; 90 | virtual void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream) = 0; 91 | 92 | private: 93 | void recursive_generate_short_decoder_funcs(const tools::Binary_node* node_curr, std::ostream &stream); 94 | void recursive_generate_graph (const tools::Binary_node* node_curr, std::ostream &stream); 95 | void recursive_generate_short_graph (const tools::Binary_node* node_curr, std::ostream &stream); 96 | }; 97 | } 98 | } 99 | 100 | #endif /* GENERATOR_POLAR_SYS_ */ 101 | -------------------------------------------------------------------------------- /src/Generator/Polar/TTA/Generator_polar_TTA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Generator_polar_TTA.hpp" 9 | 10 | using namespace aff3ct; 11 | using namespace aff3ct::generator; 12 | 13 | Generator_polar_TTA 14 | ::Generator_polar_TTA(const int& K, 15 | const int& N, 16 | const float& snr, 17 | const std::vector& frozen_bits, 18 | const std::vector &patterns, 19 | const int idx_r0, 20 | const int idx_r1, 21 | std::string mother_class_name, 22 | std::string MOTHER_CLASS_NAME, 23 | std::ostream &dec_stream, 24 | std::ostream &short_dec_stream, 25 | std::ostream &graph_stream, 26 | std::ostream &short_graph_stream, 27 | const bool enable_short_decoder) 28 | : Generator_polar(K, 29 | N, 30 | snr, 31 | frozen_bits, 32 | patterns, 33 | idx_r0, 34 | idx_r1, 35 | mother_class_name, 36 | MOTHER_CLASS_NAME, 37 | dec_stream, 38 | short_dec_stream, 39 | graph_stream, 40 | short_graph_stream, 41 | enable_short_decoder) 42 | { 43 | } 44 | 45 | Generator_polar_TTA 46 | ::~Generator_polar_TTA() 47 | { 48 | } 49 | 50 | void Generator_polar_TTA 51 | ::generate_header(const std::string mother_class_name, const std::vector &frozen_bits, 52 | const std::string fbits_name, std::ostream &stream) 53 | { 54 | } 55 | 56 | void Generator_polar_TTA 57 | ::generate_footer(std::ostream &stream) 58 | { 59 | } -------------------------------------------------------------------------------- /src/Generator/Polar/TTA/Generator_polar_TTA.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_TTA 2 | #define GENERATOR_POLAR_TTA 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../Generator_polar.hpp" 10 | 11 | namespace aff3ct 12 | { 13 | namespace generator 14 | { 15 | class Generator_polar_TTA : public Generator_polar 16 | { 17 | public: 18 | Generator_polar_TTA(const int& K, 19 | const int& N, 20 | const float& snr, 21 | const std::vector& frozen_bits, 22 | const std::vector &patterns, 23 | const int idx_r0, 24 | const int idx_r1, 25 | std::string mother_class_name, 26 | std::string MOTHER_CLASS_NAME, 27 | std::ostream &dec_stream = std::cout, 28 | std::ostream &short_dec_stream = std::cout, 29 | std::ostream &graph_stream = std::cout, 30 | std::ostream &short_graph_stream = std::cout, 31 | const bool enable_short_decoder = true); 32 | virtual ~Generator_polar_TTA(); 33 | 34 | protected: 35 | void generate_header(const std::string mother_class_name, 36 | const std::vector &frozen_bits, 37 | const std::string fbits_name, 38 | std::ostream &stream); 39 | 40 | virtual void generate_class_header(const std::string class_name, 41 | const std::string fbits_name, 42 | std::ostream &stream1, 43 | std::ostream &stream2) = 0; 44 | 45 | virtual void generate_class_footer(std::ostream &stream) = 0; 46 | void generate_footer (std::ostream &stream); 47 | 48 | virtual void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream) = 0; 49 | virtual void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream) = 0; 50 | }; 51 | } 52 | } 53 | 54 | #endif /* GENERATOR_POLAR_TTA */ 55 | -------------------------------------------------------------------------------- /src/Generator/Polar/TTA/SC/Generator_polar_TTA_SC_sys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Generator_polar_TTA_SC_sys.hpp" 9 | 10 | using namespace aff3ct; 11 | using namespace aff3ct::generator; 12 | 13 | Generator_polar_TTA_SC_sys 14 | ::Generator_polar_TTA_SC_sys(const int& K, 15 | const int& N, 16 | const float& snr, 17 | const std::vector& frozen_bits, 18 | const std::vector &patterns, 19 | const int idx_r0, 20 | const int idx_r1, 21 | std::ostream &dec_stream, 22 | std::ostream &graph_stream) 23 | : Generator_polar_TTA(K, 24 | N, 25 | snr, 26 | frozen_bits, 27 | patterns, 28 | idx_r0, 29 | idx_r1, 30 | "Decoder_polar_TTA_SC_sys", 31 | "DECODER_POLAR_TTA_SC_SYS", 32 | dec_stream, 33 | dec_stream, 34 | graph_stream, 35 | graph_stream, 36 | false) 37 | { 38 | } 39 | 40 | Generator_polar_TTA_SC_sys 41 | ::~Generator_polar_TTA_SC_sys() 42 | { 43 | } 44 | 45 | void Generator_polar_TTA_SC_sys 46 | ::generate_class_header(const std::string class_name, 47 | const std::string fbits_name, 48 | std::ostream &stream1, 49 | std::ostream &stream2) 50 | { 51 | stream1 << "#include \"Decoder_simd_unrolled.h\"" << std::endl; 52 | stream1 << std::endl; 53 | stream1 << "void Decoder_simd_unrolled::decode()" << std::endl; 54 | stream1 << "{" << std::endl; 55 | stream1 << tab << "char64 l_a;" << std::endl; 56 | stream1 << tab << "char64 l_b;" << std::endl; 57 | stream1 << tab << "char64 l_c;" << std::endl; 58 | stream1 << tab << "char8 temp_s;" << std::endl; 59 | stream1 << tab << std::endl; 60 | } 61 | 62 | void Generator_polar_TTA_SC_sys 63 | ::generate_class_footer(std::ostream &stream) 64 | { 65 | stream << "};" << "" << std::endl; 66 | } 67 | 68 | void Generator_polar_TTA_SC_sys 69 | ::recursive_generate_decoder(const Binary_node* node_curr, std::ostream &stream) 70 | { 71 | n_nodes_before_compression++; 72 | 73 | if (!node_curr->is_leaf()) // stop condition 74 | { 75 | if (!node_curr->get_c()->apply_f().empty()) 76 | stream << tab << node_curr->get_c()->apply_f(); 77 | 78 | this->recursive_generate_decoder(node_curr->get_left(), stream); // recursive call 79 | 80 | if (!node_curr->get_c()->apply_g().empty()) 81 | stream << tab << node_curr->get_c()->apply_g(); 82 | 83 | this->recursive_generate_decoder(node_curr->get_right(), stream); // recursive call 84 | } 85 | 86 | if (!node_curr->get_c()->apply_h().empty()) 87 | stream << tab << node_curr->get_c()->apply_h(); 88 | } 89 | 90 | void Generator_polar_TTA_SC_sys 91 | ::recursive_generate_short_decoder(const Binary_node* node_curr, std::ostream &stream) 92 | { 93 | // TODO 94 | } 95 | -------------------------------------------------------------------------------- /src/Generator/Polar/TTA/SC/Generator_polar_TTA_SC_sys.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_TTA_SC_SYS_ 2 | #define GENERATOR_POLAR_TTA_SC_SYS_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../Generator_polar_TTA.hpp" 9 | 10 | namespace aff3ct 11 | { 12 | namespace generator 13 | { 14 | class Generator_polar_TTA_SC_sys : public Generator_polar_TTA 15 | { 16 | public: 17 | Generator_polar_TTA_SC_sys(const int& K, 18 | const int& N, 19 | const float& snr, 20 | const std::vector& frozen_bits, 21 | const std::vector &patterns, 22 | const int idx_r0, 23 | const int idx_r1, 24 | std::ostream &dec_stream = std::cout, 25 | std::ostream &graph_stream = std::cout); 26 | virtual ~Generator_polar_TTA_SC_sys(); 27 | 28 | protected: 29 | void generate_class_header(const std::string class_name, 30 | const std::string fbits_name, 31 | std::ostream &stream1, 32 | std::ostream &stream2); 33 | void generate_class_footer( std::ostream &stream); 34 | 35 | void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream); 36 | void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream); 37 | }; 38 | } 39 | } 40 | 41 | #endif /* GENERATOR_POLAR_TTA_SC_SYS_ */ 42 | -------------------------------------------------------------------------------- /src/Generator/Polar/TTA/SCAN/Generator_polar_TTA_SCAN_sys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Generator_polar_TTA_SCAN_sys.hpp" 9 | 10 | #include "../../../../Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_std.hpp" 11 | 12 | using namespace aff3ct; 13 | using namespace aff3ct::generator; 14 | 15 | Generator_polar_TTA_SCAN_sys 16 | ::Generator_polar_TTA_SCAN_sys(const int& K, 17 | const int& N, 18 | const int& n_ite, 19 | const float& snr, 20 | const std::vector& frozen_bits, 21 | const std::vector &patterns, 22 | const int idx_r0, 23 | const int idx_r1, 24 | std::ostream &dec_stream, 25 | std::ostream &graph_stream) 26 | : Generator_polar_TTA(K, 27 | N, 28 | snr, 29 | frozen_bits, 30 | patterns, 31 | idx_r0, 32 | idx_r1, 33 | "Decoder_polar_SCAN_sys", 34 | "DECODER_POLAR_SCAN_SYS", 35 | dec_stream, 36 | dec_stream, 37 | graph_stream, 38 | graph_stream, 39 | false), 40 | n_ite(n_ite) 41 | { 42 | } 43 | 44 | Generator_polar_TTA_SCAN_sys 45 | ::~Generator_polar_TTA_SCAN_sys() 46 | { 47 | } 48 | 49 | void Generator_polar_TTA_SCAN_sys 50 | ::generate_class_header(const std::string class_name, 51 | const std::string fbits_name, 52 | std::ostream &stream1, 53 | std::ostream &stream2) 54 | { 55 | stream1 << "#include \"Decoder_simd_scan.h\"" << std::endl; 56 | stream1 << std::endl; 57 | stream1 << "char64 b[192] __attribute__((address_space(3)));" << std::endl; 58 | stream1 << std::endl; 59 | stream1 << "void Decoder_simd_scan::decode()" << std::endl; 60 | stream1 << "{" << std::endl; 61 | stream1 << tab << "char64 l_a;" << std::endl; 62 | stream1 << tab << "char64 l_b;" << std::endl; 63 | stream1 << tab << "char64 l_c;" << std::endl; 64 | stream1 << tab << "char64 b_a;" << std::endl; 65 | stream1 << tab << "char64 b_b;" << std::endl; 66 | stream1 << tab << "char64 b_c;" << std::endl; 67 | stream1 << tab << std::endl; 68 | stream1 << tab << "for (int i = 0; i < " << this->n_ite << "; i++)" << std::endl; 69 | stream1 << tab << "{" << std::endl; 70 | } 71 | 72 | void Generator_polar_TTA_SCAN_sys 73 | ::generate_class_footer(std::ostream &stream) 74 | { 75 | stream << tab << "}" << "" << std::endl; 76 | auto root = this->parser.get_polar_tree().get_root(); 77 | auto root_pattern = dynamic_cast(root->get_c()); 78 | stream << tab << root_pattern->final_apply_h(); 79 | stream << "};" << "" << std::endl; 80 | } 81 | 82 | void Generator_polar_TTA_SCAN_sys 83 | ::recursive_generate_decoder(const Binary_node* node_curr, std::ostream &stream) 84 | { 85 | n_nodes_before_compression++; 86 | 87 | if (!node_curr->is_leaf()) // stop condition 88 | { 89 | if (!node_curr->get_c()->apply_f().empty()) 90 | { 91 | stream << tab << tab << "// apply_f" << std::endl; 92 | stream << tab << node_curr->get_c()->apply_f(); 93 | } 94 | 95 | this->recursive_generate_decoder(node_curr->get_left(), stream); // recursive call 96 | 97 | if (!node_curr->get_c()->apply_g().empty()) 98 | { 99 | stream << tab << tab << "// apply_g" << std::endl; 100 | stream << tab << node_curr->get_c()->apply_g(); 101 | } 102 | 103 | this->recursive_generate_decoder(node_curr->get_right(), stream); // recursive call 104 | } 105 | 106 | if (!node_curr->get_c()->apply_h().empty()) 107 | { 108 | stream << tab << tab << "// apply_h" << std::endl; 109 | stream << tab << node_curr->get_c()->apply_h(); 110 | } 111 | } 112 | 113 | void Generator_polar_TTA_SCAN_sys 114 | ::recursive_generate_short_decoder(const Binary_node* node_curr, std::ostream &stream) 115 | { 116 | // TODO 117 | } 118 | -------------------------------------------------------------------------------- /src/Generator/Polar/TTA/SCAN/Generator_polar_TTA_SCAN_sys.hpp: -------------------------------------------------------------------------------- 1 | #ifndef GENERATOR_POLAR_TTA_SCAN_SYS_ 2 | #define GENERATOR_POLAR_TTA_SCAN_SYS_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../Generator_polar_TTA.hpp" 10 | 11 | namespace aff3ct 12 | { 13 | namespace generator 14 | { 15 | class Generator_polar_TTA_SCAN_sys : public Generator_polar_TTA 16 | { 17 | private: 18 | const int n_ite; 19 | public: 20 | Generator_polar_TTA_SCAN_sys(const int& K, 21 | const int& N, 22 | const int& n_ite, 23 | const float& snr, 24 | const std::vector& frozen_bits, 25 | const std::vector &patterns, 26 | const int idx_r0, 27 | const int idx_r1, 28 | std::ostream &dec_stream = std::cout, 29 | std::ostream &graph_stream = std::cout); 30 | virtual ~Generator_polar_TTA_SCAN_sys(); 31 | 32 | protected: 33 | void generate_class_header(const std::string class_name, 34 | const std::string fbits_name, 35 | std::ostream &stream1, 36 | std::ostream &stream2); 37 | void generate_class_footer( std::ostream &stream); 38 | 39 | void recursive_generate_decoder (const tools::Binary_node* node_curr, std::ostream &stream); 40 | void recursive_generate_short_decoder(const tools::Binary_node* node_curr, std::ostream &stream); 41 | }; 42 | } 43 | } 44 | 45 | #endif /* GENERATOR_POLAR_TTA_SCAN_SYS_ */ 46 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_r0.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_RATE_0_HPP_ 2 | #define PATTERN_POLAR_SC_RATE_0_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_r0 : public Pattern_polar_r0 11 | { 12 | protected: 13 | Pattern_polar_SC_r0(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r0(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SC_r0(const int min_level = 0, const int max_level = -1) 21 | : Pattern_polar_r0(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SC_r0() {} 24 | 25 | virtual Pattern_polar_SC_r0* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SC_r0(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SC_r0(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | return ""; 46 | } 47 | }; 48 | } 49 | } 50 | 51 | #endif /* PATTERN_POLAR_SC_RATE_0_HPP_ */ 52 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_r0_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_RATE_0_LEFT_HPP_ 2 | #define PATTERN_POLAR_SC_RATE_0_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_r0_left : public Pattern_polar_r0_left 11 | { 12 | protected: 13 | Pattern_polar_SC_r0_left(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_r0_left(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SC_r0_left(const int min_level = 1, const int max_level = -1) 21 | : Pattern_polar_r0_left(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SC_r0_left() {} 24 | 25 | virtual Pattern_polar_r0_left* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SC_r0_left(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SC_r0_left(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | // using namespace std; 41 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 42 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 43 | 44 | auto apply_g0 = g() + " "; 45 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 46 | 47 | std::stringstream stream; 48 | stream << "API_polar::template " << apply_g0 << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 49 | << " " 50 | << "l, " 51 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 52 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 53 | << spaces << " " 54 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 55 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 56 | 57 | return stream.str(); 58 | } 59 | 60 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 61 | { 62 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 63 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 64 | 65 | auto apply_xo0 = h(); 66 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 67 | 68 | std::stringstream stream; 69 | stream << "API_polar::template " << apply_xo0 << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 70 | << "s, " 71 | << " " 72 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 73 | << spaces << " " 74 | << spaces << " " 75 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 76 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 77 | 78 | return stream.str(); 79 | } 80 | }; 81 | } 82 | } 83 | 84 | #endif /* PATTERN_POLAR_SC_RATE_0_LEFT_HPP_ */ 85 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_r1.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_RATE_1_HPP_ 2 | #define PATTERN_POLAR_SC_RATE_1_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_r1 : public Pattern_polar_r1 11 | { 12 | protected: 13 | Pattern_polar_SC_r1(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r1(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SC_r1(const int min_level = 0, const int max_level = -1) 21 | : Pattern_polar_r1(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SC_r1() {} 24 | 25 | virtual Pattern_polar_SC_r1* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SC_r1(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SC_r1(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 46 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 47 | 48 | auto apply_h = h() + " "; 49 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 50 | 51 | std::stringstream stream; 52 | stream << "API_polar::template " << apply_h << "<" << std::setw(this->n2_dig) << this->size << ">(" 53 | << "s, " 54 | << "l, " 55 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 56 | << spaces << " " 57 | << spaces << " " 58 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 59 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 60 | 61 | return stream.str(); 62 | } 63 | }; 64 | } 65 | } 66 | 67 | #endif /* PATTERN_POLAR_SC_RATE_1_HPP_ */ 68 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_rep.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_REP_HPP_ 2 | #define PATTERN_POLAR_SC_REP_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_rep : public Pattern_polar_rep 11 | { 12 | protected: 13 | Pattern_polar_SC_rep(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_rep(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SC_rep(const int min_level = 1, const int max_level = -1) 21 | : Pattern_polar_rep(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SC_rep() {} 24 | 25 | virtual Pattern_polar_SC_rep* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SC_rep(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SC_rep(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const { 34 | return ""; 35 | } 36 | 37 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 38 | { 39 | return ""; 40 | } 41 | 42 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 43 | { 44 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 45 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 46 | 47 | auto apply_rep = h(); 48 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 49 | 50 | std::stringstream stream; 51 | stream << "API_polar::template " << apply_rep << "<" << std::setw(this->n2_dig) << this->size << ">(" 52 | << "s, " 53 | << "l, " 54 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 55 | << spaces << " " 56 | << spaces << " " 57 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 58 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 59 | 60 | return stream.str(); 61 | } 62 | }; 63 | } 64 | } 65 | 66 | #endif /* PATTERN_POLAR_SC_REP_HPP_ */ 67 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_rep_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_REP_LEFT_HPP_ 2 | #define PATTERN_POLAR_SC_REP_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_rep_left : public Pattern_polar_rep_left 11 | { 12 | protected: 13 | Pattern_polar_SC_rep_left(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_rep_left(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SC_rep_left(const int min_level = 2, const int max_level = -1) 21 | : Pattern_polar_rep_left(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SC_rep_left() {} 24 | 25 | virtual Pattern_polar_SC_rep_left* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SC_rep_left(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SC_rep_left(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | // using namespace std; 36 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 37 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 38 | 39 | auto apply_f = f() + " "; 40 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 41 | 42 | std::stringstream stream; 43 | stream << "API_polar::template " << apply_f << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 44 | << " " 45 | << "l, " 46 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 47 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 48 | << spaces << " " 49 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 50 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 51 | 52 | return stream.str(); 53 | } 54 | 55 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 56 | { 57 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 58 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 59 | 60 | auto apply_gr = g() + " "; 61 | 62 | std::stringstream stream; 63 | stream << "API_polar::template " << apply_gr << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 64 | << "s, " 65 | << "l, " 66 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 67 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 68 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 69 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 70 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 71 | 72 | return stream.str(); 73 | } 74 | 75 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 76 | { 77 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 78 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 79 | 80 | auto apply_xo = h() + " "; 81 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 82 | 83 | std::stringstream stream; 84 | stream << "API_polar::template " << apply_xo << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 85 | << "s, " 86 | << " " 87 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 88 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 89 | << spaces << " " 90 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 91 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 92 | 93 | return stream.str(); 94 | } 95 | }; 96 | } 97 | } 98 | 99 | #endif /* PATTERN_POLAR_SC_REP_LEFT_HPP_ */ 100 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_spc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_SPC_HPP_ 2 | #define PATTERN_POLAR_SC_SPC_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_spc : public Pattern_polar_spc 11 | { 12 | protected: 13 | Pattern_polar_SC_spc(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_spc(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SC_spc(const int min_level = 2, const int max_level = -1) 21 | : Pattern_polar_spc(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SC_spc() {} 24 | 25 | virtual Pattern_polar_SC_spc* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SC_spc(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SC_spc(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 46 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 47 | 48 | auto apply_spc = h(); 49 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 50 | 51 | std::stringstream stream; 52 | stream << "API_polar::template " << apply_spc << "<" << std::setw(this->n2_dig) << this->size << ">(" 53 | << "s, " 54 | << "l, " 55 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 56 | << spaces << " " 57 | << spaces << " " 58 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 59 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 60 | 61 | return stream.str(); 62 | } 63 | }; 64 | } 65 | } 66 | 67 | #endif /* PATTERN_POLAR_SC_SPC_HPP_ */ 68 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SC/Pattern_polar_SC_std.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SC_STANDARD_HPP_ 2 | #define PATTERN_POLAR_SC_STANDARD_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SC_std : public Pattern_polar_std 11 | { 12 | protected: 13 | Pattern_polar_SC_std(const int &N, const Binary_node* node) 14 | : Pattern_polar_std(N, node) 15 | { 16 | } 17 | 18 | public: 19 | Pattern_polar_SC_std() : Pattern_polar_std() {} 20 | 21 | virtual ~Pattern_polar_SC_std() {} 22 | 23 | virtual Pattern_polar_SC_std* alloc(const int &N, const Binary_node* node) const 24 | { 25 | if (node == nullptr) 26 | return new Pattern_polar_SC_std(); 27 | else 28 | return new Pattern_polar_SC_std(N, node); 29 | } 30 | 31 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 32 | { 33 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 34 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 35 | 36 | auto apply_f = f() + " "; 37 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 38 | 39 | std::stringstream stream; 40 | stream << "API_polar::template " << apply_f << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 41 | << " " 42 | << "l, " 43 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 44 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 45 | << spaces << " " 46 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 47 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 48 | 49 | return stream.str(); 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 55 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 56 | 57 | auto apply_g = g() + " "; 58 | 59 | std::stringstream stream; 60 | stream << "API_polar::template " << apply_g << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 61 | << "s, " 62 | << "l, " 63 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 64 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 65 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 66 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 67 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 68 | 69 | return stream.str(); 70 | } 71 | 72 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 73 | { 74 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 75 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 76 | 77 | auto apply_xo = h() + " "; 78 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 79 | 80 | std::stringstream stream; 81 | stream << "API_polar::template " << apply_xo << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 82 | << "s, " 83 | << " " 84 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 85 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 86 | << spaces << " " 87 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 88 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 89 | 90 | return stream.str(); 91 | } 92 | }; 93 | } 94 | } 95 | 96 | #endif /* PATTERN_POLAR_SC_STANDARD_HPP_ */ 97 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_r0.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_RATE_0_HPP_ 2 | #define PATTERN_POLAR_SCL_RATE_0_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_r0 : public Pattern_polar_r0 11 | { 12 | protected: 13 | Pattern_polar_SCL_r0(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r0(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SCL_r0(const int min_level = 0, const int max_level = -1) 21 | : Pattern_polar_r0(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SCL_r0() {} 24 | 25 | virtual Pattern_polar_SCL_r0* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SCL_r0(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SCL_r0(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 46 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 47 | 48 | std::stringstream stream; 49 | stream << si << "this->template update_paths_r0<" << this->rev_depth << ", " << this->size << ">(" 50 | << str_off_l << ", " 51 | << str_off_s << ");" 52 | << std::endl; 53 | stream << si << "normalize_scl_metrics(this->metrics, this->L);" << std::endl; 54 | 55 | return stream.str(); 56 | } 57 | }; 58 | } 59 | } 60 | 61 | #endif /* PATTERN_POLAR_SCL_RATE_0_HPP_ */ 62 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_r0_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_RATE_0_LEFT_HPP_ 2 | #define PATTERN_POLAR_SCL_RATE_0_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_r0_left : public Pattern_polar_r0_left 11 | { 12 | protected: 13 | Pattern_polar_SCL_r0_left(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_r0_left(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SCL_r0_left(const int min_level = 1, const int max_level = -1) 21 | : Pattern_polar_r0_left(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SCL_r0_left() {} 24 | 25 | virtual Pattern_polar_SCL_r0_left* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SCL_r0_left(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SCL_r0_left(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 36 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 37 | 38 | std::stringstream stream; 39 | if (node->get_depth() == 0) // root node 40 | { 41 | return ""; 42 | } 43 | else 44 | { 45 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 46 | << si << "{" << std::endl 47 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 48 | << si << this->tab << "const auto parent = l[this->path_2_array [path][" << this->rev_depth << " ]].data();" << std::endl 49 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 50 | << si << this->tab << "API_polar::template " << this->f() << "<" << this->si_2 << ">(" 51 | << "parent + " << str_off_l << ", " 52 | << "parent + " << str_off_l << " + " << this->si_2 << ", " 53 | << "child + " << str_off_l << " + " << this->size << ", " 54 | << this->si_2 << ");" << std::endl 55 | << si << "}" << std::endl; 56 | } 57 | 58 | return stream.str(); 59 | } 60 | 61 | virtual std::string apply_g(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 62 | { 63 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 64 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 65 | 66 | std::stringstream stream; 67 | if (node->get_depth() == 0) // root node 68 | { 69 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 70 | << si << "{" << std::endl 71 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 72 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 73 | << si << this->tab << "API_polar::template " << this->g() << "<" << this->si_2 << ">(" 74 | << "y, " 75 | << "y + " << this->si_2 << ", " 76 | << "child, " 77 | << this->si_2 << ");" << std::endl 78 | << si << "}" << std::endl; 79 | } 80 | else 81 | { 82 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 83 | << si << "{" << std::endl 84 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 85 | << si << this->tab << "const auto parent = l[this->path_2_array [path][" << this->rev_depth << " ]].data();" << std::endl 86 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 87 | << si << this->tab << "API_polar::template " << this->g() << "<" << this->si_2 << ">(" 88 | << "parent + " << str_off_l << ", " 89 | << "parent + " << str_off_l << " + " << this->si_2 << ", " 90 | << "child + " << str_off_l << " + " << this->size << ", " 91 | << this->si_2 << ");" << std::endl 92 | << si << "}" << std::endl; 93 | } 94 | 95 | return stream.str(); 96 | } 97 | 98 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 99 | { 100 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 101 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 102 | 103 | std::stringstream stream; 104 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 105 | << si << "{" << std::endl 106 | << si << this->tab << "API_polar::template " << this->h() << "<" << this->si_2 << ">(" 107 | << "s[this->paths[i]], " 108 | << str_off_s << " + " << this->si_2 << ", " 109 | << str_off_s << ", " 110 | << this->si_2 << ");" << std::endl 111 | << si << "}" << std::endl; 112 | 113 | return stream.str(); 114 | } 115 | }; 116 | } 117 | } 118 | 119 | #endif /* PATTERN_POLAR_SCL_RATE_0_LEFT_HPP_ */ 120 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_r1.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_RATE_1_HPP_ 2 | #define PATTERN_POLAR_SCL_RATE_1_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_r1 : public Pattern_polar_r1 11 | { 12 | protected: 13 | Pattern_polar_SCL_r1(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r1(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SCL_r1(const int min_level = 0, const int max_level = -1) 21 | : Pattern_polar_r1(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SCL_r1() {} 24 | 25 | virtual Pattern_polar_SCL_r1* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SCL_r1(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SCL_r1(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 46 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 47 | 48 | std::stringstream stream; 49 | stream << si << "this->template update_paths_r1<" << this->rev_depth << ", " << this->size << ">(" 50 | << str_off_l << ", " 51 | << str_off_s << ");" 52 | << std::endl; 53 | stream << si << "normalize_scl_metrics(this->metrics, this->L);" << std::endl; 54 | 55 | return stream.str(); 56 | } 57 | }; 58 | } 59 | } 60 | 61 | #endif /* PATTERN_POLAR_SCL_RATE_1_HPP_ */ 62 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_rep.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_REP_HPP_ 2 | #define PATTERN_POLAR_SCL_REP_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_rep : public Pattern_polar_rep 11 | { 12 | protected: 13 | Pattern_polar_SCL_rep(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_rep(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SCL_rep(const int min_level = 1, const int max_level = -1) 21 | : Pattern_polar_rep(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SCL_rep() {} 24 | 25 | virtual Pattern_polar_SCL_rep* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SCL_rep(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SCL_rep(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 46 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 47 | 48 | std::stringstream stream; 49 | stream << si << "this->template update_paths_rep<" << this->rev_depth << ", " << this->size << ">(" 50 | << str_off_l << ", " 51 | << str_off_s << ");" 52 | << std::endl; 53 | stream << si << "normalize_scl_metrics(this->metrics, this->L);" << std::endl; 54 | 55 | return stream.str(); 56 | } 57 | }; 58 | } 59 | } 60 | 61 | #endif /* PATTERN_POLAR_SCL_REP_HPP_ */ 62 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_rep_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_REP_LEFT_HPP_ 2 | #define PATTERN_POLAR_SCL_REP_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_rep_left : public Pattern_polar_rep_left 11 | { 12 | protected: 13 | Pattern_polar_SCL_rep_left(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_rep_left(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SCL_rep_left(const int min_level = 2, const int max_level = -1) 21 | : Pattern_polar_rep_left(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SCL_rep_left() {} 24 | 25 | virtual Pattern_polar_SCL_rep_left* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SCL_rep_left(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SCL_rep_left(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 36 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 37 | 38 | std::stringstream stream; 39 | if (node->get_depth() == 0) // root node 40 | { 41 | stream << si << "API_polar::template " << this->f() << "<" << this->si_2 << ">(" 42 | << "y, " 43 | << "y + " << this->si_2 << ", " 44 | << "l[0].data(), " 45 | << this->si_2 << ");" << std::endl; 46 | } 47 | else 48 | { 49 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 50 | << si << "{" << std::endl 51 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 52 | << si << this->tab << "const auto parent = l[this->path_2_array [path][" << this->rev_depth << " ]].data();" << std::endl 53 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 54 | << si << this->tab << "API_polar::template " << this->f() << "<" << this->si_2 << ">(" 55 | << "parent + " << str_off_l << ", " 56 | << "parent + " << str_off_l << " + " << this->si_2 << ", " 57 | << "child + " << str_off_l << " + " << this->size << ", " 58 | << this->si_2 << ");" << std::endl 59 | << si << "}" << std::endl; 60 | } 61 | 62 | return stream.str(); 63 | } 64 | 65 | virtual std::string apply_g(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 66 | { 67 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 68 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 69 | 70 | std::stringstream stream; 71 | if (node->get_depth() == 0) // root node 72 | { 73 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 74 | << si << "{" << std::endl 75 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 76 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 77 | << si << this->tab << "API_polar::template " << this->g() << "<" << this->si_2 << ">(" 78 | << "y, " 79 | << "y + " << this->si_2 << ", " 80 | << "s[path].data() + " << str_off_s << ", " 81 | << "child, " 82 | << this->si_2 << ");" << std::endl 83 | << si << "}" << std::endl; 84 | } 85 | else 86 | { 87 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 88 | << si << "{" << std::endl 89 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 90 | << si << this->tab << "const auto parent = l[this->path_2_array [path][" << this->rev_depth << " ]].data();" << std::endl 91 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 92 | << si << this->tab << "API_polar::template " << this->g() << "<" << this->si_2 << ">(" 93 | << "parent + " << str_off_l << ", " 94 | << "parent + " << str_off_l << " + " << this->si_2 << ", " 95 | << "s[path].data() + " << str_off_s << ", " 96 | << "child + " << str_off_l << " + " << this->size << ", " 97 | << this->si_2 << ");" << std::endl 98 | << si << "}" << std::endl; 99 | } 100 | 101 | return stream.str(); 102 | } 103 | 104 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 105 | { 106 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 107 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 108 | 109 | std::stringstream stream; 110 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 111 | << si << "{" << std::endl 112 | << si << this->tab << "API_polar::template " << this->h() << "<" << this->si_2 << ">(" 113 | << "s[this->paths[i]], " 114 | << str_off_s << ", " 115 | << str_off_s << " + " << this->si_2 << ", " 116 | << str_off_s << ", " 117 | << this->si_2 << ");" << std::endl 118 | << si << "}" << std::endl; 119 | 120 | return stream.str(); 121 | } 122 | }; 123 | } 124 | } 125 | 126 | #endif /* PATTERN_POLAR_SCL_REP_LEFT_HPP_ */ 127 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_spc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_SPC_HPP_ 2 | #define PATTERN_POLAR_SCL_SPC_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_spc : public Pattern_polar_spc 11 | { 12 | protected: 13 | Pattern_polar_SCL_spc(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_spc(N, node, min_level, max_level) 16 | { 17 | } 18 | 19 | public: 20 | Pattern_polar_SCL_spc(const int min_level = 2, const int max_level = -1) 21 | : Pattern_polar_spc(min_level, max_level) {} 22 | 23 | virtual ~Pattern_polar_SCL_spc() {} 24 | 25 | virtual Pattern_polar_SCL_spc* alloc(const int &N, const Binary_node* node) const 26 | { 27 | if (node == nullptr) 28 | return new Pattern_polar_SCL_spc(this->min_level, this->max_level); 29 | else 30 | return new Pattern_polar_SCL_spc(N, node, this->min_level, this->max_level); 31 | } 32 | 33 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 34 | { 35 | return ""; 36 | } 37 | 38 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 39 | { 40 | return ""; 41 | } 42 | 43 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 44 | { 45 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 46 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 47 | 48 | std::stringstream stream; 49 | stream << si << "this->template update_paths_spc<" << this->rev_depth << ", " << this->size << ">(" 50 | << str_off_l << ", " 51 | << str_off_s << ");" 52 | << std::endl; 53 | stream << si << "normalize_scl_metrics(this->metrics, this->L);" << std::endl; 54 | 55 | return stream.str(); 56 | } 57 | }; 58 | } 59 | } 60 | 61 | #endif /* PATTERN_POLAR_SCL_SPC_HPP_ */ 62 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/GPP/SCL/Pattern_polar_SCL_std.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_SCL_STANDARD_HPP_ 2 | #define PATTERN_POLAR_SCL_STANDARD_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_SCL_std : public Pattern_polar_std 11 | { 12 | protected: 13 | Pattern_polar_SCL_std(const int &N, const Binary_node* node) 14 | : Pattern_polar_std(N, node) 15 | { 16 | } 17 | 18 | public: 19 | Pattern_polar_SCL_std() : Pattern_polar_std() {} 20 | 21 | virtual ~Pattern_polar_SCL_std() {} 22 | 23 | virtual Pattern_polar_SCL_std* alloc(const int &N, const Binary_node* node) const 24 | { 25 | if (node == nullptr) 26 | return new Pattern_polar_SCL_std(); 27 | else 28 | return new Pattern_polar_SCL_std(N, node); 29 | } 30 | 31 | virtual std::string apply_f(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 32 | { 33 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 34 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 35 | 36 | std::stringstream stream; 37 | if (node->get_depth() == 0) // root node 38 | { 39 | stream << si << "API_polar::template " << this->f() << "<" << this->si_2 << ">(" 40 | << "y, " 41 | << "y + " << this->si_2 << ", " 42 | << "l[0].data(), " 43 | << this->si_2 << ");" << std::endl; 44 | } 45 | else 46 | { 47 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 48 | << si << "{" << std::endl 49 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 50 | << si << this->tab << "const auto parent = l[this->path_2_array [path][" << this->rev_depth << " ]].data();" << std::endl 51 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 52 | << si << this->tab << "API_polar::template " << this->f() << "<" << this->si_2 << ">(" 53 | << "parent + " << str_off_l << ", " 54 | << "parent + " << str_off_l << " + " << this->si_2 << ", " 55 | << "child + " << str_off_l << " + " << this->size << ", " 56 | << this->si_2 << ");" << std::endl 57 | << si << "}" << std::endl; 58 | } 59 | 60 | return stream.str(); 61 | } 62 | 63 | virtual std::string apply_g(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 64 | { 65 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 66 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 67 | 68 | std::stringstream stream; 69 | if (node->get_depth() == 0) // root node 70 | { 71 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 72 | << si << "{" << std::endl 73 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 74 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 75 | << si << this->tab << "API_polar::template " << this->g() << "<" << this->si_2 << ">(" 76 | << "y, " 77 | << "y + " << this->si_2 << ", " 78 | << "s[path].data() + " << str_off_s << ", " 79 | << "child, " 80 | << this->si_2 << ");" << std::endl 81 | << si << "}" << std::endl; 82 | } 83 | else 84 | { 85 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 86 | << si << "{" << std::endl 87 | << si << this->tab << "const auto path = this->paths[i];" << std::endl 88 | << si << this->tab << "const auto parent = l[this->path_2_array [path][" << this->rev_depth << " ]].data();" << std::endl 89 | << si << this->tab << "const auto child = l[this->up_ref_array_idx(path, " << this->rev_depth << " -1)].data();" << std::endl 90 | << si << this->tab << "API_polar::template " << this->g() << "<" << this->si_2 << ">(" 91 | << "parent + " << str_off_l << ", " 92 | << "parent + " << str_off_l << " + " << this->si_2 << ", " 93 | << "s[path].data() + " << str_off_s << ", " 94 | << "child + " << str_off_l << " + " << this->size << ", " 95 | << this->si_2 << ");" << std::endl 96 | << si << "}" << std::endl; 97 | } 98 | 99 | return stream.str(); 100 | } 101 | 102 | virtual std::string apply_h(std::string si = "", std::string str_off_l = "", std::string str_off_s = "") const 103 | { 104 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l - this->N); 105 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s ); 106 | 107 | std::stringstream stream; 108 | stream << si << "for (auto i = 0; i < this->n_active_paths; i++) " << std::endl 109 | << si << "{" << std::endl 110 | << si << this->tab << "API_polar::template " << this->h() << "<" << this->si_2 << ">(" 111 | << "s[this->paths[i]], " 112 | << str_off_s << ", " 113 | << str_off_s << " + " << this->si_2 << ", " 114 | << str_off_s << ", " 115 | << this->si_2 << ");" << std::endl 116 | << si << "}" << std::endl; 117 | 118 | return stream.str(); 119 | } 120 | }; 121 | } 122 | } 123 | 124 | #endif /* PATTERN_POLAR_SCL_STANDARD_HPP_ */ 125 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/Pattern_polar_tile.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_RATE_TILE_HPP_ 2 | #define PATTERN_POLAR_RATE_TILE_HPP_ 3 | 4 | namespace aff3ct 5 | { 6 | namespace tools 7 | { 8 | class Pattern_polar_tile : public Pattern_polar_i 9 | { 10 | public: 11 | const uint8_t TILE = static_cast(polar_node_t::SPC) +1; 12 | 13 | protected: 14 | Pattern_polar_tile(const int &N, const Binary_node* node, 15 | const int min_level = 3, const int max_level = 3) 16 | : Pattern_polar_i(N, node, min_level, max_level) 17 | { 18 | auto n_elm_2 = this->N / 2; 19 | auto local_off_l = 0; 20 | 21 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 22 | { 23 | if ((n_elm_2 * 2) > 64) 24 | local_off_l += n_elm_2 * 2; 25 | else 26 | local_off_l += 64; 27 | n_elm_2 /= 2; 28 | } 29 | 30 | const int *p_off_l = &off_l; 31 | *const_cast(p_off_l) = local_off_l; 32 | } 33 | 34 | public: 35 | Pattern_polar_tile(const int level = 3) 36 | : Pattern_polar_i(level, level) 37 | { 38 | } 39 | 40 | virtual Pattern_polar_tile* alloc(const int &N, const Binary_node* node) const 41 | { 42 | if (node == nullptr) 43 | return new Pattern_polar_tile(min_level); 44 | else 45 | return new Pattern_polar_tile(N, node, min_level, max_level); 46 | } 47 | 48 | virtual ~Pattern_polar_tile() {} 49 | 50 | virtual polar_node_t type() const { return static_cast(TILE); } 51 | virtual std::string name() const { return "Tile"; } 52 | virtual std::string short_name() const { return "t"; } 53 | virtual std::string fill_color() const { return "#AD7FA8"; } 54 | virtual std::string font_color() const { return "#FFFFFF"; } 55 | 56 | virtual std::string f() const { return ""; } 57 | virtual std::string g() const { return ""; } 58 | virtual std::string h() const { return ""; } 59 | 60 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 61 | { 62 | std::stringstream stream; 63 | 64 | stream << "_TCE_POLAR_TILE8(l_c, f_b[" << (this->off_s >> 3) << "], s[" << (this->off_s >> 6) << "][" << ((this->off_s >> 3) & 7) << "]);"; 65 | stream << std::endl; 66 | 67 | return stream.str(); 68 | } 69 | 70 | virtual int _match(const int &reverse_graph_depth, const Binary_node* node_curr) const 71 | { 72 | return (reverse_graph_depth == 3) ? 30 : 0; 73 | } 74 | 75 | virtual bool is_terminal() const { return true; } 76 | }; 77 | } 78 | } 79 | 80 | #endif /* PATTERN_POLAR_RATE_TILE_HPP_ */ 81 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/Pattern_polar_tile_scan.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_RATE_TILE_SCAN_HPP_ 2 | #define PATTERN_POLAR_RATE_TILE_SCAN_HPP_ 3 | 4 | namespace aff3ct 5 | { 6 | namespace tools 7 | { 8 | class Pattern_polar_tile_scan : public Pattern_polar_i 9 | { 10 | public: 11 | const uint8_t TILE = static_cast(polar_node_t::SPC) +1; 12 | 13 | protected: 14 | Pattern_polar_tile_scan(const int &N, const Binary_node* node, 15 | const int min_level = 3, const int max_level = 3) 16 | : Pattern_polar_i(N, node, min_level, max_level) 17 | { 18 | auto n_elm_2 = this->N / 2; 19 | auto local_off_l = 0; 20 | 21 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 22 | { 23 | if ((n_elm_2 * 2) > 64) 24 | local_off_l += n_elm_2 * 2; 25 | else 26 | local_off_l += 64; 27 | n_elm_2 /= 2; 28 | } 29 | 30 | const int *p_off_l = &off_l; 31 | *const_cast(p_off_l) = local_off_l; 32 | } 33 | 34 | public: 35 | Pattern_polar_tile_scan(const int level = 3) 36 | : Pattern_polar_i(level, level) 37 | { 38 | } 39 | 40 | virtual Pattern_polar_tile_scan* alloc(const int &N, const Binary_node* node) const 41 | { 42 | if (node == nullptr) 43 | return new Pattern_polar_tile_scan(min_level); 44 | else 45 | return new Pattern_polar_tile_scan(N, node, min_level, max_level); 46 | } 47 | 48 | virtual ~Pattern_polar_tile_scan() {} 49 | 50 | virtual polar_node_t type() const { return static_cast(TILE); } 51 | virtual std::string name() const { return "Tile"; } 52 | virtual std::string short_name() const { return "t"; } 53 | virtual std::string fill_color() const { return "#AD7FA8"; } 54 | virtual std::string font_color() const { return "#FFFFFF"; } 55 | 56 | virtual std::string f() const { return ""; } 57 | virtual std::string g() const { return ""; } 58 | virtual std::string h() const { return ""; } 59 | 60 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 61 | { 62 | std::stringstream stream; 63 | stream << tab << "_TCE_LDOFF(" << this->off_l << ", l_a);" << std::endl; 64 | stream << tab << tab << "_TCE_LDOFF_B(" << (this->m - this->rev_depth) * this->N + ((this->off_s * 4) & 0x7) << ", b_a);" << std::endl; 65 | stream << tab << tab << "_TCE_POLAR_TILE8_SCAN(l_a, b_a, " << ((this->off_s % 16) ? 1 : 0) << ", b_a);" << std::endl; 66 | stream << tab << tab << "_TCE_STOFF_B(" << (this->m - this->rev_depth) * this->N + ((this->off_s * 4) & 0x7) << ", b_a);" << std::endl; 67 | 68 | return stream.str(); 69 | } 70 | 71 | virtual int _match(const int &reverse_graph_depth, const Binary_node* node_curr) const 72 | { 73 | return (reverse_graph_depth == 3) ? 30 : 0; 74 | } 75 | 76 | virtual bool is_terminal() const { return true; } 77 | }; 78 | } 79 | } 80 | 81 | #endif /* PATTERN_POLAR_RATE_TILE_SCAN_HPP_ */ 82 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_r0.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_RATE_0_HPP_ 2 | #define PATTERN_POLAR_TTA_SC_RATE_0_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_r0 : public Pattern_polar_r0 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_r0(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r0(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SC_r0(const int min_level = 0, const int max_level = -1) 35 | : Pattern_polar_r0(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SC_r0() {} 38 | 39 | virtual Pattern_polar_TTA_SC_r0* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SC_r0(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SC_r0(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | return ""; 55 | } 56 | 57 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 58 | { 59 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 60 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 61 | 62 | std::stringstream stream; 63 | int code = (2 << 16) | (this->size >> 3); 64 | 65 | if (this->size <= 64) 66 | { 67 | stream << "_TCE_POLAR_LEAF(l_c, s[" << (this->off_s >> 6) << "], " << (this->off_s >> 3); 68 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << (this->off_s >> 6) << "]);"; 69 | stream << std::endl; 70 | } 71 | else // n_elm 72 | { 73 | for ( auto i = 0; (64 * i) < this->size; i++) 74 | { 75 | if(i) 76 | stream << tab; 77 | stream << "_TCE_LDOFF(" << (this->off_l + i * 64) << ", l_a);" << std::endl; 78 | stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << ((this->off_s >> 6) + i) << "], " << (this->off_s >> 3); 79 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << ((this->off_s >> 6) + i) << "]);"; 80 | stream << std::endl; 81 | } 82 | } 83 | 84 | 85 | return stream.str(); 86 | } 87 | }; 88 | } 89 | } 90 | 91 | #endif /* PATTERN_POLAR_TTA_SC_RATE_0_HPP_ */ 92 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_r0_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_RATE_0_LEFT_HPP_ 2 | #define PATTERN_POLAR_TTA_SC_RATE_0_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_r0_left : public Pattern_polar_r0_left 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_r0_left(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_r0_left(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SC_r0_left(const int min_level = 1, const int max_level = -1) 35 | : Pattern_polar_r0_left(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SC_r0_left() {} 38 | 39 | virtual Pattern_polar_TTA_SC_r0_left* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SC_r0_left(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SC_r0_left(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 55 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 56 | 57 | std::stringstream stream; 58 | 59 | if (this->si_2 <= 64) 60 | { 61 | // TODO only one load ? 62 | stream << "_TCE_LDOFF(" << this->off_l << ", l_a);" << std::endl; 63 | 64 | if (this->si_2 == 64) 65 | stream << tab << "_TCE_LDOFF(" << this->off_l + 64 << ", l_b);" << std::endl; 66 | else if (this->si_2 == 32) 67 | stream << tab << "_TCE_LDOFF_8X32(" << this->off_l + 32 << ", l_b);" << std::endl; 68 | else if (this->si_2 == 16) 69 | stream << tab << "_TCE_LDOFF_8X16(" << this->off_l + 16 << ", l_b);" << std::endl; 70 | else if (this->si_2 == 8) 71 | stream << tab << "_TCE_LDOFF_8X8(" << this->off_l + 8 << ", l_b);" << std::endl; 72 | 73 | if (this->si_2 != 64) 74 | stream << tab << "_TCE_ALIGN_8X8(s[" << (off_s >> 6) << "]," << ((off_s >> 3) & 7) << ", temp_s);" << std::endl; 75 | else 76 | stream << tab << "_TCE_POLAR_G8X64(l_a, l_b, s[" << (off_s >> 6) << "], l_c);" << std::endl; 77 | 78 | stream << tab << "_TCE_POLAR_G8X64(l_a, l_b, temp_s, l_c);" << std::endl; 79 | if (! this->node->get_right()->get_c()->is_terminal()) 80 | { 81 | if (this->si_2 != 64) 82 | stream << tab << "_TCE_STOFF(" << this->off_l + 64 << ", l_c);" << std::endl; 83 | else 84 | stream << tab << "_TCE_STOFF(" << this->off_l + this->size << ", l_c);" << std::endl; 85 | } 86 | // TODO do not store if last leaf 87 | } 88 | else // n_elm 89 | { 90 | for (auto i = 0; i < this->si_2; i += 64) 91 | { if (i) 92 | stream << tab; 93 | stream << "_TCE_LDOFF(" << this->off_l + i << ", l_a);" << std::endl; 94 | stream << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_b);" << std::endl; 95 | stream << tab << "_TCE_POLAR_G8X64(l_a, l_b, s[" << ((off_s >> 6) + (i >> 6)) << "], l_c);" << std::endl; 96 | stream << tab << "_TCE_STOFF(" << this->off_l + i + this->size << ", l_c);" << std::endl; 97 | } 98 | } 99 | 100 | 101 | return stream.str(); 102 | } 103 | 104 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 105 | { 106 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 107 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 108 | 109 | std::stringstream stream; 110 | if (this->si_2 < 64) 111 | { 112 | stream << "_TCE_PS_COMBINE(s[" << (off_s >> 6) << "]," << (off_s >> 3) << ", " << (this->si_2 >> 3) <<", "; 113 | stream << "s[" << (off_s >> 6) << "]);" << std::endl; 114 | } 115 | else 116 | { 117 | for (auto i = 0; i < (this->si_2 >> 6); i++) 118 | { 119 | if(i) 120 | stream << tab; 121 | stream << "temp_s"; 122 | stream << " = "; 123 | stream << "s[" << (this->off_s >> 6) + i << "]"; 124 | stream << " ^ "; 125 | stream << "s[" << (((this->off_s + + this->si_2) >> 6) + i) << "];" << std::endl; 126 | 127 | 128 | stream << tab << "s[" << (this->off_s >> 6) + i << "]"; 129 | stream << " = "; 130 | stream << "temp_s;" << std::endl; 131 | 132 | } 133 | } 134 | 135 | return stream.str(); 136 | } 137 | }; 138 | } 139 | } 140 | 141 | #endif /* PATTERN_POLAR_TTA_SC_RATE_0_LEFT_HPP_ */ 142 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_r1.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_RATE_1_HPP_ 2 | #define PATTERN_POLAR_TTA_SC_RATE_1_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_r1 : public Pattern_polar_r1 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_r1(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r1(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SC_r1(const int min_level = 0, const int max_level = -1) 35 | : Pattern_polar_r1(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SC_r1() {} 38 | 39 | virtual Pattern_polar_TTA_SC_r1* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SC_r1(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SC_r1(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | return ""; 55 | } 56 | 57 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 58 | { 59 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 60 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 61 | 62 | std::stringstream stream; 63 | int code = (3 << 16) | (this->size >> 3); 64 | 65 | if (this->size <= 64) 66 | { 67 | stream << "_TCE_POLAR_LEAF(l_c, s[" << (this->off_s >> 6) << "], " << (this->off_s >> 3); 68 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << (this->off_s >> 6) << "]);"; 69 | stream << std::endl; 70 | } 71 | else // n_elm 72 | { 73 | for ( auto i = 0; (64 * i) < this->size; i++) 74 | { 75 | if(i) 76 | stream << tab; 77 | stream << "_TCE_LDOFF(" << (this->off_l + i * 64) << ", l_a);" << std::endl; 78 | stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << ((this->off_s >> 6) + i) << "], " << (this->off_s >> 3); 79 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << ((this->off_s >> 6) + i) << "]);"; 80 | stream << std::endl; 81 | } 82 | } 83 | 84 | return stream.str(); 85 | } 86 | }; 87 | } 88 | } 89 | 90 | #endif /* PATTERN_POLAR_TTA_SC_RATE_1_HPP_ */ 91 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_rep.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_REP_HPP 2 | #define PATTERN_POLAR_TTA_SC_REP_HPP 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_rep : public Pattern_polar_rep 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_rep(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_rep(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SC_rep(const int min_level = 1, const int max_level = -1) 35 | : Pattern_polar_rep(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SC_rep() {} 38 | 39 | virtual Pattern_polar_TTA_SC_rep* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SC_rep(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SC_rep(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const { 48 | return ""; 49 | } 50 | 51 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 52 | { 53 | return ""; 54 | } 55 | 56 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 57 | { 58 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 59 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 60 | 61 | auto apply_rep = h(); 62 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 63 | 64 | std::stringstream stream; 65 | stream << "API_polar::template " << apply_rep << "<" << std::setw(this->n2_dig) << this->size << ">(" 66 | << "s, " 67 | << "l, " 68 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 69 | << spaces << " " 70 | << spaces << " " 71 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 72 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 73 | 74 | return stream.str(); 75 | } 76 | }; 77 | } 78 | } 79 | 80 | #endif /* PATTERN_POLAR_TTA_SC_REP_HPP */ 81 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_rep_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_REP_LEFT_HPP_ 2 | #define PATTERN_POLAR_TTA_SC_REP_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_rep_left : public Pattern_polar_rep_left 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_rep_left(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_rep_left(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SC_rep_left(const int min_level = 2, const int max_level = -1) 35 | : Pattern_polar_rep_left(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SC_rep_left() {} 38 | 39 | virtual Pattern_polar_TTA_SC_rep_left* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SC_rep_left(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SC_rep_left(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | // using namespace std; 50 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 51 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 52 | 53 | auto apply_f = f() + " "; 54 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 55 | 56 | std::stringstream stream; 57 | stream << "API_polar::template " << apply_f << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 58 | << " " 59 | << "l, " 60 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 61 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 62 | << spaces << " " 63 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 64 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 65 | 66 | return stream.str(); 67 | } 68 | 69 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 70 | { 71 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 72 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 73 | 74 | auto apply_gr = g() + " "; 75 | 76 | std::stringstream stream; 77 | stream << "API_polar::template " << apply_gr << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 78 | << "s, " 79 | << "l, " 80 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 81 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 82 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 83 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 84 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 85 | 86 | return stream.str(); 87 | } 88 | 89 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 90 | { 91 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 92 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 93 | 94 | auto apply_xo = h() + " "; 95 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 96 | 97 | std::stringstream stream; 98 | stream << "API_polar::template " << apply_xo << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 99 | << "s, " 100 | << " " 101 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 102 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 103 | << spaces << " " 104 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 105 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 106 | 107 | return stream.str(); 108 | } 109 | }; 110 | } 111 | } 112 | 113 | #endif /* PATTERN_POLAR_TTA_SC_REP_LEFT_HPP_ */ 114 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_spc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_SPC_HPP_ 2 | #define PATTERN_POLAR_TTA_SC_SPC_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_spc : public Pattern_polar_spc 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_spc(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_spc(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SC_spc(const int min_level = 2, const int max_level = -1) 35 | : Pattern_polar_spc(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SC_spc() {} 38 | 39 | virtual Pattern_polar_TTA_SC_spc* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SC_spc(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SC_spc(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | return ""; 55 | } 56 | 57 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 58 | { 59 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 60 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 61 | 62 | auto apply_spc = h(); 63 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 64 | 65 | std::stringstream stream; 66 | stream << "API_polar::template " << apply_spc << "<" << std::setw(this->n2_dig) << this->size << ">(" 67 | << "s, " 68 | << "l, " 69 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 70 | << spaces << " " 71 | << spaces << " " 72 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 73 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 74 | 75 | return stream.str(); 76 | } 77 | }; 78 | } 79 | } 80 | 81 | #endif /* PATTERN_POLAR_TTA_SC_SPC_HPP_ */ 82 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SC/Pattern_polar_TTA_SC_std.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SC_STANDARD_HPP_ 2 | #define PATTERN_POLAR_TTA_SC_STANDARD_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SC_std : public Pattern_polar_std 11 | { 12 | protected: 13 | Pattern_polar_TTA_SC_std(const int &N, const Binary_node* node) 14 | : Pattern_polar_std(N, node) 15 | { 16 | auto n_elm_2 = this->N / 2; 17 | auto local_off_l = 0; 18 | 19 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 20 | { 21 | if ((n_elm_2 * 2) > 64) 22 | local_off_l += n_elm_2 * 2; 23 | else 24 | local_off_l += 64; 25 | n_elm_2 /= 2; 26 | } 27 | 28 | const int *p_off_l = &off_l; 29 | *const_cast(p_off_l) = local_off_l; 30 | } 31 | 32 | public: 33 | Pattern_polar_TTA_SC_std() : Pattern_polar_std() {} 34 | 35 | virtual ~Pattern_polar_TTA_SC_std() {} 36 | 37 | virtual Pattern_polar_TTA_SC_std* alloc(const int &N, const Binary_node* node) const 38 | { 39 | if (node == nullptr) 40 | return new Pattern_polar_TTA_SC_std(); 41 | else 42 | return new Pattern_polar_TTA_SC_std(N, node); 43 | } 44 | 45 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 46 | { 47 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 48 | 49 | std::stringstream stream; 50 | 51 | if (this->si_2 <= 64) 52 | { 53 | // TODO only one load ? 54 | stream << "_TCE_LDOFF(" << this->off_l << ", l_a);" << std::endl; 55 | if (this->si_2 == 64) 56 | stream << tab << "_TCE_LDOFF(" << this->off_l + 64 << ", l_b);" << std::endl; 57 | else if (this->si_2 == 32) 58 | stream << tab << "_TCE_LDOFF_8X32(" << this->off_l + 32 << ", l_b);" << std::endl; 59 | else if (this->si_2 == 16) 60 | stream << tab << "_TCE_LDOFF_8X16(" << this->off_l + 16 << ", l_b);" << std::endl; 61 | else if (this->si_2 == 8) 62 | stream << tab << "_TCE_LDOFF_8X8(" << this->off_l + 8 << ", l_b);" << std::endl; 63 | stream << tab << "_TCE_POLAR_F8X64(l_a, l_b, l_c);" << std::endl; 64 | if (! this->node->get_left()->get_c()->is_terminal()) 65 | { 66 | if (this->si_2 == 64) 67 | stream << tab << "_TCE_STOFF(" << this->off_l + this->size << ", l_c);" << std::endl; 68 | else 69 | stream << tab << "_TCE_STOFF(" << this->off_l + 64 << ", l_c);" << std::endl; 70 | } 71 | } 72 | else // n_elm 73 | { 74 | for (auto i = 0; i < this->si_2; i += 64) 75 | { if (i) 76 | stream << tab; 77 | stream << "_TCE_LDOFF(" << this->off_l + i << ", l_a);" << std::endl; 78 | stream << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_b);" << std::endl; 79 | stream << tab << "_TCE_POLAR_F8X64(l_a, l_b, l_c);" << std::endl; 80 | stream << tab << "_TCE_STOFF(" << this->off_l + i + this->size << ", l_c);" << std::endl; 81 | } 82 | } 83 | 84 | 85 | return stream.str(); 86 | } 87 | 88 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 89 | { 90 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 91 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 92 | 93 | std::stringstream stream; 94 | 95 | if (this->si_2 <= 64) 96 | { 97 | // TODO only one load ? 98 | stream << "_TCE_LDOFF(" << this->off_l << ", l_a);" << std::endl; 99 | 100 | if (this->si_2 == 64) 101 | stream << tab << "_TCE_LDOFF(" << this->off_l + 64 << ", l_b);" << std::endl; 102 | else if (this->si_2 == 32) 103 | stream << tab << "_TCE_LDOFF_8X32(" << this->off_l + 32 << ", l_b);" << std::endl; 104 | else if (this->si_2 == 16) 105 | stream << tab << "_TCE_LDOFF_8X16(" << this->off_l + 16 << ", l_b);" << std::endl; 106 | else if (this->si_2 == 8) 107 | stream << tab << "_TCE_LDOFF_8X8(" << this->off_l + 8 << ", l_b);" << std::endl; 108 | 109 | if (this->si_2 != 64) 110 | { 111 | stream << tab << "_TCE_ALIGN_8X8(s[" << (off_s >> 6) << "]," << ((off_s >> 3) & 7) << ", temp_s);" << std::endl; 112 | stream << tab << "_TCE_POLAR_G8X64(l_a, l_b, temp_s, l_c);" << std::endl; 113 | if (! this->node->get_right()->get_c()->is_terminal()) 114 | stream << tab << "_TCE_STOFF(" << this->off_l + 64 << ", l_c);" << std::endl; 115 | } 116 | else 117 | { 118 | stream << tab << "_TCE_POLAR_G8X64(l_a, l_b, s[" << (off_s >> 6) << "], l_c);" << std::endl; 119 | if (! this->node->get_right()->get_c()->is_terminal()) 120 | stream << tab << "_TCE_STOFF(" << this->off_l + this->size << ", l_c);" << std::endl; 121 | } 122 | } 123 | else // n_elm 124 | { 125 | for (auto i = 0; i < this->si_2; i += 64) 126 | { if (i) 127 | stream << tab; 128 | stream << "_TCE_LDOFF(" << this->off_l + i << ", l_a);" << std::endl; 129 | stream << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_b);" << std::endl; 130 | stream << tab << "_TCE_POLAR_G8X64(l_a, l_b, s[" << ((off_s >> 6) + (i >> 6)) << "], l_c);" << std::endl; 131 | stream << tab << "_TCE_STOFF(" << this->off_l + i + this->size << ", l_c);" << std::endl; 132 | } 133 | } 134 | 135 | 136 | return stream.str(); 137 | } 138 | 139 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 140 | { 141 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 142 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 143 | 144 | std::stringstream stream; 145 | if (this->si_2 < 64) 146 | { 147 | stream << "_TCE_PS_COMBINE(s[" << (off_s >> 6) << "]," << (off_s >> 3) << ", " << (this->si_2 >> 3) <<", "; 148 | stream << "s[" << (off_s >> 6) << "]);" << std::endl; 149 | } 150 | else 151 | { 152 | for (auto i = 0; i < (this->si_2 >> 6); i++) 153 | { 154 | if(i) 155 | stream << tab; 156 | stream << "temp_s"; 157 | stream << " = "; 158 | stream << "s[" << (this->off_s >> 6) + i << "]"; 159 | stream << " ^ "; 160 | stream << "s[" << (((this->off_s + + this->si_2) >> 6) + i) << "];" << std::endl; 161 | 162 | 163 | stream << tab << "s[" << (this->off_s >> 6) + i << "]"; 164 | stream << " = "; 165 | stream << "temp_s;" << std::endl; 166 | 167 | } 168 | } 169 | 170 | return stream.str(); 171 | } 172 | }; 173 | } 174 | } 175 | 176 | #endif /* PATTERN_POLAR_TTA_SC_STANDARD_HPP_ */ 177 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_r0.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_RATE_0_HPP_ 2 | #define PATTERN_POLAR_TTA_SCAN_RATE_0_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_r0 : public Pattern_polar_r0 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_r0(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r0(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SCAN_r0(const int min_level = 0, const int max_level = -1) 35 | : Pattern_polar_r0(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SCAN_r0() {} 38 | 39 | virtual Pattern_polar_TTA_SCAN_r0* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SCAN_r0(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SCAN_r0(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | return ""; 55 | } 56 | 57 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 58 | { 59 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 60 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 61 | 62 | std::stringstream stream; 63 | int code = (2 << 16) | (this->size >> 3); 64 | 65 | if (this->size < 64) 66 | { 67 | // stream << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 68 | // stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << (this->off_s >> 6) << "], " << (this->off_s >> 3); 69 | // stream << ", 0x" << std::hex << code << std::dec << ", s[" << (this->off_s >> 6) << "]);"; 70 | // stream << std::endl; 71 | } 72 | else // n_elm 73 | { 74 | for ( auto i = 0; (64 * i) < this->size; i++) 75 | { 76 | if(i) 77 | stream << tab; 78 | stream << "_TCE_LDOFF(" << (this->off_l + i * 64) << ", l_a);" << std::endl; 79 | stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << ((this->off_s >> 6) + i) << "], " << (this->off_s >> 3); 80 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << ((this->off_s >> 6) + i) << "]);"; 81 | stream << std::endl; 82 | } 83 | } 84 | 85 | 86 | return stream.str(); 87 | } 88 | }; 89 | } 90 | } 91 | 92 | #endif /* PATTERN_POLAR_TTA_SCAN_RATE_0_HPP_ */ 93 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_r0_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_RATE_0_LEFT_HPP_ 2 | #define PATTERN_POLAR_TTA_SCAN_RATE_0_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_r0_left : public Pattern_polar_r0_left 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_r0_left(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_r0_left(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SCAN_r0_left(const int min_level = 1, const int max_level = -1) 35 | : Pattern_polar_r0_left(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SCAN_r0_left() {} 38 | 39 | virtual Pattern_polar_TTA_SCAN_r0_left* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SCAN_r0_left(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SCAN_r0_left(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | // using namespace std; 55 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 56 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 57 | 58 | auto apply_g0 = g() + " "; 59 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 60 | 61 | std::stringstream stream; 62 | stream << "API_polar::template " << apply_g0 << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 63 | << " " 64 | << "l, " 65 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 66 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 67 | << spaces << " " 68 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 69 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 70 | 71 | return stream.str(); 72 | } 73 | 74 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 75 | { 76 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 77 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 78 | 79 | auto apply_xo0 = h(); 80 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 81 | 82 | std::stringstream stream; 83 | stream << "API_polar::template " << apply_xo0 << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 84 | << "s, " 85 | << " " 86 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 87 | << spaces << " " 88 | << spaces << " " 89 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 90 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 91 | 92 | return stream.str(); 93 | } 94 | }; 95 | } 96 | } 97 | 98 | #endif /* PATTERN_POLAR_TTA_SCAN_RATE_0_LEFT_HPP_ */ 99 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_r1.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_RATE_1_HPP_ 2 | #define PATTERN_POLAR_TTA_SCAN_RATE_1_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_r1 : public Pattern_polar_r1 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_r1(const int &N, const Binary_node* node, 14 | const int min_level = 0, const int max_level = -1) 15 | : Pattern_polar_r1(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SCAN_r1(const int min_level = 0, const int max_level = -1) 35 | : Pattern_polar_r1(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SCAN_r1() {} 38 | 39 | virtual Pattern_polar_TTA_SCAN_r1* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SCAN_r1(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SCAN_r1(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | return ""; 55 | } 56 | 57 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 58 | { 59 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 60 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 61 | 62 | std::stringstream stream; 63 | int code = (3 << 16) | (this->size >> 3); 64 | 65 | if (this->si_2 < 64) 66 | { 67 | stream << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 68 | stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << (this->off_s >> 6) << "], " << (this->off_s >> 3); 69 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << (this->off_s >> 6) << "]);"; 70 | stream << std::endl; 71 | } 72 | else // n_elm 73 | { 74 | for ( auto i = 0; (64 * i) < this->size; i++) 75 | { 76 | if(i) 77 | stream << tab; 78 | stream << "_TCE_LDOFF(" << (this->off_l + i * 64) << ", l_a);" << std::endl; 79 | stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << ((this->off_s >> 6) + i) << "], " << (this->off_s >> 3); 80 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << ((this->off_s >> 6) + i) << "]);"; 81 | stream << std::endl; 82 | } 83 | } 84 | 85 | return stream.str(); 86 | } 87 | }; 88 | } 89 | } 90 | 91 | #endif /* PATTERN_POLAR_TTA_SCAN_RATE_1_HPP_ */ 92 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_rep.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_REP_HPP 2 | #define PATTERN_POLAR_TTA_SCAN_REP_HPP 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_rep : public Pattern_polar_rep 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_rep(const int &N, const Binary_node* node, 14 | const int min_level = 1, const int max_level = -1) 15 | : Pattern_polar_rep(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SCAN_rep(const int min_level = 1, const int max_level = -1) 35 | : Pattern_polar_rep(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SCAN_rep() {} 38 | 39 | virtual Pattern_polar_TTA_SCAN_rep* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SCAN_rep(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SCAN_rep(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const { 48 | return ""; 49 | } 50 | 51 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 52 | { 53 | return ""; 54 | } 55 | 56 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 57 | { 58 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 59 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 60 | 61 | auto apply_rep = h(); 62 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 63 | 64 | std::stringstream stream; 65 | stream << "API_polar::template " << apply_rep << "<" << std::setw(this->n2_dig) << this->size << ">(" 66 | << "s, " 67 | << "l, " 68 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 69 | << spaces << " " 70 | << spaces << " " 71 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 72 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 73 | 74 | return stream.str(); 75 | } 76 | }; 77 | } 78 | } 79 | 80 | #endif /* PATTERN_POLAR_TTA_SCAN_REP_HPP */ 81 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_rep_left.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_REP_LEFT_HPP_ 2 | #define PATTERN_POLAR_TTA_SCAN_REP_LEFT_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_rep_left : public Pattern_polar_rep_left 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_rep_left(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_rep_left(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SCAN_rep_left(const int min_level = 2, const int max_level = -1) 35 | : Pattern_polar_rep_left(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SCAN_rep_left() {} 38 | 39 | virtual Pattern_polar_TTA_SCAN_rep_left* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SCAN_rep_left(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SCAN_rep_left(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | // using namespace std; 50 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 51 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 52 | 53 | auto apply_f = f() + " "; 54 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 55 | 56 | std::stringstream stream; 57 | stream << "API_polar::template " << apply_f << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 58 | << " " 59 | << "l, " 60 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 61 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 62 | << spaces << " " 63 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 64 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 65 | 66 | return stream.str(); 67 | } 68 | 69 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 70 | { 71 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 72 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 73 | 74 | auto apply_gr = g() + " "; 75 | 76 | std::stringstream stream; 77 | stream << "API_polar::template " << apply_gr << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 78 | << "s, " 79 | << "l, " 80 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 81 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 82 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 83 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << this->size << ", " 84 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 85 | 86 | return stream.str(); 87 | } 88 | 89 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 90 | { 91 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 92 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 93 | 94 | auto apply_xo = h() + " "; 95 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 96 | 97 | std::stringstream stream; 98 | stream << "API_polar::template " << apply_xo << "<" << std::setw(this->n2_dig) << this->si_2 << ">(" 99 | << "s, " 100 | << " " 101 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 102 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << this->si_2 << ", " 103 | << spaces << " " 104 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 105 | << std::setw(this->n2_dig) << this->si_2 << ");" << std::endl; 106 | 107 | return stream.str(); 108 | } 109 | }; 110 | } 111 | } 112 | 113 | #endif /* PATTERN_POLAR_TTA_SCAN_REP_LEFT_HPP_ */ 114 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_spc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_SPC_HPP_ 2 | #define PATTERN_POLAR_TTA_SCAN_SPC_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_spc : public Pattern_polar_spc 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_spc(const int &N, const Binary_node* node, 14 | const int min_level = 2, const int max_level = -1) 15 | : Pattern_polar_spc(N, node, min_level, max_level) 16 | { 17 | auto n_elm_2 = this->N / 2; 18 | auto local_off_l = 0; 19 | 20 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 21 | { 22 | if ((n_elm_2 * 2) > 64) 23 | local_off_l += n_elm_2 * 2; 24 | else 25 | local_off_l += 64; 26 | n_elm_2 /= 2; 27 | } 28 | 29 | const int *p_off_l = &off_l; 30 | *const_cast(p_off_l) = local_off_l; 31 | } 32 | 33 | public: 34 | Pattern_polar_TTA_SCAN_spc(const int min_level = 2, const int max_level = -1) 35 | : Pattern_polar_spc(min_level, max_level) {} 36 | 37 | virtual ~Pattern_polar_TTA_SCAN_spc() {} 38 | 39 | virtual Pattern_polar_TTA_SCAN_spc* alloc(const int &N, const Binary_node* node) const 40 | { 41 | if (node == nullptr) 42 | return new Pattern_polar_TTA_SCAN_spc(this->min_level, this->max_level); 43 | else 44 | return new Pattern_polar_TTA_SCAN_spc(N, node, this->min_level, this->max_level); 45 | } 46 | 47 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 48 | { 49 | return ""; 50 | } 51 | 52 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 53 | { 54 | return ""; 55 | } 56 | 57 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 58 | { 59 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 60 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 61 | 62 | auto apply_spc = h(); 63 | std::string spaces = ""; for (auto i = 0; i < 2*this->n_dig+1; i++) spaces += " "; 64 | 65 | std::stringstream stream; 66 | stream << "API_polar::template " << apply_spc << "<" << std::setw(this->n2_dig) << this->size << ">(" 67 | << "s, " 68 | << "l, " 69 | << std::setw(this->n_dig ) << str_off_l << "+" << std::setw(this->n_dig ) << 0 << ", " 70 | << spaces << " " 71 | << spaces << " " 72 | << std::setw(this->n_dig ) << str_off_s << "+" << std::setw(this->n_dig ) << 0 << ", " 73 | << std::setw(this->n2_dig) << this->size << ");" << std::endl; 74 | 75 | return stream.str(); 76 | } 77 | }; 78 | } 79 | } 80 | 81 | #endif /* PATTERN_POLAR_TTA_SCAN_SPC_HPP_ */ 82 | -------------------------------------------------------------------------------- /src/Tools/Code/Polar/Patterns/TTA/SCAN/Pattern_polar_TTA_SCAN_std.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PATTERN_POLAR_TTA_SCAN_STANDARD_HPP_ 2 | #define PATTERN_POLAR_TTA_SCAN_STANDARD_HPP_ 3 | 4 | #include 5 | 6 | namespace aff3ct 7 | { 8 | namespace tools 9 | { 10 | class Pattern_polar_TTA_SCAN_std : public Pattern_polar_std 11 | { 12 | protected: 13 | Pattern_polar_TTA_SCAN_std(const int &N, const Binary_node* node) 14 | : Pattern_polar_std(N, node) 15 | { 16 | auto n_elm_2 = this->N / 2; 17 | auto local_off_l = 0; 18 | 19 | for (auto layer = this->m; layer > (this->m - node->get_depth()); layer--) 20 | { 21 | if ((n_elm_2 * 2) > 64) 22 | local_off_l += n_elm_2 * 2; 23 | else 24 | local_off_l += 64; 25 | n_elm_2 /= 2; 26 | } 27 | 28 | const int *p_off_l = &off_l; 29 | *const_cast(p_off_l) = local_off_l; 30 | } 31 | 32 | public: 33 | Pattern_polar_TTA_SCAN_std() : Pattern_polar_std() {} 34 | 35 | virtual ~Pattern_polar_TTA_SCAN_std() {} 36 | 37 | virtual Pattern_polar_TTA_SCAN_std* alloc(const int &N, const Binary_node* node) const 38 | { 39 | if (node == nullptr) 40 | return new Pattern_polar_TTA_SCAN_std(); 41 | else 42 | return new Pattern_polar_TTA_SCAN_std(N, node); 43 | } 44 | 45 | virtual std::string apply_f(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 46 | { 47 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 48 | 49 | std::stringstream stream; 50 | 51 | if (this->si_2 <= 32) 52 | { 53 | stream << tab << "_TCE_LDOFF(" << str_off_l << ", l_b);" << std::endl; 54 | stream << tab << tab << "_TCE_ROTLELEM_8X64(l_b, " << this->si_2 << ", l_b);" << std::endl; 55 | stream << tab << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 56 | if (this->si_2 == 32) 57 | { 58 | stream << tab << tab << "_TCE_LDOFF_B_8X32(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 << ", b_a);" << std::endl; 59 | } 60 | else if (this->si_2 == 16) 61 | { 62 | stream << tab << tab << "_TCE_LDOFF_B_8X16(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 << ", b_a);" << std::endl; 63 | } 64 | else if (this->si_2 == 8) 65 | { 66 | int off_b = (this->m - this->rev_depth + 1) * this->N + (this->off_s + this->si_2) * 4; 67 | stream << tab << tab << "_TCE_LDOFF_B_8X8(" << off_b << ", b_a);" << std::endl; 68 | } 69 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(l_a, l_b, b_a, l_c);" << std::endl; 70 | stream << tab << tab << "_TCE_STOFF(" << str_off_l << " + 64, l_c);" << std::endl; 71 | } 72 | else // n_elm 73 | { 74 | for (auto i = 0; i < this->si_2; i += 64) 75 | { if (i) 76 | stream << tab; 77 | stream << tab << "_TCE_LDOFF(" << this->off_l + i << ", l_a);" << std::endl; 78 | stream << tab << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_b);" << std::endl; 79 | stream << tab << tab << "_TCE_LDOFF_B(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 + i << ", b_a);" << std::endl; 80 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(l_a, l_b, b_a, l_c);" << std::endl; 81 | stream << tab << tab << "_TCE_STOFF(" << this->off_l + i + this->size << ", l_c);" << std::endl; 82 | } 83 | } 84 | 85 | 86 | return stream.str(); 87 | } 88 | 89 | virtual std::string apply_g(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 90 | { 91 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 92 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 93 | 94 | std::stringstream stream; 95 | if (this->si_2 <= 32) 96 | { 97 | 98 | stream << tab << "_TCE_LDOFF(" << str_off_l << ", l_b);" << std::endl; 99 | stream << tab << tab << "_TCE_ROTLELEM_8X64(l_b, " << this->si_2 << ", l_b);" << std::endl; 100 | stream << tab << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 101 | if (this->si_2 == 32) 102 | { 103 | stream << tab << tab << "_TCE_LDOFF_B_8X32(" << (this->m - this->rev_depth + 1) * this->N + this->off_s << ", b_a);" << std::endl; 104 | } 105 | else if (this->si_2 == 16) 106 | { 107 | stream << tab << tab << "_TCE_LDOFF_B_8X16(" << (this->m - this->rev_depth + 1) * this->N + this->off_s << ", b_a);" << std::endl; 108 | } 109 | else if (this->si_2 == 8) 110 | { 111 | int off_b = (this->m - this->rev_depth + 1) * this->N + this->off_s * 4; 112 | stream << tab << tab << "_TCE_LDOFF_B_8X8(" << off_b << ", b_a);" << std::endl; 113 | } 114 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(l_a, l_b, b_a, l_c);" << std::endl; 115 | stream << tab << tab << "_TCE_STOFF(" << str_off_l << " + 64, l_c);" << std::endl; 116 | } 117 | else // n_elm 118 | { 119 | for (auto i = 0; i < this->si_2; i += 64) 120 | { if (i) 121 | stream << tab; 122 | stream << tab << "_TCE_LDOFF(" << this->off_l + i << ", l_a);" << std::endl; 123 | stream << tab << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_b);" << std::endl; 124 | stream << tab << tab << "_TCE_LDOFF_B(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + i << ", b_a);" << std::endl; 125 | stream << tab << tab << "_TCE_POLAR_G_SCAN8X64(l_a, l_b, b_a, l_c);" << std::endl; 126 | stream << tab << tab << "_TCE_STOFF(" << this->off_l + i + this->size << ", l_c);" << std::endl; 127 | } 128 | } 129 | 130 | 131 | return stream.str(); 132 | } 133 | 134 | virtual std::string apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 135 | { 136 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 137 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 138 | 139 | std::stringstream stream; 140 | if (this->rev_depth == this->m) 141 | return ""; 142 | else if (this->si_2 == 32) 143 | { 144 | stream << tab << "_TCE_LDOFF_B_8X32(" << (this->m - this->rev_depth + 1) * this->N + this->off_s << ", b_a);" << std::endl; 145 | stream << tab << tab << "_TCE_LDOFF_B_8X32(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 << ", b_b);" << std::endl; 146 | stream << tab << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 147 | stream << tab << tab << "_TCE_ROTLELEM_8X64(l_a, " << this->si_2 << ", l_b);" << std::endl; 148 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_b, b_c);" << std::endl; 149 | stream << tab << tab << "_TCE_STOFF_B_8X32(" << (this->m - this->rev_depth ) * this->N + this->off_s << ", b_c);" << std::endl; 150 | stream << tab << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_a, b_c);" << std::endl; 151 | stream << tab << tab << "_TCE_STOFF_B_8X32(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 << ", b_c);" << std::endl; 152 | } 153 | else if (this->si_2 == 16) 154 | { 155 | stream << tab << "_TCE_LDOFF_B_8X16(" << (this->m - this->rev_depth + 1) * this->N + this->off_s << ", b_a);" << std::endl; 156 | stream << tab << tab << "_TCE_LDOFF_B_8X16(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 << ", b_b);" << std::endl; 157 | stream << tab << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 158 | stream << tab << tab << "_TCE_ROTLELEM_8X64(l_a, " << this->si_2 << ", l_b);" << std::endl; 159 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_b, b_c);" << std::endl; 160 | stream << tab << tab << "_TCE_STOFF_B_8X16(" << (this->m - this->rev_depth ) * this->N + this->off_s << ", b_c);" << std::endl; 161 | stream << tab << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_a, b_c);" << std::endl; 162 | stream << tab << tab << "_TCE_STOFF_B_8X16(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 << ", b_c);" << std::endl; 163 | } 164 | else if (this->si_2 == 8) 165 | { 166 | int off_b_a = (this->m - this->rev_depth + 1) * this->N + this->off_s * 4; 167 | int off_b_b = (this->m - this->rev_depth + 1) * this->N + (this->off_s + this->si_2) * 4; 168 | stream << tab << "_TCE_LDOFF_B_8X8(" << off_b_a << ", b_a);" << std::endl; 169 | stream << tab << tab << "_TCE_LDOFF_B_8X8(" << off_b_b << ", b_b);" << std::endl; 170 | stream << tab << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 171 | stream << tab << tab << "_TCE_ROTLELEM_8X64(l_a, " << this->si_2 << ", l_b);" << std::endl; 172 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_b, b_c);" << std::endl; 173 | stream << tab << tab << "_TCE_STOFF_B_8X8(" << (this->m - this->rev_depth ) * this->N + this->off_s << ", b_c);" << std::endl; 174 | stream << tab << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_a, b_c);" << std::endl; 175 | stream << tab << tab << "_TCE_STOFF_B_8X8(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 << ", b_c);" << std::endl; 176 | } 177 | else 178 | { 179 | for (auto i = 0; i < this->si_2; i += 64) 180 | { 181 | if(i) 182 | stream << tab; 183 | stream << tab << "_TCE_LDOFF_B(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + i << ", b_a);" << std::endl; 184 | stream << tab << tab << "_TCE_LDOFF_B(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 + i << ", b_b);" << std::endl; 185 | stream << tab << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_c);" << std::endl; 186 | stream << tab << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_c, b_c);" << std::endl; 187 | stream << tab << tab << "_TCE_STOFF_B(" << (this->m - this->rev_depth ) * this->N + this->off_s + i << ", b_c);" << std::endl; 188 | stream << tab << tab << "_TCE_LDOFF(" << this->off_l + i << ", l_c);" << std::endl; 189 | stream << tab << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_c, b_c);" << std::endl; 190 | stream << tab << tab << "_TCE_STOFF_B(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 + i << ", b_c);" << std::endl; 191 | } 192 | } 193 | 194 | return stream.str(); 195 | } 196 | 197 | std::string final_apply_h(std::string start_indent = "", std::string str_off_l = "", std::string str_off_s = "") const 198 | { 199 | if (str_off_l.empty()) str_off_l = std::to_string(this->off_l); 200 | if (str_off_s.empty()) str_off_s = std::to_string(this->off_s); 201 | 202 | 203 | std::stringstream stream; 204 | if (this->si_2 == 32) 205 | { 206 | stream << "_TCE_LDOFF_B_8X32(" << (this->m - this->rev_depth + 1) * this->N + this->off_s << ", b_a);" << std::endl; 207 | stream << tab << "_TCE_LDOFF_B_8X32(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 << ", b_b);" << std::endl; 208 | stream << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 209 | stream << tab << "_TCE_ROTLELEM_8X64(l_a, " << this->si_2 << ", l_b);" << std::endl; 210 | stream << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_b, b_c);" << std::endl; 211 | stream << tab << "_TCE_STOFF_B_8X32(" << (this->m - this->rev_depth ) * this->N + this->off_s << ", b_c);" << std::endl; 212 | stream << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_a, b_c);" << std::endl; 213 | stream << tab << "_TCE_STOFF_B_8X32(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 << ", b_c);" << std::endl; 214 | } 215 | else if (this->si_2 == 16) 216 | { 217 | stream << "_TCE_LDOFF_B_8X16(" << (this->m - this->rev_depth + 1) * this->N + this->off_s << ", b_a);" << std::endl; 218 | stream << tab << "_TCE_LDOFF_B_8X16(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 << ", b_b);" << std::endl; 219 | stream << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 220 | stream << tab << "_TCE_ROTLELEM_8X64(l_a, " << this->si_2 << ", l_b);" << std::endl; 221 | stream << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_b, b_c);" << std::endl; 222 | stream << tab << "_TCE_STOFF_B_8X16(" << (this->m - this->rev_depth ) * this->N + this->off_s << ", b_c);" << std::endl; 223 | stream << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_a, b_c);" << std::endl; 224 | stream << tab << "_TCE_STOFF_B_8X16(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 << ", b_c);" << std::endl; 225 | } 226 | else if (this->si_2 == 8) 227 | { 228 | int off_b_a = (this->m - this->rev_depth + 1) * this->N + this->off_s * 4; 229 | int off_b_b = (this->m - this->rev_depth + 1) * this->N + (this->off_s + this->si_2) * 4; 230 | stream << "_TCE_LDOFF_B_8X8(" << off_b_a << ", b_a);" << std::endl; 231 | stream << tab << "_TCE_LDOFF_B_8X8(" << off_b_b << ", b_b);" << std::endl; 232 | stream << tab << "_TCE_LDOFF(" << str_off_l << ", l_a);" << std::endl; 233 | stream << tab << "_TCE_ROTLELEM_8X64(l_a, " << this->si_2 << ", l_b);" << std::endl; 234 | stream << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_b, b_c);" << std::endl; 235 | stream << tab << "_TCE_STOFF_B_8X8(" << (this->m - this->rev_depth ) * this->N + this->off_s << ", b_c);" << std::endl; 236 | stream << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_a, b_c);" << std::endl; 237 | stream << tab << "_TCE_STOFF_B_8X8(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 << ", b_c);" << std::endl; 238 | } 239 | else 240 | { 241 | for (auto i = 0; i < this->si_2; i += 64) 242 | { 243 | if(i) 244 | stream << tab; 245 | stream << "_TCE_LDOFF_B(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + i << ", b_a);" << std::endl; 246 | stream << tab << "_TCE_LDOFF_B(" << (this->m - this->rev_depth + 1) * this->N + this->off_s + this->si_2 + i << ", b_b);" << std::endl; 247 | stream << tab << "_TCE_LDOFF(" << this->off_l + i + this->si_2 << ", l_c);" << std::endl; 248 | stream << tab << "_TCE_POLAR_F_SCAN8X64(b_a, b_b, l_c, b_c);" << std::endl; 249 | stream << tab << "_TCE_STOFF_B(" << (this->m - this->rev_depth ) * this->N + this->off_s + i << ", b_c);" << std::endl; 250 | stream << tab << "_TCE_LDOFF(" << this->off_l + i << ", l_c);" << std::endl; 251 | stream << tab << "_TCE_POLAR_G_SCAN8X64(b_a, b_b, l_c, b_c);" << std::endl; 252 | stream << tab << "_TCE_STOFF_B(" << (this->m - this->rev_depth ) * this->N + this->off_s + this->si_2 + i << ", b_c);" << std::endl; 253 | } 254 | } 255 | 256 | int code = (3 << 16) | (this->size >> 3); 257 | 258 | if (this->si_2 < 64) 259 | { 260 | stream << "EE : final_apply_h undefined for N < 64" << std::endl; 261 | exit(EXIT_FAILURE); 262 | } 263 | else // n_elm 264 | { 265 | for ( auto i = 0; (64 * i) < this->size; i++) 266 | { 267 | stream << tab; 268 | stream << "_TCE_LDOFF_B(" << this->off_s + i * 64 << ", b_a);" << std::endl; 269 | stream << tab << "_TCE_POLAR_LEAF(l_a, s[" << ((this->off_s >> 6) + i) << "], " << (this->off_s >> 3); 270 | stream << ", 0x" << std::hex << code << std::dec << ", s[" << ((this->off_s >> 6) + i) << "]);"; 271 | stream << std::endl; 272 | } 273 | } 274 | 275 | return stream.str(); 276 | } 277 | 278 | 279 | }; 280 | } 281 | } 282 | 283 | #endif /* PATTERN_POLAR_TTA_SCAN_STANDARD_HPP_ */ 284 | -------------------------------------------------------------------------------- /tests/refs.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aff3ct/polar_decoder_gen/7d02025aa62bbef58b88f8fca65f5ee9ed86727e/tests/refs.zip -------------------------------------------------------------------------------- /tests/run_tests.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | if [ ! -d "tests/refs" ]; then 4 | cd tests 5 | unzip refs.zip 6 | rc=$?; if [[ $rc != 0 ]]; then echo "Unzip the refs failed :-(!"; exit $rc; fi 7 | cd .. 8 | fi 9 | 10 | ./scripts/generate_polar_gpp_decoders.sh tests_output_GPP 11 | rm -rf tests/tests_output_GPP 12 | mv tests_output_GPP tests 13 | rm tests/tests_output_GPP/SC/*.report 14 | rm tests/tests_output_GPP/SCL/CRC/*.report 15 | 16 | diff tests/tests_output_GPP/SC tests/refs/GPP/SC 17 | rc=$?; if [[ $rc != 0 ]]; then echo "Tests GPP SC failed :-(!"; exit $rc; fi 18 | echo "Tests GPP SC passed successfully!" 19 | 20 | diff tests/tests_output_GPP/SCL/CRC tests/refs/GPP/SCL/CRC 21 | rc=$?; if [[ $rc != 0 ]]; then echo "Tests GPP SCL failed :-(!"; exit $rc; fi 22 | echo "Tests GPP SCL passed successfully!" 23 | 24 | rm -rf tests/tests_output_GPP 25 | 26 | ./scripts/generate_polar_tta_decoders.sh tests_output_TTA 27 | rm -rf tests/tests_output_TTA 28 | mv tests_output_TTA tests 29 | rm tests/tests_output_TTA/SC/*.report 30 | rm tests/tests_output_TTA/SCAN/*.report 31 | 32 | diff tests/tests_output_TTA/SC tests/refs/TTA/SC 33 | rc=$?; if [[ $rc != 0 ]]; then echo "Tests TTA SC failed :-(!"; exit $rc; fi 34 | echo "Tests TTA SC passed successfully!" 35 | 36 | diff tests/tests_output_TTA/SCAN tests/refs/TTA/SCAN 37 | rc=$?; if [[ $rc != 0 ]]; then echo "Tests TTA SCL failed :-(!"; exit $rc; fi 38 | echo "Tests TTA SCL passed successfully!" 39 | 40 | rm -rf tests/tests_output_TTA --------------------------------------------------------------------------------