strncpy.S 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. */
  17. #include <sysdep.h>
  18. .set noat
  19. .set noreorder
  20. .text
  21. ENTRY(strncpy)
  22. ldgp gp, 0(pv)
  23. #ifdef PROF
  24. lda AT, _mcount
  25. jsr AT, (AT), _mcount
  26. #endif
  27. .prologue 1
  28. mov a0, v0 # set return value now
  29. beq a2, $zerocount
  30. jsr t9, __stxncpy # do the work of the copy
  31. bne a2, $multiword # do we have full words left?
  32. .align 3
  33. subq t8, 1, t2 # e0 : guess not
  34. subq t10, 1, t3 # .. e1 :
  35. or t2, t8, t2 # e0 : clear the bits between the last
  36. or t3, t10, t3 # .. e1 : written byte and the last byte in
  37. andnot t3, t2, t3 # e0 : COUNT
  38. zap t0, t3, t0 # e1 :
  39. stq_u t0, 0(a0) # e0 :
  40. ret # .. e1 :
  41. $multiword:
  42. subq t8, 1, t7 # e0 : clear the final bits in the prev
  43. or t7, t8, t7 # e1 : word
  44. zapnot t0, t7, t0 # e0 :
  45. subq a2, 1, a2 # .. e1 :
  46. stq_u t0, 0(a0) # e0 :
  47. addq a0, 8, a0 # .. e1 :
  48. beq a2, 1f # e1 :
  49. blbc a2, 0f # e1 :
  50. stq_u zero, 0(a0) # e0 : zero one word
  51. subq a2, 1, a2 # .. e1 :
  52. addq a0, 8, a0 # e0 :
  53. beq a2, 1f # .. e1 :
  54. 0: stq_u zero, 0(a0) # e0 : zero two words
  55. subq a2, 2, a2 # .. e1 :
  56. stq_u zero, 8(a0) # e0 :
  57. addq a0, 16, a0 # .. e1 :
  58. bne a2, 0b # e1 :
  59. unop
  60. 1: ldq_u t0, 0(a0) # e0 : clear the leading bits in the final
  61. subq t10, 1, t7 # .. e1 : word
  62. or t7, t10, t7 # e0 :
  63. zap t0, t7, t0 # e1 (stall)
  64. stq_u t0, 0(a0) # e0 :
  65. $zerocount:
  66. ret # .. e1 :
  67. END(strncpy)
  68. libc_hidden_builtin_def (strncpy)