memmove.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Taken from generic/memmove.c; trivially modified to work with
  2. arch-specific memcopy.h for Cris.
  3. Copy memory to memory until the specified number of bytes
  4. has been copied. Overlap is handled correctly.
  5. Copyright (C) 1991, 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
  6. This file is part of the GNU C Library.
  7. Contributed by Torbjorn Granlund (tege@sics.se).
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with the GNU C Library; if not, write to the Free
  18. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19. 02111-1307 USA. */
  20. #include <string.h>
  21. #include "memcopy.h"
  22. #include "../generic/pagecopy.h"
  23. void *memmove (void *dest, const void *src, size_t len)
  24. {
  25. unsigned long int dstp = (long int) dest;
  26. unsigned long int srcp = (long int) src;
  27. /* This test makes the forward copying code be used whenever possible.
  28. Reduces the working set. */
  29. if (dstp - srcp >= len) /* *Unsigned* compare! */
  30. {
  31. #if 1
  32. #warning REMINDER: Cris arch-opt memmove assumes memcpy does forward copying!
  33. memcpy(dest, src, len);
  34. #else
  35. /* Copy from the beginning to the end. */
  36. /* If there not too few bytes to copy, use word copy. */
  37. if (len >= OP_T_THRES)
  38. {
  39. /* Copy just a few bytes to make DSTP aligned. */
  40. len -= (-dstp) % OPSIZ;
  41. BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
  42. /* Copy whole pages from SRCP to DSTP by virtual address
  43. manipulation, as much as possible. */
  44. PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
  45. /* Copy from SRCP to DSTP taking advantage of the known
  46. alignment of DSTP. Number of bytes remaining is put
  47. in the third argument, i.e. in LEN. This number may
  48. vary from machine to machine. */
  49. WORD_COPY_FWD (dstp, srcp, len, len);
  50. /* Fall out and copy the tail. */
  51. }
  52. /* There are just a few bytes to copy. Use byte memory operations. */
  53. BYTE_COPY_FWD (dstp, srcp, len);
  54. #endif
  55. }
  56. else
  57. {
  58. /* Copy from the end to the beginning. */
  59. srcp += len;
  60. dstp += len;
  61. /* If there not too few bytes to copy, use word copy. */
  62. if (len >= OP_T_THRES)
  63. {
  64. /* Copy just a few bytes to make DSTP aligned. */
  65. len -= dstp % OPSIZ;
  66. BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
  67. /* Copy from SRCP to DSTP taking advantage of the known
  68. alignment of DSTP. Number of bytes remaining is put
  69. in the third argument, i.e. in LEN. This number may
  70. vary from machine to machine. */
  71. WORD_COPY_BWD (dstp, srcp, len, len);
  72. /* Fall out and copy the tail. */
  73. }
  74. /* There are just a few bytes to copy. Use byte memory operations. */
  75. BYTE_COPY_BWD (dstp, srcp, len);
  76. }
  77. return (dest);
  78. }
  79. libc_hidden_def(memmove)