memchr.S 676 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2005-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the Clear BSD license or the GPL-2 (or later)
  5. */
  6. #include <linux/linkage.h>
  7. /* void *memchr(const void *s, int c, size_t n);
  8. * R0 = address (s)
  9. * R1 = sought byte (c)
  10. * R2 = count (n)
  11. *
  12. * Returns pointer to located character.
  13. */
  14. .text
  15. .align 2
  16. ENTRY(_memchr)
  17. P0 = R0; /* P0 = address */
  18. P2 = R2; /* P2 = count */
  19. R1 = R1.B(Z);
  20. CC = R2 == 0;
  21. IF CC JUMP .Lfailed;
  22. .Lbytes:
  23. LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
  24. .Lbyte_loop_s:
  25. R3 = B[P0++](Z);
  26. CC = R3 == R1;
  27. IF CC JUMP .Lfound;
  28. .Lbyte_loop_e:
  29. NOP;
  30. .Lfailed:
  31. R0=0;
  32. RTS;
  33. .Lfound:
  34. R0 = P0;
  35. R0 += -1;
  36. RTS;
  37. ENDPROC(_memchr)