strncpy.S 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * arch/alpha/lib/strncpy.S
  3. * Contributed by Richard Henderson (rth@tamu.edu)
  4. *
  5. * Copy no more than COUNT bytes of the null-terminated string from
  6. * SRC to DST. If SRC does not cover all of COUNT, the balance is
  7. * zeroed.
  8. *
  9. * Or, rather, if the kernel cared about that weird ANSI quirk. This
  10. * version has cropped that bit o' nastiness as well as assuming that
  11. * __stxncpy is in range of a branch.
  12. */
  13. .set noat
  14. .set noreorder
  15. .text
  16. .align 4
  17. .globl strncpy
  18. .ent strncpy
  19. strncpy:
  20. .frame $30, 0, $26
  21. .prologue 0
  22. mov $16, $0 # set return value now
  23. beq $18, $zerolen
  24. unop
  25. bsr $23, __stxncpy # do the work of the copy
  26. unop
  27. bne $18, $multiword # do we have full words left?
  28. subq $24, 1, $3 # nope
  29. subq $27, 1, $4
  30. or $3, $24, $3 # clear the bits between the last
  31. or $4, $27, $4 # written byte and the last byte in COUNT
  32. andnot $3, $4, $4
  33. zap $1, $4, $1
  34. stq_u $1, 0($16)
  35. ret
  36. .align 4
  37. $multiword:
  38. subq $27, 1, $2 # clear the final bits in the prev word
  39. or $2, $27, $2
  40. zapnot $1, $2, $1
  41. subq $18, 1, $18
  42. stq_u $1, 0($16)
  43. addq $16, 8, $16
  44. unop
  45. beq $18, 1f
  46. nop
  47. unop
  48. nop
  49. blbc $18, 0f
  50. stq_u $31, 0($16) # zero one word
  51. subq $18, 1, $18
  52. addq $16, 8, $16
  53. beq $18, 1f
  54. 0: stq_u $31, 0($16) # zero two words
  55. subq $18, 2, $18
  56. stq_u $31, 8($16)
  57. addq $16, 16, $16
  58. bne $18, 0b
  59. 1: ldq_u $1, 0($16) # clear the leading bits in the final word
  60. subq $24, 1, $2
  61. or $2, $24, $2
  62. zap $1, $2, $1
  63. stq_u $1, 0($16)
  64. $zerolen:
  65. ret
  66. .end strncpy