memcpy.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* memcpy.S: optimised assembly memcpy
  2. *
  3. * Copyright (C) 2003, 2004 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public
  17. * License along with this library; if not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. #include <features.h>
  21. .text
  22. .p2align 4
  23. ###############################################################################
  24. #
  25. # void *memcpy(void *to, const char *from, size_t count)
  26. #
  27. # - NOTE: must not use any stack. exception detection performs function return
  28. # to caller's fixup routine, aborting the remainder of the copy
  29. #
  30. ###############################################################################
  31. .globl memcpy
  32. .type memcpy,@function
  33. memcpy:
  34. or.p gr8,gr9,gr4
  35. orcc gr10,gr0,gr0,icc3
  36. or.p gr10,gr4,gr4
  37. beqlr icc3,#0
  38. # optimise based on best common alignment for to, from & count
  39. andicc.p gr4,#0x1f,gr0,icc0
  40. setlos #8,gr11
  41. andicc.p gr4,#0x0f,gr0,icc1
  42. beq icc0,#0,memcpy_32
  43. andicc.p gr4,#0x07,gr0,icc0
  44. beq icc1,#0,memcpy_16
  45. andicc.p gr4,#0x03,gr0,icc1
  46. beq icc0,#0,memcpy_8
  47. andicc.p gr4,#0x01,gr0,icc0
  48. beq icc1,#0,memcpy_4
  49. setlos.p #1,gr11
  50. beq icc0,#0,memcpy_2
  51. # do byte by byte copy
  52. sub.p gr8,gr11,gr3
  53. sub gr9,gr11,gr9
  54. 0: ldubu.p @(gr9,gr11),gr4
  55. subicc gr10,#1,gr10,icc0
  56. stbu.p gr4,@(gr3,gr11)
  57. bne icc0,#2,0b
  58. bralr
  59. # do halfword by halfword copy
  60. memcpy_2:
  61. setlos #2,gr11
  62. sub.p gr8,gr11,gr3
  63. sub gr9,gr11,gr9
  64. 0: lduhu.p @(gr9,gr11),gr4
  65. subicc gr10,#2,gr10,icc0
  66. sthu.p gr4,@(gr3,gr11)
  67. bne icc0,#2,0b
  68. bralr
  69. # do word by word copy
  70. memcpy_4:
  71. setlos #4,gr11
  72. sub.p gr8,gr11,gr3
  73. sub gr9,gr11,gr9
  74. 0: ldu.p @(gr9,gr11),gr4
  75. subicc gr10,#4,gr10,icc0
  76. stu.p gr4,@(gr3,gr11)
  77. bne icc0,#2,0b
  78. bralr
  79. # do double-word by double-word copy
  80. memcpy_8:
  81. sub.p gr8,gr11,gr3
  82. sub gr9,gr11,gr9
  83. 0: lddu.p @(gr9,gr11),gr4
  84. subicc gr10,#8,gr10,icc0
  85. stdu.p gr4,@(gr3,gr11)
  86. bne icc0,#2,0b
  87. bralr
  88. # do quad-word by quad-word copy
  89. memcpy_16:
  90. sub.p gr8,gr11,gr3
  91. sub gr9,gr11,gr9
  92. 0: lddu @(gr9,gr11),gr4
  93. lddu.p @(gr9,gr11),gr6
  94. subicc gr10,#16,gr10,icc0
  95. stdu gr4,@(gr3,gr11)
  96. stdu.p gr6,@(gr3,gr11)
  97. bne icc0,#2,0b
  98. bralr
  99. # do eight-word by eight-word copy
  100. memcpy_32:
  101. sub.p gr8,gr11,gr3
  102. sub gr9,gr11,gr9
  103. 0: lddu @(gr9,gr11),gr4
  104. lddu @(gr9,gr11),gr6
  105. lddu @(gr9,gr11),gr12
  106. lddu.p @(gr9,gr11),gr14
  107. subicc gr10,#32,gr10,icc0
  108. stdu gr4,@(gr3,gr11)
  109. stdu gr6,@(gr3,gr11)
  110. stdu gr12,@(gr3,gr11)
  111. stdu.p gr14,@(gr3,gr11)
  112. bne icc0,#2,0b
  113. bralr
  114. .size memcpy, .-memcpy
  115. libc_hidden_def(memcpy)