memchr.S 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Based on arch/arm/lib/memchr.S
  3. *
  4. * Copyright (C) 1995-2000 Russell King
  5. * Copyright (C) 2013 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/linkage.h>
  20. #include <asm/assembler.h>
  21. /*
  22. * Find a character in an area of memory.
  23. *
  24. * Parameters:
  25. * x0 - buf
  26. * x1 - c
  27. * x2 - n
  28. * Returns:
  29. * x0 - address of first occurrence of 'c' or 0
  30. */
  31. ENTRY(memchr)
  32. and w1, w1, #0xff
  33. 1: subs x2, x2, #1
  34. b.mi 2f
  35. ldrb w3, [x0], #1
  36. cmp w3, w1
  37. b.ne 1b
  38. sub x0, x0, #1
  39. ret
  40. 2: mov x0, #0
  41. ret
  42. ENDPIPROC(memchr)