strncmp.S 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. /* Return: the result of the comparison
  18. Inputs:
  19. in0: s1
  20. in1: s2
  21. in2: n
  22. Unlike memcmp(), this function is optimized for mismatches within the
  23. first few characters. */
  24. #include "sysdep.h"
  25. #undef ret
  26. #define s1 in0
  27. #define s2 in1
  28. #define n in2
  29. #define val1 r15
  30. #define val2 r16
  31. ENTRY(strncmp)
  32. alloc r2 = ar.pfs, 3, 0, 0, 0
  33. mov ret0 = r0
  34. cmp.eq p6, p0 = r0, r0 /* set p6 */
  35. cmp.eq p7, p0 = n, r0 /* return immediately if n == 0 */
  36. (p7) br.cond.spnt .restore_and_exit ;;
  37. .loop:
  38. ld1 val1 = [s1], 1
  39. ld1 val2 = [s2], 1
  40. adds n = -1, n /* n-- */
  41. ;;
  42. cmp.ne.and p6, p0 = val1, r0
  43. cmp.ne.and p6, p0 = val2, r0
  44. cmp.ne.and p6, p0 = n, r0
  45. cmp.eq.and p6, p0 = val1, val2
  46. (p6) br.cond.sptk .loop
  47. sub ret0 = val1, val2
  48. .restore_and_exit:
  49. br.ret.sptk.many b0
  50. END(strncmp)
  51. libc_hidden_weak (strncmp)