strings.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by Florian Klaempfl, member of the
  4. Free Pascal development team
  5. Processor dependent part of strings.pp, that can be shared with
  6. sysutils unit.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program 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.
  12. **********************************************************************}
  13. {$ASMMODE GAS}
  14. {$ifndef FPC_UNIT_HAS_STRCOMP}
  15. {$define FPC_UNIT_HAS_STRCOMP}
  16. function StrComp(Str1, Str2: PChar): SizeInt;assembler;nostackframe;
  17. asm
  18. {$ifndef win64}
  19. movq %rsi,%rdx
  20. movq %rdi,%rcx
  21. {$endif win64}
  22. subq %rcx,%rdx
  23. .balign 16
  24. .Lloop: { unrolled 4 times }
  25. movb (%rcx),%al
  26. cmpb (%rdx,%rcx),%al
  27. jne .Ldiff
  28. testb %al,%al
  29. jz .Leq
  30. movb 1(%rcx),%al
  31. cmpb 1(%rdx,%rcx),%al
  32. jne .Ldiff
  33. testb %al,%al
  34. jz .Leq
  35. movb 2(%rcx),%al
  36. cmpb 2(%rdx,%rcx),%al
  37. jne .Ldiff
  38. testb %al,%al
  39. jz .Leq
  40. movb 3(%rcx),%al
  41. add $4,%rcx
  42. cmpb -1(%rdx,%rcx),%al
  43. jne .Ldiff
  44. testb %al,%al
  45. jnz .Lloop
  46. .Leq:
  47. xorq %rax,%rax
  48. jmp .Lexit
  49. .Ldiff:
  50. sbbq %rax,%rax { -1 if CF was set, 0 otherwise }
  51. orb $1,%al { 0 becomes 1, -1 remains unchanged }
  52. .Lexit:
  53. end;
  54. {$endif FPC_UNIT_HAS_STRCOMP}