string.S 1.4 KB

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