19
19
* along with lsp-r3d-base-lib. If not, see <https://www.gnu.org/licenses/>.
20
20
*/
21
21
22
+ #include < lsp-plug.in/common/types.h>
22
23
#include < lsp-plug.in/r3d/base/backend.h>
23
24
#include < lsp-plug.in/stdlib/string.h>
24
25
@@ -161,6 +162,52 @@ namespace lsp
161
162
162
163
void base_backend_t::memswap (void *a, void *b, size_t bytes)
163
164
{
165
+ #ifdef ARCH_64BIT
166
+ // 32-byte blocks
167
+ uint64_t *xa = reinterpret_cast <uint64_t *>(a);
168
+ uint64_t *xb = reinterpret_cast <uint64_t *>(b);
169
+
170
+ for (; bytes >= 32 ; bytes -= 32 , xa += 4 , xb += 4 )
171
+ {
172
+ uint64_t t0 = xa[0 ];
173
+ uint64_t t1 = xa[1 ];
174
+ uint64_t t2 = xa[2 ];
175
+ uint64_t t3 = xa[3 ];
176
+
177
+ xa[0 ] = xb[0 ];
178
+ xa[1 ] = xb[1 ];
179
+ xa[2 ] = xb[2 ];
180
+ xa[3 ] = xb[3 ];
181
+
182
+ xb[0 ] = t0;
183
+ xb[1 ] = t1;
184
+ xb[2 ] = t2;
185
+ xb[3 ] = t3;
186
+ }
187
+
188
+ // 4-byte blocks
189
+ uint32_t *ya = reinterpret_cast <uint32_t *>(xa);
190
+ uint32_t *yb = reinterpret_cast <uint32_t *>(xb);
191
+
192
+ for (; bytes >= 4 ; bytes -= 4 , ++ya, ++yb)
193
+ {
194
+ uint32_t t0 = ya[0 ];
195
+ ya[0 ] = yb[0 ];
196
+ yb[0 ] = t0;
197
+ }
198
+
199
+ // 1-byte blocks
200
+ uint8_t *za = reinterpret_cast <uint8_t *>(ya);
201
+ uint8_t *zb = reinterpret_cast <uint8_t *>(yb);
202
+
203
+ for (size_t i=0 ; i<bytes; ++i)
204
+ {
205
+ uint8_t t0 = za[i];
206
+ za[i] = zb[i];
207
+ zb[i] = t0;
208
+ }
209
+ #else
210
+ // 16-byte blocks
164
211
uint32_t *xa = reinterpret_cast <uint32_t *>(a);
165
212
uint32_t *xb = reinterpret_cast <uint32_t *>(b);
166
213
for (; bytes >= 16 ; bytes -= 16 , xa += 4 , xb += 4 )
@@ -181,13 +228,15 @@ namespace lsp
181
228
xb[3 ] = t3;
182
229
}
183
230
184
- for (; bytes >= 4 ; bytes -= 4 , xa += 1 , xb += 1 )
231
+ // 4-byte blocks
232
+ for (; bytes >= 4 ; bytes -= 4 , ++xa, ++xb)
185
233
{
186
234
uint32_t t0 = xa[0 ];
187
235
xa[0 ] = xb[0 ];
188
236
xb[0 ] = t0;
189
237
}
190
238
239
+ // 1-byte blocks
191
240
uint8_t *ya = reinterpret_cast <uint8_t *>(xa);
192
241
uint8_t *yb = reinterpret_cast <uint8_t *>(xb);
193
242
@@ -197,6 +246,7 @@ namespace lsp
197
246
ya[i] = yb[i];
198
247
yb[i] = t0;
199
248
}
249
+ #endif /* ARCH_64BIT */
200
250
}
201
251
202
252
void base_backend_t::swap_rows (void *buf, size_t rows, size_t bytes_per_row)
0 commit comments