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