root / host / lib / convert / sse2_fc64_to_sc16.cpp @ 4c244c78
History | View | Annotate | Download (5.48 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2011-2012 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include "convert_common.hpp" |
| 19 |
#include <uhd/utils/byteswap.hpp> |
| 20 |
#include <emmintrin.h> |
| 21 |
|
| 22 |
using namespace uhd::convert; |
| 23 |
|
| 24 |
DECLARE_CONVERTER(fc64, 1, sc16_item32_le, 1, PRIORITY_SIMD){ |
| 25 |
const fc64_t *input = reinterpret_cast<const fc64_t *>(inputs[0]); |
| 26 |
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]); |
| 27 |
|
| 28 |
const __m128d scalar = _mm_set1_pd(scale_factor);
|
| 29 |
|
| 30 |
#define convert_fc64_1_to_item32_1_nswap_guts(_al_) \
|
| 31 |
for (; i+3 < nsamps; i+=4){ \ |
| 32 |
/* load from input */ \
|
| 33 |
__m128d tmp0 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+0)); \ |
| 34 |
__m128d tmp1 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+1)); \ |
| 35 |
__m128d tmp2 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+2)); \ |
| 36 |
__m128d tmp3 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+3)); \ |
| 37 |
\ |
| 38 |
/* convert and scale */ \
|
| 39 |
__m128i tmpi0 = _mm_cvttpd_epi32(_mm_mul_pd(tmp0, scalar)); \ |
| 40 |
__m128i tmpi1 = _mm_cvttpd_epi32(_mm_mul_pd(tmp1, scalar)); \ |
| 41 |
__m128i tmpilo = _mm_unpacklo_epi64(tmpi0, tmpi1); \ |
| 42 |
__m128i tmpi2 = _mm_cvttpd_epi32(_mm_mul_pd(tmp2, scalar)); \ |
| 43 |
__m128i tmpi3 = _mm_cvttpd_epi32(_mm_mul_pd(tmp3, scalar)); \ |
| 44 |
__m128i tmpihi = _mm_unpacklo_epi64(tmpi2, tmpi3); \ |
| 45 |
\ |
| 46 |
/* pack + swap 16-bit pairs */ \
|
| 47 |
__m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi); \ |
| 48 |
tmpi = _mm_shufflelo_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); \ |
| 49 |
tmpi = _mm_shufflehi_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); \ |
| 50 |
\ |
| 51 |
/* store to output */ \
|
| 52 |
_mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi); \
|
| 53 |
} \ |
| 54 |
|
| 55 |
size_t i = 0;
|
| 56 |
|
| 57 |
//dispatch according to alignment
|
| 58 |
if ((size_t(input) & 0xf) == 0){ |
| 59 |
convert_fc64_1_to_item32_1_nswap_guts(_) |
| 60 |
} |
| 61 |
else{
|
| 62 |
convert_fc64_1_to_item32_1_nswap_guts(u_) |
| 63 |
} |
| 64 |
|
| 65 |
//convert remainder
|
| 66 |
xx_to_item32_sc16<uhd::htowx>(input+i, output+i, nsamps-i, scale_factor); |
| 67 |
} |
| 68 |
|
| 69 |
DECLARE_CONVERTER(fc64, 1, sc16_item32_be, 1, PRIORITY_SIMD){ |
| 70 |
const fc64_t *input = reinterpret_cast<const fc64_t *>(inputs[0]); |
| 71 |
item32_t *output = reinterpret_cast<item32_t *>(outputs[0]); |
| 72 |
|
| 73 |
const __m128d scalar = _mm_set1_pd(scale_factor);
|
| 74 |
|
| 75 |
#define convert_fc64_1_to_item32_1_bswap_guts(_al_) \
|
| 76 |
for (; i+3 < nsamps; i+=4){ \ |
| 77 |
/* load from input */ \
|
| 78 |
__m128d tmp0 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+0)); \ |
| 79 |
__m128d tmp1 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+1)); \ |
| 80 |
__m128d tmp2 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+2)); \ |
| 81 |
__m128d tmp3 = _mm_load ## _al_ ## pd(reinterpret_cast<const double *>(input+i+3)); \ |
| 82 |
\ |
| 83 |
/* convert and scale */ \
|
| 84 |
__m128i tmpi0 = _mm_cvttpd_epi32(_mm_mul_pd(tmp0, scalar)); \ |
| 85 |
__m128i tmpi1 = _mm_cvttpd_epi32(_mm_mul_pd(tmp1, scalar)); \ |
| 86 |
__m128i tmpilo = _mm_unpacklo_epi64(tmpi0, tmpi1); \ |
| 87 |
__m128i tmpi2 = _mm_cvttpd_epi32(_mm_mul_pd(tmp2, scalar)); \ |
| 88 |
__m128i tmpi3 = _mm_cvttpd_epi32(_mm_mul_pd(tmp3, scalar)); \ |
| 89 |
__m128i tmpihi = _mm_unpacklo_epi64(tmpi2, tmpi3); \ |
| 90 |
\ |
| 91 |
/* pack + byteswap -> byteswap 16 bit words */ \
|
| 92 |
__m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi); \ |
| 93 |
tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8)); \ |
| 94 |
\ |
| 95 |
/* store to output */ \
|
| 96 |
_mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi); \
|
| 97 |
} \ |
| 98 |
|
| 99 |
size_t i = 0;
|
| 100 |
|
| 101 |
//dispatch according to alignment
|
| 102 |
if ((size_t(input) & 0xf) == 0){ |
| 103 |
convert_fc64_1_to_item32_1_bswap_guts(_) |
| 104 |
} |
| 105 |
else{
|
| 106 |
convert_fc64_1_to_item32_1_bswap_guts(u_) |
| 107 |
} |
| 108 |
|
| 109 |
//convert remainder
|
| 110 |
xx_to_item32_sc16<uhd::htonx>(input+i, output+i, nsamps-i, scale_factor); |
| 111 |
} |