Vector Optimized Library of Kernels 3.1.0
Architecture-tuned implementations of math kernels
volk_16i_max_star_16i.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2012, 2014 Free Software Foundation, Inc.
4 *
5 * This file is part of VOLK
6 *
7 * SPDX-License-Identifier: LGPL-3.0-or-later
8 */
9
40#ifndef INCLUDED_volk_16i_max_star_16i_a_H
41#define INCLUDED_volk_16i_max_star_16i_a_H
42
43#include <inttypes.h>
44#include <stdio.h>
45
46#ifdef LV_HAVE_SSSE3
47
48#include <emmintrin.h>
49#include <tmmintrin.h>
50#include <xmmintrin.h>
51
52static inline void
53volk_16i_max_star_16i_a_ssse3(short* target, short* src0, unsigned int num_points)
54{
55 const unsigned int num_bytes = num_points * 2;
56
57 short candidate = src0[0];
58 short cands[8];
59 __m128i xmm0, xmm1, xmm3, xmm4, xmm5, xmm6;
60
61 __m128i* p_src0;
62
63 p_src0 = (__m128i*)src0;
64
65 int bound = num_bytes >> 4;
66 int leftovers = (num_bytes >> 1) & 7;
67
68 int i = 0;
69
70 xmm1 = _mm_setzero_si128();
71 xmm0 = _mm_setzero_si128();
72 //_mm_insert_epi16(xmm0, candidate, 0);
73
74 xmm0 = _mm_shuffle_epi8(xmm0, xmm1);
75
76 for (i = 0; i < bound; ++i) {
77 xmm1 = _mm_load_si128(p_src0);
78 p_src0 += 1;
79 // xmm2 = _mm_sub_epi16(xmm1, xmm0);
80
81 xmm3 = _mm_cmpgt_epi16(xmm0, xmm1);
82 xmm4 = _mm_cmpeq_epi16(xmm0, xmm1);
83 xmm5 = _mm_cmpgt_epi16(xmm1, xmm0);
84
85 xmm6 = _mm_xor_si128(xmm4, xmm5);
86
87 xmm3 = _mm_and_si128(xmm3, xmm0);
88 xmm4 = _mm_and_si128(xmm6, xmm1);
89
90 xmm0 = _mm_add_epi16(xmm3, xmm4);
91 }
92
93 _mm_store_si128((__m128i*)cands, xmm0);
94
95 for (i = 0; i < 8; ++i) {
96 candidate = ((short)(candidate - cands[i]) > 0) ? candidate : cands[i];
97 }
98
99 for (i = 0; i < leftovers; ++i) {
100 candidate = ((short)(candidate - src0[(bound << 3) + i]) > 0)
101 ? candidate
102 : src0[(bound << 3) + i];
103 }
104
105 target[0] = candidate;
106}
107
108#endif /*LV_HAVE_SSSE3*/
109
110#ifdef LV_HAVE_GENERIC
111
112static inline void
113volk_16i_max_star_16i_generic(short* target, short* src0, unsigned int num_points)
114{
115 const unsigned int num_bytes = num_points * 2;
116
117 int i = 0;
118
119 int bound = num_bytes >> 1;
120
121 short candidate = src0[0];
122 for (i = 1; i < bound; ++i) {
123 candidate = ((short)(candidate - src0[i]) > 0) ? candidate : src0[i];
124 }
125 target[0] = candidate;
126}
127
128#endif /*LV_HAVE_GENERIC*/
129
130
131#endif /*INCLUDED_volk_16i_max_star_16i_a_H*/