memchr.S 1016 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. ENTRY(_memchr)
  22. P0 = R0; // P0 = address
  23. P2 = R2; // P2 = count
  24. R1 = R1.B(Z);
  25. CC = R2 == 0;
  26. IF CC JUMP .Lfailed;
  27. .Lbytes:
  28. LSETUP (.Lbyte_loop_s, .Lbyte_loop_e) LC0=P2;
  29. .Lbyte_loop_s:
  30. R3 = B[P0++](Z);
  31. CC = R3 == R1;
  32. IF CC JUMP .Lfound;
  33. .Lbyte_loop_e:
  34. NOP;
  35. .Lfailed:
  36. R0=0;
  37. RTS;
  38. .Lfound:
  39. R0 = P0;
  40. R0 += -1;
  41. RTS;
  42. .size _memchr,.-_memchr
  43. libc_hidden_def (memchr)