OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [tools/] [riscv-gnu-toolchain-master/] [glibc/] [sysdeps/] [riscv/] [memcpy.c] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
#include <string.h>
2
#include <stdint.h>
3
 
4
void* __memcpy(void* aa, const void* bb, size_t n)
5
{
6
  #define BODY(a, b, t) { \
7
    t tt = *b; \
8
    a++, b++; \
9
    *(a-1) = tt; \
10
  }
11
 
12
  char* a = (char*)aa;
13
  const char* b = (const char*)bb;
14
  char* end = a+n;
15
  uintptr_t msk = sizeof(long)-1;
16
  if (__builtin_expect(((uintptr_t)a & msk) != ((uintptr_t)b & msk) || n < sizeof(long), 0))
17
  {
18
small:
19
    if (__builtin_expect(a < end, 1))
20
      while (a < end)
21
        BODY(a, b, char);
22
    return aa;
23
  }
24
 
25
  if (__builtin_expect(((uintptr_t)a & msk) != 0, 0))
26
    while ((uintptr_t)a & msk)
27
      BODY(a, b, char);
28
 
29
  long* la = (long*)a;
30
  const long* lb = (const long*)b;
31
  long* lend = (long*)((uintptr_t)end & ~msk);
32
 
33
  if (__builtin_expect(la < lend-8, 0))
34
  {
35
    while (la < lend-8)
36
    {
37
      long b0 = *lb++;
38
      long b1 = *lb++;
39
      long b2 = *lb++;
40
      long b3 = *lb++;
41
      long b4 = *lb++;
42
      long b5 = *lb++;
43
      long b6 = *lb++;
44
      long b7 = *lb++;
45
      long b8 = *lb++;
46
      *la++ = b0;
47
      *la++ = b1;
48
      *la++ = b2;
49
      *la++ = b3;
50
      *la++ = b4;
51
      *la++ = b5;
52
      *la++ = b6;
53
      *la++ = b7;
54
      *la++ = b8;
55
    }
56
  }
57
 
58
  while (la < lend)
59
    BODY(la, lb, long);
60
 
61
  a = (char*)la;
62
  b = (const char*)lb;
63
  if (__builtin_expect(a < end, 0))
64
    goto small;
65
  return aa;
66
}
67
weak_alias (__memcpy, memcpy)
68
libc_hidden_builtin_def (memcpy)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.