Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory alignment for SIMD #1937

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/engine/Port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ static const int PORT_MAX_CHANNELS = 16;

struct 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. */
float voltages[PORT_MAX_CHANNELS] = {};
/** DEPRECATED. Unstable API. Use getVoltage() and setVoltage() instead. */
Expand Down
6 changes: 4 additions & 2 deletions include/simd/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ struct Vector<float, 4> {
using type = float;
constexpr static int size = 4;

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

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