mem_64.S 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * String handling functions for PowerPC.
  3. *
  4. * Copyright (C) 1996 Paul Mackerras.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <asm/processor.h>
  12. #include <asm/errno.h>
  13. #include <asm/ppc_asm.h>
  14. _GLOBAL(memset)
  15. neg r0,r3
  16. rlwimi r4,r4,8,16,23
  17. andi. r0,r0,7 /* # bytes to be 8-byte aligned */
  18. rlwimi r4,r4,16,0,15
  19. cmplw cr1,r5,r0 /* do we get that far? */
  20. rldimi r4,r4,32,0
  21. PPC_MTOCRF(1,r0)
  22. mr r6,r3
  23. blt cr1,8f
  24. beq+ 3f /* if already 8-byte aligned */
  25. subf r5,r0,r5
  26. bf 31,1f
  27. stb r4,0(r6)
  28. addi r6,r6,1
  29. 1: bf 30,2f
  30. sth r4,0(r6)
  31. addi r6,r6,2
  32. 2: bf 29,3f
  33. stw r4,0(r6)
  34. addi r6,r6,4
  35. 3: srdi. r0,r5,6
  36. clrldi r5,r5,58
  37. mtctr r0
  38. beq 5f
  39. 4: std r4,0(r6)
  40. std r4,8(r6)
  41. std r4,16(r6)
  42. std r4,24(r6)
  43. std r4,32(r6)
  44. std r4,40(r6)
  45. std r4,48(r6)
  46. std r4,56(r6)
  47. addi r6,r6,64
  48. bdnz 4b
  49. 5: srwi. r0,r5,3
  50. clrlwi r5,r5,29
  51. PPC_MTOCRF(1,r0)
  52. beq 8f
  53. bf 29,6f
  54. std r4,0(r6)
  55. std r4,8(r6)
  56. std r4,16(r6)
  57. std r4,24(r6)
  58. addi r6,r6,32
  59. 6: bf 30,7f
  60. std r4,0(r6)
  61. std r4,8(r6)
  62. addi r6,r6,16
  63. 7: bf 31,8f
  64. std r4,0(r6)
  65. addi r6,r6,8
  66. 8: cmpwi r5,0
  67. PPC_MTOCRF(1,r5)
  68. beqlr+
  69. bf 29,9f
  70. stw r4,0(r6)
  71. addi r6,r6,4
  72. 9: bf 30,10f
  73. sth r4,0(r6)
  74. addi r6,r6,2
  75. 10: bflr 31
  76. stb r4,0(r6)
  77. blr
  78. _GLOBAL_TOC(memmove)
  79. cmplw 0,r3,r4
  80. bgt backwards_memcpy
  81. b memcpy
  82. _GLOBAL(backwards_memcpy)
  83. rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */
  84. add r6,r3,r5
  85. add r4,r4,r5
  86. beq 2f
  87. andi. r0,r6,3
  88. mtctr r7
  89. bne 5f
  90. 1: lwz r7,-4(r4)
  91. lwzu r8,-8(r4)
  92. stw r7,-4(r6)
  93. stwu r8,-8(r6)
  94. bdnz 1b
  95. andi. r5,r5,7
  96. 2: cmplwi 0,r5,4
  97. blt 3f
  98. lwzu r0,-4(r4)
  99. subi r5,r5,4
  100. stwu r0,-4(r6)
  101. 3: cmpwi 0,r5,0
  102. beqlr
  103. mtctr r5
  104. 4: lbzu r0,-1(r4)
  105. stbu r0,-1(r6)
  106. bdnz 4b
  107. blr
  108. 5: mtctr r0
  109. 6: lbzu r7,-1(r4)
  110. stbu r7,-1(r6)
  111. bdnz 6b
  112. subf r5,r0,r5
  113. rlwinm. r7,r5,32-3,3,31
  114. beq 2b
  115. mtctr r7
  116. b 1b