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