memchr.S 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* memchr.S
  2. * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved.
  3. *
  4. * This file is subject to the terms and conditions of the GNU Library General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. *
  8. * Non-LGPL License also available as part of VisualDSP++
  9. * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
  10. */
  11. #include <sysdep.h>
  12. /* void *memchr(const void *s, int c, size_t n);
  13. * R0 = address (s)
  14. * R1 = sought byte (c)
  15. * R2 = count (n)
  16. *
  17. * Returns pointer to located character.
  18. */
  19. .text
  20. .align 2
  21. .weak _memchr
  22. ENTRY(_memchr)
  23. P0 = R0; /* P0 = address */
  24. P2 = R2; /* P2 = count */
  25. R1 = R1.B(Z);
  26. CC = R2 == 0;
  27. IF CC JUMP .Lfailed;
  28. .Lbytes:
  29. LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
  30. .Lbyte_loop_s:
  31. R3 = B[P0++](Z);
  32. CC = R3 == R1;
  33. IF CC JUMP .Lfound;
  34. .Lbyte_loop_e:
  35. NOP;
  36. .Lfailed:
  37. R0=0;
  38. RTS;
  39. .Lfound:
  40. R0 = P0;
  41. R0 += -1;
  42. RTS;
  43. .size _memchr,.-_memchr
  44. libc_hidden_def (memchr)