From 87c97721283a08627f8a8c55c619a0bdc66c6396 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 28 Dec 2015 16:52:10 -0800 Subject: [PATCH] More M4 instruction wrappers, with vector typed arguments. --- firmware/common/simd.hpp | 108 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 firmware/common/simd.hpp diff --git a/firmware/common/simd.hpp b/firmware/common/simd.hpp new file mode 100644 index 00000000..0d65b8dd --- /dev/null +++ b/firmware/common/simd.hpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, 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; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SIMD_H__ +#define __SIMD_H__ + +#if defined(LPC43XX_M4) + +#include + +#include + +struct vec4_s8 { + union { + int8_t v[4]; + uint32_t w; + }; +}; + +struct vec2_s16 { + constexpr vec2_s16( + ) : v { 0, 0 } + { + } + + constexpr vec2_s16( + const int16_t v0, + const int16_t v1 + ) : v { v0, v1 } + { + } + + constexpr vec2_s16( + const vec2_s16& other + ) : w { other.w } + { + } + + vec2_s16& operator=(const vec2_s16& other) { + w = other.w; + return *this; + } + + union { + int16_t v[2]; + uint32_t w; + }; +}; + +static inline vec4_s8 rev16(const vec4_s8 v) { + vec4_s8 result; + result.w = __REV16(v.w); + return result; +} + +static inline vec4_s8 pkhbt(const vec4_s8 v1, const vec4_s8 v2, const size_t sh = 0) { + vec4_s8 result; + result.w = __PKHBT(v1.w, v2.w, sh); + return result; +} + +static inline vec2_s16 pkhbt(const vec2_s16 v1, const vec2_s16 v2, const size_t sh = 0) { + vec2_s16 result; + result.w = __PKHBT(v1.w, v2.w, sh); + return result; +} + +static inline vec2_s16 pkhtb(const vec2_s16 v1, const vec2_s16 v2, const size_t sh = 0) { + vec2_s16 result; + result.w = __PKHTB(v1.w, v2.w, sh); + return result; +} + +static inline vec2_s16 sxtb16(const vec4_s8 v, const size_t sh = 0) { + vec2_s16 result; + result.w = __SXTB16(v.w, sh); + return result; +} + +static inline int32_t smlsd(const vec2_s16 v1, const vec2_s16 v2, const int32_t accum) { + return __SMLSD(v1.w, v2.w, accum); +} + +static inline int32_t smlad(const vec2_s16 v1, const vec2_s16 v2, const int32_t accum) { + return __SMLAD(v1.w, v2.w, accum); +} + +#endif /* defined(LPC43XX_M4) */ + +#endif/*__SIMD_H__*/