Overview
Comment: | OFMatrix4x4: Minor cleanups |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
b5c3a36731dadb45e2ef02743b9b4786 |
User & Date: | js on 2023-11-02 23:00:22 |
Other Links: | manifest | tags |
Context
2023-11-03
| ||
00:16 | OFMatrix4x4: SSE4.1 for -[transformVectors:count:] check-in: 7f304f573b user: js tags: trunk | |
2023-11-02
| ||
23:00 | OFMatrix4x4: Minor cleanups check-in: b5c3a36731 user: js tags: trunk | |
22:48 | OFMatrix4x4: Move __asm__ out of loop check-in: 0d671245d4 user: js tags: trunk | |
Changes
Modified src/OFMatrix4x4.m from [a12ee064b0] to [740fcdd16f].
︙ | ︙ | |||
28 29 30 31 32 33 34 | { 0, 0, 0, 1 } }; @implementation OFMatrix4x4 #if (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) # ifndef __clang__ # pragma GCC push_options | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | { 0, 0, 0, 1 } }; @implementation OFMatrix4x4 #if (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__) # ifndef __clang__ # pragma GCC push_options # pragma GCC target("3dnow,3dnowa") # 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]; |
︙ | ︙ | |||
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | "femms" : "+r"(resultPtr), "+r"(left), "+r"(right) :: "cx", "mm0", "mm1", "memory" ); memcpy(self->_values, result, sizeof(result)); } 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]; __asm__ __volatile__ ( | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | "femms" : "+r"(resultPtr), "+r"(left), "+r"(right) :: "cx", "mm0", "mm1", "memory" ); memcpy(self->_values, result, sizeof(result)); } static void transformVectors_enhanced3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D *vectors, size_t count) { __asm__ __volatile__ ( "test %0, %0\n\t" "jz 0f\n" "\n\t" "0:\n\t" "movq (%1), %%mm0\n\t" "movq 8(%1), %%mm1\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul (%2), %%mm2\n\t" "pfmul 8(%2), %%mm3\n\t" "pfadd %%mm3, %%mm2\n\t" "pswapd %%mm2, %%mm3\n\t" "pfadd %%mm3, %%mm2\n" "\n\t" "movq %%mm0, %%mm3\n\t" "movq %%mm1, %%mm4\n\t" "pfmul 16(%2), %%mm3\n\t" "pfmul 24(%2), %%mm4\n\t" "pfadd %%mm4, %%mm3\n\t" "pswapd %%mm3, %%mm4\n\t" "pfadd %%mm4, %%mm3\n" "\n\t" "punpckldq %%mm3, %%mm2\n\t" "movq %%mm2, (%1)\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul 32(%2), %%mm2\n\t" "pfmul 40(%2), %%mm3\n\t" "pfadd %%mm3, %%mm2\n\t" "pswapd %%mm2, %%mm3\n\t" "pfadd %%mm3, %%mm2\n" "\n\t" "pfmul 48(%2), %%mm0\n\t" "pfmul 56(%2), %%mm1\n\t" "pfadd %%mm1, %%mm0\n\t" "pswapd %%mm0, %%mm1\n\t" "pfadd %%mm1, %%mm0\n" "\n\t" "punpckldq %%mm0, %%mm2\n\t" "movq %%mm2, 8(%1)\n" "\n\t" "add $16, %1\n\t" "dec %0\n\t" "jnz 0b\n" "\n\t" "0:\n\t" "femms" : "+r"(count), "+r"(vectors) : "r"(&self->_values) : "mm0", "mm1", "mm2", "mm3", "mm4", "memory" ); } # ifndef __clang__ # pragma GCC pop_options # endif # ifndef __clang__ # pragma GCC push_options # 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]; __asm__ __volatile__ ( |
︙ | ︙ | |||
115 116 117 118 119 120 121 122 | : "+r"(resultPtr), "+r"(left), "+r"(right) :: "cx", "mm0", "mm1", "memory" ); memcpy(self->_values, result, sizeof(result)); } static void | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | : "+r"(resultPtr), "+r"(left), "+r"(right) :: "cx", "mm0", "mm1", "memory" ); memcpy(self->_values, result, sizeof(result)); } static void transformVectors_3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D *vectors, size_t count) { __asm__ __volatile__ ( "test %0, %0\n\t" "jz 0f\n" "\n\t" "0:\n\t" "movq (%1), %%mm0\n\t" "movq 8(%1), %%mm1\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul (%2), %%mm2\n\t" "pfmul 8(%2), %%mm3\n\t" |
︙ | ︙ | |||
229 230 231 232 233 234 235 | "pfadd %%mm1, %%mm0\n" "\n\t" "punpckldq %%mm0, %%mm2\n\t" "movq %%mm2, 8(%1)\n" "\n\t" "add $16, %1\n\t" "dec %0\n\t" | | > | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | "pfadd %%mm1, %%mm0\n" "\n\t" "punpckldq %%mm0, %%mm2\n\t" "movq %%mm2, 8(%1)\n" "\n\t" "add $16, %1\n\t" "dec %0\n\t" "jnz 0b\n" "\n\t" "0:\n\t" "femms" : "+r"(count), "+r"(vectors) : "r"(&self->_values) : "mm0", "mm1", "mm2", "mm3", "mm4", "memory" ); } |
︙ | ︙ | |||
253 254 255 256 257 258 259 | return; # define REPLACE(selector, func) \ typeEncoding = method_getTypeEncoding( \ class_getInstanceMethod(self, selector)); \ class_replaceMethod(self, selector, (IMP)func, typeEncoding); | > | | | | | | | | | | > | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | return; # define REPLACE(selector, func) \ typeEncoding = method_getTypeEncoding( \ class_getInstanceMethod(self, selector)); \ class_replaceMethod(self, selector, (IMP)func, typeEncoding); if ([OFSystemInfo supports3DNow]) { if ([OFSystemInfo supportsEnhanced3DNow]) { REPLACE(@selector(multiplyWithMatrix:), multiplyWithMatrix_enhanced3DNow) REPLACE(@selector(transformVectors:count:), transformVectors_enhanced3DNow) } else { REPLACE(@selector(multiplyWithMatrix:), multiplyWithMatrix_3DNow) REPLACE(@selector(transformVectors:count:), transformVectors_3DNow) } } # undef REPLACE } #endif + (OFMatrix4x4 *)identityMatrix |
︙ | ︙ |