1#include "libxr_def.hpp"
5 uint8_t* d =
static_cast<uint8_t*
>(dst);
6 const uint8_t* s =
static_cast<const uint8_t*
>(src);
8 uintptr_t d_offset =
reinterpret_cast<uintptr_t
>(d) & (LIBXR_ALIGN_SIZE - 1);
9 uintptr_t s_offset =
reinterpret_cast<uintptr_t
>(s) & (LIBXR_ALIGN_SIZE - 1);
15 if (d_offset == s_offset)
20 size_t head = LIBXR_ALIGN_SIZE - d_offset;
32#if LIBXR_ALIGN_SIZE == 8
34 auto* dw =
reinterpret_cast<uint64_t*
>(d);
35 auto* sw =
reinterpret_cast<const uint64_t*
>(s);
57 d =
reinterpret_cast<uint8_t*
>(dw);
58 s =
reinterpret_cast<const uint8_t*
>(sw);
61 auto* dw =
reinterpret_cast<uint32_t*
>(d);
62 auto* sw =
reinterpret_cast<const uint32_t*
>(s);
84 d =
reinterpret_cast<uint8_t*
>(dw);
85 s =
reinterpret_cast<const uint8_t*
>(sw);
94 uintptr_t addr_diff =
reinterpret_cast<uintptr_t
>(s) -
reinterpret_cast<uintptr_t
>(d);
96#if LIBXR_ALIGN_SIZE == 8
98 if ((addr_diff & 3) == 0 && size > 0)
100 while ((
reinterpret_cast<uintptr_t
>(d) & 3) && size)
105 auto* d32 =
reinterpret_cast<uint32_t*
>(d);
106 auto* s32 =
reinterpret_cast<const uint32_t*
>(s);
128 d =
reinterpret_cast<uint8_t*
>(d32);
129 s =
reinterpret_cast<const uint8_t*
>(s32);
134 if ((addr_diff & 1) == 0 && size > 0)
136 if (
reinterpret_cast<uintptr_t
>(d) & 1)
141 auto* d16 =
reinterpret_cast<uint16_t*
>(d);
142 auto* s16 =
reinterpret_cast<const uint16_t*
>(s);
164 d =
reinterpret_cast<uint8_t*
>(d16);
165 s =
reinterpret_cast<const uint8_t*
>(s16);
184 uint8_t* d =
static_cast<uint8_t*
>(dst);
186 uintptr_t d_offset =
reinterpret_cast<uintptr_t
>(d) & (LIBXR_ALIGN_SIZE - 1);
191 size_t head = LIBXR_ALIGN_SIZE - d_offset;
203#if LIBXR_ALIGN_SIZE == 8
205 uint64_t pat = value;
210 auto* dw =
reinterpret_cast<uint64_t*
>(d);
231 d =
reinterpret_cast<uint8_t*
>(dw);
234 uint32_t pat = value;
238 auto* dw =
reinterpret_cast<uint32_t*
>(d);
259 d =
reinterpret_cast<uint8_t*
>(dw);
271 const uint8_t* p =
static_cast<const uint8_t*
>(a);
272 const uint8_t* q =
static_cast<const uint8_t*
>(b);
274 if ((size == 0) || (p == q))
279 auto byte_cmp = [](
const uint8_t* x,
const uint8_t* y,
size_t n) ->
int
281 for (
size_t i = 0; i < n; ++i)
283 int diff =
static_cast<int>(x[i]) -
static_cast<int>(y[i]);
292 uintptr_t p_off =
reinterpret_cast<uintptr_t
>(p) & (LIBXR_ALIGN_SIZE - 1);
293 uintptr_t q_off =
reinterpret_cast<uintptr_t
>(q) & (LIBXR_ALIGN_SIZE - 1);
296 if ((p_off == q_off) && (p_off != 0))
298 size_t head = LIBXR_ALIGN_SIZE - p_off;
306 int diff =
static_cast<int>(*p++) -
static_cast<int>(*q++);
315#if LIBXR_ALIGN_SIZE == 8
317 if ((((
reinterpret_cast<uintptr_t
>(p) |
reinterpret_cast<uintptr_t
>(q)) & 7u) == 0u))
319 auto* pw =
reinterpret_cast<const uint64_t*
>(p);
320 auto* qw =
reinterpret_cast<const uint64_t*
>(q);
326 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 0),
327 reinterpret_cast<const uint8_t*
>(qw + 0), 8);
331 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 1),
332 reinterpret_cast<const uint8_t*
>(qw + 1), 8);
336 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 2),
337 reinterpret_cast<const uint8_t*
>(qw + 2), 8);
341 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 3),
342 reinterpret_cast<const uint8_t*
>(qw + 3), 8);
346 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 4),
347 reinterpret_cast<const uint8_t*
>(qw + 4), 8);
351 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 5),
352 reinterpret_cast<const uint8_t*
>(qw + 5), 8);
356 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 6),
357 reinterpret_cast<const uint8_t*
>(qw + 6), 8);
361 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 7),
362 reinterpret_cast<const uint8_t*
>(qw + 7), 8);
374 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw),
375 reinterpret_cast<const uint8_t*
>(qw), 8);
382 p =
reinterpret_cast<const uint8_t*
>(pw);
383 q =
reinterpret_cast<const uint8_t*
>(qw);
387 if ((((
reinterpret_cast<uintptr_t
>(p) |
reinterpret_cast<uintptr_t
>(q)) & 3u) == 0u))
389 auto* pw =
reinterpret_cast<const uint32_t*
>(p);
390 auto* qw =
reinterpret_cast<const uint32_t*
>(q);
396 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 0),
397 reinterpret_cast<const uint8_t*
>(qw + 0), 4);
401 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 1),
402 reinterpret_cast<const uint8_t*
>(qw + 1), 4);
406 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 2),
407 reinterpret_cast<const uint8_t*
>(qw + 2), 4);
411 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 3),
412 reinterpret_cast<const uint8_t*
>(qw + 3), 4);
416 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 4),
417 reinterpret_cast<const uint8_t*
>(qw + 4), 4);
421 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 5),
422 reinterpret_cast<const uint8_t*
>(qw + 5), 4);
426 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 6),
427 reinterpret_cast<const uint8_t*
>(qw + 6), 4);
431 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw + 7),
432 reinterpret_cast<const uint8_t*
>(qw + 7), 4);
444 return byte_cmp(
reinterpret_cast<const uint8_t*
>(pw),
445 reinterpret_cast<const uint8_t*
>(qw), 4);
452 p =
reinterpret_cast<const uint8_t*
>(pw);
453 q =
reinterpret_cast<const uint8_t*
>(qw);
460 int diff =
static_cast<int>(*p++) -
static_cast<int>(*q++);
static void FastSet(void *dst, uint8_t value, size_t size)
快速内存填充 / Fast memory fill
static int FastCmp(const void *a, const void *b, size_t size)
快速内存比较 / Fast memory comparison
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy