blob: 513ab052d1595ffe7848422dec65fe3e7056412d [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file conv_acc_sse.c
Vadim Yanitskiy46e533c2017-06-19 18:21:02 +07002 * Accelerated Viterbi decoder implementation
Harald Welteb93f60f2017-11-17 11:41:34 +01003 * for architectures with only SSSE3 available. */
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02004/*
Tom Tsou34e228a2017-04-29 00:16:43 +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 *
Tom Tsou34e228a2017-04-29 00:16:43 +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.
Tom Tsou34e228a2017-04-29 00:16:43 +070020 */
21
22#include <stdint.h>
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070023#include "config.h"
24
Tom Tsou34e228a2017-04-29 00:16:43 +070025#include <emmintrin.h>
26#include <tmmintrin.h>
27#include <xmmintrin.h>
28
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070029#if defined(HAVE_SSE4_1)
30#include <smmintrin.h>
Tom Tsou34e228a2017-04-29 00:16:43 +070031#endif
32
33#define SSE_ALIGN 16
34
Tom Tsou34e228a2017-04-29 00:16:43 +070035/* Broadcast 16-bit integer
36 * Repeat the low 16-bit integer to all elements of the 128-bit SSE
37 * register. Only AVX2 has a dedicated broadcast instruction; use repeat
38 * unpacks for SSE only architectures. This is a destructive operation and
39 * the source register is overwritten.
40 *
41 * Input:
42 * M0 - Low 16-bit element is read
43 *
44 * Output:
45 * M0 - Contains broadcasted values
46 */
Tom Tsou34e228a2017-04-29 00:16:43 +070047#define SSE_BROADCAST(M0) \
48{ \
49 M0 = _mm_unpacklo_epi16(M0, M0); \
50 M0 = _mm_unpacklo_epi32(M0, M0); \
51 M0 = _mm_unpacklo_epi64(M0, M0); \
52}
Tom Tsou34e228a2017-04-29 00:16:43 +070053
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070054/**
55 * Include common SSE implementation
Tom Tsou34e228a2017-04-29 00:16:43 +070056 */
Vadim Yanitskiye4fe71c2017-06-19 17:59:48 +070057#include <conv_acc_sse_impl.h>
Tom Tsou34e228a2017-04-29 00:16:43 +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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070065int16_t *osmo_conv_sse_vdec_malloc(size_t n)
Tom Tsou34e228a2017-04-29 00:16:43 +070066{
67 return (int16_t *) _mm_malloc(sizeof(int16_t) * n, SSE_ALIGN);
68}
69
70__attribute__ ((visibility("hidden")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070071void osmo_conv_sse_vdec_free(int16_t *ptr)
Tom Tsou34e228a2017-04-29 00:16:43 +070072{
73 _mm_free(ptr);
74}
75
76__attribute__ ((visibility("hidden")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070077void osmo_conv_sse_metrics_k5_n2(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +070078 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070086void osmo_conv_sse_metrics_k5_n3(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +070087 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +070095void osmo_conv_sse_metrics_k5_n4(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +070096 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +0700104void osmo_conv_sse_metrics_k7_n2(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +0700105 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +0700113void osmo_conv_sse_metrics_k7_n3(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +0700114 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")))
Vadim Yanitskiy0d49f472017-05-28 18:20:02 +0700122void osmo_conv_sse_metrics_k7_n4(const int8_t *val, const int16_t *out,
Tom Tsou34e228a2017-04-29 00:16:43 +0700123 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}