memcpy.S 3.2 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, write to the Free
  18. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. .text
  21. .p2align 4
  22. ###############################################################################
  23. #
  24. # void *memcpy(void *to, const char *from, size_t count)
  25. #
  26. # - NOTE: must not use any stack. exception detection performs function return
  27. # to caller's fixup routine, aborting the remainder of the copy
  28. #
  29. ###############################################################################
  30. .globl memcpy
  31. .set memcpy,__memcpy
  32. .globl __memcpy
  33. .hidden __memcpy
  34. .type __memcpy,@function
  35. __memcpy:
  36. or.p gr8,gr9,gr4
  37. orcc gr10,gr0,gr0,icc3
  38. or.p gr10,gr4,gr4
  39. beqlr icc3,#0
  40. # optimise based on best common alignment for to, from & count
  41. andicc.p gr4,#0x1f,gr0,icc0
  42. setlos #8,gr11
  43. andicc.p gr4,#0x0f,gr0,icc1
  44. beq icc0,#0,memcpy_32
  45. andicc.p gr4,#0x07,gr0,icc0
  46. beq icc1,#0,memcpy_16
  47. andicc.p gr4,#0x03,gr0,icc1
  48. beq icc0,#0,memcpy_8
  49. andicc.p gr4,#0x01,gr0,icc0
  50. beq icc1,#0,memcpy_4
  51. setlos.p #1,gr11
  52. beq icc0,#0,memcpy_2
  53. # do byte by byte copy
  54. sub.p gr8,gr11,gr3
  55. sub gr9,gr11,gr9
  56. 0: ldubu.p @(gr9,gr11),gr4
  57. subicc gr10,#1,gr10,icc0
  58. stbu.p gr4,@(gr3,gr11)
  59. bne icc0,#2,0b
  60. bralr
  61. # do halfword by halfword copy
  62. memcpy_2:
  63. setlos #2,gr11
  64. sub.p gr8,gr11,gr3
  65. sub gr9,gr11,gr9
  66. 0: lduhu.p @(gr9,gr11),gr4
  67. subicc gr10,#2,gr10,icc0
  68. sthu.p gr4,@(gr3,gr11)
  69. bne icc0,#2,0b
  70. bralr
  71. # do word by word copy
  72. memcpy_4:
  73. setlos #4,gr11
  74. sub.p gr8,gr11,gr3
  75. sub gr9,gr11,gr9
  76. 0: ldu.p @(gr9,gr11),gr4
  77. subicc gr10,#4,gr10,icc0
  78. stu.p gr4,@(gr3,gr11)
  79. bne icc0,#2,0b
  80. bralr
  81. # do double-word by double-word copy
  82. memcpy_8:
  83. sub.p gr8,gr11,gr3
  84. sub gr9,gr11,gr9
  85. 0: lddu.p @(gr9,gr11),gr4
  86. subicc gr10,#8,gr10,icc0
  87. stdu.p gr4,@(gr3,gr11)
  88. bne icc0,#2,0b
  89. bralr
  90. # do quad-word by quad-word copy
  91. memcpy_16:
  92. sub.p gr8,gr11,gr3
  93. sub gr9,gr11,gr9
  94. 0: lddu @(gr9,gr11),gr4
  95. lddu.p @(gr9,gr11),gr6
  96. subicc gr10,#16,gr10,icc0
  97. stdu gr4,@(gr3,gr11)
  98. stdu.p gr6,@(gr3,gr11)
  99. bne icc0,#2,0b
  100. bralr
  101. # do eight-word by eight-word copy
  102. memcpy_32:
  103. sub.p gr8,gr11,gr3
  104. sub gr9,gr11,gr9
  105. 0: lddu @(gr9,gr11),gr4
  106. lddu @(gr9,gr11),gr6
  107. lddu @(gr9,gr11),gr12
  108. lddu.p @(gr9,gr11),gr14
  109. subicc gr10,#32,gr10,icc0
  110. stdu gr4,@(gr3,gr11)
  111. stdu gr6,@(gr3,gr11)
  112. stdu gr12,@(gr3,gr11)
  113. stdu.p gr14,@(gr3,gr11)
  114. bne icc0,#2,0b
  115. bralr
  116. .size __memcpy, .-__memcpy