memchr.S 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* memchr.S
  2. * Copyright (C) 2003, 2005, 2006 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. /* void *memchr(const void *s, int c, size_t n);
  12. * R0 = address (s)
  13. * R1 = sought byte (c)
  14. * R2 = count (n)
  15. *
  16. * Returns pointer to located character.
  17. */
  18. .text
  19. .align 2
  20. .global _memchr
  21. .type _memchr, STT_FUNC
  22. _memchr:
  23. P0 = R0; // P0 = address
  24. P2 = R2; // P2 = count
  25. R1 = R1.B(Z);
  26. CC = R2 == 0;
  27. IF CC JUMP failed;
  28. bytes:
  29. LSETUP (byte_loop_s , byte_loop_e) LC0=P2;
  30. byte_loop_s:
  31. R3 = B[P0++](Z);
  32. CC = R3 == R1;
  33. IF CC JUMP found;
  34. byte_loop_e:
  35. NOP;
  36. failed:
  37. R0=0;
  38. RTS;
  39. found:
  40. R0 = P0;
  41. R0 += -1;
  42. RTS;
  43. .size _memchr,.-_memchr
  44. libc_hidden_def (memchr)