strcpy.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Optimized strcpy for Xtensa.
  2. Copyright (C) 2001, 2007 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include <bits/xtensa-config.h>
  17. #ifdef __XTENSA_EB__
  18. #define MASK0 0xff000000
  19. #define MASK1 0x00ff0000
  20. #define MASK2 0x0000ff00
  21. #define MASK3 0x000000ff
  22. #else
  23. #define MASK0 0x000000ff
  24. #define MASK1 0x0000ff00
  25. #define MASK2 0x00ff0000
  26. #define MASK3 0xff000000
  27. #endif
  28. .text
  29. ENTRY (strcpy)
  30. /* a2 = dst, a3 = src */
  31. mov a10, a2 /* leave dst in return value register */
  32. movi a4, MASK0
  33. movi a5, MASK1
  34. movi a6, MASK2
  35. movi a7, MASK3
  36. bbsi.l a3, 0, .Lsrc1mod2
  37. bbsi.l a3, 1, .Lsrc2mod4
  38. .Lsrcaligned:
  39. /* Check if the destination is aligned. */
  40. movi a8, 3
  41. bnone a10, a8, .Laligned
  42. j .Ldstunaligned
  43. .Lsrc1mod2: /* src address is odd */
  44. l8ui a8, a3, 0 /* get byte 0 */
  45. addi a3, a3, 1 /* advance src pointer */
  46. s8i a8, a10, 0 /* store byte 0 */
  47. beqz a8, 1f /* if byte 0 is zero */
  48. addi a10, a10, 1 /* advance dst pointer */
  49. bbci.l a3, 1, .Lsrcaligned /* if src is now word-aligned */
  50. .Lsrc2mod4: /* src address is 2 mod 4 */
  51. l8ui a8, a3, 0 /* get byte 0 */
  52. /* 1-cycle interlock */
  53. s8i a8, a10, 0 /* store byte 0 */
  54. beqz a8, 1f /* if byte 0 is zero */
  55. l8ui a8, a3, 1 /* get byte 0 */
  56. addi a3, a3, 2 /* advance src pointer */
  57. s8i a8, a10, 1 /* store byte 0 */
  58. addi a10, a10, 2 /* advance dst pointer */
  59. bnez a8, .Lsrcaligned
  60. 1: abi_ret
  61. /* dst is word-aligned; src is word-aligned. */
  62. .align 4
  63. #if XCHAL_HAVE_LOOPS
  64. /* (2 mod 4) alignment for loop instruction */
  65. .Laligned:
  66. _movi.n a8, 0 /* set up for the maximum loop count */
  67. loop a8, .Lz3 /* loop forever (almost anyway) */
  68. l32i a8, a3, 0 /* get word from src */
  69. addi a3, a3, 4 /* advance src pointer */
  70. bnone a8, a4, .Lz0 /* if byte 0 is zero */
  71. bnone a8, a5, .Lz1 /* if byte 1 is zero */
  72. bnone a8, a6, .Lz2 /* if byte 2 is zero */
  73. s32i a8, a10, 0 /* store word to dst */
  74. bnone a8, a7, .Lz3 /* if byte 3 is zero */
  75. addi a10, a10, 4 /* advance dst pointer */
  76. #else /* !XCHAL_HAVE_LOOPS */
  77. 1: addi a10, a10, 4 /* advance dst pointer */
  78. .Laligned:
  79. l32i a8, a3, 0 /* get word from src */
  80. addi a3, a3, 4 /* advance src pointer */
  81. bnone a8, a4, .Lz0 /* if byte 0 is zero */
  82. bnone a8, a5, .Lz1 /* if byte 1 is zero */
  83. bnone a8, a6, .Lz2 /* if byte 2 is zero */
  84. s32i a8, a10, 0 /* store word to dst */
  85. bany a8, a7, 1b /* if byte 3 is zero */
  86. #endif /* !XCHAL_HAVE_LOOPS */
  87. .Lz3: /* Byte 3 is zero. */
  88. abi_ret
  89. .Lz0: /* Byte 0 is zero. */
  90. #ifdef __XTENSA_EB__
  91. movi a8, 0
  92. #endif
  93. s8i a8, a10, 0
  94. abi_ret
  95. .Lz1: /* Byte 1 is zero. */
  96. #ifdef __XTENSA_EB__
  97. extui a8, a8, 16, 16
  98. #endif
  99. s16i a8, a10, 0
  100. abi_ret
  101. .Lz2: /* Byte 2 is zero. */
  102. #ifdef __XTENSA_EB__
  103. extui a8, a8, 16, 16
  104. #endif
  105. s16i a8, a10, 0
  106. movi a8, 0
  107. s8i a8, a10, 2
  108. abi_ret
  109. .align 4
  110. /* (2 mod 4) alignment for loop instruction */
  111. .Ldstunaligned:
  112. #if XCHAL_HAVE_LOOPS
  113. _movi.n a8, 0 /* set up for the maximum loop count */
  114. loop a8, 2f /* loop forever (almost anyway) */
  115. #endif
  116. 1: l8ui a8, a3, 0
  117. addi a3, a3, 1
  118. s8i a8, a10, 0
  119. addi a10, a10, 1
  120. #if XCHAL_HAVE_LOOPS
  121. beqz a8, 2f
  122. #else
  123. bnez a8, 1b
  124. #endif
  125. 2: abi_ret
  126. libc_hidden_def (strcpy)