Index: src/OFMatrix4x4.h ================================================================== --- src/OFMatrix4x4.h +++ src/OFMatrix4x4.h @@ -21,11 +21,11 @@ * @brief A 4x4 matrix of floats. */ OF_SUBCLASSING_RESTRICTED @interface OFMatrix4x4: OFObject { - float _values[4][4] OF_ALIGN(16); + float (*_values)[4]; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (readonly, class) OFMatrix4x4 *identityMatrix; #endif Index: src/OFMatrix4x4.m ================================================================== --- src/OFMatrix4x4.m +++ src/OFMatrix4x4.m @@ -36,12 +36,12 @@ # endif static void multiplyWithMatrix_enhanced3DNow(OFMatrix4x4 *self, SEL _cmd, OFMatrix4x4 *matrix) { - float *left = &matrix->_values[0][0], *right = &self->_values[0][0]; - float result[4][4], *resultPtr = &result[0][0]; + float (*left)[4] = matrix->_values, (*right)[4] = self->_values; + float result[4][4], (*resultPtr)[4] = result; __asm__ __volatile__ ( "xorw %%cx, %%cx\n" "\n\t" "0:\n\t" @@ -72,11 +72,11 @@ "femms" : "+r"(resultPtr), "+r"(left), "+r"(right) :: "cx", "mm0", "mm1", "memory" ); - memcpy(self->_values, result, sizeof(result)); + memcpy(self->_values, result, 16 * sizeof(float)); } static void transformVectors_enhanced3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D *vectors, size_t count) @@ -130,11 +130,11 @@ "jnz 0b\n" "\n\t" "0:\n\t" "femms" : "+r"(count), "+r"(vectors) - : "r"(&self->_values) + : "r"(self->_values) : "mm0", "mm1", "mm2", "mm3", "mm4", "memory" ); } # ifndef __clang__ # pragma GCC pop_options @@ -145,12 +145,12 @@ # pragma GCC target("3dnow") # endif static void multiplyWithMatrix_3DNow(OFMatrix4x4 *self, SEL _cmd, OFMatrix4x4 *matrix) { - float *left = &matrix->_values[0][0], *right = &self->_values[0][0]; - float result[4][4], *resultPtr = &result[0][0]; + float (*left)[4] = matrix->_values, (*right)[4] = self->_values; + float result[4][4], (*resultPtr)[4] = result; __asm__ __volatile__ ( "xorw %%cx, %%cx\n" "\n\t" "0:\n\t" @@ -182,11 +182,11 @@ "femms" : "+r"(resultPtr), "+r"(left), "+r"(right) :: "cx", "mm0", "mm1", "memory" ); - memcpy(self->_values, result, sizeof(result)); + memcpy(self->_values, result, 16 * sizeof(float)); } static void transformVectors_3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D *vectors, size_t count) @@ -244,11 +244,11 @@ "jnz 0b\n" "\n\t" "0:\n\t" "femms" : "+r"(count), "+r"(vectors) - : "r"(&self->_values) + : "r"(self->_values) : "mm0", "mm1", "mm2", "mm3", "mm4", "memory" ); } # ifndef __clang__ # pragma GCC pop_options @@ -281,10 +281,22 @@ } # undef REPLACE } #endif + ++ (instancetype)alloc +{ + OFMatrix4x4 *instance; + float (*values)[4]; + + instance = OFAllocObject(self, 16 * sizeof(float), 16, + (void **)&values); + instance->_values = values; + + return instance; +} + (OFMatrix4x4 *)identityMatrix { return [[[OFMatrix4x4 alloc] initWithValues: identityValues] autorelease]; @@ -302,11 +314,11 @@ - (instancetype)initWithValues: (const float [4][4])values { self = [super init]; - memcpy(_values, values, sizeof(_values)); + memcpy(_values, values, 16 * sizeof(float)); return self; } - (float (*)[4])values @@ -314,20 +326,19 @@ return _values; } - (instancetype)copy { - return [[OFMatrix4x4 alloc] - initWithValues: (const float (*)[4])_values]; + return [[OFMatrix4x4 alloc] initWithValues: _values]; } - (bool)isEqual: (OFMatrix4x4 *)matrix { if (![matrix isKindOfClass: [OFMatrix4x4 class]]) return false; - return (memcmp(_values, matrix->_values, sizeof(_values)) == 0); + return (memcmp(_values, matrix->_values, 16 * sizeof(float)) == 0); } - (unsigned long)hash { unsigned long hash; @@ -353,11 +364,11 @@ matrix->_values[i][0] * _values[0][j] + matrix->_values[i][1] * _values[1][j] + matrix->_values[i][2] * _values[2][j] + matrix->_values[i][3] * _values[3][j]; - memcpy(_values, result, sizeof(result)); + memcpy(_values, result, 16 * sizeof(float)); } - (void)translateWithVector: (OFVector3D)vector { OFMatrix4x4 *translation = [[OFMatrix4x4 alloc] initWithValues: