summaryrefslogtreecommitdiffstats
path: root/src/conv_acc_sse.c
blob: 63d8722acc00e963874507173371c5c697cc8446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*! \file conv_acc_sse.c
 * Accelerated Viterbi decoder implementation
 * for architectures with only SSSE3 available. */
/*
 * Copyright (C) 2013, 2014 Thomas Tsou <tom@tsou.cc>
 *
 * All Rights Reserved
 *
 * SPDX-License-Identifier: GPL-2.0+
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdint.h>
#include "config.h"

#include <emmintrin.h>
#include <tmmintrin.h>
#include <xmmintrin.h>

#if defined(HAVE_SSE4_1)
#include <smmintrin.h>
#endif

#define SSE_ALIGN 16

/* Broadcast 16-bit integer
 * Repeat the low 16-bit integer to all elements of the 128-bit SSE
 * register. Only AVX2 has a dedicated broadcast instruction; use repeat
 * unpacks for SSE only architectures. This is a destructive operation and
 * the source register is overwritten.
 *
 * Input:
 * M0 - Low 16-bit element is read
 *
 * Output:
 * M0 - Contains broadcasted values
 */
#define SSE_BROADCAST(M0) \
{ \
	M0 = _mm_unpacklo_epi16(M0, M0); \
	M0 = _mm_unpacklo_epi32(M0, M0); \
	M0 = _mm_unpacklo_epi64(M0, M0); \
}

/**
 * Include common SSE implementation
 */
#include <conv_acc_sse_impl.h>

/* Aligned Memory Allocator
 * SSE requires 16-byte memory alignment. We store relevant trellis values
 * (accumulated sums, outputs, and path decisions) as 16 bit signed integers
 * so the allocated memory is casted as such.
 */
__attribute__ ((visibility("hidden")))
int16_t *osmo_conv_sse_vdec_malloc(size_t n)
{
	return (int16_t *) _mm_malloc(sizeof(int16_t) * n, SSE_ALIGN);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_vdec_free(int16_t *ptr)
{
	_mm_free(ptr);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_metrics_k5_n2(const int8_t *val, const int16_t *out,
	int16_t *sums, int16_t *paths, int norm)
{
	const int16_t _val[4] = { val[0], val[1], val[0], val[1] };

	_sse_metrics_k5_n2(_val, out, sums, paths, norm);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_metrics_k5_n3(const int8_t *val, const int16_t *out,
	int16_t *sums, int16_t *paths, int norm)
{
	const int16_t _val[4] = { val[0], val[1], val[2], 0 };

	_sse_metrics_k5_n4(_val, out, sums, paths, norm);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_metrics_k5_n4(const int8_t *val, const int16_t *out,
	int16_t *sums, int16_t *paths, int norm)
{
	const int16_t _val[4] = { val[0], val[1], val[2], val[3] };

	_sse_metrics_k5_n4(_val, out, sums, paths, norm);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_metrics_k7_n2(const int8_t *val, const int16_t *out,
	int16_t *sums, int16_t *paths, int norm)
{
	const int16_t _val[4] = { val[0], val[1], val[0], val[1] };

	_sse_metrics_k7_n2(_val, out, sums, paths, norm);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_metrics_k7_n3(const int8_t *val, const int16_t *out,
	int16_t *sums, int16_t *paths, int norm)
{
	const int16_t _val[4] = { val[0], val[1], val[2], 0 };

	_sse_metrics_k7_n4(_val, out, sums, paths, norm);
}

__attribute__ ((visibility("hidden")))
void osmo_conv_sse_metrics_k7_n4(const int8_t *val, const int16_t *out,
	int16_t *sums, int16_t *paths, int norm)
{
	const int16_t _val[4] = { val[0], val[1], val[2], val[3] };

	_sse_metrics_k7_n4(_val, out, sums, paths, norm);
}