string.S 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * String handling functions for PowerPC.
  4. *
  5. * Copyright (C) 1996 Paul Mackerras.
  6. */
  7. #include <asm/ppc_asm.h>
  8. #include <asm/export.h>
  9. #include <asm/cache.h>
  10. .text
  11. /* This clears out any unused part of the destination buffer,
  12. just as the libc version does. -- paulus */
  13. _GLOBAL(strncpy)
  14. PPC_LCMPI 0,r5,0
  15. beqlr
  16. mtctr r5
  17. addi r6,r3,-1
  18. addi r4,r4,-1
  19. .balign IFETCH_ALIGN_BYTES
  20. 1: lbzu r0,1(r4)
  21. cmpwi 0,r0,0
  22. stbu r0,1(r6)
  23. bdnzf 2,1b /* dec ctr, branch if ctr != 0 && !cr0.eq */
  24. bnelr /* if we didn't hit a null char, we're done */
  25. mfctr r5
  26. PPC_LCMPI 0,r5,0 /* any space left in destination buffer? */
  27. beqlr /* we know r0 == 0 here */
  28. 2: stbu r0,1(r6) /* clear it out if so */
  29. bdnz 2b
  30. blr
  31. EXPORT_SYMBOL(strncpy)
  32. _GLOBAL(strncmp)
  33. PPC_LCMPI 0,r5,0
  34. beq- 2f
  35. mtctr r5
  36. addi r5,r3,-1
  37. addi r4,r4,-1
  38. .balign IFETCH_ALIGN_BYTES
  39. 1: lbzu r3,1(r5)
  40. cmpwi 1,r3,0
  41. lbzu r0,1(r4)
  42. subf. r3,r0,r3
  43. beqlr 1
  44. bdnzt eq,1b
  45. blr
  46. 2: li r3,0
  47. blr
  48. EXPORT_SYMBOL(strncmp)
  49. _GLOBAL(memchr)
  50. PPC_LCMPI 0,r5,0
  51. beq- 2f
  52. mtctr r5
  53. addi r3,r3,-1
  54. .balign IFETCH_ALIGN_BYTES
  55. 1: lbzu r0,1(r3)
  56. cmpw 0,r0,r4
  57. bdnzf 2,1b
  58. beqlr
  59. 2: li r3,0
  60. blr
  61. EXPORT_SYMBOL(memchr)