stringss.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Jonas Maebe, member of the
  5. Free Pascal development team
  6. Processor dependent part of strings.pp, not shared with
  7. sysutils unit.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. function strpas(p : pchar) : string; assembler;
  15. asm
  16. { load the begin of the string in the data cache }
  17. dcbt r0,r3
  18. { load result address in r9 }
  19. li r29,__RESULT@l
  20. addis r29,__RESULT@ha
  21. { maxlength }
  22. li r30,255
  23. mtctr r30
  24. lwz r29,0(r29)
  25. { save address for at the end }
  26. mr r3,r29
  27. { no "subi r29,r29,1" because the first byte = length byte }
  28. subi r4,r4,1
  29. LStrPasLoop:
  30. lbzu r30,1(r4)
  31. cmpli r30,0
  32. stbu r30,1(r29)
  33. bdnzf cr0*4+eq, LStrPasLoop
  34. { get remaining count for length }
  35. mfctr r30
  36. { if we stopped because of a terminating #0, decrease the length by 1 }
  37. mfcr r4
  38. subfic r30,r30,255
  39. { put "equal" condition bit of cr0 in bit position 31 (= rightmost) }
  40. { and clear other bits }
  41. rlwinm r4,r4,cr0*4+eq+1,31,31
  42. sub r30,r30,r4
  43. { store length }
  44. stb r30,0(r3)
  45. end ['r3','r4','r29','r30','cr0','ctr'];
  46. function strpcopy(d : pchar;const s : string) : pchar;assembler;
  47. asm
  48. { get length }
  49. lbz r30,0(r4)
  50. { put in counter }
  51. cmpli r30,0
  52. mtctr r30
  53. subi r29,r3,1
  54. beq LStrPCopyEmpty
  55. LStrPCopyLoop:
  56. { copy everything }
  57. lbzu r30,1(r4)
  58. stbu r30,1(r29)
  59. bdnz LStrPCopyLoop
  60. { add terminating #0 }
  61. li r30,0
  62. LStrPCopyEmpty:
  63. stb r30,1(r29)
  64. end ['r4','r29','r30','cr0','ctr'];
  65. {
  66. $Log$
  67. Revision 1.3 2001-07-07 12:46:12 jonas
  68. * some small bugfixes and cache optimizations
  69. Revision 1.2 2001/02/11 12:15:03 jonas
  70. * some small optimizations and bugfixes
  71. Revision 1.1 2001/02/10 16:10:32 jonas
  72. * initial implementation: everything implemented, nothing tested
  73. }