blob: f389085048fc69f848dac2be34ec1d5d3910c13d [file] [log] [blame]
Tom Tsou34e228a2017-04-29 00:16:43 +07001/*
2 * Intel SSE 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>
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070024#include "config.h"
25
Tom Tsou34e228a2017-04-29 00:16:43 +070026#include <emmintrin.h>
27#include <tmmintrin.h>
28#include <xmmintrin.h>
29
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070030#if defined(HAVE_SSE4_1)
31#include <smmintrin.h>
Tom Tsou34e228a2017-04-29 00:16:43 +070032#endif
33
34#define SSE_ALIGN 16
35
Tom Tsou34e228a2017-04-29 00:16:43 +070036/* Broadcast 16-bit integer
37 * Repeat the low 16-bit integer to all elements of the 128-bit SSE
38 * register. Only AVX2 has a dedicated broadcast instruction; use repeat
39 * unpacks for SSE only architectures. This is a destructive operation and
40 * the source register is overwritten.
41 *
42 * Input:
43 * M0 - Low 16-bit element is read
44 *
45 * Output:
46 * M0 - Contains broadcasted values
47 */
Tom Tsou34e228a2017-04-29 00:16:43 +070048#define SSE_BROADCAST(M0) \
49{ \
50 M0 = _mm_unpacklo_epi16(M0, M0); \
51 M0 = _mm_unpacklo_epi32(M0, M0); \
52 M0 = _mm_unpacklo_epi64(M0, M0); \
53}
Tom Tsou34e228a2017-04-29 00:16:43 +070054
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070055/**
56 * Include common SSE implementation
Tom Tsou34e228a2017-04-29 00:16:43 +070057 */
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070058#include <viterbi_sse_common.h>
Tom Tsou34e228a2017-04-29 00:16:43 +070059
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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070066int16_t *osmo_conv_sse_vdec_malloc(size_t n)
Tom Tsou34e228a2017-04-29 00:16:43 +070067{
68 return (int16_t *) _mm_malloc(sizeof(int16_t) * n, SSE_ALIGN);
69}
70
71__attribute__ ((visibility("hidden")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070072void osmo_conv_sse_vdec_free(int16_t *ptr)
Tom Tsou34e228a2017-04-29 00:16:43 +070073{
74 _mm_free(ptr);
75}
76
77__attribute__ ((visibility("hidden")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070078void osmo_conv_sse_metrics_k5_n2(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +070079 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070087void osmo_conv_sse_metrics_k5_n3(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +070088 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070096void osmo_conv_sse_metrics_k5_n4(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +070097 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +0700105void osmo_conv_sse_metrics_k7_n2(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +0700106 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +0700114void osmo_conv_sse_metrics_k7_n3(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +0700115 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +0700123void osmo_conv_sse_metrics_k7_n4(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +0700124 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}