stpncpy.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (C) 1996-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <https://www.gnu.org/licenses/>. */
  14. /* Copy no more than COUNT bytes of the null-terminated string from
  15. SRC to DST. If SRC does not cover all of COUNT, the balance is
  16. zeroed. Return the address of the terminating null in DEST, if
  17. any, else DEST + COUNT. */
  18. #include <sysdep.h>
  19. .set noat
  20. .set noreorder
  21. .text
  22. ENTRY(__stpncpy)
  23. ldgp gp, 0(pv)
  24. #ifdef PROF
  25. lda AT, _mcount
  26. jsr AT, (AT), _mcount
  27. #endif
  28. .prologue 1
  29. beq a2, $zerocount
  30. jsr t9, __stxncpy # do the work of the copy
  31. and t8, 0xf0, t3 # binary search for byte offset of the
  32. and t8, 0xcc, t2 # last byte written.
  33. and t8, 0xaa, t1
  34. andnot a0, 7, v0
  35. cmovne t3, 4, t3
  36. cmovne t2, 2, t2
  37. cmovne t1, 1, t1
  38. addq v0, t3, v0
  39. addq t1, t2, t1
  40. addq v0, t1, v0
  41. bne a2, $multiword # do we have full words left?
  42. .align 3
  43. zapnot t0, t8, t4 # e0 : was last byte a null?
  44. subq t8, 1, t2 # .. e1 :
  45. addq v0, 1, t5 # e0 :
  46. subq t10, 1, t3 # .. e1 :
  47. or t2, t8, t2 # e0 : clear the bits between the last
  48. or t3, t10, t3 # .. e1 : written byte and the last byte in
  49. andnot t3, t2, t3 # e0 : COUNT
  50. cmovne t4, t5, v0 # .. e1 : if last written wasn't null, inc v0
  51. zap t0, t3, t0 # e0 :
  52. stq_u t0, 0(a0) # e1 :
  53. ret # .. e1 :
  54. .align 3
  55. $multiword:
  56. subq t8, 1, t7 # e0 : clear the final bits in the prev
  57. or t7, t8, t7 # e1 : word
  58. zapnot t0, t7, t0 # e0 :
  59. subq a2, 1, a2 # .. e1 :
  60. stq_u t0, 0(a0) # e0 :
  61. addq a0, 8, a0 # .. e1 :
  62. beq a2, 1f # e1 :
  63. blbc a2, 0f # e1 :
  64. stq_u zero, 0(a0) # e0 : zero one word
  65. subq a2, 1, a2 # .. e1 :
  66. addq a0, 8, a0 # e0 :
  67. beq a2, 1f # .. e1 :
  68. 0: stq_u zero, 0(a0) # e0 : zero two words
  69. subq a2, 2, a2 # .. e1 :
  70. stq_u zero, 8(a0) # e0 :
  71. addq a0, 16, a0 # .. e1 :
  72. bne a2, 0b # e1 :
  73. unop
  74. 1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final
  75. subq t10, 1, t7 # .. e1 : word
  76. or t7, t10, t7 # e0 :
  77. zap t0, t7, t0 # e1 (stall)
  78. stq_u t0, 0(a0) # e0 :
  79. ret # .. e1 :
  80. $zerocount:
  81. mov a0, v0
  82. ret
  83. END(__stpncpy)
  84. libc_hidden_def (__stpncpy)
  85. weak_alias (__stpncpy, stpncpy)