strncmp.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Optimized version of the standard strncmp() function.
  2. This file is part of the GNU C Library.
  3. Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
  4. Contributed by Dan Pop <Dan.Pop@cern.ch>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. /* Return: the result of the comparison
  17. Inputs:
  18. in0: s1
  19. in1: s2
  20. in2: n
  21. Unlike memcmp(), this function is optimized for mismatches within the
  22. first few characters. */
  23. #include <sysdep.h>
  24. #undef ret
  25. #define s1 in0
  26. #define s2 in1
  27. #define n in2
  28. #define val1 r15
  29. #define val2 r16
  30. ENTRY(strncmp)
  31. alloc r2 = ar.pfs, 3, 0, 0, 0
  32. mov ret0 = r0
  33. cmp.eq p6, p0 = r0, r0 /* set p6 */
  34. cmp.eq p7, p0 = n, r0 /* return immediately if n == 0 */
  35. (p7) br.cond.spnt .restore_and_exit ;;
  36. .loop:
  37. ld1 val1 = [s1], 1
  38. ld1 val2 = [s2], 1
  39. adds n = -1, n /* n-- */
  40. ;;
  41. cmp.ne.and p6, p0 = val1, r0
  42. cmp.ne.and p6, p0 = val2, r0
  43. cmp.ne.and p6, p0 = n, r0
  44. cmp.eq.and p6, p0 = val1, val2
  45. (p6) br.cond.sptk .loop
  46. sub ret0 = val1, val2
  47. .restore_and_exit:
  48. br.ret.sptk.many b0
  49. END(strncmp)
  50. libc_hidden_weak (strncmp)