memmove.c 3.3 KB

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