memset-mips.s 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. TEXT memset(SB),$12
  2. MOVW R1, 0(FP)
  3. /*
  4. * performance:
  5. * about 1us/call and 28mb/sec
  6. */
  7. MOVW n+8(FP), R3 /* R3 is count */
  8. MOVW p+0(FP), R4 /* R4 is pointer */
  9. MOVW c+4(FP), R5 /* R5 is char */
  10. ADDU R3,R4, R6 /* R6 is end pointer */
  11. /*
  12. * if not at least 4 chars,
  13. * dont even mess around.
  14. * 3 chars to guarantee any
  15. * rounding up to a word
  16. * boundary and 4 characters
  17. * to get at least maybe one
  18. * full word store.
  19. */
  20. SGT $4,R3, R1
  21. BNE R1, out
  22. /*
  23. * turn R5 into a word of characters
  24. */
  25. AND $0xff, R5
  26. SLL $8,R5, R1
  27. OR R1, R5
  28. SLL $16,R5, R1
  29. OR R1, R5
  30. /*
  31. * store one byte at a time until pointer
  32. * is alligned on a word boundary
  33. */
  34. l1:
  35. AND $3,R4, R1
  36. BEQ R1, l2
  37. MOVB R5, 0(R4)
  38. ADDU $1, R4
  39. JMP l1
  40. /*
  41. * turn R3 into end pointer-15
  42. * store 16 at a time while theres room
  43. */
  44. l2:
  45. ADDU $-15,R6, R3
  46. l3:
  47. SGTU R3,R4, R1
  48. BEQ R1, l4
  49. MOVW R5, 0(R4)
  50. MOVW R5, 4(R4)
  51. ADDU $16, R4
  52. MOVW R5, -8(R4)
  53. MOVW R5, -4(R4)
  54. JMP l3
  55. /*
  56. * turn R3 into end pointer-3
  57. * store 4 at a time while theres room
  58. */
  59. l4:
  60. ADDU $-3,R6, R3
  61. l5:
  62. SGTU R3,R4, R1
  63. BEQ R1, out
  64. MOVW R5, 0(R4)
  65. ADDU $4, R4
  66. JMP l5
  67. /*
  68. * last loop, store byte at a time
  69. */
  70. out:
  71. SGTU R6,R4 ,R1
  72. BEQ R1, ret
  73. MOVB R5, 0(R4)
  74. ADDU $1, R4
  75. JMP out
  76. ret:
  77. MOVW s1+0(FP), R1
  78. RET
  79. END