Overview
Comment: | OFMatrix4x4: Add Enhanced 3DNow! implementation |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
089a51310c4bf164dff368be43772daa |
User & Date: | js on 2023-10-31 23:53:14 |
Other Links: | manifest | tags |
Context
2023-11-01
| ||
20:54 | Add -[OFMatrix4x4 transformVectors:count:] check-in: ad6b3e6442 user: js tags: trunk | |
2023-10-31
| ||
23:53 | OFMatrix4x4: Add Enhanced 3DNow! implementation check-in: 089a51310c user: js tags: trunk | |
23:14 | Move x86/Mach-O assembly back to AT&T syntax check-in: 22e2cd67a2 user: js tags: trunk | |
Changes
Modified src/OFMatrix4x4.m from [240d8b02dd] to [e50ac72e61].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | @implementation OFMatrix4x4 #if defined(OF_AMD64) || defined(OF_X86) # ifndef __clang__ # pragma GCC push_options # pragma GCC target("3dnow") # endif static void multiplyWithMatrix_3DNow(OFMatrix4x4 *self, SEL _cmd, OFMatrix4x4 *matrix) { float result[4][4]; for (uint_fast8_t i = 0; i < 4; i++) { for (uint_fast8_t j = 0; j < 4; j++) { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | @implementation OFMatrix4x4 #if defined(OF_AMD64) || defined(OF_X86) # ifndef __clang__ # pragma GCC push_options # pragma GCC target("3dnow") # endif static void multiplyWithMatrix_enhanced3DNow(OFMatrix4x4 *self, SEL _cmd, OFMatrix4x4 *matrix) { float result[4][4]; for (uint_fast8_t i = 0; i < 4; i++) { for (uint_fast8_t j = 0; j < 4; j++) { __asm__ ( "movd (%2), %%mm0\n\t" "punpckldq 16(%2), %%mm0\n\t" "pfmul (%1), %%mm0\n\t" "movd 32(%2), %%mm1\n\t" "punpckldq 48(%2), %%mm1\n\t" "pfmul 8(%1), %%mm1\n\t" "pfadd %%mm1, %%mm0\n\t" "pswapd %%mm0, %%mm1\n\t" "pfadd %%mm1, %%mm0\n\t" "movd %%mm0, %0" :: "m"(result[i][j]), "r"(&matrix->_values[i][0]), "r"(&self->_values[0][j]) : "mm0", "mm1", "memory" ); } } __asm__ ("femms"); memcpy(self->_values, result, sizeof(result)); } static void multiplyWithMatrix_3DNow(OFMatrix4x4 *self, SEL _cmd, OFMatrix4x4 *matrix) { float result[4][4]; for (uint_fast8_t i = 0; i < 4; i++) { for (uint_fast8_t j = 0; j < 4; j++) { |
︙ | ︙ | |||
60 61 62 63 64 65 66 67 68 69 70 71 72 73 | } } __asm__ ("femms"); memcpy(self->_values, result, sizeof(result)); } static OFVector4D transformedVector_3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D vector) { OFVector4D result; __asm__ ( | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 154 155 156 | } } __asm__ ("femms"); memcpy(self->_values, result, sizeof(result)); } static OFVector4D transformedVector_enhanced3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D vector) { OFVector4D result; __asm__ ( "movq (%2), %%mm0\n\t" "movq 8(%2), %%mm1\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul (%1), %%mm2\n\t" "pfmul 8(%1), %%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(%1), %%mm3\n\t" "pfmul 24(%1), %%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, (%0)\n" "\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "pfmul 32(%1), %%mm2\n\t" "pfmul 40(%1), %%mm3\n\t" "pfadd %%mm3, %%mm2\n\t" "pswapd %%mm2, %%mm3\n\t" "pfadd %%mm3, %%mm2\n" "\n\t" "pfmul 48(%1), %%mm0\n\t" "pfmul 56(%1), %%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(%0)\n" "\n\t" "femms" :: "r"(&result), "r"(&self->_values), "r"(&vector) : "mm0", "mm1", "mm2", "mm3", "mm4", "memory" ); return result; } static OFVector4D transformedVector_3DNow(OFMatrix4x4 *self, SEL _cmd, OFVector4D vector) { OFVector4D result; __asm__ ( |
︙ | ︙ | |||
123 124 125 126 127 128 129 130 131 132 | } # ifndef __clang__ # pragma GCC pop_options # endif + (void)initialize { if (self != [OFMatrix4x4 class]) return; | > > < < < | < | | | < > > > | < | > | > | > > | 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | } # ifndef __clang__ # pragma GCC pop_options # endif + (void)initialize { const char *typeEncoding; if (self != [OFMatrix4x4 class]) return; # define REPLACE(selector, func) \ typeEncoding = method_getTypeEncoding( \ class_getInstanceMethod(self, selector)); \ class_replaceMethod(self, selector, (IMP)func, typeEncoding); if ([OFSystemInfo supportsEnhanced3DNow]) { REPLACE(@selector(multiplyWithMatrix:), multiplyWithMatrix_enhanced3DNow) REPLACE(@selector(transformedVector:), transformedVector_enhanced3DNow) } else if ([OFSystemInfo supports3DNow]) { REPLACE(@selector(multiplyWithMatrix:), multiplyWithMatrix_3DNow) REPLACE(@selector(transformedVector:), transformedVector_3DNow) } # undef REPLACE } #endif + (OFMatrix4x4 *)identityMatrix { return [[[OFMatrix4x4 alloc] initWithValues: identityValues] autorelease]; |
︙ | ︙ |