strpas.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Processor specific implementation of strpas
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. r3: result address
  14. r4: src
  15. }
  16. asm
  17. { nil? }
  18. cmplwi r4, 0
  19. { load the begin of the string in the data cache }
  20. dcbt 0,r4
  21. { maxlength }
  22. li r10,255
  23. mtctr r10
  24. { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
  25. { = 255 - 255 - 0 if the soure = nil -> perfect :) }
  26. beq LStrPasDone
  27. { save address for at the end and use r5 in loop }
  28. mr r5,r3
  29. { no "subi r5,r5,1" because the first byte = length byte }
  30. subi r4,r4,1
  31. LStrPasLoop:
  32. lbzu r10,1(r4)
  33. cmplwi cr0,r10,0
  34. stbu r10,1(r5)
  35. bdnzf cr0*4+eq, LStrPasLoop
  36. { if we stopped because of a terminating #0, decrease the length by 1 }
  37. cntlzw r4,r10
  38. { get remaining count for length }
  39. mfctr r10
  40. { if r10 was zero (-> stopped because of zero byte), then r4 will be 32 }
  41. { (32 leading zero bits) -> shr 5 = 1, otherwise this will be zero }
  42. srwi r4,r4,5
  43. LStrPasDone:
  44. subfic r10,r10,255
  45. sub r10,r10,r4
  46. { store length }
  47. stb r10,0(r3)
  48. end ['R0','R3','R4','R10','R11','CR0','CTR'];
  49. {
  50. $Log$
  51. Revision 1.9 2003-04-27 16:25:08 jonas
  52. * support nil as parameter and some other fixes
  53. Revision 1.8 2002/10/17 10:14:46 jonas
  54. * fixed srwi's after cntlzw instructions (should be 5 instead of 31)
  55. Revision 1.7 2002/09/11 07:49:40 jonas
  56. * fixed assembler errors
  57. Revision 1.6 2002/09/07 16:01:26 peter
  58. * old logs removed and tabs fixed
  59. Revision 1.5 2002/08/18 22:11:10 florian
  60. * fixed remaining assembler errors
  61. Revision 1.4 2002/08/18 21:37:48 florian
  62. * several errors in inline assembler fixed
  63. Revision 1.3 2002/08/10 17:14:36 jonas
  64. * various fixes, mostly changing the names of the modifies registers to
  65. upper case since that seems to be required by the compiler
  66. }