From 91790751b614b86393dd7963f1a4476d0e60ed4a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 4 Jan 2011 17:11:52 -0800 Subject: uhd: added new convert directory with type conversion registry (needs testing) --- host/lib/convert/CMakeLists.txt | 66 ++++++++++++ host/lib/convert/convert.cpp | 117 ++++++++++++++++++++ host/lib/convert/convert_common.hpp | 90 ++++++++++++++++ host/lib/convert/convert_general.cpp | 63 +++++++++++ host/lib/convert/convert_with_neon.cpp | 62 +++++++++++ host/lib/convert/convert_with_sse2.cpp | 148 +++++++++++++++++++++++++ host/lib/convert/gen_convert_general.py | 93 ++++++++++++++++ host/lib/convert/gen_convert_impl.py | 186 ++++++++++++++++++++++++++++++++ 8 files changed, 825 insertions(+) create mode 100644 host/lib/convert/CMakeLists.txt create mode 100644 host/lib/convert/convert.cpp create mode 100644 host/lib/convert/convert_common.hpp create mode 100644 host/lib/convert/convert_general.cpp create mode 100644 host/lib/convert/convert_with_neon.cpp create mode 100644 host/lib/convert/convert_with_sse2.cpp create mode 100644 host/lib/convert/gen_convert_general.py create mode 100644 host/lib/convert/gen_convert_impl.py (limited to 'host/lib/convert') diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt new file mode 100644 index 000000000..9324a94b0 --- /dev/null +++ b/host/lib/convert/CMakeLists.txt @@ -0,0 +1,66 @@ +# +# Copyright 2011 Ettus Research LLC +# +# 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 3 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, see . +# + +######################################################################## +# This file included, use CMake directory variables +######################################################################## +INCLUDE(CheckIncludeFileCXX) +MESSAGE(STATUS "") + +######################################################################## +# Check for SIMD headers +######################################################################## +CHECK_INCLUDE_FILE_CXX(emmintrin.h HAVE_EMMINTRIN_H) +IF(HAVE_EMMINTRIN_H) + LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/convert_with_sse2.cpp + ) +ENDIF(HAVE_EMMINTRIN_H) + +CHECK_INCLUDE_FILE_CXX(arm_neon.h HAVE_ARM_NEON_H) +IF(HAVE_ARM_NEON_H) + LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/convert_with_neon.cpp + ) +ENDIF(HAVE_ARM_NEON_H) + +######################################################################## +# Convert types generation +######################################################################## +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) + +LIBUHD_PYTHON_GEN_SOURCE( + ${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_impl.py + ${CMAKE_CURRENT_BINARY_DIR}/convert_impl.hpp +) + +INCLUDE(AddFileDependencies) +ADD_FILE_DEPENDENCIES( + ${CMAKE_CURRENT_SOURCE_DIR}/convert.cpp + ${CMAKE_CURRENT_BINARY_DIR}/convert_impl.hpp +) + +LIBUHD_PYTHON_GEN_SOURCE( + ${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_general.py + ${CMAKE_CURRENT_BINARY_DIR}/convert_general.cpp +) + +LIBUHD_APPEND_SOURCES( + ${CMAKE_CURRENT_SOURCE_DIR}/convert.cpp + ${CMAKE_CURRENT_BINARY_DIR}/convert_general.cpp +) diff --git a/host/lib/convert/convert.cpp b/host/lib/convert/convert.cpp new file mode 100644 index 000000000..f635a1040 --- /dev/null +++ b/host/lib/convert/convert.cpp @@ -0,0 +1,117 @@ +// +// Copyright 2011 Ettus Research LLC +// +// 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 3 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, see . +// + +#include +#include +#include +#include + +using namespace uhd; + +#include "convert_impl.hpp" + +static const bool debug = false; + +/*********************************************************************** + * Define types for the function tables + **********************************************************************/ +struct fcn_table_entry_type{ + convert::priority_type prio; + convert::function_type fcn; + fcn_table_entry_type(void) + : prio(convert::PRIORITY_EMPTY), fcn(NULL){ + /* NOP */ + } +}; +typedef std::vector fcn_table_type; + +/*********************************************************************** + * Setup the table registry + **********************************************************************/ +UHD_SINGLETON_FCN(fcn_table_type, get_cpu_to_otw_table); +UHD_SINGLETON_FCN(fcn_table_type, get_otw_to_cpu_table); + +fcn_table_type &get_table(dir_type dir){ + switch(dir){ + case DIR_OTW_TO_CPU: return get_otw_to_cpu_table(); + case DIR_CPU_TO_OTW: return get_cpu_to_otw_table(); + } + UHD_THROW_INVALID_CODE_PATH(); +} + +/*********************************************************************** + * The registry functions + **********************************************************************/ +void uhd::convert::register_converter( + const std::string &markup, + function_type fcn, + priority_type prio +){ + //extract the predicate and direction from the markup + dir_type dir; + pred_type pred = make_pred(markup, dir); + + //get a reference to the function table + fcn_table_type &table = get_table(dir); + + //resize the table so that its at least pred+1 + if (table.size() <= pred) table.resize(pred+1); + + //register the function if higher priority + if (table[pred].prio < prio){ + table[pred].fcn = fcn; + table[pred].prio = prio; + } + + //----------------------------------------------------------------// + if (debug) std::cout << "register_converter: " << markup << std::endl + << " prio: " << prio << std::endl + << " pred: " << pred << std::endl + << " dir: " << dir << std::endl + << std::endl + ; + //----------------------------------------------------------------// +} + +/*********************************************************************** + * The converter functions + **********************************************************************/ +void uhd::convert::io_type_to_otw_type( + const io_type_t &io_type, + const otw_type_t &otw_type, + input_type &input_buffs, + output_type &output_buffs, + size_t nsamps_per_io_buff +){ + pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); + fcn_table_type table = get_cpu_to_otw_table(); + function_type fcn = table.at(pred).fcn; + fcn(input_buffs, output_buffs, nsamps_per_io_buff); +} + +void uhd::convert::otw_type_to_io_type( + const io_type_t &io_type, + const otw_type_t &otw_type, + input_type &input_buffs, + output_type &output_buffs, + size_t nsamps_per_io_buff +){ + pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); + fcn_table_type table = get_otw_to_cpu_table(); + function_type fcn = table.at(pred).fcn; + fcn(input_buffs, output_buffs, nsamps_per_io_buff); +} diff --git a/host/lib/convert/convert_common.hpp b/host/lib/convert/convert_common.hpp new file mode 100644 index 000000000..1a653a56f --- /dev/null +++ b/host/lib/convert/convert_common.hpp @@ -0,0 +1,90 @@ +// +// Copyright 2011 Ettus Research LLC +// +// 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 3 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, see . +// + +#ifndef INCLUDED_LIBUHD_CONVERT_COMMON_HPP +#define INCLUDED_LIBUHD_CONVERT_COMMON_HPP + +#include +#include +#include +#include + +#define DECLARE_CONVERTER(fcn, prio) \ + static void fcn( \ + uhd::convert::input_type &inputs, \ + uhd::convert::output_type &outputs, \ + size_t nsamps \ + ); \ + UHD_STATIC_BLOCK(register_##fcn##_##prio){ \ + uhd::convert::register_converter(#fcn, fcn, prio); \ + } \ + static void fcn( \ + uhd::convert::input_type &inputs, \ + uhd::convert::output_type &outputs, \ + size_t nsamps \ + ) + +/*********************************************************************** + * Typedefs + **********************************************************************/ +typedef std::complex fc32_t; +typedef std::complex sc16_t; +typedef boost::uint32_t item32_t; + +/*********************************************************************** + * Convert complex short buffer to items32 + **********************************************************************/ +static UHD_INLINE item32_t sc16_to_item32(sc16_t num){ + boost::uint16_t real = num.real(); + boost::uint16_t imag = num.imag(); + return (item32_t(real) << 16) | (item32_t(imag) << 0); +} + +/*********************************************************************** + * Convert items32 buffer to complex short + **********************************************************************/ +static UHD_INLINE sc16_t item32_to_sc16(item32_t item){ + return sc16_t( + boost::int16_t(item >> 16), + boost::int16_t(item >> 0) + ); +} + +/*********************************************************************** + * Convert complex float buffer to items32 (no swap) + **********************************************************************/ +static const float shorts_per_float = float(32767); + +static UHD_INLINE item32_t fc32_to_item32(fc32_t num){ + boost::uint16_t real = boost::int16_t(num.real()*shorts_per_float); + boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_float); + return (item32_t(real) << 16) | (item32_t(imag) << 0); +} + +/*********************************************************************** + * Convert items32 buffer to complex float + **********************************************************************/ +static const float floats_per_short = float(1.0/shorts_per_float); + +static UHD_INLINE fc32_t item32_to_fc32(item32_t item){ + return fc32_t( + float(boost::int16_t(item >> 16)*floats_per_short), + float(boost::int16_t(item >> 0)*floats_per_short) + ); +} + +#endif /* INCLUDED_LIBUHD_CONVERT_COMMON_HPP */ diff --git a/host/lib/convert/convert_general.cpp b/host/lib/convert/convert_general.cpp new file mode 100644 index 000000000..5e52acea2 --- /dev/null +++ b/host/lib/convert/convert_general.cpp @@ -0,0 +1,63 @@ +// +// Copyright 2010 Ettus Research LLC +// +// 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 3 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, see . +// + +#include "convert_common.hpp" +#include + +using namespace uhd::convert; + +/*********************************************************************** + * Convert complex short buffer to items32 + **********************************************************************/ +DECLARE_CONVERTER(convert_sc16_1_to_item32_1_nswap, PRIORITY_GENERAL){ + const sc16_t *input = reinterpret_cast(inputs[0]); + item32_t *output = reinterpret_cast(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + output[i] = sc16_to_item32(input[i]); + } +} + +DECLARE_CONVERTER(convert_sc16_1_to_item32_1_bswap, PRIORITY_GENERAL){ + const sc16_t *input = reinterpret_cast(inputs[0]); + item32_t *output = reinterpret_cast(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + output[i] = uhd::byteswap(sc16_to_item32(input[i])); + } +} + +/*********************************************************************** + * Convert items32 buffer to complex short + **********************************************************************/ +DECLARE_CONVERTER(convert_item32_1_to_sc16_1_nswap, PRIORITY_GENERAL){ + const item32_t *input = reinterpret_cast(inputs[0]); + sc16_t *output = reinterpret_cast(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + output[i] = item32_to_sc16(input[i]); + } +} + +DECLARE_CONVERTER(convert_item32_1_to_sc16_1_bswap, PRIORITY_GENERAL){ + const item32_t *input = reinterpret_cast(inputs[0]); + sc16_t *output = reinterpret_cast(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + output[i] = item32_to_sc16(uhd::byteswap(input[i])); + } +} diff --git a/host/lib/convert/convert_with_neon.cpp b/host/lib/convert/convert_with_neon.cpp new file mode 100644 index 000000000..1ed841125 --- /dev/null +++ b/host/lib/convert/convert_with_neon.cpp @@ -0,0 +1,62 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// 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 3 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, see . +// + +#include "convert_common.hpp" +#include +#include + +using namespace uhd::convert; + +DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_CUSTOM){ + const fc32_t *input = reinterpret_cast(inputs[0]); + item32_t *output = reinterpret_cast(outputs[0]); + + size_t i; + + float32x4_t Q0 = vdupq_n_f32(shorts_per_float); + for (i=0; i < (nsamps & ~0x03); i+=2) { + float32x4_t Q1 = vld1q_f32(reinterpret_cast(&input[i])); + float32x4_t Q2 = vmulq_f32(Q1, Q0); + int32x4_t Q3 = vcvtq_s32_f32(Q2); + int16x4_t D8 = vmovn_s32(Q3); + int16x4_t D9 = vrev32_s16(D8); + vst1_s16((reinterpret_cast(&output[i])), D9); + } + + for (; i < nsamps; i++) + output[i] = fc32_to_item32(input[i]); +} + +DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_CUSTOM){ + const item32_t *input = reinterpret_cast(inputs[0]); + fc32_t *output = reinterpret_cast(outputs[0]); + + size_t i; + + float32x4_t Q1 = vdupq_n_f32(floats_per_short); + for (i=0; i < (nsamps & ~0x03); i+=2) { + int16x4_t D0 = vld1_s16(reinterpret_cast(&input[i])); + int16x4_t D1 = vrev32_s16(D0); + int32x4_t Q2 = vmovl_s16(D1); + float32x4_t Q3 = vcvtq_f32_s32(Q2); + float32x4_t Q4 = vmulq_f32(Q3, Q1); + vst1q_f32((reinterpret_cast(&output[i])), Q4); + } + + for (; i < nsamps; i++) + output[i] = item32_to_fc32(input[i]); +} diff --git a/host/lib/convert/convert_with_sse2.cpp b/host/lib/convert/convert_with_sse2.cpp new file mode 100644 index 000000000..8d5a8a6a5 --- /dev/null +++ b/host/lib/convert/convert_with_sse2.cpp @@ -0,0 +1,148 @@ +// +// Copyright 2010-2011 Ettus Research LLC +// +// 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 3 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, see . +// + +#include "convert_common.hpp" +#include +#include + +using namespace uhd::convert; + +DECLARE_CONVERTER(convert_fc32_1_to_item32_1_nswap, PRIORITY_CUSTOM){ + const fc32_t *input = reinterpret_cast(inputs[0]); + item32_t *output = reinterpret_cast(outputs[0]); + + __m128 scalar = _mm_set_ps1(shorts_per_float); + + //convert blocks of samples with intrinsics + size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ + //load from input + __m128 tmplo = _mm_loadu_ps(reinterpret_cast(input+i+0)); + __m128 tmphi = _mm_loadu_ps(reinterpret_cast(input+i+2)); + + //convert and scale + __m128i tmpilo = _mm_cvtps_epi32(_mm_mul_ps(tmplo, scalar)); + __m128i tmpihi = _mm_cvtps_epi32(_mm_mul_ps(tmphi, scalar)); + + //pack + swap 16-bit pairs + __m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi); + tmpi = _mm_shufflelo_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); + tmpi = _mm_shufflehi_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); + + //store to output + _mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi); + } + + //convert remainder + for (; i < nsamps; i++){ + output[i] = fc32_to_item32(input[i]); + } +} + +DECLARE_CONVERTER(convert_fc32_1_to_item32_1_bswap, PRIORITY_CUSTOM){ + const fc32_t *input = reinterpret_cast(inputs[0]); + item32_t *output = reinterpret_cast(outputs[0]); + + __m128 scalar = _mm_set_ps1(shorts_per_float); + + //convert blocks of samples with intrinsics + size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ + //load from input + __m128 tmplo = _mm_loadu_ps(reinterpret_cast(input+i+0)); + __m128 tmphi = _mm_loadu_ps(reinterpret_cast(input+i+2)); + + //convert and scale + __m128i tmpilo = _mm_cvtps_epi32(_mm_mul_ps(tmplo, scalar)); + __m128i tmpihi = _mm_cvtps_epi32(_mm_mul_ps(tmphi, scalar)); + + //pack + byteswap -> byteswap 16 bit words + __m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi); + tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8)); + + //store to output + _mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi); + } + + //convert remainder + for (; i < nsamps; i++){ + output[i] = uhd::byteswap(fc32_to_item32(input[i])); + } +} + +DECLARE_CONVERTER(convert_item32_1_to_fc32_1_nswap, PRIORITY_CUSTOM){ + const item32_t *input = reinterpret_cast(inputs[0]); + fc32_t *output = reinterpret_cast(outputs[0]); + + __m128 scalar = _mm_set_ps1(floats_per_short/(1 << 16)); + __m128i zeroi = _mm_setzero_si128(); + + //convert blocks of samples with intrinsics + size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ + //load from input + __m128i tmpi = _mm_loadu_si128(reinterpret_cast(input+i)); + + //unpack + swap 16-bit pairs + tmpi = _mm_shufflelo_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); + tmpi = _mm_shufflehi_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); + __m128i tmpilo = _mm_unpacklo_epi16(zeroi, tmpi); //value in upper 16 bits + __m128i tmpihi = _mm_unpackhi_epi16(zeroi, tmpi); + + //convert and scale + __m128 tmplo = _mm_mul_ps(_mm_cvtepi32_ps(tmpilo), scalar); + __m128 tmphi = _mm_mul_ps(_mm_cvtepi32_ps(tmpihi), scalar); + + //store to output + _mm_storeu_ps(reinterpret_cast(output+i+0), tmplo); + _mm_storeu_ps(reinterpret_cast(output+i+2), tmphi); + } + + //convert remainder + for (; i < nsamps; i++){ + output[i] = item32_to_fc32(input[i]); + } +} + +DECLARE_CONVERTER(convert_item32_1_to_fc32_1_bswap, PRIORITY_CUSTOM){ + const item32_t *input = reinterpret_cast(inputs[0]); + fc32_t *output = reinterpret_cast(outputs[0]); + + __m128 scalar = _mm_set_ps1(floats_per_short/(1 << 16)); + __m128i zeroi = _mm_setzero_si128(); + + //convert blocks of samples with intrinsics + size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ + //load from input + __m128i tmpi = _mm_loadu_si128(reinterpret_cast(input+i)); + + //byteswap + unpack -> byteswap 16 bit words + tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8)); + __m128i tmpilo = _mm_unpacklo_epi16(zeroi, tmpi); //value in upper 16 bits + __m128i tmpihi = _mm_unpackhi_epi16(zeroi, tmpi); + + //convert and scale + __m128 tmplo = _mm_mul_ps(_mm_cvtepi32_ps(tmpilo), scalar); + __m128 tmphi = _mm_mul_ps(_mm_cvtepi32_ps(tmpihi), scalar); + + //store to output + _mm_storeu_ps(reinterpret_cast(output+i+0), tmplo); + _mm_storeu_ps(reinterpret_cast(output+i+2), tmphi); + } + + //convert remainder + for (; i < nsamps; i++){ + output[i] = item32_to_fc32(uhd::byteswap(input[i])); + } +} diff --git a/host/lib/convert/gen_convert_general.py b/host/lib/convert/gen_convert_general.py new file mode 100644 index 000000000..47c4cd7d0 --- /dev/null +++ b/host/lib/convert/gen_convert_general.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# +# Copyright 2011 Ettus Research LLC +# +# 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 3 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, see . +# + +TMPL_HEADER = """ +#import time +/*********************************************************************** + * This file was generated by $file on $time.strftime("%c") + **********************************************************************/ + +\#include "convert_common.hpp" +\#include + +using namespace uhd::convert; +""" + +TMPL_CONV_TO_FROM_ITEM32_1 = """ +DECLARE_CONVERTER(convert_$(cpu_type)_1_to_item32_1_$(swap), PRIORITY_GENERAL){ + const $(cpu_type)_t *input = reinterpret_cast(inputs[0]); + item32_t *output = reinterpret_cast(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + output[i] = $(swap_fcn)($(cpu_type)_to_item32(input[i])); + } +} + +DECLARE_CONVERTER(convert_item32_1_to_$(cpu_type)_1_$(swap), PRIORITY_GENERAL){ + const item32_t *input = reinterpret_cast(inputs[0]); + $(cpu_type)_t *output = reinterpret_cast<$(cpu_type)_t *>(outputs[0]); + + for (size_t i = 0; i < nsamps; i++){ + output[i] = item32_to_$(cpu_type)($(swap_fcn)(input[i])); + } +} +""" +TMPL_CONV_TO_FROM_ITEM32_X = """ +DECLARE_CONVERTER(convert_$(cpu_type)_$(width)_to_item32_1_$(swap), PRIORITY_GENERAL){ + #for $w in range($width) + const $(cpu_type)_t *input$(w) = reinterpret_cast(inputs[$(w)]); + #end for + item32_t *output = reinterpret_cast(outputs[0]); + + for (size_t i = 0, j = 0; i < nsamps; i++){ + #for $w in range($width) + output[j++] = $(swap_fcn)($(cpu_type)_to_item32(input$(w)[i])); + #end for + } +} + +DECLARE_CONVERTER(convert_item32_1_to_$(cpu_type)_$(width)_$(swap), PRIORITY_GENERAL){ + const item32_t *input = reinterpret_cast(inputs[0]); + #for $w in range($width) + $(cpu_type)_t *output$(w) = reinterpret_cast<$(cpu_type)_t *>(outputs[$(w)]); + #end for + + for (size_t i = 0, j = 0; i < nsamps; i++){ + #for $w in range($width) + output$(w)[i] = item32_to_$(cpu_type)($(swap_fcn)(input[j++])); + #end for + } +} +""" + +def parse_tmpl(_tmpl_text, **kwargs): + from Cheetah.Template import Template + return str(Template(_tmpl_text, kwargs)) + +if __name__ == '__main__': + import sys, os + file = os.path.basename(__file__) + output = parse_tmpl(TMPL_HEADER, file=file) + for width in 1, 2, 3, 4: + for swap, swap_fcn in (('nswap', ''), ('bswap', 'uhd::byteswap')): + for cpu_type in 'fc32', 'sc16': + output += parse_tmpl( + TMPL_CONV_TO_FROM_ITEM32_1 if width == 1 else TMPL_CONV_TO_FROM_ITEM32_X, + width=width, swap=swap, swap_fcn=swap_fcn, cpu_type=cpu_type + ) + open(sys.argv[1], 'w').write(output) diff --git a/host/lib/convert/gen_convert_impl.py b/host/lib/convert/gen_convert_impl.py new file mode 100644 index 000000000..71095ab97 --- /dev/null +++ b/host/lib/convert/gen_convert_impl.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python +# +# Copyright 2010-2011 Ettus Research LLC +# +# 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 3 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, see . +# + +TMPL_TEXT = """ +#import time +/*********************************************************************** + * This file was generated by $file on $time.strftime("%c") + **********************************************************************/ +typedef size_t pred_type; + +\#include +\#include +\#include +\#include + +enum dir_type{ + DIR_OTW_TO_CPU = 0, + DIR_CPU_TO_OTW = 1 +}; + +pred_type make_pred(const std::string &markup, dir_type &dir){ + pred_type pred = 0; + + try{ + std::vector tokens = std::split_string(markup, "_"); + //token 0 is + std::string inp_type = tokens.at(1); + std::string num_inps = tokens.at(2); + //token 3 is + std::string out_type = tokens.at(4); + std::string num_outs = tokens.at(5); + std::string swap_type = tokens.at(6); + + std::string cpu_type, otw_type; + if (inp_type.find("item") == std::string::npos){ + cpu_type = inp_type; + otw_type = out_type; + dir = DIR_CPU_TO_OTW; + } + else{ + cpu_type = out_type; + otw_type = inp_type; + dir = DIR_OTW_TO_CPU; + } + + if (cpu_type == "fc32") pred |= $ph.fc32_p; + else if (cpu_type == "sc16") pred |= $ph.sc16_p; + else throw std::runtime_error("unhandled io type " + cpu_type); + + if (otw_type == "item32") pred |= $ph.item32_p; + else throw std::runtime_error("unhandled otw type " + otw_type); + + int num_inputs = boost::lexical_cast(num_inps); + int num_outputs = boost::lexical_cast(num_outs); + + switch(num_inputs*num_outputs){ //FIXME treated as one value + case 1: pred |= $ph.chan1_p; break; + case 2: pred |= $ph.chan2_p; break; + case 3: pred |= $ph.chan3_p; break; + case 4: pred |= $ph.chan4_p; break; + default: throw std::runtime_error("unhandled number of channels"); + } + + if (swap_type == "bswap") pred |= $ph.bswap_p; + else if (swap_type == "nswap") pred |= $ph.nswap_p; + else throw std::runtime_error("unhandled swap type"); + + } + catch(...){ + throw std::runtime_error("convert::make_pred: could not parse markup: " + markup); + } + + return pred; +} + +UHD_INLINE pred_type make_pred( + const io_type_t &io_type, + const otw_type_t &otw_type, + size_t num_inputs, + size_t num_outputs +){ + pred_type pred = 0; + + switch(otw_type.byteorder){ + \#ifdef BOOST_BIG_ENDIAN + case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.nswap_p; break; + case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.bswap_p; break; + \#else + case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.bswap_p; break; + case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break; + \#endif + case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break; + default: throw std::runtime_error("unhandled otw byteorder type"); + } + + switch(otw_type.get_sample_size()){ + case sizeof(boost::uint32_t): pred |= $ph.item32_p; break; + default: throw std::runtime_error("unhandled otw sample size"); + } + + switch(io_type.tid){ + case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break; + case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break; + default: throw std::runtime_error("unhandled io type id"); + } + + switch(num_inputs*num_outputs){ //FIXME treated as one value + case 1: pred |= $ph.chan1_p; break; + case 2: pred |= $ph.chan2_p; break; + case 3: pred |= $ph.chan3_p; break; + case 4: pred |= $ph.chan4_p; break; + default: throw std::runtime_error("unhandled number of channels"); + } + + return pred; +} +""" + +def parse_tmpl(_tmpl_text, **kwargs): + from Cheetah.Template import Template + return str(Template(_tmpl_text, kwargs)) + +class ph: + bswap_p = 0b00001 + nswap_p = 0b00000 + item32_p = 0b00000 + sc16_p = 0b00010 + fc32_p = 0b00000 + chan1_p = 0b00000 + chan2_p = 0b00100 + chan3_p = 0b01000 + chan4_p = 0b01100 + + nbits = 4 #see above + + @staticmethod + def has(pred, mask, flag): return (pred & mask) == flag + + @staticmethod + def get_swap_type(pred): + mask = 0b1 + if ph.has(pred, mask, ph.bswap_p): return 'bswap' + if ph.has(pred, mask, ph.nswap_p): return 'nswap' + raise NotImplementedError + + @staticmethod + def get_dev_type(pred): + mask = 0b0 + if ph.has(pred, mask, ph.item32_p): return 'item32' + raise NotImplementedError + + @staticmethod + def get_host_type(pred): + mask = 0b10 + if ph.has(pred, mask, ph.sc16_p): return 'sc16' + if ph.has(pred, mask, ph.fc32_p): return 'fc32' + raise NotImplementedError + + @staticmethod + def get_num_chans(pred): + mask = 0b1100 + if ph.has(pred, mask, ph.chan1_p): return 1 + if ph.has(pred, mask, ph.chan2_p): return 2 + if ph.has(pred, mask, ph.chan3_p): return 3 + if ph.has(pred, mask, ph.chan4_p): return 4 + raise NotImplementedError + +if __name__ == '__main__': + import sys, os + file = os.path.basename(__file__) + open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=file, ph=ph)) -- cgit v1.2.3 From d5aef80d35bfef42c6050d76fb9d0441a1af1cb4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 4 Jan 2011 19:46:31 -0800 Subject: uhd: removed convert types, replaced by convert --- host/include/uhd/transport/CMakeLists.txt | 2 - host/include/uhd/transport/convert_types.hpp | 96 -------- host/include/uhd/transport/convert_types.ipp | 43 ---- host/lib/convert/gen_convert_impl.py | 58 ++--- host/lib/transport/CMakeLists.txt | 34 --- host/lib/transport/convert_types_impl.hpp | 345 --------------------------- host/lib/transport/gen_convert_types.py | 211 ---------------- 7 files changed, 17 insertions(+), 772 deletions(-) delete mode 100644 host/include/uhd/transport/convert_types.hpp delete mode 100644 host/include/uhd/transport/convert_types.ipp delete mode 100644 host/lib/transport/convert_types_impl.hpp delete mode 100755 host/lib/transport/gen_convert_types.py (limited to 'host/lib/convert') diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt index 726306ec1..8dfd8d9f1 100644 --- a/host/include/uhd/transport/CMakeLists.txt +++ b/host/include/uhd/transport/CMakeLists.txt @@ -20,8 +20,6 @@ INSTALL(FILES bounded_buffer.hpp bounded_buffer.ipp buffer_pool.hpp - convert_types.hpp - convert_types.ipp if_addrs.hpp udp_simple.hpp udp_zero_copy.hpp diff --git a/host/include/uhd/transport/convert_types.hpp b/host/include/uhd/transport/convert_types.hpp deleted file mode 100644 index dc7fa6c1a..000000000 --- a/host/include/uhd/transport/convert_types.hpp +++ /dev/null @@ -1,96 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// 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 3 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, see . -// - -#ifndef INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP -#define INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP - -#include -#include -#include -#include - -namespace uhd{ namespace transport{ - -/*! - * Convert IO samples to OWT samples. - * - * \param io_buff memory containing samples - * \param io_type the type of these samples - * \param otw_buff memory to write converted samples - * \param otw_type the type of these samples - * \param num_samps the number of samples in io_buff - */ -UHD_API void convert_io_type_to_otw_type( - const void *io_buff, const io_type_t &io_type, - void *otw_buff, const otw_type_t &otw_type, - size_t num_samps -); - -/*! - * Convert IO samples to OWT samples + interleave. - * - * \param io_buffs buffers containing samples - * \param io_type the type of these samples - * \param otw_buff memory to write converted samples - * \param otw_type the type of these samples - * \param nsamps_per_io_buff samples per io_buff - */ -UHD_API void convert_io_type_to_otw_type( - const std::vector &io_buffs, - const io_type_t &io_type, - void *otw_buff, - const otw_type_t &otw_type, - size_t nsamps_per_io_buff -); - -/*! - * Convert OTW samples to IO samples. - * - * \param otw_buff memory containing samples - * \param otw_type the type of these samples - * \param io_buff memory to write converted samples - * \param io_type the type of these samples - * \param num_samps the number of samples in io_buff - */ -UHD_API void convert_otw_type_to_io_type( - const void *otw_buff, const otw_type_t &otw_type, - void *io_buff, const io_type_t &io_type, - size_t num_samps -); - -/*! - * Convert OTW samples to IO samples + de-interleave. - * - * \param otw_buff memory containing samples - * \param otw_type the type of these samples - * \param io_buffs buffers to write converted samples - * \param io_type the type of these samples - * \param nsamps_per_io_buff samples per io_buff - */ -UHD_API void convert_otw_type_to_io_type( - const void *otw_buff, - const otw_type_t &otw_type, - std::vector &io_buffs, - const io_type_t &io_type, - size_t nsamps_per_io_buff -); - -}} //namespace - -#include - -#endif /* INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_HPP */ diff --git a/host/include/uhd/transport/convert_types.ipp b/host/include/uhd/transport/convert_types.ipp deleted file mode 100644 index 914ca6f17..000000000 --- a/host/include/uhd/transport/convert_types.ipp +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// 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 3 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, see . -// - -#ifndef INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP -#define INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP - -UHD_INLINE void uhd::transport::convert_io_type_to_otw_type( - const void *io_buff, const io_type_t &io_type, - void *otw_buff, const otw_type_t &otw_type, - size_t num_samps -){ - std::vector buffs(1, io_buff); - return uhd::transport::convert_io_type_to_otw_type( - buffs, io_type, otw_buff, otw_type, num_samps - ); -} - -UHD_INLINE void uhd::transport::convert_otw_type_to_io_type( - const void *otw_buff, const otw_type_t &otw_type, - void *io_buff, const io_type_t &io_type, - size_t num_samps -){ - std::vector buffs(1, io_buff); - return uhd::transport::convert_otw_type_to_io_type( - otw_buff, otw_type, buffs, io_type, num_samps - ); -} - -#endif /* INCLUDED_UHD_TRANSPORT_CONVERT_TYPES_IPP */ diff --git a/host/lib/convert/gen_convert_impl.py b/host/lib/convert/gen_convert_impl.py index 71095ab97..70d437ba2 100644 --- a/host/lib/convert/gen_convert_impl.py +++ b/host/lib/convert/gen_convert_impl.py @@ -26,6 +26,7 @@ typedef size_t pred_type; \#include \#include \#include +\#include \#include enum dir_type{ @@ -33,6 +34,13 @@ enum dir_type{ DIR_CPU_TO_OTW = 1 }; +struct pred_error : std::runtime_error{ + pred_error(const std::string &what) + :std::runtime_error("convert::make_pred: " + what){ + /* NOP */ + } +}; + pred_type make_pred(const std::string &markup, dir_type &dir){ pred_type pred = 0; @@ -60,10 +68,10 @@ pred_type make_pred(const std::string &markup, dir_type &dir){ if (cpu_type == "fc32") pred |= $ph.fc32_p; else if (cpu_type == "sc16") pred |= $ph.sc16_p; - else throw std::runtime_error("unhandled io type " + cpu_type); + else throw pred_error("unhandled io type " + cpu_type); if (otw_type == "item32") pred |= $ph.item32_p; - else throw std::runtime_error("unhandled otw type " + otw_type); + else throw pred_error("unhandled otw type " + otw_type); int num_inputs = boost::lexical_cast(num_inps); int num_outputs = boost::lexical_cast(num_outs); @@ -73,16 +81,16 @@ pred_type make_pred(const std::string &markup, dir_type &dir){ case 2: pred |= $ph.chan2_p; break; case 3: pred |= $ph.chan3_p; break; case 4: pred |= $ph.chan4_p; break; - default: throw std::runtime_error("unhandled number of channels"); + default: throw pred_error("unhandled number of channels"); } if (swap_type == "bswap") pred |= $ph.bswap_p; else if (swap_type == "nswap") pred |= $ph.nswap_p; - else throw std::runtime_error("unhandled swap type"); + else throw pred_error("unhandled swap type"); } catch(...){ - throw std::runtime_error("convert::make_pred: could not parse markup: " + markup); + throw pred_error("could not parse markup: " + markup); } return pred; @@ -105,18 +113,18 @@ UHD_INLINE pred_type make_pred( case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break; \#endif case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break; - default: throw std::runtime_error("unhandled otw byteorder type"); + default: throw pred_error("unhandled otw byteorder type"); } switch(otw_type.get_sample_size()){ case sizeof(boost::uint32_t): pred |= $ph.item32_p; break; - default: throw std::runtime_error("unhandled otw sample size"); + default: throw pred_error("unhandled otw sample size"); } switch(io_type.tid){ case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break; case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break; - default: throw std::runtime_error("unhandled io type id"); + default: throw pred_error("unhandled io type id"); } switch(num_inputs*num_outputs){ //FIXME treated as one value @@ -124,7 +132,7 @@ UHD_INLINE pred_type make_pred( case 2: pred |= $ph.chan2_p; break; case 3: pred |= $ph.chan3_p; break; case 4: pred |= $ph.chan4_p; break; - default: throw std::runtime_error("unhandled number of channels"); + default: throw pred_error("unhandled number of channels"); } return pred; @@ -148,38 +156,6 @@ class ph: nbits = 4 #see above - @staticmethod - def has(pred, mask, flag): return (pred & mask) == flag - - @staticmethod - def get_swap_type(pred): - mask = 0b1 - if ph.has(pred, mask, ph.bswap_p): return 'bswap' - if ph.has(pred, mask, ph.nswap_p): return 'nswap' - raise NotImplementedError - - @staticmethod - def get_dev_type(pred): - mask = 0b0 - if ph.has(pred, mask, ph.item32_p): return 'item32' - raise NotImplementedError - - @staticmethod - def get_host_type(pred): - mask = 0b10 - if ph.has(pred, mask, ph.sc16_p): return 'sc16' - if ph.has(pred, mask, ph.fc32_p): return 'fc32' - raise NotImplementedError - - @staticmethod - def get_num_chans(pred): - mask = 0b1100 - if ph.has(pred, mask, ph.chan1_p): return 1 - if ph.has(pred, mask, ph.chan2_p): return 2 - if ph.has(pred, mask, ph.chan3_p): return 3 - if ph.has(pred, mask, ph.chan4_p): return 4 - raise NotImplementedError - if __name__ == '__main__': import sys, os file = os.path.basename(__file__) diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index ac92ffe6d..914ba3ba9 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -46,25 +46,6 @@ ELSE(ENABLE_USB) ) ENDIF(ENABLE_USB) -######################################################################## -# Check for SIMD headers -######################################################################## -MESSAGE(STATUS "") - -INCLUDE(CheckIncludeFileCXX) -CHECK_INCLUDE_FILE_CXX(emmintrin.h HAVE_EMMINTRIN_H) - -IF(HAVE_EMMINTRIN_H) - ADD_DEFINITIONS(-DHAVE_EMMINTRIN_H) -ENDIF(HAVE_EMMINTRIN_H) - -INCLUDE(CheckIncludeFileCXX) -CHECK_INCLUDE_FILE_CXX(arm_neon.h HAVE_ARM_NEON_H) - -IF(HAVE_ARM_NEON_H) - ADD_DEFINITIONS(-DHAVE_ARM_NEON_H) -ENDIF(HAVE_ARM_NEON_H) - ######################################################################## # Setup defines for interface address discovery ######################################################################## @@ -93,21 +74,6 @@ LIBUHD_PYTHON_GEN_SOURCE( ${CMAKE_CURRENT_BINARY_DIR}/vrt_if_packet.cpp ) -LIBUHD_PYTHON_GEN_SOURCE( - ${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_types.py - ${CMAKE_CURRENT_BINARY_DIR}/convert_types.cpp -) - -# append this directory to the include path so the generated convert types -# can include the implementation convert types file in the source directory -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - -# make the generated convert types depend on the implementation header -SET_SOURCE_FILES_PROPERTIES( - ${CMAKE_CURRENT_BINARY_DIR}/convert_types.cpp PROPERTIES - OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/convert_types_impl.hpp -) - LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/buffer_pool.cpp ${CMAKE_CURRENT_SOURCE_DIR}/if_addrs.cpp diff --git a/host/lib/transport/convert_types_impl.hpp b/host/lib/transport/convert_types_impl.hpp deleted file mode 100644 index 48ff99725..000000000 --- a/host/lib/transport/convert_types_impl.hpp +++ /dev/null @@ -1,345 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// 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 3 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, see . -// - -#ifndef INCLUDED_LIBUHD_TRANSPORT_CONVERT_TYPES_IMPL_HPP -#define INCLUDED_LIBUHD_TRANSPORT_CONVERT_TYPES_IMPL_HPP - -#include -#include -#include -#include -#include - -#ifdef HAVE_EMMINTRIN_H - #define USE_EMMINTRIN_H //use sse2 intrinsics -#endif - -#if defined(USE_EMMINTRIN_H) - #include -#endif - -#ifdef HAVE_ARM_NEON_H - #define USE_ARM_NEON_H -#endif - -#if defined(USE_ARM_NEON_H) - #include -#endif - -/*********************************************************************** - * Typedefs - **********************************************************************/ -typedef std::complex fc32_t; -typedef std::complex sc16_t; -typedef boost::uint32_t item32_t; - -/*********************************************************************** - * Convert complex short buffer to items32 - **********************************************************************/ -static UHD_INLINE item32_t sc16_to_item32(sc16_t num){ - boost::uint16_t real = num.real(); - boost::uint16_t imag = num.imag(); - return (item32_t(real) << 16) | (item32_t(imag) << 0); -} - -static UHD_INLINE void sc16_to_item32_nswap( - const sc16_t *input, item32_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = sc16_to_item32(input[i]); - } -} - -static UHD_INLINE void sc16_to_item32_bswap( - const sc16_t *input, item32_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = uhd::byteswap(sc16_to_item32(input[i])); - } -} - -/*********************************************************************** - * Convert items32 buffer to complex short - **********************************************************************/ -static UHD_INLINE sc16_t item32_to_sc16(item32_t item){ - return sc16_t( - boost::int16_t(item >> 16), - boost::int16_t(item >> 0) - ); -} - -static UHD_INLINE void item32_to_sc16_nswap( - const item32_t *input, sc16_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = item32_to_sc16(input[i]); - } -} - -static UHD_INLINE void item32_to_sc16_bswap( - const item32_t *input, sc16_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = item32_to_sc16(uhd::byteswap(input[i])); - } -} - -/*********************************************************************** - * Convert complex float buffer to items32 (no swap) - **********************************************************************/ -static const float shorts_per_float = float(32767); - -static UHD_INLINE item32_t fc32_to_item32(fc32_t num){ - boost::uint16_t real = boost::int16_t(num.real()*shorts_per_float); - boost::uint16_t imag = boost::int16_t(num.imag()*shorts_per_float); - return (item32_t(real) << 16) | (item32_t(imag) << 0); -} - -//////////////////////////////////// -// none-swap -//////////////////////////////////// -#if defined(USE_EMMINTRIN_H) -static UHD_INLINE void fc32_to_item32_nswap( - const fc32_t *input, item32_t *output, size_t nsamps -){ - __m128 scalar = _mm_set_ps1(shorts_per_float); - - //convert blocks of samples with intrinsics - size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ - //load from input - __m128 tmplo = _mm_loadu_ps(reinterpret_cast(input+i+0)); - __m128 tmphi = _mm_loadu_ps(reinterpret_cast(input+i+2)); - - //convert and scale - __m128i tmpilo = _mm_cvtps_epi32(_mm_mul_ps(tmplo, scalar)); - __m128i tmpihi = _mm_cvtps_epi32(_mm_mul_ps(tmphi, scalar)); - - //pack + swap 16-bit pairs - __m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi); - tmpi = _mm_shufflelo_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); - tmpi = _mm_shufflehi_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); - - //store to output - _mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi); - } - - //convert remainder - for (; i < nsamps; i++){ - output[i] = fc32_to_item32(input[i]); - } -} - -#elif defined(USE_ARM_NEON_H) -static UHD_INLINE void fc32_to_item32_nswap( - const fc32_t *input, item32_t *output, size_t nsamps) -{ - size_t i; - - float32x4_t Q0 = vdupq_n_f32(shorts_per_float); - for (i=0; i < (nsamps & ~0x03); i+=2) { - float32x4_t Q1 = vld1q_f32(reinterpret_cast(&input[i])); - float32x4_t Q2 = vmulq_f32(Q1, Q0); - int32x4_t Q3 = vcvtq_s32_f32(Q2); - int16x4_t D8 = vmovn_s32(Q3); - int16x4_t D9 = vrev32_s16(D8); - vst1_s16((reinterpret_cast(&output[i])), D9); - } - - for (; i < nsamps; i++) - output[i] = fc32_to_item32(input[i]); -} - -#else -static UHD_INLINE void fc32_to_item32_nswap( - const fc32_t *input, item32_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = fc32_to_item32(input[i]); - } -} - -#endif - -//////////////////////////////////// -// byte-swap -//////////////////////////////////// -#if defined(USE_EMMINTRIN_H) -static UHD_INLINE void fc32_to_item32_bswap( - const fc32_t *input, item32_t *output, size_t nsamps -){ - __m128 scalar = _mm_set_ps1(shorts_per_float); - - //convert blocks of samples with intrinsics - size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ - //load from input - __m128 tmplo = _mm_loadu_ps(reinterpret_cast(input+i+0)); - __m128 tmphi = _mm_loadu_ps(reinterpret_cast(input+i+2)); - - //convert and scale - __m128i tmpilo = _mm_cvtps_epi32(_mm_mul_ps(tmplo, scalar)); - __m128i tmpihi = _mm_cvtps_epi32(_mm_mul_ps(tmphi, scalar)); - - //pack + byteswap -> byteswap 16 bit words - __m128i tmpi = _mm_packs_epi32(tmpilo, tmpihi); - tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8)); - - //store to output - _mm_storeu_si128(reinterpret_cast<__m128i *>(output+i), tmpi); - } - - //convert remainder - for (; i < nsamps; i++){ - output[i] = uhd::byteswap(fc32_to_item32(input[i])); - } -} - -#else -static UHD_INLINE void fc32_to_item32_bswap( - const fc32_t *input, item32_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = uhd::byteswap(fc32_to_item32(input[i])); - } -} - -#endif - -/*********************************************************************** - * Convert items32 buffer to complex float - **********************************************************************/ -static const float floats_per_short = float(1.0/shorts_per_float); - -static UHD_INLINE fc32_t item32_to_fc32(item32_t item){ - return fc32_t( - float(boost::int16_t(item >> 16)*floats_per_short), - float(boost::int16_t(item >> 0)*floats_per_short) - ); -} - -//////////////////////////////////// -// none-swap -//////////////////////////////////// -#if defined(USE_EMMINTRIN_H) -static UHD_INLINE void item32_to_fc32_nswap( - const item32_t *input, fc32_t *output, size_t nsamps -){ - __m128 scalar = _mm_set_ps1(floats_per_short/(1 << 16)); - __m128i zeroi = _mm_setzero_si128(); - - //convert blocks of samples with intrinsics - size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ - //load from input - __m128i tmpi = _mm_loadu_si128(reinterpret_cast(input+i)); - - //unpack + swap 16-bit pairs - tmpi = _mm_shufflelo_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); - tmpi = _mm_shufflehi_epi16(tmpi, _MM_SHUFFLE(2, 3, 0, 1)); - __m128i tmpilo = _mm_unpacklo_epi16(zeroi, tmpi); //value in upper 16 bits - __m128i tmpihi = _mm_unpackhi_epi16(zeroi, tmpi); - - //convert and scale - __m128 tmplo = _mm_mul_ps(_mm_cvtepi32_ps(tmpilo), scalar); - __m128 tmphi = _mm_mul_ps(_mm_cvtepi32_ps(tmpihi), scalar); - - //store to output - _mm_storeu_ps(reinterpret_cast(output+i+0), tmplo); - _mm_storeu_ps(reinterpret_cast(output+i+2), tmphi); - } - - //convert remainder - for (; i < nsamps; i++){ - output[i] = item32_to_fc32(input[i]); - } -} - -#elif defined(USE_ARM_NEON_H) -static UHD_INLINE void item32_to_fc32_nswap( - const item32_t *input, fc32_t *output, size_t nsamps) -{ - size_t i; - - float32x4_t Q1 = vdupq_n_f32(floats_per_short); - for (i=0; i < (nsamps & ~0x03); i+=2) { - int16x4_t D0 = vld1_s16(reinterpret_cast(&input[i])); - int16x4_t D1 = vrev32_s16(D0); - int32x4_t Q2 = vmovl_s16(D1); - float32x4_t Q3 = vcvtq_f32_s32(Q2); - float32x4_t Q4 = vmulq_f32(Q3, Q1); - vst1q_f32((reinterpret_cast(&output[i])), Q4); - } - - for (; i < nsamps; i++) - output[i] = item32_to_fc32(input[i]); -} - -#else -static UHD_INLINE void item32_to_fc32_nswap( - const item32_t *input, fc32_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = item32_to_fc32(input[i]); - } -} -#endif - -//////////////////////////////////// -// byte-swap -//////////////////////////////////// -#if defined(USE_EMMINTRIN_H) -static UHD_INLINE void item32_to_fc32_bswap( - const item32_t *input, fc32_t *output, size_t nsamps -){ - __m128 scalar = _mm_set_ps1(floats_per_short/(1 << 16)); - __m128i zeroi = _mm_setzero_si128(); - - //convert blocks of samples with intrinsics - size_t i = 0; for (; i < (nsamps & ~0x3); i+=4){ - //load from input - __m128i tmpi = _mm_loadu_si128(reinterpret_cast(input+i)); - - //byteswap + unpack -> byteswap 16 bit words - tmpi = _mm_or_si128(_mm_srli_epi16(tmpi, 8), _mm_slli_epi16(tmpi, 8)); - __m128i tmpilo = _mm_unpacklo_epi16(zeroi, tmpi); //value in upper 16 bits - __m128i tmpihi = _mm_unpackhi_epi16(zeroi, tmpi); - - //convert and scale - __m128 tmplo = _mm_mul_ps(_mm_cvtepi32_ps(tmpilo), scalar); - __m128 tmphi = _mm_mul_ps(_mm_cvtepi32_ps(tmpihi), scalar); - - //store to output - _mm_storeu_ps(reinterpret_cast(output+i+0), tmplo); - _mm_storeu_ps(reinterpret_cast(output+i+2), tmphi); - } - - //convert remainder - for (; i < nsamps; i++){ - output[i] = item32_to_fc32(uhd::byteswap(input[i])); - } -} - -#else -static UHD_INLINE void item32_to_fc32_bswap( - const item32_t *input, fc32_t *output, size_t nsamps -){ - for (size_t i = 0; i < nsamps; i++){ - output[i] = item32_to_fc32(uhd::byteswap(input[i])); - } -} - -#endif - -#endif /* INCLUDED_LIBUHD_TRANSPORT_CONVERT_TYPES_IMPL_HPP */ diff --git a/host/lib/transport/gen_convert_types.py b/host/lib/transport/gen_convert_types.py deleted file mode 100755 index f9509c81d..000000000 --- a/host/lib/transport/gen_convert_types.py +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2010 Ettus Research LLC -# -# 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 3 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, see . -# - -TMPL_TEXT = """ -#import time -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#include -\#include -\#include -\#include -\#include -\#include "convert_types_impl.hpp" - -using namespace uhd; - -/*********************************************************************** - * Generate predicate for jump table - **********************************************************************/ -UHD_INLINE boost::uint8_t get_pred( - const io_type_t &io_type, - const otw_type_t &otw_type, - size_t num_chans -){ - boost::uint8_t pred = 0; - - switch(otw_type.byteorder){ - \#ifdef BOOST_BIG_ENDIAN - case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.nswap_p; break; - case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.bswap_p; break; - \#else - case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.bswap_p; break; - case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break; - \#endif - case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break; - default: throw std::runtime_error("unhandled otw byteorder type"); - } - - switch(otw_type.get_sample_size()){ - case sizeof(boost::uint32_t): pred |= $ph.item32_p; break; - default: throw std::runtime_error("unhandled otw sample size"); - } - - switch(io_type.tid){ - case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break; - case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break; - default: throw std::runtime_error("unhandled io type id"); - } - - switch(num_chans){ - case 1: pred |= $ph.chan1_p; break; - case 2: pred |= $ph.chan2_p; break; - case 3: pred |= $ph.chan3_p; break; - case 4: pred |= $ph.chan4_p; break; - default: throw std::runtime_error("unhandled number of channels"); - } - - return pred; -} - -/*********************************************************************** - * Convert host type to device type - **********************************************************************/ -void transport::convert_io_type_to_otw_type( - const std::vector &io_buffs, - const io_type_t &io_type, - void *otw_buff, - const otw_type_t &otw_type, - size_t nsamps_per_io_buff -){ - switch(get_pred(io_type, otw_type, io_buffs.size())){ - #for $pred in range(2**$ph.nbits) - case $pred: - #set $out_type = $ph.get_dev_type($pred) - #set $in_type = $ph.get_host_type($pred) - #set $num_chans = $ph.get_num_chans($pred) - #set $converter = '_'.join([$in_type, 'to', $out_type]) - #if $num_chans == 1 - $(converter)_$ph.get_swap_type($pred)( - reinterpret_cast(io_buffs.front()), - reinterpret_cast<$(out_type)_t *>(otw_buff), - nsamps_per_io_buff - ); - #else - for (size_t i = 0, j = 0; i < nsamps_per_io_buff; i++){ - #for $j in range($num_chans) - reinterpret_cast<$(out_type)_t *>(otw_buff)[j++] = - #if $ph.get_swap_type($pred) == 'bswap' - uhd::byteswap($(converter)(reinterpret_cast(io_buffs[$j])[i])); - #else - $(converter)(reinterpret_cast(io_buffs[$j])[i]); - #end if - #end for - } - #end if - break; - #end for - } -} - -/*********************************************************************** - * Convert device type to host type - **********************************************************************/ -void transport::convert_otw_type_to_io_type( - const void *otw_buff, - const otw_type_t &otw_type, - std::vector &io_buffs, - const io_type_t &io_type, - size_t nsamps_per_io_buff -){ - switch(get_pred(io_type, otw_type, io_buffs.size())){ - #for $pred in range(2**$ph.nbits) - case $pred: - #set $out_type = $ph.get_host_type($pred) - #set $in_type = $ph.get_dev_type($pred) - #set $num_chans = $ph.get_num_chans($pred) - #set $converter = '_'.join([$in_type, 'to', $out_type]) - #if $num_chans == 1 - $(converter)_$ph.get_swap_type($pred)( - reinterpret_cast(otw_buff), - reinterpret_cast<$(out_type)_t *>(io_buffs.front()), - nsamps_per_io_buff - ); - #else - for (size_t i = 0, j = 0; i < nsamps_per_io_buff; i++){ - #for $j in range($num_chans) - reinterpret_cast<$(out_type)_t *>(io_buffs[$j])[i] = - #if $ph.get_swap_type($pred) == 'bswap' - $(converter)(uhd::byteswap(reinterpret_cast(otw_buff)[j++])); - #else - $(converter)(reinterpret_cast(otw_buff)[j++]); - #end if - #end for - } - #end if - break; - #end for - } -} - -""" - -def parse_tmpl(_tmpl_text, **kwargs): - from Cheetah.Template import Template - return str(Template(_tmpl_text, kwargs)) - -class ph: - bswap_p = 0b00001 - nswap_p = 0b00000 - item32_p = 0b00000 - sc16_p = 0b00010 - fc32_p = 0b00000 - chan1_p = 0b00000 - chan2_p = 0b00100 - chan3_p = 0b01000 - chan4_p = 0b01100 - - nbits = 4 #see above - - @staticmethod - def has(pred, mask, flag): return (pred & mask) == flag - - @staticmethod - def get_swap_type(pred): - mask = 0b1 - if ph.has(pred, mask, ph.bswap_p): return 'bswap' - if ph.has(pred, mask, ph.nswap_p): return 'nswap' - raise NotImplementedError - - @staticmethod - def get_dev_type(pred): - mask = 0b0 - if ph.has(pred, mask, ph.item32_p): return 'item32' - raise NotImplementedError - - @staticmethod - def get_host_type(pred): - mask = 0b10 - if ph.has(pred, mask, ph.sc16_p): return 'sc16' - if ph.has(pred, mask, ph.fc32_p): return 'fc32' - raise NotImplementedError - - @staticmethod - def get_num_chans(pred): - mask = 0b1100 - if ph.has(pred, mask, ph.chan1_p): return 1 - if ph.has(pred, mask, ph.chan2_p): return 2 - if ph.has(pred, mask, ph.chan3_p): return 3 - if ph.has(pred, mask, ph.chan4_p): return 4 - raise NotImplementedError - -if __name__ == '__main__': - import sys - open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=__file__, ph=ph)) -- cgit v1.2.3 From 03f4ce0fb260b8ebf7982a896fbd2ce8ab4c9c5a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 11:37:12 -0800 Subject: uhd: renamed and tweaked some of the convert files --- host/lib/convert/CMakeLists.txt | 10 +-- host/lib/convert/convert.cpp | 117 ------------------------- host/lib/convert/convert_impl.cpp | 117 +++++++++++++++++++++++++ host/lib/convert/gen_convert_impl.py | 162 ---------------------------------- host/lib/convert/gen_convert_pred.py | 163 +++++++++++++++++++++++++++++++++++ 5 files changed, 285 insertions(+), 284 deletions(-) delete mode 100644 host/lib/convert/convert.cpp create mode 100644 host/lib/convert/convert_impl.cpp delete mode 100644 host/lib/convert/gen_convert_impl.py create mode 100644 host/lib/convert/gen_convert_pred.py (limited to 'host/lib/convert') diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt index 9324a94b0..06f7ba12a 100644 --- a/host/lib/convert/CMakeLists.txt +++ b/host/lib/convert/CMakeLists.txt @@ -45,14 +45,14 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) LIBUHD_PYTHON_GEN_SOURCE( - ${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_impl.py - ${CMAKE_CURRENT_BINARY_DIR}/convert_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/gen_convert_pred.py + ${CMAKE_CURRENT_BINARY_DIR}/convert_pred.hpp ) INCLUDE(AddFileDependencies) ADD_FILE_DEPENDENCIES( - ${CMAKE_CURRENT_SOURCE_DIR}/convert.cpp - ${CMAKE_CURRENT_BINARY_DIR}/convert_impl.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/convert_impl.cpp + ${CMAKE_CURRENT_BINARY_DIR}/convert_pred.hpp ) LIBUHD_PYTHON_GEN_SOURCE( @@ -61,6 +61,6 @@ LIBUHD_PYTHON_GEN_SOURCE( ) LIBUHD_APPEND_SOURCES( - ${CMAKE_CURRENT_SOURCE_DIR}/convert.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/convert_impl.cpp ${CMAKE_CURRENT_BINARY_DIR}/convert_general.cpp ) diff --git a/host/lib/convert/convert.cpp b/host/lib/convert/convert.cpp deleted file mode 100644 index f635a1040..000000000 --- a/host/lib/convert/convert.cpp +++ /dev/null @@ -1,117 +0,0 @@ -// -// Copyright 2011 Ettus Research LLC -// -// 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 3 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, see . -// - -#include -#include -#include -#include - -using namespace uhd; - -#include "convert_impl.hpp" - -static const bool debug = false; - -/*********************************************************************** - * Define types for the function tables - **********************************************************************/ -struct fcn_table_entry_type{ - convert::priority_type prio; - convert::function_type fcn; - fcn_table_entry_type(void) - : prio(convert::PRIORITY_EMPTY), fcn(NULL){ - /* NOP */ - } -}; -typedef std::vector fcn_table_type; - -/*********************************************************************** - * Setup the table registry - **********************************************************************/ -UHD_SINGLETON_FCN(fcn_table_type, get_cpu_to_otw_table); -UHD_SINGLETON_FCN(fcn_table_type, get_otw_to_cpu_table); - -fcn_table_type &get_table(dir_type dir){ - switch(dir){ - case DIR_OTW_TO_CPU: return get_otw_to_cpu_table(); - case DIR_CPU_TO_OTW: return get_cpu_to_otw_table(); - } - UHD_THROW_INVALID_CODE_PATH(); -} - -/*********************************************************************** - * The registry functions - **********************************************************************/ -void uhd::convert::register_converter( - const std::string &markup, - function_type fcn, - priority_type prio -){ - //extract the predicate and direction from the markup - dir_type dir; - pred_type pred = make_pred(markup, dir); - - //get a reference to the function table - fcn_table_type &table = get_table(dir); - - //resize the table so that its at least pred+1 - if (table.size() <= pred) table.resize(pred+1); - - //register the function if higher priority - if (table[pred].prio < prio){ - table[pred].fcn = fcn; - table[pred].prio = prio; - } - - //----------------------------------------------------------------// - if (debug) std::cout << "register_converter: " << markup << std::endl - << " prio: " << prio << std::endl - << " pred: " << pred << std::endl - << " dir: " << dir << std::endl - << std::endl - ; - //----------------------------------------------------------------// -} - -/*********************************************************************** - * The converter functions - **********************************************************************/ -void uhd::convert::io_type_to_otw_type( - const io_type_t &io_type, - const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff -){ - pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); - fcn_table_type table = get_cpu_to_otw_table(); - function_type fcn = table.at(pred).fcn; - fcn(input_buffs, output_buffs, nsamps_per_io_buff); -} - -void uhd::convert::otw_type_to_io_type( - const io_type_t &io_type, - const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff -){ - pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); - fcn_table_type table = get_otw_to_cpu_table(); - function_type fcn = table.at(pred).fcn; - fcn(input_buffs, output_buffs, nsamps_per_io_buff); -} diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp new file mode 100644 index 000000000..74837cc51 --- /dev/null +++ b/host/lib/convert/convert_impl.cpp @@ -0,0 +1,117 @@ +// +// Copyright 2011 Ettus Research LLC +// +// 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 3 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, see . +// + +#include +#include +#include +#include + +using namespace uhd; + +#include "convert_pred.hpp" + +static const bool debug = false; + +/*********************************************************************** + * Define types for the function tables + **********************************************************************/ +struct fcn_table_entry_type{ + convert::priority_type prio; + convert::function_type fcn; + fcn_table_entry_type(void) + : prio(convert::PRIORITY_EMPTY), fcn(NULL){ + /* NOP */ + } +}; +typedef std::vector fcn_table_type; + +/*********************************************************************** + * Setup the table registry + **********************************************************************/ +UHD_SINGLETON_FCN(fcn_table_type, get_cpu_to_otw_table); +UHD_SINGLETON_FCN(fcn_table_type, get_otw_to_cpu_table); + +fcn_table_type &get_table(dir_type dir){ + switch(dir){ + case DIR_OTW_TO_CPU: return get_otw_to_cpu_table(); + case DIR_CPU_TO_OTW: return get_cpu_to_otw_table(); + } + UHD_THROW_INVALID_CODE_PATH(); +} + +/*********************************************************************** + * The registry functions + **********************************************************************/ +void uhd::convert::register_converter( + const std::string &markup, + function_type fcn, + priority_type prio +){ + //extract the predicate and direction from the markup + dir_type dir; + pred_type pred = make_pred(markup, dir); + + //get a reference to the function table + fcn_table_type &table = get_table(dir); + + //resize the table so that its at least pred+1 + if (table.size() <= pred) table.resize(pred+1); + + //register the function if higher priority + if (table[pred].prio < prio){ + table[pred].fcn = fcn; + table[pred].prio = prio; + } + + //----------------------------------------------------------------// + if (debug) std::cout << "register_converter: " << markup << std::endl + << " prio: " << prio << std::endl + << " pred: " << pred << std::endl + << " dir: " << dir << std::endl + << std::endl + ; + //----------------------------------------------------------------// +} + +/*********************************************************************** + * The converter functions + **********************************************************************/ +void uhd::convert::io_type_to_otw_type( + const io_type_t &io_type, + const otw_type_t &otw_type, + input_type &input_buffs, + output_type &output_buffs, + size_t nsamps_per_io_buff +){ + pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); + fcn_table_type table = get_cpu_to_otw_table(); + function_type fcn = table.at(pred).fcn; + fcn(input_buffs, output_buffs, nsamps_per_io_buff); +} + +void uhd::convert::otw_type_to_io_type( + const io_type_t &io_type, + const otw_type_t &otw_type, + input_type &input_buffs, + output_type &output_buffs, + size_t nsamps_per_io_buff +){ + pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); + fcn_table_type table = get_otw_to_cpu_table(); + function_type fcn = table.at(pred).fcn; + fcn(input_buffs, output_buffs, nsamps_per_io_buff); +} diff --git a/host/lib/convert/gen_convert_impl.py b/host/lib/convert/gen_convert_impl.py deleted file mode 100644 index 70d437ba2..000000000 --- a/host/lib/convert/gen_convert_impl.py +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2010-2011 Ettus Research LLC -# -# 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 3 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, see . -# - -TMPL_TEXT = """ -#import time -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ -typedef size_t pred_type; - -\#include -\#include -\#include -\#include -\#include - -enum dir_type{ - DIR_OTW_TO_CPU = 0, - DIR_CPU_TO_OTW = 1 -}; - -struct pred_error : std::runtime_error{ - pred_error(const std::string &what) - :std::runtime_error("convert::make_pred: " + what){ - /* NOP */ - } -}; - -pred_type make_pred(const std::string &markup, dir_type &dir){ - pred_type pred = 0; - - try{ - std::vector tokens = std::split_string(markup, "_"); - //token 0 is - std::string inp_type = tokens.at(1); - std::string num_inps = tokens.at(2); - //token 3 is - std::string out_type = tokens.at(4); - std::string num_outs = tokens.at(5); - std::string swap_type = tokens.at(6); - - std::string cpu_type, otw_type; - if (inp_type.find("item") == std::string::npos){ - cpu_type = inp_type; - otw_type = out_type; - dir = DIR_CPU_TO_OTW; - } - else{ - cpu_type = out_type; - otw_type = inp_type; - dir = DIR_OTW_TO_CPU; - } - - if (cpu_type == "fc32") pred |= $ph.fc32_p; - else if (cpu_type == "sc16") pred |= $ph.sc16_p; - else throw pred_error("unhandled io type " + cpu_type); - - if (otw_type == "item32") pred |= $ph.item32_p; - else throw pred_error("unhandled otw type " + otw_type); - - int num_inputs = boost::lexical_cast(num_inps); - int num_outputs = boost::lexical_cast(num_outs); - - switch(num_inputs*num_outputs){ //FIXME treated as one value - case 1: pred |= $ph.chan1_p; break; - case 2: pred |= $ph.chan2_p; break; - case 3: pred |= $ph.chan3_p; break; - case 4: pred |= $ph.chan4_p; break; - default: throw pred_error("unhandled number of channels"); - } - - if (swap_type == "bswap") pred |= $ph.bswap_p; - else if (swap_type == "nswap") pred |= $ph.nswap_p; - else throw pred_error("unhandled swap type"); - - } - catch(...){ - throw pred_error("could not parse markup: " + markup); - } - - return pred; -} - -UHD_INLINE pred_type make_pred( - const io_type_t &io_type, - const otw_type_t &otw_type, - size_t num_inputs, - size_t num_outputs -){ - pred_type pred = 0; - - switch(otw_type.byteorder){ - \#ifdef BOOST_BIG_ENDIAN - case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.nswap_p; break; - case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.bswap_p; break; - \#else - case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.bswap_p; break; - case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break; - \#endif - case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break; - default: throw pred_error("unhandled otw byteorder type"); - } - - switch(otw_type.get_sample_size()){ - case sizeof(boost::uint32_t): pred |= $ph.item32_p; break; - default: throw pred_error("unhandled otw sample size"); - } - - switch(io_type.tid){ - case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break; - case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break; - default: throw pred_error("unhandled io type id"); - } - - switch(num_inputs*num_outputs){ //FIXME treated as one value - case 1: pred |= $ph.chan1_p; break; - case 2: pred |= $ph.chan2_p; break; - case 3: pred |= $ph.chan3_p; break; - case 4: pred |= $ph.chan4_p; break; - default: throw pred_error("unhandled number of channels"); - } - - return pred; -} -""" - -def parse_tmpl(_tmpl_text, **kwargs): - from Cheetah.Template import Template - return str(Template(_tmpl_text, kwargs)) - -class ph: - bswap_p = 0b00001 - nswap_p = 0b00000 - item32_p = 0b00000 - sc16_p = 0b00010 - fc32_p = 0b00000 - chan1_p = 0b00000 - chan2_p = 0b00100 - chan3_p = 0b01000 - chan4_p = 0b01100 - - nbits = 4 #see above - -if __name__ == '__main__': - import sys, os - file = os.path.basename(__file__) - open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=file, ph=ph)) diff --git a/host/lib/convert/gen_convert_pred.py b/host/lib/convert/gen_convert_pred.py new file mode 100644 index 000000000..800897589 --- /dev/null +++ b/host/lib/convert/gen_convert_pred.py @@ -0,0 +1,163 @@ +#!/usr/bin/env python +# +# Copyright 2010-2011 Ettus Research LLC +# +# 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 3 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, see . +# + +TMPL_TEXT = """ +#import time +/*********************************************************************** + * This file was generated by $file on $time.strftime("%c") + **********************************************************************/ +typedef size_t pred_type; + +\#include +\#include +\#include +\#include +\#include +\#include +\#include + +enum dir_type{ + DIR_OTW_TO_CPU = 0, + DIR_CPU_TO_OTW = 1 +}; + +struct pred_error : std::runtime_error{ + pred_error(const std::string &what) + :std::runtime_error("convert::make_pred: " + what){ + /* NOP */ + } +}; + +pred_type make_pred(const std::string &markup, dir_type &dir){ + pred_type pred = 0; + + try{ + boost::tokenizer > tokenizer(markup, boost::char_separator("_")); + std::vector tokens(tokenizer.begin(), tokenizer.end()); + //token 0 is + std::string inp_type = tokens.at(1); + std::string num_inps = tokens.at(2); + //token 3 is + std::string out_type = tokens.at(4); + std::string num_outs = tokens.at(5); + std::string swap_type = tokens.at(6); + + std::string cpu_type, otw_type; + if (inp_type.find("item") == std::string::npos){ + cpu_type = inp_type; + otw_type = out_type; + dir = DIR_CPU_TO_OTW; + } + else{ + cpu_type = out_type; + otw_type = inp_type; + dir = DIR_OTW_TO_CPU; + } + + if (cpu_type == "fc32") pred |= $ph.fc32_p; + else if (cpu_type == "sc16") pred |= $ph.sc16_p; + else throw pred_error("unhandled io type " + cpu_type); + + if (otw_type == "item32") pred |= $ph.item32_p; + else throw pred_error("unhandled otw type " + otw_type); + + int num_inputs = boost::lexical_cast(num_inps); + int num_outputs = boost::lexical_cast(num_outs); + + switch(num_inputs*num_outputs){ //FIXME treated as one value + case 1: pred |= $ph.chan1_p; break; + case 2: pred |= $ph.chan2_p; break; + case 3: pred |= $ph.chan3_p; break; + case 4: pred |= $ph.chan4_p; break; + default: throw pred_error("unhandled number of channels"); + } + + if (swap_type == "bswap") pred |= $ph.bswap_p; + else if (swap_type == "nswap") pred |= $ph.nswap_p; + else throw pred_error("unhandled swap type"); + + } + catch(...){ + throw pred_error("could not parse markup: " + markup); + } + + return pred; +} + +UHD_INLINE pred_type make_pred( + const io_type_t &io_type, + const otw_type_t &otw_type, + size_t num_inputs, + size_t num_outputs +){ + pred_type pred = 0; + + switch(otw_type.byteorder){ + \#ifdef BOOST_BIG_ENDIAN + case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.nswap_p; break; + case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.bswap_p; break; + \#else + case otw_type_t::BO_BIG_ENDIAN: pred |= $ph.bswap_p; break; + case otw_type_t::BO_LITTLE_ENDIAN: pred |= $ph.nswap_p; break; + \#endif + case otw_type_t::BO_NATIVE: pred |= $ph.nswap_p; break; + default: throw pred_error("unhandled otw byteorder type"); + } + + switch(otw_type.get_sample_size()){ + case sizeof(boost::uint32_t): pred |= $ph.item32_p; break; + default: throw pred_error("unhandled otw sample size"); + } + + switch(io_type.tid){ + case io_type_t::COMPLEX_FLOAT32: pred |= $ph.fc32_p; break; + case io_type_t::COMPLEX_INT16: pred |= $ph.sc16_p; break; + default: throw pred_error("unhandled io type id"); + } + + switch(num_inputs*num_outputs){ //FIXME treated as one value + case 1: pred |= $ph.chan1_p; break; + case 2: pred |= $ph.chan2_p; break; + case 3: pred |= $ph.chan3_p; break; + case 4: pred |= $ph.chan4_p; break; + default: throw pred_error("unhandled number of channels"); + } + + return pred; +} +""" + +def parse_tmpl(_tmpl_text, **kwargs): + from Cheetah.Template import Template + return str(Template(_tmpl_text, kwargs)) + +class ph: + bswap_p = 0b00001 + nswap_p = 0b00000 + item32_p = 0b00000 + sc16_p = 0b00010 + fc32_p = 0b00000 + chan1_p = 0b00000 + chan2_p = 0b00100 + chan3_p = 0b01000 + chan4_p = 0b01100 + +if __name__ == '__main__': + import sys, os + file = os.path.basename(__file__) + open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=file, ph=ph)) -- cgit v1.2.3 From a076dc12aa09d695e851575f68687a224636589b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 5 Jan 2011 20:49:45 -0800 Subject: uhd: update copyright dates --- host/Modules/FindDocutils.cmake | 2 +- host/Modules/UHDVersion.cmake | 2 +- host/docs/CMakeLists.txt | 2 +- host/include/uhd/config.hpp | 2 +- host/include/uhd/transport/CMakeLists.txt | 2 +- host/include/uhd/transport/buffer_pool.hpp | 2 +- host/include/uhd/transport/if_addrs.hpp | 2 +- host/include/uhd/types/CMakeLists.txt | 2 +- host/include/uhd/types/dict.hpp | 2 +- host/include/uhd/types/dict.ipp | 2 +- host/include/uhd/types/ranges.hpp | 2 +- host/include/uhd/usrp/multi_usrp.hpp | 2 +- host/include/uhd/utils/gain_group.hpp | 2 +- host/lib/convert/convert_general.cpp | 2 +- host/lib/convert/convert_with_neon.cpp | 2 +- host/lib/convert/convert_with_sse2.cpp | 2 +- host/lib/convert/gen_convert_pred.py | 2 +- host/lib/ranges.cpp | 2 +- host/lib/transport/CMakeLists.txt | 2 +- host/lib/transport/buffer_pool.cpp | 2 +- host/lib/transport/libusb1_zero_copy.cpp | 2 +- host/lib/transport/udp_zero_copy_asio.cpp | 2 +- host/lib/transport/vrt_packet_handler.hpp | 2 +- host/lib/usrp/dboard/db_xcvr2450.cpp | 2 +- host/lib/usrp/usrp2/fw_common.h | 2 +- host/lib/usrp/usrp2/io_impl.cpp | 2 +- host/lib/usrp/usrp2/mboard_impl.cpp | 2 +- host/lib/usrp/usrp2/usrp2_regs.cpp | 2 +- host/lib/usrp/usrp2/usrp2_regs.hpp | 2 +- host/lib/utils/gain_group.cpp | 2 +- host/test/CMakeLists.txt | 2 +- host/test/convert_test.cpp | 2 +- host/test/gain_group_test.cpp | 2 +- host/test/ranges_test.cpp | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) (limited to 'host/lib/convert') diff --git a/host/Modules/FindDocutils.cmake b/host/Modules/FindDocutils.cmake index b9996f3f1..3a97d8643 100644 --- a/host/Modules/FindDocutils.cmake +++ b/host/Modules/FindDocutils.cmake @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2011-2011 Ettus Research LLC # # 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 diff --git a/host/Modules/UHDVersion.cmake b/host/Modules/UHDVersion.cmake index a952b893e..e40f02568 100644 --- a/host/Modules/UHDVersion.cmake +++ b/host/Modules/UHDVersion.cmake @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/docs/CMakeLists.txt b/host/docs/CMakeLists.txt index cd17b648a..ace48f008 100644 --- a/host/docs/CMakeLists.txt +++ b/host/docs/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index f7ccb62e5..912fbc204 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/transport/CMakeLists.txt b/host/include/uhd/transport/CMakeLists.txt index 8dfd8d9f1..14ca82226 100644 --- a/host/include/uhd/transport/CMakeLists.txt +++ b/host/include/uhd/transport/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/include/uhd/transport/buffer_pool.hpp b/host/include/uhd/transport/buffer_pool.hpp index b6c683948..84a338097 100644 --- a/host/include/uhd/transport/buffer_pool.hpp +++ b/host/include/uhd/transport/buffer_pool.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/transport/if_addrs.hpp b/host/include/uhd/transport/if_addrs.hpp index 84f24cb5a..c831750d7 100644 --- a/host/include/uhd/transport/if_addrs.hpp +++ b/host/include/uhd/transport/if_addrs.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index a96976b5e..316a8e14b 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index d0ca36512..97fa8f09c 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/types/dict.ipp b/host/include/uhd/types/dict.ipp index cd64594e1..0c014474e 100644 --- a/host/include/uhd/types/dict.ipp +++ b/host/include/uhd/types/dict.ipp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp index 5bb74f976..253536a42 100644 --- a/host/include/uhd/types/ranges.hpp +++ b/host/include/uhd/types/ranges.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp index 80772742d..1db96a27e 100644 --- a/host/include/uhd/usrp/multi_usrp.hpp +++ b/host/include/uhd/usrp/multi_usrp.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/include/uhd/utils/gain_group.hpp b/host/include/uhd/utils/gain_group.hpp index c4115f224..3d22b9118 100644 --- a/host/include/uhd/utils/gain_group.hpp +++ b/host/include/uhd/utils/gain_group.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/convert/convert_general.cpp b/host/lib/convert/convert_general.cpp index 5e52acea2..566580e9e 100644 --- a/host/lib/convert/convert_general.cpp +++ b/host/lib/convert/convert_general.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/lib/convert/convert_with_neon.cpp b/host/lib/convert/convert_with_neon.cpp index 1ed841125..f379f4d29 100644 --- a/host/lib/convert/convert_with_neon.cpp +++ b/host/lib/convert/convert_with_neon.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2011 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/lib/convert/convert_with_sse2.cpp b/host/lib/convert/convert_with_sse2.cpp index 8d5a8a6a5..96ee9134c 100644 --- a/host/lib/convert/convert_with_sse2.cpp +++ b/host/lib/convert/convert_with_sse2.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010-2011 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/lib/convert/gen_convert_pred.py b/host/lib/convert/gen_convert_pred.py index 800897589..1d573bf1a 100644 --- a/host/lib/convert/gen_convert_pred.py +++ b/host/lib/convert/gen_convert_pred.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2010-2011 Ettus Research LLC +# Copyright 2011-2011 Ettus Research LLC # # 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 diff --git a/host/lib/ranges.cpp b/host/lib/ranges.cpp index 0503cc71c..4a0d05d80 100644 --- a/host/lib/ranges.cpp +++ b/host/lib/ranges.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt index 914ba3ba9..67865e0fe 100644 --- a/host/lib/transport/CMakeLists.txt +++ b/host/lib/transport/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/lib/transport/buffer_pool.cpp b/host/lib/transport/buffer_pool.cpp index 88ecedd2f..971bbb75a 100644 --- a/host/lib/transport/buffer_pool.cpp +++ b/host/lib/transport/buffer_pool.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 5dc230527..806d923e9 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 4f5fbebc2..5c049cfad 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index e4c5539d1..ab58e3416 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 6fdac7c6f..78eceff99 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 2cdfdc359..67ba90658 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp index 86fb512cc..910e45880 100644 --- a/host/lib/usrp/usrp2/io_impl.cpp +++ b/host/lib/usrp/usrp2/io_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index 9ca47cdc3..d23afe723 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/usrp/usrp2/usrp2_regs.cpp b/host/lib/usrp/usrp2/usrp2_regs.cpp index 13f475413..84907c32e 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.cpp +++ b/host/lib/usrp/usrp2/usrp2_regs.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/usrp/usrp2/usrp2_regs.hpp b/host/lib/usrp/usrp2/usrp2_regs.hpp index 68b8796d2..977b342cb 100644 --- a/host/lib/usrp/usrp2/usrp2_regs.hpp +++ b/host/lib/usrp/usrp2/usrp2_regs.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp index cba5056ea..d577c71bc 100644 --- a/host/lib/utils/gain_group.cpp +++ b/host/lib/utils/gain_group.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt index 581799d98..fb9b98ac7 100644 --- a/host/test/CMakeLists.txt +++ b/host/test/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/test/convert_test.cpp b/host/test/convert_test.cpp index de0245c1d..ca1f039aa 100644 --- a/host/test/convert_test.cpp +++ b/host/test/convert_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2011-2011 Ettus Research LLC // // 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 diff --git a/host/test/gain_group_test.cpp b/host/test/gain_group_test.cpp index 79487b2ba..57560aaa1 100644 --- a/host/test/gain_group_test.cpp +++ b/host/test/gain_group_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 diff --git a/host/test/ranges_test.cpp b/host/test/ranges_test.cpp index bbc7f4661..68c339f41 100644 --- a/host/test/ranges_test.cpp +++ b/host/test/ranges_test.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // // 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 -- cgit v1.2.3 From 599771914d0848875a0056cd60850eec39b06654 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 11 Jan 2011 12:19:22 -0800 Subject: usrp2: restart read before mode switch, added comments use cmake compiler force macro (to simplify things), added copyright updates dates to some files --- firmware/zpu/CMakeLists.txt | 7 +++---- firmware/zpu/apps/txrx_uhd.c | 2 +- firmware/zpu/lib/pkt_ctrl.c | 16 +++++++--------- firmware/zpu/lib/pkt_ctrl.h | 6 +++--- firmware/zpu/usrp2/CMakeLists.txt | 2 +- firmware/zpu/usrp2p/CMakeLists.txt | 2 +- firmware/zpu/usrp2p/bootloader/CMakeLists.txt | 2 +- host/lib/convert/convert_with_neon.cpp | 1 - 8 files changed, 17 insertions(+), 21 deletions(-) (limited to 'host/lib/convert') diff --git a/firmware/zpu/CMakeLists.txt b/firmware/zpu/CMakeLists.txt index 2df0a6140..d7cedbfb9 100644 --- a/firmware/zpu/CMakeLists.txt +++ b/firmware/zpu/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 @@ -19,10 +19,9 @@ # setup project and compiler ######################################################################## CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(CMAKE_C_COMPILER zpu-elf-gcc) #force the compiler because the check wont use the special flag below -SET(CMAKE_C_COMPILER_WORKS TRUE) -SET(CMAKE_C_COMPILER_FORCED TRUE) +INCLUDE(CMakeForceCompiler) +CMAKE_FORCE_C_COMPILER(zpu-elf-gcc GNU) PROJECT(USRP_NXXX_FW C) ######################################################################## diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index ab960dac8..61a2c1f76 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC // /* * Copyright 2007,2008 Free Software Foundation, Inc. diff --git a/firmware/zpu/lib/pkt_ctrl.c b/firmware/zpu/lib/pkt_ctrl.c index 341ad44e1..2bbe2f843 100644 --- a/firmware/zpu/lib/pkt_ctrl.c +++ b/firmware/zpu/lib/pkt_ctrl.c @@ -1,5 +1,5 @@ /* - * Copyright 2010 Ettus Research LLC + * Copyright 2010-2011 Ettus Research LLC * * 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 @@ -18,7 +18,6 @@ #include "pkt_ctrl.h" #include "memory_map.h" #include -#include //status signals from WB into PR #define CPU_STAT_RD_DONE (1 << 0) @@ -46,13 +45,12 @@ void pkt_ctrl_program_inspector( } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ - mdelay(100); //give a little delay to space out subsequent calls - switch(mode){ - case PKT_CTRL_ROUTING_MODE_SLAVE: router_ctrl->mode_ctrl = 0; break; - case PKT_CTRL_ROUTING_MODE_MASTER: router_ctrl->mode_ctrl = 1; break; - } - router_ctrl->iface_ctrl = CPU_CTRL_WR_CLEAR; //reset the write state machine - pkt_ctrl_release_incoming_buffer(); //reset the read state machine, and read + //About to change the mode; ensure that we are accepting packets. + //The plumbing will not switch if it cannot pass an end of packet. + pkt_ctrl_release_incoming_buffer(); + + //Change the mode; this switches the valves and crossbars. + router_ctrl->mode_ctrl = mode; } static inline void cpu_stat_wait_for(int bm){ diff --git a/firmware/zpu/lib/pkt_ctrl.h b/firmware/zpu/lib/pkt_ctrl.h index 410ffdaa4..15e4b0c4d 100644 --- a/firmware/zpu/lib/pkt_ctrl.h +++ b/firmware/zpu/lib/pkt_ctrl.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Ettus Research LLC + * Copyright 2010-2011 Ettus Research LLC * * 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 @@ -24,8 +24,8 @@ #include typedef enum { - PKT_CTRL_ROUTING_MODE_SLAVE, - PKT_CTRL_ROUTING_MODE_MASTER, + PKT_CTRL_ROUTING_MODE_SLAVE = 0, + PKT_CTRL_ROUTING_MODE_MASTER = 1 } pkt_ctrl_routing_mode_t; //! Program the decision values into the packet inspector diff --git a/firmware/zpu/usrp2/CMakeLists.txt b/firmware/zpu/usrp2/CMakeLists.txt index d126c921c..e54499084 100644 --- a/firmware/zpu/usrp2/CMakeLists.txt +++ b/firmware/zpu/usrp2/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/firmware/zpu/usrp2p/CMakeLists.txt b/firmware/zpu/usrp2p/CMakeLists.txt index 93ccf82c3..c7ab9abdb 100644 --- a/firmware/zpu/usrp2p/CMakeLists.txt +++ b/firmware/zpu/usrp2p/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/firmware/zpu/usrp2p/bootloader/CMakeLists.txt b/firmware/zpu/usrp2p/bootloader/CMakeLists.txt index 155915011..2c7efb43a 100644 --- a/firmware/zpu/usrp2p/bootloader/CMakeLists.txt +++ b/firmware/zpu/usrp2p/bootloader/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC # # 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 diff --git a/host/lib/convert/convert_with_neon.cpp b/host/lib/convert/convert_with_neon.cpp index f379f4d29..3d677db5b 100644 --- a/host/lib/convert/convert_with_neon.cpp +++ b/host/lib/convert/convert_with_neon.cpp @@ -16,7 +16,6 @@ // #include "convert_common.hpp" -#include #include using namespace uhd::convert; -- cgit v1.2.3 From 0bc30138240890aef6017e57264c5adb6c7268cf Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 12 Jan 2011 12:21:43 -0800 Subject: uhd: removed unused/forgotten file --- host/lib/convert/convert_general.cpp | 63 ------------------------------------ 1 file changed, 63 deletions(-) delete mode 100644 host/lib/convert/convert_general.cpp (limited to 'host/lib/convert') diff --git a/host/lib/convert/convert_general.cpp b/host/lib/convert/convert_general.cpp deleted file mode 100644 index 566580e9e..000000000 --- a/host/lib/convert/convert_general.cpp +++ /dev/null @@ -1,63 +0,0 @@ -// -// Copyright 2011-2011 Ettus Research LLC -// -// 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 3 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, see . -// - -#include "convert_common.hpp" -#include - -using namespace uhd::convert; - -/*********************************************************************** - * Convert complex short buffer to items32 - **********************************************************************/ -DECLARE_CONVERTER(convert_sc16_1_to_item32_1_nswap, PRIORITY_GENERAL){ - const sc16_t *input = reinterpret_cast(inputs[0]); - item32_t *output = reinterpret_cast(outputs[0]); - - for (size_t i = 0; i < nsamps; i++){ - output[i] = sc16_to_item32(input[i]); - } -} - -DECLARE_CONVERTER(convert_sc16_1_to_item32_1_bswap, PRIORITY_GENERAL){ - const sc16_t *input = reinterpret_cast(inputs[0]); - item32_t *output = reinterpret_cast(outputs[0]); - - for (size_t i = 0; i < nsamps; i++){ - output[i] = uhd::byteswap(sc16_to_item32(input[i])); - } -} - -/*********************************************************************** - * Convert items32 buffer to complex short - **********************************************************************/ -DECLARE_CONVERTER(convert_item32_1_to_sc16_1_nswap, PRIORITY_GENERAL){ - const item32_t *input = reinterpret_cast(inputs[0]); - sc16_t *output = reinterpret_cast(outputs[0]); - - for (size_t i = 0; i < nsamps; i++){ - output[i] = item32_to_sc16(input[i]); - } -} - -DECLARE_CONVERTER(convert_item32_1_to_sc16_1_bswap, PRIORITY_GENERAL){ - const item32_t *input = reinterpret_cast(inputs[0]); - sc16_t *output = reinterpret_cast(outputs[0]); - - for (size_t i = 0; i < nsamps; i++){ - output[i] = item32_to_sc16(uhd::byteswap(input[i])); - } -} -- cgit v1.2.3 From 6f814f04c4af020a627f6772f7f9b14083d312f4 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 12 Jan 2011 15:41:32 -0800 Subject: uhd: changed convert routines to return the function pointer changed the vrt packet handler to get the function pointer (once), this may be a minor performance help --- host/include/uhd/convert.hpp | 34 +++++++++++---------------- host/lib/convert/convert_impl.cpp | 26 ++++++++------------- host/lib/transport/vrt_packet_handler.hpp | 39 ++++++++++++++++++------------- host/test/convert_test.cpp | 36 ++++++++++++++-------------- 4 files changed, 65 insertions(+), 70 deletions(-) (limited to 'host/lib/convert') diff --git a/host/include/uhd/convert.hpp b/host/include/uhd/convert.hpp index 488cba98e..bfe8c8267 100644 --- a/host/include/uhd/convert.hpp +++ b/host/include/uhd/convert.hpp @@ -58,37 +58,31 @@ namespace uhd{ namespace convert{ ); /*! - * Convert IO samples to OWT samples: - * + * Get a converter function that converts cpu to otw. * \param io_type the type of the input samples * \param otw_type the type of the output samples - * \param input_buffs input buffers to read samples - * \param output_buffs output buffers to write samples - * \param nsamps_per_io_buff samples per IO buffer + * \param num_input_buffs the number of inputs + * \param num_output_buffs the number of outputs */ - UHD_API void io_type_to_otw_type( + UHD_API const function_type &get_converter_cpu_to_otw( const io_type_t &io_type, const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff + size_t num_input_buffs, + size_t num_output_buffs ); /*! - * Convert OTW samples to IO samples: - * - * \param io_type the type of the output samples - * \param otw_type the type of the input samples - * \param input_buffs input buffers to read samples - * \param output_buffs output buffers to write samples - * \param nsamps_per_io_buff samples per IO buffer + * Get a converter function that converts otw to cpu. + * \param io_type the type of the input samples + * \param otw_type the type of the output samples + * \param num_input_buffs the number of inputs + * \param num_output_buffs the number of outputs */ - UHD_API void otw_type_to_io_type( + UHD_API const function_type &get_converter_otw_to_cpu( const io_type_t &io_type, const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff + size_t num_input_buffs, + size_t num_output_buffs ); }} //namespace diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index 74837cc51..6a5a1465d 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -90,28 +90,22 @@ void uhd::convert::register_converter( /*********************************************************************** * The converter functions **********************************************************************/ -void uhd::convert::io_type_to_otw_type( +const convert::function_type &convert::get_converter_cpu_to_otw( const io_type_t &io_type, const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff + size_t num_input_buffs, + size_t num_output_buffs ){ - pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); - fcn_table_type table = get_cpu_to_otw_table(); - function_type fcn = table.at(pred).fcn; - fcn(input_buffs, output_buffs, nsamps_per_io_buff); + pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs); + return get_cpu_to_otw_table().at(pred).fcn; } -void uhd::convert::otw_type_to_io_type( +const convert::function_type &convert::get_converter_otw_to_cpu( const io_type_t &io_type, const otw_type_t &otw_type, - input_type &input_buffs, - output_type &output_buffs, - size_t nsamps_per_io_buff + size_t num_input_buffs, + size_t num_output_buffs ){ - pred_type pred = make_pred(io_type, otw_type, input_buffs.size(), output_buffs.size()); - fcn_table_type table = get_otw_to_cpu_table(); - function_type fcn = table.at(pred).fcn; - fcn(input_buffs, output_buffs, nsamps_per_io_buff); + pred_type pred = make_pred(io_type, otw_type, num_input_buffs, num_output_buffs); + return get_otw_to_cpu_table().at(pred).fcn; } diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp index ab58e3416..0507ae328 100644 --- a/host/lib/transport/vrt_packet_handler.hpp +++ b/host/lib/transport/vrt_packet_handler.hpp @@ -35,6 +35,9 @@ namespace vrt_packet_handler{ +//this may change in the future but its a constant for now +static const size_t OTW_BYTES_PER_SAMP = sizeof(boost::uint32_t); + template UHD_INLINE T get_context_code( const boost::uint32_t *vrt_hdr, const uhd::transport::vrt::if_packet_info_t &if_packet_info @@ -145,8 +148,7 @@ template UHD_INLINE T get_context_code( size_t offset_bytes, size_t total_samps, uhd::rx_metadata_t &metadata, - const uhd::io_type_t &io_type, - const uhd::otw_type_t &otw_type, + uhd::convert::function_type &converter, double tick_rate, const vrt_unpacker_t &vrt_unpacker, const get_recv_buffs_t &get_recv_buffs, @@ -184,7 +186,7 @@ template UHD_INLINE T get_context_code( } //extract the number of samples available to copy - size_t bytes_per_item = otw_type.get_sample_size(); + size_t bytes_per_item = OTW_BYTES_PER_SAMP; size_t nsamps_available = state.size_of_copy_buffs/bytes_per_item; size_t nsamps_to_copy = std::min(total_samps*chans_per_otw_buff, nsamps_available); size_t bytes_to_copy = nsamps_to_copy*bytes_per_item; @@ -200,9 +202,7 @@ template UHD_INLINE T get_context_code( //copy-convert the samples from the recv buffer uhd::convert::input_type otw_buffs(1, state.copy_buffs[i]); - uhd::convert::otw_type_to_io_type( - io_type, otw_type, otw_buffs, io_buffs, nsamps_to_copy_per_io_buff - ); + converter(otw_buffs, io_buffs, nsamps_to_copy_per_io_buff); //update the rx copy buffer to reflect the bytes copied state.copy_buffs[i] += bytes_to_copy; @@ -236,6 +236,11 @@ template UHD_INLINE T get_context_code( size_t vrt_header_offset_words32 = 0, size_t chans_per_otw_buff = 1 ){ + uhd::convert::function_type converter( + uhd::convert::get_converter_otw_to_cpu( + io_type, otw_type, 1, buffs.size() + )); + switch(recv_mode){ //////////////////////////////////////////////////////////////// @@ -246,7 +251,7 @@ template UHD_INLINE T get_context_code( buffs, 0, total_num_samps, metadata, - io_type, otw_type, + converter, tick_rate, vrt_unpacker, get_recv_buffs, @@ -267,7 +272,7 @@ template UHD_INLINE T get_context_code( buffs, accum_num_samps*io_type.size, total_num_samps - accum_num_samps, (accum_num_samps == 0)? metadata : tmp_md, //only the first metadata gets kept - io_type, otw_type, + converter, tick_rate, vrt_unpacker, get_recv_buffs, @@ -311,15 +316,14 @@ template UHD_INLINE T get_context_code( const size_t offset_bytes, const size_t num_samps, uhd::transport::vrt::if_packet_info_t &if_packet_info, - const uhd::io_type_t &io_type, - const uhd::otw_type_t &otw_type, + uhd::convert::function_type &converter, const vrt_packer_t &vrt_packer, const get_send_buffs_t &get_send_buffs, const size_t vrt_header_offset_words32, const size_t chans_per_otw_buff ){ //load the rest of the if_packet_info in here - if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*otw_type.get_sample_size())/sizeof(boost::uint32_t); + if_packet_info.num_payload_words32 = (num_samps*chans_per_otw_buff*OTW_BYTES_PER_SAMP)/sizeof(boost::uint32_t); if_packet_info.packet_count = state.next_packet_seq; //get send buffers for each channel @@ -340,9 +344,7 @@ template UHD_INLINE T get_context_code( //copy-convert the samples into the send buffer uhd::convert::output_type otw_buffs(1, otw_mem); - uhd::convert::io_type_to_otw_type( - io_type, otw_type, io_buffs, otw_buffs, num_samps - ); + converter(io_buffs, otw_buffs, num_samps); //commit the samples to the zero-copy interface size_t num_bytes_total = (vrt_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t); @@ -370,6 +372,11 @@ template UHD_INLINE T get_context_code( size_t vrt_header_offset_words32 = 0, size_t chans_per_otw_buff = 1 ){ + uhd::convert::function_type converter( + uhd::convert::get_converter_cpu_to_otw( + io_type, otw_type, buffs.size(), 1 + )); + //translate the metadata to vrt if packet info uhd::transport::vrt::if_packet_info_t if_packet_info; if_packet_info.has_sid = false; @@ -405,7 +412,7 @@ template UHD_INLINE T get_context_code( buffs_, 0, std::min(total_num_samps_, max_samples_per_packet), if_packet_info, - io_type, otw_type, + converter, vrt_packer, get_send_buffs, vrt_header_offset_words32, @@ -438,7 +445,7 @@ template UHD_INLINE T get_context_code( buffs, total_num_samps_sent*io_type.size, std::min(total_num_samps_unsent, max_samples_per_packet), if_packet_info, - io_type, otw_type, + converter, vrt_packer, get_send_buffs, vrt_header_offset_words32, diff --git a/host/test/convert_test.cpp b/host/test/convert_test.cpp index ca1f039aa..5f2aaf3d1 100644 --- a/host/test/convert_test.cpp +++ b/host/test/convert_test.cpp @@ -52,14 +52,14 @@ template static void loopback( convert::output_type output0(1, &interm[0]), output1(1, &output[0]); //convert to intermediate type - convert::io_type_to_otw_type( - io_type, otw_type, input0, output0, nsamps - ); + convert::get_converter_cpu_to_otw( + io_type, otw_type, input0.size(), output0.size() + )(input0, output0, nsamps); //convert back to host type - convert::otw_type_to_io_type( - io_type, otw_type, input1, output1, nsamps - ); + convert::get_converter_otw_to_cpu( + io_type, otw_type, input1.size(), output1.size() + )(input1, output1, nsamps); } /*********************************************************************** @@ -177,14 +177,14 @@ BOOST_AUTO_TEST_CASE(test_convert_types_fc32_to_sc16){ convert::output_type output0(1, &interm[0]), output1(1, &output[0]); //convert float to intermediate - convert::io_type_to_otw_type( - io_type_in, otw_type, input0, output0, nsamps - ); + convert::get_converter_cpu_to_otw( + io_type_in, otw_type, input0.size(), output0.size() + )(input0, output0, nsamps); //convert intermediate to short - convert::otw_type_to_io_type( - io_type_out, otw_type, input1, output1, nsamps - ); + convert::get_converter_otw_to_cpu( + io_type_out, otw_type, input1.size(), output1.size() + )(input1, output1, nsamps); //test that the inputs and outputs match for (size_t i = 0; i < nsamps; i++){ @@ -217,14 +217,14 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_to_fc32){ convert::output_type output0(1, &interm[0]), output1(1, &output[0]); //convert short to intermediate - convert::io_type_to_otw_type( - io_type_in, otw_type, input0, output0, nsamps - ); + convert::get_converter_cpu_to_otw( + io_type_in, otw_type, input0.size(), output0.size() + )(input0, output0, nsamps); //convert intermediate to float - convert::otw_type_to_io_type( - io_type_out, otw_type, input1, output1, nsamps - ); + convert::get_converter_otw_to_cpu( + io_type_out, otw_type, input1.size(), output1.size() + )(input1, output1, nsamps); //test that the inputs and outputs match for (size_t i = 0; i < nsamps; i++){ -- cgit v1.2.3 From 4818bd27f07acea1e663086d59fbb7d44bd5af81 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 14 Jan 2011 10:07:31 -0800 Subject: uhd: more useful prints for component macro made libuhd a component so we can just build the docs do the python tests in the top level cmakelists misc other tweaks --- .gitignore | 3 --- host/CMakeLists.txt | 21 +++++++++++++++++++-- host/Modules/UHDComponent.cmake | 9 ++++++--- host/lib/CMakeLists.txt | 22 +--------------------- host/lib/convert/CMakeLists.txt | 1 - 5 files changed, 26 insertions(+), 30 deletions(-) delete mode 100644 .gitignore (limited to 'host/lib/convert') diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b275f0e49..000000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*~ -\#*\# -a.out diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index d7e6a6a50..32a3f0a62 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -90,7 +90,7 @@ IF(UNIX AND EXISTS "/usr/lib64") ENDIF(UNIX AND EXISTS "/usr/lib64") SET(Boost_ADDITIONAL_VERSIONS "1.42.0" "1.42" "1.43.0" "1.43" "1.44.0" "1.44") -FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS +FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} COMPONENTS date_time filesystem program_options @@ -103,6 +103,23 @@ FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) +######################################################################## +# Check Python Modules +######################################################################## +INCLUDE(UHDPython) + +PYTHON_CHECK_MODULE( + "Python version 2.6 or greater" + "platform" "platform.python_version() >= '2.6'" + HAVE_PYTHON_PLAT_MIN_VERSION +) + +PYTHON_CHECK_MODULE( + "Cheetah templates 2.0.0 or greater" + "Cheetah" "Cheetah.Version >= '2.0.0'" + HAVE_PYTHON_MODULE_CHEETAH +) + ######################################################################## # Create Uninstall Target ######################################################################## @@ -141,7 +158,7 @@ INSTALL(FILES ######################################################################## # Register top level components ######################################################################## -SET(ENABLE_LIBUHD ON) #always enabled +LIBUHD_REGISTER_COMPONENT("LibUHD" ENABLE_LIBUHD ON "Boost_FOUND;HAVE_PYTHON_PLAT_MIN_VERSION;HAVE_PYTHON_MODULE_CHEETAH" OFF) LIBUHD_REGISTER_COMPONENT("Examples" ENABLE_EXAMPLES ON "ENABLE_LIBUHD" OFF) LIBUHD_REGISTER_COMPONENT("Utils" ENABLE_UTILS ON "ENABLE_LIBUHD" OFF) LIBUHD_REGISTER_COMPONENT("Tests" ENABLE_TESTS ON "ENABLE_LIBUHD" OFF) diff --git a/host/Modules/UHDComponent.cmake b/host/Modules/UHDComponent.cmake index 63b32eadf..4ea55bbb9 100644 --- a/host/Modules/UHDComponent.cmake +++ b/host/Modules/UHDComponent.cmake @@ -30,7 +30,9 @@ SET(_uhd_disabled_components "" CACHE INTERNAL "" FORCE) MACRO(LIBUHD_REGISTER_COMPONENT name var enb deps dis) MESSAGE(STATUS "") MESSAGE(STATUS "Configuring ${name} support...") - MESSAGE(STATUS "Manually override with -D${var}=ON/OFF") + FOREACH(dep ${deps}) + MESSAGE(STATUS " Dependency ${dep} = ${${dep}}") + ENDFOREACH(dep) #setup the dependent option for this component INCLUDE(CMakeDependentOption) @@ -44,6 +46,7 @@ MACRO(LIBUHD_REGISTER_COMPONENT name var enb deps dis) MESSAGE(STATUS " Disabling ${name} support.") LIST(APPEND _uhd_disabled_components ${name}) ENDIF(${var}) + MESSAGE(STATUS " Override with -D${var}=ON/OFF") #make components lists into global variables SET(_uhd_enabled_components ${_uhd_enabled_components} CACHE INTERNAL "" FORCE) @@ -56,7 +59,7 @@ ENDMACRO(LIBUHD_REGISTER_COMPONENT) FUNCTION(UHD_PRINT_COMPONENT_SUMMARY) MESSAGE(STATUS "") MESSAGE(STATUS "######################################################") - MESSAGE(STATUS "# LibUHD enabled components ") + MESSAGE(STATUS "# UHD enabled components ") MESSAGE(STATUS "######################################################") FOREACH(comp ${_uhd_enabled_components}) MESSAGE(STATUS " * ${comp}") @@ -64,7 +67,7 @@ FUNCTION(UHD_PRINT_COMPONENT_SUMMARY) MESSAGE(STATUS "") MESSAGE(STATUS "######################################################") - MESSAGE(STATUS "# LibUHD disabled components ") + MESSAGE(STATUS "# UHD disabled components ") MESSAGE(STATUS "######################################################") FOREACH(comp ${_uhd_disabled_components}) MESSAGE(STATUS " * ${comp}") diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 0fe137432..d2845ffda 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -15,27 +15,6 @@ # along with this program. If not, see . # -######################################################################## -# Check Python Modules -######################################################################## -INCLUDE(UHDPython) - -PYTHON_CHECK_MODULE( - "Python version 2.6 or greater" - "platform" "platform.python_version() >= '2.6'" - HAVE_PYTHON_PLAT_MIN_VERSION -) - -PYTHON_CHECK_MODULE( - "Cheetah templates 2.0.0 or greater" - "Cheetah" "Cheetah.Version >= '2.0.0'" - HAVE_PYTHON_MODULE_CHEETAH -) - -IF(NOT HAVE_PYTHON_PLAT_MIN_VERSION OR NOT HAVE_PYTHON_MODULE_CHEETAH) - MESSAGE(FATAL_ERROR "Error: python requirements not met for the build system.") -ENDIF(NOT HAVE_PYTHON_PLAT_MIN_VERSION OR NOT HAVE_PYTHON_MODULE_CHEETAH) - ######################################################################## # Helpful Macros ######################################################################## @@ -128,6 +107,7 @@ LIBUHD_APPEND_SOURCES( ADD_LIBRARY(uhd SHARED ${libuhd_sources}) TARGET_LINK_LIBRARIES(uhd ${Boost_LIBRARIES} ${libuhd_libs}) SET_TARGET_PROPERTIES(uhd PROPERTIES DEFINE_SYMBOL "UHD_DLL_EXPORTS") +SET_TARGET_PROPERTIES(uhd PROPERTIES SOVERSION ${UHD_VERSION_MAJOR}) INSTALL(TARGETS uhd LIBRARY DESTINATION ${LIBRARY_DIR} # .so file diff --git a/host/lib/convert/CMakeLists.txt b/host/lib/convert/CMakeLists.txt index 06f7ba12a..a9f977cdc 100644 --- a/host/lib/convert/CMakeLists.txt +++ b/host/lib/convert/CMakeLists.txt @@ -62,5 +62,4 @@ LIBUHD_PYTHON_GEN_SOURCE( LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_SOURCE_DIR}/convert_impl.cpp - ${CMAKE_CURRENT_BINARY_DIR}/convert_general.cpp ) -- cgit v1.2.3