source: rtems/c/src/lib/libcpu/m68k/shared/misc/memcpy.c @ 3f5480c

4.104.114.84.95
Last change on this file since 3f5480c was 3f5480c, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 5, 2002 at 7:03:52 PM

2002-08-05 Joel Sherrill <joel@…>

  • Per PR260 eliminate use of make-target-options. This impacted RTEMS allowing a distinction between the CPU32 and CPU32+ in the SuperCore? and required that the m68k optimized memcpy be moved to libcpu.
  • shared/misc/memcpy.c: Moved from score/cpu/m68k.
  • configure.ac, shared/Makefile.am: Modified to reflect new directory.
  • shared/misc/.cvsignore, shared/misc/Makefile.am: New file.
  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*
2 *  C library memcpy routine
3 *
4 *  This routine has code to optimize performance on the CPU32+
5 *  and another version for other 68k machines.
6 *
7 *  It could be optimized more for machines with MOVE16 instructions.
8 *
9 *  The routine is placed in this source directory to ensure that it
10 *  is picked up by all applications.
11 *
12 *  W. Eric Norum
13 *  Saskatchewan Accelerator Laboratory
14 *  University of Saskatchewan
15 *  Saskatoon, Saskatchewan, CANADA
16 *  eric@skatter.usask.ca
17 */
18
19#include <string.h>
20#include <rtems/score/m68k.h>
21
22#if defined(__mcpu32__)
23#define COPYSETUP(n)    n--
24#define COPY(to,from,n,size) \
25        asm volatile ("1:\n" \
26             "\tmove." size " (%0)+,(%1)+\n" \
27             "\tdbf %2,1b\n"  \
28             "\tsub.l #0x10000,%2\n" \
29             "\tbpl.b 1b\n" : \
30                "=a" (from), "=a" (to), "=d" (n) :\
31                 "0" (from),  "1" (to), "2" (n) : \
32                 "cc", "memory")
33#else
34#define COPYSETUP(n)
35#define COPY(to,from,n,size) \
36        asm volatile ("1:\n" \
37             "\tmove." size " (%0)+,(%1)+\n" \
38             "\tsubq.l #1,%2\n\tbne.b 1b\n" : \
39                "=a" (from), "=a" (to), "=d" (n) :\
40                 "0" (from),  "1" (to), "2" (n) : \
41                 "cc", "memory")
42#endif
43
44/* gcc doesn't know that cpu32+ is better than cpu32 :( */
45#if defined(__mcpu32p__)
46#undef M68k_HAS_MISALIGNED
47#define M68k_HAS_MISALIGNED 1
48#endif
49
50void *
51memcpy(void *s1, const void *s2, size_t n)
52{
53        char *p1 = s1;
54        const char *p2 = s2;
55
56        if (n) {
57                if (n < 16) {
58                        COPYSETUP (n);
59                        COPY (p1, p2, n, "b");
60                }
61                else {
62                        int nbyte;
63                        int nl;
64                        nbyte = (int)p1 & 0x3;
65                        if (nbyte) {
66                                nbyte = 4 - nbyte;
67                                n -= nbyte;
68                                COPYSETUP (nbyte);
69                                COPY (p1, p2, nbyte, "b");
70                        }
71#if (M68K_HAS_MISALIGNED == 0)
72                        /*
73                         * Take care of machines that can't
74                         * handle misaligned references.
75                         */
76                        if ((int)p2 & 0x1) {
77                                COPYSETUP (n);
78                                COPY (p1, p2, n, "b");
79                                return s1;
80                        }
81#endif
82                        nl = (unsigned int)n >> 2;
83                        COPYSETUP (nl);
84                        COPY (p1, p2, nl, "l");
85                        nbyte = (int)n & 0x3;
86                        if (nbyte) {
87                                COPYSETUP (nbyte);
88                                COPY (p1, p2, nbyte, "b");
89                        }
90                }
91        }
92        return s1;
93}
Note: See TracBrowser for help on using the repository browser.