Browse Source

Fix memory alignment for SIMD

Signed-off-by: falkTX <falktx@falktx.com>
pull/1937/head
falkTX 3 years ago
parent
commit
8be9f48d55
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 7 additions and 3 deletions
  1. +3
    -1
      include/engine/Port.hpp
  2. +4
    -2
      include/simd/Vector.hpp

+ 3
- 1
include/engine/Port.hpp View File

@@ -13,7 +13,9 @@ static const int PORT_MAX_CHANNELS = 16;


struct Port { struct Port {
/** Voltage of the port. */ /** Voltage of the port. */
union {
/** NOTE alignas is required in order to allow SSE usage.
Consecutive data (like in a vector) would otherwise pack Ports in a way that breaks SSE. */
union alignas(32) {
/** Unstable API. Use getVoltage() and setVoltage() instead. */ /** Unstable API. Use getVoltage() and setVoltage() instead. */
float voltages[PORT_MAX_CHANNELS] = {}; float voltages[PORT_MAX_CHANNELS] = {};
/** DEPRECATED. Unstable API. Use getVoltage() and setVoltage() instead. */ /** DEPRECATED. Unstable API. Use getVoltage() and setVoltage() instead. */


+ 4
- 2
include/simd/Vector.hpp View File

@@ -34,7 +34,8 @@ struct Vector<float, 4> {
using type = float; using type = float;
constexpr static int size = 4; constexpr static int size = 4;


union {
/** NOTE alignas is required in order to allow SSE usage. */
union alignas(32) {
__m128 v; __m128 v;
/** Accessing this array of scalars is slow and defeats the purpose of vectorizing. /** Accessing this array of scalars is slow and defeats the purpose of vectorizing.
*/ */
@@ -108,7 +109,8 @@ struct Vector<int32_t, 4> {
using type = int32_t; using type = int32_t;
constexpr static int size = 4; constexpr static int size = 4;


union {
/** NOTE alignas is required in order to allow SSE usage. */
union alignas(32) {
__m128i v; __m128i v;
int32_t s[4]; int32_t s[4];
}; };


Loading…
Cancel
Save