memcpy.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #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. .hidden __memcpy
  33. .type __memcpy,@function
  34. __memcpy:
  35. or.p gr8,gr9,gr4
  36. orcc gr10,gr0,gr0,icc3
  37. or.p gr10,gr4,gr4
  38. beqlr icc3,#0
  39. # optimise based on best common alignment for to, from & count
  40. andicc.p gr4,#0x1f,gr0,icc0
  41. setlos #8,gr11
  42. andicc.p gr4,#0x0f,gr0,icc1
  43. beq icc0,#0,memcpy_32
  44. andicc.p gr4,#0x07,gr0,icc0
  45. beq icc1,#0,memcpy_16
  46. andicc.p gr4,#0x03,gr0,icc1
  47. beq icc0,#0,memcpy_8
  48. andicc.p gr4,#0x01,gr0,icc0
  49. beq icc1,#0,memcpy_4
  50. setlos.p #1,gr11
  51. beq icc0,#0,memcpy_2
  52. # do byte by byte copy
  53. sub.p gr8,gr11,gr3
  54. sub gr9,gr11,gr9
  55. 0: ldubu.p @(gr9,gr11),gr4
  56. subicc gr10,#1,gr10,icc0
  57. stbu.p gr4,@(gr3,gr11)
  58. bne icc0,#2,0b
  59. bralr
  60. # do halfword by halfword copy
  61. memcpy_2:
  62. setlos #2,gr11
  63. sub.p gr8,gr11,gr3
  64. sub gr9,gr11,gr9
  65. 0: lduhu.p @(gr9,gr11),gr4
  66. subicc gr10,#2,gr10,icc0
  67. sthu.p gr4,@(gr3,gr11)
  68. bne icc0,#2,0b
  69. bralr
  70. # do word by word copy
  71. memcpy_4:
  72. setlos #4,gr11
  73. sub.p gr8,gr11,gr3
  74. sub gr9,gr11,gr9
  75. 0: ldu.p @(gr9,gr11),gr4
  76. subicc gr10,#4,gr10,icc0
  77. stu.p gr4,@(gr3,gr11)
  78. bne icc0,#2,0b
  79. bralr
  80. # do double-word by double-word copy
  81. memcpy_8:
  82. sub.p gr8,gr11,gr3
  83. sub gr9,gr11,gr9
  84. 0: lddu.p @(gr9,gr11),gr4
  85. subicc gr10,#8,gr10,icc0
  86. stdu.p gr4,@(gr3,gr11)
  87. bne icc0,#2,0b
  88. bralr
  89. # do quad-word by quad-word copy
  90. memcpy_16:
  91. sub.p gr8,gr11,gr3
  92. sub gr9,gr11,gr9
  93. 0: lddu @(gr9,gr11),gr4
  94. lddu.p @(gr9,gr11),gr6
  95. subicc gr10,#16,gr10,icc0
  96. stdu gr4,@(gr3,gr11)
  97. stdu.p gr6,@(gr3,gr11)
  98. bne icc0,#2,0b
  99. bralr
  100. # do eight-word by eight-word copy
  101. memcpy_32:
  102. sub.p gr8,gr11,gr3
  103. sub gr9,gr11,gr9
  104. 0: lddu @(gr9,gr11),gr4
  105. lddu @(gr9,gr11),gr6
  106. lddu @(gr9,gr11),gr12
  107. lddu.p @(gr9,gr11),gr14
  108. subicc gr10,#32,gr10,icc0
  109. stdu gr4,@(gr3,gr11)
  110. stdu gr6,@(gr3,gr11)
  111. stdu gr12,@(gr3,gr11)
  112. stdu.p gr14,@(gr3,gr11)
  113. bne icc0,#2,0b
  114. bralr
  115. .size __memcpy, .-__memcpy
  116. strong_alias(__memcpy,memcpy)