memcpy.S 3.1 KB

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