Index: src/OFMatrix4x4.h ================================================================== --- src/OFMatrix4x4.h +++ src/OFMatrix4x4.h @@ -91,13 +91,18 @@ */ - (OFVector4D)transformedVector: (OFVector4D)vector; /** * @brief Transforms the specified vectors in-place according to the matrix. + * + * @warning Please note that the vectors must be 16 byte aligned! This is + * required to allow SIMD optimizations. Passing a pointer to vectors + * that are not 16 byte aligned will crash if SIMD optimizations are + * enabled. * * @param vectors The vectors to transform * @param count The count of the specified vectors */ - (void)transformVectors: (OFVector4D *)vectors count: (size_t)count; @end OF_ASSUME_NONNULL_END Index: src/OFMatrix4x4.m ================================================================== --- src/OFMatrix4x4.m +++ src/OFMatrix4x4.m @@ -362,11 +362,11 @@ [scale release]; } - (OFVector4D)transformedVector: (OFVector4D)vector { - OFVector4D copy = vector; + OF_ALIGN(16) OFVector4D copy = vector; [self transformVectors: © count: 1]; return copy; } Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -347,11 +347,11 @@ /** * @struct OFVector4D OFObject.h ObjFW/OFObject.h * * @brief A vector in 4D space. */ -typedef struct OF_ALIGN(16) OF_BOXABLE OFVector4D { +typedef struct OF_BOXABLE OFVector4D { /** The x coordinate of the vector */ float x; /** The y coordinate of the vector */ float y; /** The z coordinate of the vector */ Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -100,18 +100,16 @@ # define OF_CONST_FUNC # define OF_NO_RETURN_FUNC # define OF_WEAK_REF(sym) #endif -#ifdef __GNUC__ -# define OF_ALIGN(alignment) __attribute__((__aligned__(alignment))) -#endif - #if __STDC_VERSION__ >= 201112L +# define OF_ALIGN(size) _Alignas(size) # define OF_ALIGNOF(type) _Alignof(type) # define OF_ALIGNAS(type) _Alignas(type) #else +# define OF_ALIGN(size) __attribute__((__aligned__(size))) # define OF_ALIGNOF(type) __alignof__(type) # define OF_ALIGNAS(type) OF_ALIGN(OF_ALIGNOF(type)) #endif #ifdef __BIGGEST_ALIGNMENT__ Index: tests/OFMatrix4x4Tests.m ================================================================== --- tests/OFMatrix4x4Tests.m +++ tests/OFMatrix4x4Tests.m @@ -147,11 +147,11 @@ OTAssertEqual(point.w, 1); } - (void)testTransformVectorsCount { - OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }}; + OF_ALIGN(16) OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }}; [_matrix transformVectors: points count: 2]; OTAssertEqual(points[0].x, 18); OTAssertEqual(points[0].y, 46);