memmove.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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, see
  18. <http://www.gnu.org/licenses/>. */
  19. #include <string.h>
  20. #include "memcopy.h"
  21. #include "../generic/pagecopy.h"
  22. void *memmove (void *dest, const void *src, size_t len)
  23. {
  24. unsigned long int dstp = (long int) dest;
  25. unsigned long int srcp = (long int) src;
  26. /* This test makes the forward copying code be used whenever possible.
  27. Reduces the working set. */
  28. if (dstp - srcp >= len) /* *Unsigned* compare! */
  29. {
  30. #if 1
  31. #warning REMINDER: Cris arch-opt memmove assumes memcpy does forward copying!
  32. memcpy(dest, src, len);
  33. #else
  34. /* Copy from the beginning to the end. */
  35. /* If there not too few bytes to copy, use word copy. */
  36. if (len >= OP_T_THRES)
  37. {
  38. /* Copy just a few bytes to make DSTP aligned. */
  39. len -= (-dstp) % OPSIZ;
  40. BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
  41. /* Copy whole pages from SRCP to DSTP by virtual address
  42. manipulation, as much as possible. */
  43. PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
  44. /* Copy from SRCP to DSTP taking advantage of the known
  45. alignment of DSTP. Number of bytes remaining is put
  46. in the third argument, i.e. in LEN. This number may
  47. vary from machine to machine. */
  48. WORD_COPY_FWD (dstp, srcp, len, len);
  49. /* Fall out and copy the tail. */
  50. }
  51. /* There are just a few bytes to copy. Use byte memory operations. */
  52. BYTE_COPY_FWD (dstp, srcp, len);
  53. #endif
  54. }
  55. else
  56. {
  57. /* Copy from the end to the beginning. */
  58. srcp += len;
  59. dstp += len;
  60. /* If there not too few bytes to copy, use word copy. */
  61. if (len >= OP_T_THRES)
  62. {
  63. /* Copy just a few bytes to make DSTP aligned. */
  64. len -= dstp % OPSIZ;
  65. BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
  66. /* Copy from SRCP to DSTP taking advantage of the known
  67. alignment of DSTP. Number of bytes remaining is put
  68. in the third argument, i.e. in LEN. This number may
  69. vary from machine to machine. */
  70. WORD_COPY_BWD (dstp, srcp, len, len);
  71. /* Fall out and copy the tail. */
  72. }
  73. /* There are just a few bytes to copy. Use byte memory operations. */
  74. BYTE_COPY_BWD (dstp, srcp, len);
  75. }
  76. return (dest);
  77. }
  78. libc_hidden_def(memmove)