blob: 2ad353a487c4f755c14e27c9a83b2b591e1af696 [file] [log] [blame]
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +07001/*
Vadim Yanitskiy46e533c2017-06-19 18:21:02 +07002 * Accelerated Viterbi decoder implementation
3 * for architectures with both SSE3 and AVX2 support
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +07004 *
5 * Copyright (C) 2013, 2014 Thomas Tsou <tom@tsou.cc>
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#include <stdint.h>
25#include "config.h"
26
27#include <emmintrin.h>
28#include <tmmintrin.h>
29#include <xmmintrin.h>
30#include <immintrin.h>
31
32#if defined(HAVE_SSE4_1)
33#include <smmintrin.h>
34#endif
35
36#define SSE_ALIGN 16
37
38
39/* Broadcast 16-bit integer
40 * Repeat the low 16-bit integer to all elements of the 128-bit SSE
41 * register. Only AVX2 has a dedicated broadcast instruction; use repeat
42 * unpacks for SSE only architectures. This is a destructive operation and
43 * the source register is overwritten.
44 *
45 * Input:
46 * M0 - Low 16-bit element is read
47 *
48 * Output:
49 * M0 - Contains broadcasted values
50 */
51#define SSE_BROADCAST(M0) \
52{ \
53 M0 = _mm_broadcastw_epi16(M0); \
54}
55
56/**
57 * Include common SSE implementation
58 */
Vadim Yanitskiye4fe71c2017-06-19 17:59:48 +070059#include <conv_acc_sse_impl.h>
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070060
61/* Aligned Memory Allocator
62 * SSE requires 16-byte memory alignment. We store relevant trellis values
63 * (accumulated sums, outputs, and path decisions) as 16 bit signed integers
64 * so the allocated memory is casted as such.
65 */
66__attribute__ ((visibility("hidden")))
67int16_t *osmo_conv_sse_avx_vdec_malloc(size_t n)
68{
69 return (int16_t *) _mm_malloc(sizeof(int16_t) * n, SSE_ALIGN);
70}
71
72__attribute__ ((visibility("hidden")))
73void osmo_conv_sse_avx_vdec_free(int16_t *ptr)
74{
75 _mm_free(ptr);
76}
77
78__attribute__ ((visibility("hidden")))
79void osmo_conv_sse_avx_metrics_k5_n2(const int8_t *val,
80 const int16_t *out, int16_t *sums, int16_t *paths, int norm)
81{
82 const int16_t _val[4] = { val[0], val[1], val[0], val[1] };
83
84 _sse_metrics_k5_n2(_val, out, sums, paths, norm);
85}
86
87__attribute__ ((visibility("hidden")))
88void osmo_conv_sse_avx_metrics_k5_n3(const int8_t *val,
89 const int16_t *out, int16_t *sums, int16_t *paths, int norm)
90{
91 const int16_t _val[4] = { val[0], val[1], val[2], 0 };
92
93 _sse_metrics_k5_n4(_val, out, sums, paths, norm);
94}
95
96__attribute__ ((visibility("hidden")))
97void osmo_conv_sse_avx_metrics_k5_n4(const int8_t *val,
98 const int16_t *out, int16_t *sums, int16_t *paths, int norm)
99{
100 const int16_t _val[4] = { val[0], val[1], val[2], val[3] };
101
102 _sse_metrics_k5_n4(_val, out, sums, paths, norm);
103}
104
105__attribute__ ((visibility("hidden")))
106void osmo_conv_sse_avx_metrics_k7_n2(const int8_t *val,
107 const int16_t *out, int16_t *sums, int16_t *paths, int norm)
108{
109 const int16_t _val[4] = { val[0], val[1], val[0], val[1] };
110
111 _sse_metrics_k7_n2(_val, out, sums, paths, norm);
112}
113
114__attribute__ ((visibility("hidden")))
115void osmo_conv_sse_avx_metrics_k7_n3(const int8_t *val,
116 const int16_t *out, int16_t *sums, int16_t *paths, int norm)
117{
118 const int16_t _val[4] = { val[0], val[1], val[2], 0 };
119
120 _sse_metrics_k7_n4(_val, out, sums, paths, norm);
121}
122
123__attribute__ ((visibility("hidden")))
124void osmo_conv_sse_avx_metrics_k7_n4(const int8_t *val,
125 const int16_t *out, int16_t *sums, int16_t *paths, int norm)
126{
127 const int16_t _val[4] = { val[0], val[1], val[2], val[3] };
128
129 _sse_metrics_k7_n4(_val, out, sums, paths, norm);
130}