2
0

powerpc.inc 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000-2006 by the Free Pascal development team.
  4. Portions Copyright (c) 2000 by Casey Duncan ([email protected])
  5. Processor dependent implementation for the system unit for
  6. PowerPC
  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. {$IFNDEF LINUX}
  14. {$IFNDEF MORPHOS}
  15. {$IFNDEF AMIGAOS4}
  16. {$IFNDEF AIX}
  17. {$DEFINE USE_DCBZ}
  18. {$ENDIF AIX}
  19. {$ENDIF AMIGAOS4}
  20. {$ENDIF MORPHOS}
  21. {$ENDIF LINUX}
  22. {****************************************************************************
  23. PowerPC specific stuff
  24. ****************************************************************************}
  25. {$i ../ppcgen/ppcfpuex.inc}
  26. {$ifndef FPUNONE}
  27. { This function is never called directly, it's a dummy to hold the register save/
  28. load subroutines
  29. }
  30. {$ifndef MACOS}
  31. label
  32. _restfpr_14_x,
  33. _restfpr_15_x,
  34. _restfpr_16_x,
  35. _restfpr_17_x,
  36. _restfpr_18_x,
  37. _restfpr_19_x,
  38. _restfpr_20_x,
  39. _restfpr_21_x,
  40. _restfpr_22_x,
  41. _restfpr_23_x,
  42. _restfpr_24_x,
  43. _restfpr_25_x,
  44. _restfpr_26_x,
  45. _restfpr_27_x,
  46. _restfpr_28_x,
  47. _restfpr_29_x,
  48. _restfpr_30_x,
  49. _restfpr_31_x,
  50. _restfpr_14_l,
  51. _restfpr_15_l,
  52. _restfpr_16_l,
  53. _restfpr_17_l,
  54. _restfpr_18_l,
  55. _restfpr_19_l,
  56. _restfpr_20_l,
  57. _restfpr_21_l,
  58. _restfpr_22_l,
  59. _restfpr_23_l,
  60. _restfpr_24_l,
  61. _restfpr_25_l,
  62. _restfpr_26_l,
  63. _restfpr_27_l,
  64. _restfpr_28_l,
  65. _restfpr_29_l,
  66. _restfpr_30_l,
  67. _restfpr_31_l;
  68. procedure saverestorereg;assembler; nostackframe;
  69. asm
  70. { exit }
  71. .globl _restfpr_14_x
  72. _restfpr_14_x: lfd f14, -144(r11)
  73. .globl _restfpr_15_x
  74. _restfpr_15_x: lfd f15, -136(r11)
  75. .globl _restfpr_16_x
  76. _restfpr_16_x: lfd f16, -128(r11)
  77. .globl _restfpr_17_x
  78. _restfpr_17_x: lfd f17, -120(r11)
  79. .globl _restfpr_18_x
  80. _restfpr_18_x: lfd f18, -112(r11)
  81. .globl _restfpr_19_x
  82. _restfpr_19_x: lfd f19, -104(r11)
  83. .globl _restfpr_20_x
  84. _restfpr_20_x: lfd f20, -96(r11)
  85. .globl _restfpr_21_x
  86. _restfpr_21_x: lfd f21, -88(r11)
  87. .globl _restfpr_22_x
  88. _restfpr_22_x: lfd f22, -80(r11)
  89. .globl _restfpr_23_x
  90. _restfpr_23_x: lfd f23, -72(r11)
  91. .globl _restfpr_24_x
  92. _restfpr_24_x: lfd f24, -64(r11)
  93. .globl _restfpr_25_x
  94. _restfpr_25_x: lfd f25, -56(r11)
  95. .globl _restfpr_26_x
  96. _restfpr_26_x: lfd f26, -48(r11)
  97. .globl _restfpr_27_x
  98. _restfpr_27_x: lfd f27, -40(r11)
  99. .globl _restfpr_28_x
  100. _restfpr_28_x: lfd f28, -32(r11)
  101. .globl _restfpr_29_x
  102. _restfpr_29_x: lfd f29, -24(r11)
  103. .globl _restfpr_30_x
  104. _restfpr_30_x: lfd f30, -16(r11)
  105. .globl _restfpr_31_x
  106. _restfpr_31_x: lwz r0, 4(r11)
  107. lfd f31, -8(r11)
  108. mtlr r0
  109. ori r1, r11, 0
  110. blr
  111. { exit with restoring lr }
  112. .globl _restfpr_14_l
  113. _restfpr_14_l: lfd f14, -144(r11)
  114. .globl _restfpr_15_l
  115. _restfpr_15_l: lfd f15, -136(r11)
  116. .globl _restfpr_16_l
  117. _restfpr_16_l: lfd f16, -128(r11)
  118. .globl _restfpr_17_l
  119. _restfpr_17_l: lfd f17, -120(r11)
  120. .globl _restfpr_18_l
  121. _restfpr_18_l: lfd f18, -112(r11)
  122. .globl _restfpr_19_l
  123. _restfpr_19_l: lfd f19, -104(r11)
  124. .globl _restfpr_20_l
  125. _restfpr_20_l: lfd f20, -96(r11)
  126. .globl _restfpr_21_l
  127. _restfpr_21_l: lfd f21, -88(r11)
  128. .globl _restfpr_22_l
  129. _restfpr_22_l: lfd f22, -80(r11)
  130. .globl _restfpr_23_l
  131. _restfpr_23_l: lfd f23, -72(r11)
  132. .globl _restfpr_24_l
  133. _restfpr_24_l: lfd f24, -64(r11)
  134. .globl _restfpr_25_l
  135. _restfpr_25_l: lfd f25, -56(r11)
  136. .globl _restfpr_26_l
  137. _restfpr_26_l: lfd f26, -48(r11)
  138. .globl _restfpr_27_l
  139. _restfpr_27_l: lfd f27, -40(r11)
  140. .globl _restfpr_28_l
  141. _restfpr_28_l: lfd f28, -32(r11)
  142. .globl _restfpr_29_l
  143. _restfpr_29_l: lfd f29, -24(r11)
  144. .globl _restfpr_30_l
  145. _restfpr_30_l: lfd f30, -16(r11)
  146. .globl _restfpr_31_l
  147. _restfpr_31_l: lwz r0, 4(r11)
  148. lfd f31, -8(r11)
  149. mtlr r0
  150. ori r1, r11, 0
  151. blr
  152. end;
  153. {$endif MACOS}
  154. {$endif NOT FPUNONE}
  155. {****************************************************************************
  156. Move / Fill
  157. ****************************************************************************}
  158. {$ifndef FPC_SYSTEM_HAS_MOVE}
  159. {$define FPC_SYSTEM_HAS_MOVE}
  160. procedure Move(const source;var dest;count:longint);[public, alias: 'FPC_MOVE'];assembler; nostackframe;
  161. asm
  162. { count <= 0 ? }
  163. cmpwi cr0,r5,0
  164. { check if we have to do the move backwards because of overlap }
  165. sub r10,r4,r3
  166. { carry := boolean(dest-source < count) = boolean(overlap) }
  167. subc r10,r10,r5
  168. { count < 15 ? (to decide whether we will move dwords or bytes }
  169. cmpwi cr1,r5,15
  170. { if overlap, then r10 := -1 else r10 := 0 }
  171. subfe r10,r10,r10
  172. { count < 63 ? (32 + max. alignment (31) }
  173. { change to 64, because for overlap, we do not re-increment r5,
  174. which could then lead to a counter being zero at start and thus
  175. running forever }
  176. cmpwi cr7,r5,64
  177. { if count <= 0, stop }
  178. ble cr0,.LMoveDone
  179. { load the begin of the source in the data cache }
  180. dcbt 0,r3
  181. { and the dest as well }
  182. dcbtst 0,r4
  183. { if overlap, then r0 := count else r0 := 0 }
  184. and r0,r5,r10
  185. { if overlap, then point source and dest to the end }
  186. add r3,r3,r0
  187. add r4,r4,r0
  188. { if overlap, then r6 := 0, else r6 := -1 }
  189. not r6,r10
  190. { if overlap, then r10 := -2, else r10 := 0 }
  191. slwi r10,r10,1
  192. { if overlap, then r10 := -1, else r10 := 1 }
  193. addi r10,r10,1
  194. { if count < 15, copy everything byte by byte }
  195. blt cr1,.LMoveBytes
  196. { if no overlap, then source/dest += -1, otherwise they stay }
  197. { After the next instruction, r3/r4 + r10 = next position to }
  198. { load/store from/to }
  199. add r3,r3,r6
  200. add r4,r4,r6
  201. { otherwise, guarantee 4 byte alignment for dest for starters }
  202. .LMove4ByteAlignLoop:
  203. lbzux r0,r3,r10
  204. stbux r0,r4,r10
  205. { is dest now 4 aligned? }
  206. andi. r0,r4,3
  207. subi r5,r5,1
  208. { while not aligned, continue }
  209. bne cr0,.LMove4ByteAlignLoop
  210. {$ifndef ppc603}
  211. { check for 32 byte alignment }
  212. andi. r7,r4,31
  213. {$endif non ppc603}
  214. { we are going to copy one byte again (the one at the newly }
  215. { aligned address), so increase count byte 1 }
  216. { This is only true if there is no overlap, thus }
  217. { use r5:=r5-r6; which does what is needed. }
  218. sub r5,r5,r6
  219. { count div 4 for number of dwords to copy }
  220. srwi r0,r5,2
  221. { if 11 <= count < 63, copy using dwords }
  222. blt cr7,.LMoveDWords
  223. {$ifndef ppc603}
  224. { # of dwords to copy to reach 32 byte alignment (*4) }
  225. { (depends on forward/backward copy) }
  226. { if forward copy, r6 = -1 -> r8 := 32 }
  227. { if backward copy, r6 = 0 -> r8 := 0 }
  228. rlwinm r8,r6,0,31-6+1,31-6+1
  229. { if forward copy, we have to copy 32 - unaligned count bytes }
  230. { if backward copy unaligned count bytes }
  231. sub r7,r8,r7
  232. { if backward copy, the calculated value is now negate -> }
  233. { make it positive again }
  234. not r8, r6
  235. add r7, r7, r8
  236. xor r7, r7, r8
  237. {$endif not ppc603}
  238. { multiply the update count with 4 }
  239. slwi r10,r10,2
  240. slwi r6,r6,2
  241. { and adapt the source and dest }
  242. add r3,r3,r6
  243. add r4,r4,r6
  244. {$ifndef ppc603}
  245. beq cr0,.LMove32BytesAligned
  246. .L32BytesAlignMoveLoop:
  247. { count >= 39 -> align to 8 byte boundary and then use the FPU }
  248. { since we're already at 4 byte alignment, use dword store }
  249. subic. r7,r7,4
  250. lwzux r0,r3,r10
  251. subi r5,r5,4
  252. stwux r0,r4,r10
  253. bne .L32BytesAlignMoveLoop
  254. .LMove32BytesAligned:
  255. { count div 32 ( >= 1, since count was >=63 }
  256. srwi r0,r5,5
  257. { remainder }
  258. andi. r5,r5,31
  259. { to decide if we will do some dword stores (instead of only }
  260. { byte stores) afterwards or not }
  261. {$else not ppc603}
  262. srwi r0,r5,4
  263. andi. r5,r5,15
  264. {$endif not ppc603}
  265. cmpwi cr1,r5,11
  266. mtctr r0
  267. { r0 := count div 4, will be moved to ctr when copying dwords }
  268. srwi r0,r5,2
  269. {$if not defined(ppc603) and not defined(FPUNONE)}
  270. { adjust the update count: it will now be 8 or -8 depending on overlap }
  271. slwi r10,r10,1
  272. { adjust source and dest pointers: because of the above loop, dest is now }
  273. { aligned to 8 bytes. So if we add r6 we will still have an 8 bytes }
  274. { aligned address) }
  275. add r3,r3,r6
  276. add r4,r4,r6
  277. slwi r6,r6,1
  278. {$IFDEF USE_DCBZ}
  279. { the dcbz offset must give a 32 byte aligned address when added }
  280. { to the current dest address and its address must point to the }
  281. { bytes that will be overwritten in the current iteration. In case }
  282. { of a forward loop, the dest address has currently an offset of }
  283. { -8 compared to the bytes that will be overwritten (and r6 = -8). }
  284. { In case of a backward of a loop, the dest address currently has }
  285. { an offset of +32 compared to the bytes that will be overwritten }
  286. { (and r6 = 0). So the forward dcbz offset must become +8 and the }
  287. { backward -32 -> (-r6 * 5) - 32 gives the correct offset }
  288. slwi r7,r6,2
  289. add r7,r7,r6
  290. neg r7,r7
  291. subi r7,r7,32
  292. {$ENDIF USE_DCBZ}
  293. .LMove32ByteDcbz:
  294. lfdux f0,r3,r10
  295. lfdux f1,r3,r10
  296. lfdux f2,r3,r10
  297. lfdux f3,r3,r10
  298. {$IFDEF USE_DCBZ}
  299. { must be done only now, in case source and dest are less than }
  300. { 32 bytes apart! }
  301. dcbz r4,r7
  302. {$ENDIF USE_DCBZ}
  303. stfdux f0,r4,r10
  304. stfdux f1,r4,r10
  305. stfdux f2,r4,r10
  306. stfdux f3,r4,r10
  307. bdnz .LMove32ByteDcbz
  308. .LMove32ByteLoopDone:
  309. {$else not ppc603}
  310. .LMove16ByteLoop:
  311. lwzux r11,r3,r10
  312. lwzux r7,r3,r10
  313. lwzux r8,r3,r10
  314. lwzux r9,r3,r10
  315. stwux r11,r4,r10
  316. stwux r7,r4,r10
  317. stwux r8,r4,r10
  318. stwux r9,r4,r10
  319. bdnz .LMove16ByteLoop
  320. {$endif not ppc603}
  321. { cr0*4+eq is true if "count and 31" = 0 }
  322. beq cr0,.LMoveDone
  323. { make r10 again -1 or 1, but first adjust source/dest pointers }
  324. sub r3,r3,r6
  325. sub r4,r4,r6
  326. {$ifndef ppc603}
  327. srawi r10,r10,3
  328. srawi r6,r6,3
  329. {$else not ppc603}
  330. srawi r10,r10,2
  331. srawi r6,r6,2
  332. {$endif not ppc603}
  333. { cr1 contains whether count <= 11 }
  334. ble cr1,.LMoveBytes
  335. .LMoveDWords:
  336. mtctr r0
  337. andi. r5,r5,3
  338. { r10 * 4 }
  339. slwi r10,r10,2
  340. slwi r6,r6,2
  341. add r3,r3,r6
  342. add r4,r4,r6
  343. .LMoveDWordsLoop:
  344. lwzux r0,r3,r10
  345. stwux r0,r4,r10
  346. bdnz .LMoveDWordsLoop
  347. beq cr0,.LMoveDone
  348. { make r10 again -1 or 1 }
  349. sub r3,r3,r6
  350. sub r4,r4,r6
  351. srawi r10,r10,2
  352. srawi r6,r6,2
  353. .LMoveBytes:
  354. add r3,r3,r6
  355. add r4,r4,r6
  356. mtctr r5
  357. .LMoveBytesLoop:
  358. lbzux r0,r3,r10
  359. stbux r0,r4,r10
  360. bdnz .LMoveBytesLoop
  361. .LMoveDone:
  362. end;
  363. {$endif FPC_SYSTEM_HAS_MOVE}
  364. {$ifndef FPC_SYSTEM_HAS_FILLCHAR}
  365. {$define FPC_SYSTEM_HAS_FILLCHAR}
  366. Procedure FillChar(var x;count:longint;value:byte);assembler;
  367. { input: x in r3, count in r4, value in r5 }
  368. {$ifndef FPC_ABI_AIX}
  369. { in the AIX ABI, we can use te red zone for temp storage, otherwise we have }
  370. { to explicitely allocate room }
  371. var
  372. temp : packed record
  373. case byte of
  374. 0: (l1,l2: longint);
  375. {$ifndef FPUNONE}
  376. 1: (d: double);
  377. {$endif}
  378. end;
  379. {$endif FPC_ABI_AIX}
  380. asm
  381. { no bytes? }
  382. cmpwi cr6,r4,0
  383. { less than 15 bytes? }
  384. cmpwi cr7,r4,15
  385. { less than 64 bytes? }
  386. cmpwi cr1,r4,64
  387. { fill r5 with ValueValueValueValue }
  388. rlwimi r5,r5,8,16,23
  389. { setup for aligning x to multiple of 4}
  390. rlwinm r10,r3,0,31-2+1,31
  391. rlwimi r5,r5,16,0,15
  392. ble cr6,.LFillCharDone
  393. { get the start of the data in the cache (and mark it as "will be }
  394. { modified") }
  395. dcbtst 0,r3
  396. subfic r10,r10,4
  397. blt cr7,.LFillCharVerySmall
  398. { just store 4 bytes instead of using a loop to align (there are }
  399. { plenty of other instructions now to keep the processor busy }
  400. { while it handles the (possibly unaligned) store) }
  401. stw r5,0(r3)
  402. { r3 := align(r3,4) }
  403. add r3,r3,r10
  404. { decrease count with number of bytes already stored }
  405. sub r4,r4,r10
  406. {$IFNDEF FPUNONE}
  407. blt cr1,.LFillCharSmall
  408. {$IFDEF USE_DCBZ}
  409. { if we have to fill with 0 (which happens a lot), we can simply use }
  410. { dcbz for the most part, which is very fast, so make a special case }
  411. { for that }
  412. cmplwi cr1,r5,0
  413. {$ENDIF}
  414. { align to a multiple of 32 (and immediately check whether we aren't }
  415. { already 32 byte aligned) }
  416. rlwinm. r10,r3,0,31-5+1,31
  417. { setup r3 for using update forms of store instructions }
  418. subi r3,r3,4
  419. { get number of bytes to store }
  420. subfic r10,r10,32
  421. { if already 32byte aligned, skip align loop }
  422. beq .L32ByteAlignLoopDone
  423. { substract from the total count }
  424. sub r4,r4,r10
  425. .L32ByteAlignLoop:
  426. { we were already aligned to 4 byres, so this will count down to }
  427. { exactly 0 }
  428. subic. r10,r10,4
  429. stwu r5,4(r3)
  430. bne .L32ByteAlignLoop
  431. .L32ByteAlignLoopDone:
  432. { get the amount of 32 byte blocks }
  433. srwi r10,r4,5
  434. { and keep the rest in r4 (recording whether there is any rest) }
  435. rlwinm. r4,r4,0,31-5+1,31
  436. { move to ctr }
  437. mtctr r10
  438. { check how many rest there is (to decide whether we'll use }
  439. { FillCharSmall or FillCharVerySmall) }
  440. cmplwi cr7,r4,11
  441. {$IFDEF USE_DCBZ}
  442. { if filling with zero, only use dcbz }
  443. bne cr1, .LFillCharNoZero
  444. { make r3 point again to the actual store position }
  445. addi r3,r3,4
  446. .LFillCharDCBZLoop:
  447. dcbz 0,r3
  448. addi r3,r3,32
  449. bdnz .LFillCharDCBZLoop
  450. { if there was no rest, we're finished }
  451. beq .LFillCharDone
  452. b .LFillCharVerySmall
  453. {$ENDIF USE_DCBZ}
  454. .LFillCharNoZero:
  455. {$ifdef FPC_ABI_AIX}
  456. stw r5,-4(r1)
  457. stw r5,-8(r1)
  458. lfd f0,-8(r1)
  459. {$else FPC_ABI_AIX}
  460. stw r5,temp
  461. stw r5,temp+4
  462. lfd f0,temp
  463. {$endif FPC_ABI_AIX}
  464. { make r3 point to address-8, so we're able to use fp double stores }
  465. { with update (it's already -4 now) }
  466. subi r3,r3,4
  467. {$IFDEF USE_DCBZ}
  468. { load r10 with 8, so that dcbz uses the correct address }
  469. li r10, 8
  470. {$ENDIF}
  471. .LFillChar32ByteLoop:
  472. {$IFDEF USE_DCBZ}
  473. dcbz r3,r10
  474. {$ENDIF USE_DCBZ}
  475. stfdu f0,8(r3)
  476. stfdu f0,8(r3)
  477. stfdu f0,8(r3)
  478. stfdu f0,8(r3)
  479. bdnz .LFillChar32ByteLoop
  480. { if there was no rest, we're finished }
  481. beq .LFillCharDone
  482. { make r3 point again to the actual next byte that must be written }
  483. addi r3,r3,8
  484. b .LFillCharVerySmall
  485. .LFillCharSmall:
  486. {$ENDIF FPUNONE}
  487. { when we arrive here, we're already 4 byte aligned }
  488. { get count div 4 to store dwords }
  489. srwi r10,r4,2
  490. { get ready for use of update stores }
  491. subi r3,r3,4
  492. mtctr r10
  493. rlwinm. r4,r4,0,31-2+1,31
  494. .LFillCharSmallLoop:
  495. stwu r5,4(r3)
  496. bdnz .LFillCharSmallLoop
  497. { if nothing left, stop }
  498. beq .LFillCharDone
  499. { get ready to store bytes }
  500. addi r3,r3,4
  501. .LFillCharVerySmall:
  502. mtctr r4
  503. subi r3,r3,1
  504. .LFillCharVerySmallLoop:
  505. stbu r5,1(r3)
  506. bdnz .LFillCharVerySmallLoop
  507. .LFillCharDone:
  508. end;
  509. {$endif FPC_SYSTEM_HAS_FILLCHAR}
  510. {$ifndef FPC_SYSTEM_HAS_FILLDWORD}
  511. {$define FPC_SYSTEM_HAS_FILLDWORD}
  512. procedure filldword(var x;count : longint;value : dword);
  513. assembler; nostackframe;
  514. asm
  515. { registers:
  516. r3 x
  517. r4 count
  518. r5 value
  519. }
  520. cmpwi cr0,r4,0
  521. mtctr r4
  522. subi r3,r3,4
  523. ble .LFillDWordEnd //if count<=0 Then Exit
  524. .LFillDWordLoop:
  525. stwu r5,4(r3)
  526. bdnz .LFillDWordLoop
  527. .LFillDWordEnd:
  528. end;
  529. {$endif FPC_SYSTEM_HAS_FILLDWORD}
  530. {$ifndef FPC_SYSTEM_HAS_INDEXBYTE}
  531. {$define FPC_SYSTEM_HAS_INDEXBYTE}
  532. function IndexByte(const buf;len:longint;b:byte):longint; assembler; nostackframe;
  533. { input: r3 = buf, r4 = len, r5 = b }
  534. { output: r3 = position of b in buf (-1 if not found) }
  535. asm
  536. { load the begin of the buffer in the data cache }
  537. dcbt 0,r3
  538. cmplwi r4,0
  539. mtctr r4
  540. subi r10,r3,1
  541. mr r0,r3
  542. { assume not found }
  543. li r3,-1
  544. ble .LIndexByteDone
  545. .LIndexByteLoop:
  546. lbzu r9,1(r10)
  547. cmplw r9,r5
  548. bdnzf cr0*4+eq,.LIndexByteLoop
  549. { r3 still contains -1 here }
  550. bne .LIndexByteDone
  551. sub r3,r10,r0
  552. .LIndexByteDone:
  553. end;
  554. {$endif FPC_SYSTEM_HAS_INDEXBYTE}
  555. {$ifndef FPC_SYSTEM_HAS_INDEXWORD}
  556. {$define FPC_SYSTEM_HAS_INDEXWORD}
  557. function IndexWord(const buf;len:longint;b:word):longint; assembler; nostackframe;
  558. { input: r3 = buf, r4 = len, r5 = b }
  559. { output: r3 = position of b in buf (-1 if not found) }
  560. asm
  561. { load the begin of the buffer in the data cache }
  562. dcbt 0,r3
  563. cmplwi r4,0
  564. mtctr r4
  565. subi r10,r3,2
  566. mr r0,r3
  567. { assume not found }
  568. li r3,-1
  569. ble .LIndexWordDone
  570. .LIndexWordLoop:
  571. lhzu r9,2(r10)
  572. cmplw r9,r5
  573. bdnzf cr0*4+eq,.LIndexWordLoop
  574. { r3 still contains -1 here }
  575. bne .LIndexWordDone
  576. sub r3,r10,r0
  577. srawi r3,r3,1
  578. .LIndexWordDone:
  579. end;
  580. {$endif FPC_SYSTEM_HAS_INDEXWORD}
  581. {$ifndef FPC_SYSTEM_HAS_INDEXDWORD}
  582. {$define FPC_SYSTEM_HAS_INDEXDWORD}
  583. function IndexDWord(const buf;len:longint;b:DWord):longint; assembler; nostackframe;
  584. { input: r3 = buf, r4 = len, r5 = b }
  585. { output: r3 = position of b in buf (-1 if not found) }
  586. asm
  587. { load the begin of the buffer in the data cache }
  588. dcbt 0,r3
  589. cmplwi r4,0
  590. mtctr r4
  591. subi r10,r3,4
  592. mr r0,r3
  593. { assume not found }
  594. li r3,-1
  595. ble .LIndexDWordDone
  596. .LIndexDWordLoop:
  597. lwzu r9,4(r10)
  598. cmplw r9,r5
  599. bdnzf cr0*4+eq, .LIndexDWordLoop
  600. { r3 still contains -1 here }
  601. bne .LIndexDWordDone
  602. sub r3,r10,r0
  603. srawi r3,r3,2
  604. .LIndexDWordDone:
  605. end;
  606. {$endif FPC_SYSTEM_HAS_INDEXDWORD}
  607. {$ifndef FPC_SYSTEM_HAS_COMPAREBYTE}
  608. {$define FPC_SYSTEM_HAS_COMPAREBYTE}
  609. function CompareByte(const buf1,buf2;len:longint):longint; assembler; nostackframe;
  610. { input: r3 = buf1, r4 = buf2, r5 = len }
  611. { output: r3 = 0 if equal, < 0 if buf1 < str2, > 0 if buf1 > str2 }
  612. { note: almost direct copy of strlcomp() from strings.inc }
  613. asm
  614. { load the begin of the first buffer in the data cache }
  615. dcbt 0,r3
  616. { use r0 instead of r3 for buf1 since r3 contains result }
  617. cmplwi r5,0
  618. mtctr r5
  619. subi r11,r3,1
  620. subi r4,r4,1
  621. li r3,0
  622. ble .LCompByteDone
  623. .LCompByteLoop:
  624. { load next chars }
  625. lbzu r9,1(r11)
  626. lbzu r10,1(r4)
  627. { calculate difference }
  628. sub. r3,r9,r10
  629. { if chars not equal or at the end, we're ready }
  630. bdnzt cr0*4+eq, .LCompByteLoop
  631. .LCompByteDone:
  632. end;
  633. {$endif FPC_SYSTEM_HAS_COMPAREBYTE}
  634. {$ifndef FPC_SYSTEM_HAS_COMPAREWORD}
  635. {$define FPC_SYSTEM_HAS_COMPAREWORD}
  636. function CompareWord(const buf1,buf2;len:longint):longint; assembler; nostackframe;
  637. { input: r3 = buf1, r4 = buf2, r5 = len }
  638. { output: r3 = 0 if equal, < 0 if buf1 < str2, > 0 if buf1 > str2 }
  639. { note: almost direct copy of strlcomp() from strings.inc }
  640. asm
  641. { load the begin of the first buffer in the data cache }
  642. dcbt 0,r3
  643. { use r0 instead of r3 for buf1 since r3 contains result }
  644. cmplwi r5,0
  645. mtctr r5
  646. subi r11,r3,2
  647. subi r4,r4,2
  648. li r3,0
  649. ble .LCompWordDone
  650. .LCompWordLoop:
  651. { load next chars }
  652. lhzu r9,2(r11)
  653. lhzu r10,2(r4)
  654. { calculate difference }
  655. sub. r3,r9,r10
  656. { if chars not equal or at the end, we're ready }
  657. bdnzt cr0*4+eq, .LCompWordLoop
  658. .LCompWordDone:
  659. end;
  660. {$endif FPC_SYSTEM_HAS_COMPAREWORD}
  661. {$ifndef FPC_SYSTEM_HAS_COMPAREDWORD}
  662. {$define FPC_SYSTEM_HAS_COMPAREDWORD}
  663. function CompareDWord(const buf1,buf2;len:longint):longint; assembler; nostackframe;
  664. { input: r3 = buf1, r4 = buf2, r5 = len }
  665. { output: r3 = 0 if equal, < 0 if buf1 < str2, > 0 if buf1 > str2 }
  666. { note: almost direct copy of strlcomp() from strings.inc }
  667. asm
  668. { load the begin of the first buffer in the data cache }
  669. dcbt 0,r3
  670. { use r0 instead of r3 for buf1 since r3 contains result }
  671. cmplwi r5,0
  672. mtctr r5
  673. subi r11,r3,4
  674. subi r4,r4,4
  675. li r3,0
  676. ble .LCompDWordDone
  677. .LCompDWordLoop:
  678. { load next chars }
  679. lwzu r9,4(r11)
  680. lwzu r10,4(r4)
  681. { calculate difference }
  682. sub. r0,r9,r10
  683. { if chars not equal or at the end, we're ready }
  684. bdnzt cr0*4+eq, .LCompDWordLoop
  685. .LCompDWordDone:
  686. cmplw cr1,r9,r10
  687. beq .Ldone
  688. { since these were two dwords, we have to perform an additional }
  689. { unsigned comparison and set the result accordingly }
  690. bgt cr1,.Lpos
  691. li r3,-2
  692. .Lpos:
  693. addi r3,r3,1
  694. .Ldone:
  695. end;
  696. {$endif FPC_SYSTEM_HAS_COMPAREDWORD}
  697. {$ifndef FPC_SYSTEM_HAS_INDEXCHAR0}
  698. {$define FPC_SYSTEM_HAS_INDEXCHAR0}
  699. function IndexChar0(const buf;len:longint;b:AnsiChar):longint; assembler; nostackframe;
  700. { input: r3 = buf, r4 = len, r5 = b }
  701. { output: r3 = position of found position (-1 if not found) }
  702. asm
  703. { load the begin of the buffer in the data cache }
  704. dcbt 0,r3
  705. { length = 0? }
  706. cmplwi r4,0
  707. mtctr r4
  708. subi r9,r3,1
  709. subi r0,r3,1
  710. { assume not found }
  711. li r3,-1
  712. { if yes, do nothing }
  713. ble .LIndexChar0Done
  714. .LIndexChar0Loop:
  715. lbzu r10,1(r9)
  716. cmplwi cr1,r10,0
  717. cmplw r10,r5
  718. beq cr1,.LIndexChar0Done
  719. bdnzf cr0*4+eq, .LIndexChar0Loop
  720. bne .LIndexChar0Done
  721. sub r3,r9,r0
  722. .LIndexChar0Done:
  723. end;
  724. {$endif FPC_SYSTEM_HAS_INDEXCHAR0}
  725. {****************************************************************************
  726. String
  727. ****************************************************************************}
  728. {$ifndef STR_CONCAT_PROCS}
  729. (*
  730. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  731. {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  732. function fpc_shortstr_concat(const s1, s2: shortstring): shortstring; compilerproc; [public, alias: 'FPC_SHORTSTR_CONCAT'];
  733. { expects that (r3) contains a pointer to the result r4 to s1, r5 to s2 }
  734. assembler;
  735. asm
  736. { load length s1 }
  737. lbz r6, 0(r4)
  738. { load length s2 }
  739. lbz r10, 0(r5)
  740. { length 0 for s1? }
  741. cmplwi cr7,r6,0
  742. { length 255 for s1? }
  743. subfic. r7,r6,255
  744. { length 0 for s2? }
  745. cmplwi cr1,r10,0
  746. { calculate min(length(s2),255-length(s1)) }
  747. subc r8,r7,r10 { r8 := r7 - r10 }
  748. cror 4*6+2,4*1+2,4*7+2
  749. subfe r7,r7,r7 { if r7 >= r10 then r7' := 0 else r7' := -1 }
  750. mtctr r6
  751. and r7,r8,r7 { if r7 >= r10 then r7' := 0 else r7' := r7-r10 }
  752. add r7,r7,r10 { if r7 >= r10 then r7' := r10 else r7' := r7 }
  753. mr r9,r3
  754. { calculate length of final string }
  755. add r8,r7,r6
  756. stb r8,0(r3)
  757. beq cr7, .Lcopys1loopDone
  758. .Lcopys1loop:
  759. lbzu r0,1(r4)
  760. stbu r0,1(r9)
  761. bdnz .Lcopys1loop
  762. .Lcopys1loopDone:
  763. mtctr r7
  764. beq cr6, .LconcatDone
  765. .Lcopys2loop:
  766. lbzu r0,1(r5)
  767. stbu r0,1(r9)
  768. bdnz .Lcopys2loop
  769. end;
  770. {$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_CONCAT}
  771. *)
  772. {$ifndef FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
  773. {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
  774. procedure fpc_shortstr_append_shortstr(var s1: shortstring; const s2: shortstring); compilerproc;
  775. { expects that results (r3) contains a pointer to the current string s1, r4 }
  776. { high(s1) and (r5) a pointer to the one that has to be concatenated }
  777. assembler; nostackframe;
  778. asm
  779. { load length s1 }
  780. lbz r6, 0(r3)
  781. { load length s2 }
  782. lbz r10, 0(r5)
  783. { length 0? }
  784. cmplw cr1,r6,r4
  785. cmplwi r10,0
  786. { calculate min(length(s2),high(result)-length(result)) }
  787. sub r9,r4,r6
  788. subc r8,r9,r10 { r8 := r9 - r10 }
  789. cror 4*7+2,4*0+2,4*1+2
  790. subfe r9,r9,r9 { if r9 >= r10 then r9' := 0 else r9' := -1 }
  791. and r9,r8,r9 { if r9 >= r10 then r9' := 0 else r9' := r9-r10 }
  792. add r9,r9,r10 { if r9 >= r10 then r9' := r10 else r9' := r9 }
  793. { calculate new length }
  794. add r10,r6,r9
  795. { load value to copy in ctr }
  796. mtctr r9
  797. { store new length }
  798. stb r10,0(r3)
  799. { go to last current character of result }
  800. add r3,r6,r3
  801. { if nothing to do, exit }
  802. beq cr7, .LShortStrAppendDone
  803. { and concatenate }
  804. .LShortStrAppendLoop:
  805. lbzu r10,1(r5)
  806. stbu r10,1(r3)
  807. bdnz .LShortStrAppendLoop
  808. .LShortStrAppendDone:
  809. end;
  810. {$endif FPC_SYSTEM_HAS_FPC_SHORTSTR_APPEND_SHORTSTR}
  811. {$endif STR_CONCAT_PROCS}
  812. (*
  813. {$define FPC_SYSTEM_HAS_FPC_SHORTSTR_COMPARE}
  814. function fpc_shortstr_compare(const dstr,sstr:shortstring): longint; [public,alias:'FPC_SHORTSTR_COMPARE']; compilerproc;
  815. assembler;
  816. asm
  817. { load length sstr }
  818. lbz r9,0(r4)
  819. { load length dstr }
  820. lbz r10,0(r3)
  821. { save their difference for later and }
  822. { calculate min(length(sstr),length(dstr)) }
  823. subfc r7,r10,r9 { r0 := r9 - r10 }
  824. subfe r9,r9,r9 { if r9 >= r10 then r9' := 0 else r9' := -1 }
  825. and r7,r7,r9 { if r9 >= r10 then r9' := 0 else r9' := r9-r8 }
  826. add r9,r10,r7 { if r9 >= r10 then r9' := r10 else r9' := r9 }
  827. { first compare dwords (length/4) }
  828. srwi. r5,r9,2
  829. { keep length mod 4 for the ends }
  830. rlwinm r9,r9,0,30,31
  831. { already check whether length mod 4 = 0 }
  832. cmplwi cr1,r9,0
  833. { so we can load r3 with 0, in case the strings both have length 0 }
  834. mr r8,r3
  835. li r3, 0
  836. { length div 4 in ctr for loop }
  837. mtctr r5
  838. { if length < 3, goto byte comparing }
  839. beq LShortStrCompare1
  840. { setup for use of update forms of load/store with dwords }
  841. subi r4,r4,3
  842. subi r8,r8,3
  843. LShortStrCompare4Loop:
  844. lwzu r3,4(r4)
  845. lwzu r10,4(r8)
  846. sub. r3,r3,r10
  847. bdnzt cr0+eq,LShortStrCompare4Loop
  848. { r3 contains result if we stopped because of "ne" flag }
  849. bne LShortStrCompareDone
  850. { setup for use of update forms of load/store with bytes }
  851. addi r4,r4,3
  852. addi r8,r8,3
  853. LShortStrCompare1:
  854. { if comparelen mod 4 = 0, skip this and return the difference in }
  855. { lengths }
  856. beq cr1,LShortStrCompareLen
  857. mtctr r9
  858. LShortStrCompare1Loop:
  859. lbzu r3,1(r4)
  860. lbzu r10,1(r8)
  861. sub. r3,r3,r10
  862. bdnzt cr0+eq,LShortStrCompare1Loop
  863. bne LShortStrCompareDone
  864. LShortStrCompareLen:
  865. { also return result in flags, maybe we can use this in the CG }
  866. mr. r3,r3
  867. LShortStrCompareDone:
  868. end;
  869. *)
  870. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  871. {$define FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  872. procedure fpc_pchar_to_shortstr(out res : shortstring;p:PAnsiChar);assembler;[public,alias:'FPC_PCHAR_TO_SHORTSTR']; compilerproc; nostackframe;
  873. {
  874. r3: result address
  875. r4: high(result)
  876. r5: p (source)
  877. }
  878. asm
  879. { nil? }
  880. mr r8, p
  881. cmplwi p, 0
  882. { load the begin of the string in the data cache }
  883. dcbt 0, p
  884. { maxlength }
  885. mr r10,r4
  886. mtctr r10
  887. { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
  888. bne .LStrPasStart
  889. { put zero into r10 }
  890. mr r10, r8
  891. b .LStrPasDone
  892. .LStrPasStart:
  893. { save address for at the end and use r7 in loop }
  894. mr r7,r3
  895. { no "subi r7,r7,1" because the first byte = length byte }
  896. subi r8,r8,1
  897. .LStrPasLoop:
  898. lbzu r10,1(r8)
  899. cmplwi cr0,r10,0
  900. stbu r10,1(r7)
  901. bdnzf cr0*4+eq, .LStrPasLoop
  902. { if we stopped because of a terminating #0, decrease the length by 1 }
  903. cntlzw r4,r10
  904. { get remaining count for length }
  905. mfctr r10
  906. { if r10 was zero (-> stopped because of zero byte), then r4 will be 32 }
  907. { (32 leading zero bits) -> shr 5 = 1, otherwise this will be zero }
  908. srwi r4,r4,5
  909. subfic r10,r10,255
  910. sub r10,r10,r4
  911. { store length }
  912. .LStrPasDone:
  913. stb r10,0(r3)
  914. end;
  915. {$endif FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}
  916. {$ifndef FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  917. {$define FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  918. function fpc_pchar_length(p:PAnsiChar):sizeint;assembler;[public,alias:'FPC_PCHAR_LENGTH']; compilerproc; nostackframe;
  919. {$include strlen.inc}
  920. {$endif FPC_SYSTEM_HAS_FPC_PCHAR_LENGTH}
  921. {$ifndef INTERNAL_BACKTRACE}
  922. {$define FPC_SYSTEM_HAS_GET_FRAME}
  923. function get_frame:pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif} nostackframe;
  924. asm
  925. { all abi's I know use r1 as stack pointer }
  926. mr r3, r1
  927. end;
  928. {$endif INTERNAL_BACKTRACE}
  929. {NOTE: On MACOS, 68000 code might call powerpc code, through the MixedMode manager,
  930. (even in the OS in system 9). The pointer to the switching stack frame is then
  931. indicated by the first bit set to 1. This is checked below.}
  932. {Both routines below assumes that framebp is a valid framepointer or nil.}
  933. {$define FPC_SYSTEM_HAS_GET_CALLER_ADDR}
  934. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif} nostackframe;
  935. asm
  936. cmplwi r3,0
  937. beq .Lcaller_addr_invalid
  938. lwz r3,0(r3)
  939. cmplwi r3,0
  940. beq .Lcaller_addr_invalid
  941. {$ifdef MACOS}
  942. rlwinm r4,r3,0,31,31
  943. cmpwi r4,0
  944. bne cr0,.Lcaller_addr_invalid
  945. {$endif MACOS}
  946. {$ifdef FPC_ABI_AIX}
  947. lwz r3,8(r3)
  948. {$else FPC_ABI_AIX}
  949. lwz r3,4(r3)
  950. {$endif FPC_ABI_AIX}
  951. blr
  952. .Lcaller_addr_invalid:
  953. li r3,0
  954. end;
  955. {$define FPC_SYSTEM_HAS_GET_CALLER_FRAME}
  956. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif} nostackframe;
  957. asm
  958. cmplwi r3,0
  959. beq .Lcaller_frame_invalid
  960. lwz r3,0(r3)
  961. {$ifdef MACOS}
  962. rlwinm r4,r3,0,31,31
  963. cmpwi r4,0
  964. bne cr0,.Lcaller_frame_invalid
  965. {$endif MACOS}
  966. blr
  967. .Lcaller_frame_invalid:
  968. li r3,0
  969. end;
  970. {$define FPC_SYSTEM_HAS_SPTR}
  971. Function Sptr : Pointer;assembler;{$ifdef SYSTEMINLINE}inline;{$endif} nostackframe;
  972. asm
  973. mr r3,r1
  974. end;
  975. {****************************************************************************
  976. Str()
  977. ****************************************************************************}
  978. { int_str: generic implementation is used for now }
  979. {****************************************************************************
  980. Multithreading
  981. ****************************************************************************}
  982. { do a thread save inc/dec }
  983. {$define FPC_SYSTEM_HAS_DECLOCKED_LONGINT}
  984. function declocked(var l : longint) : boolean;assembler;nostackframe;
  985. { input: address of l in r3 }
  986. { output: boolean indicating whether l is zero after decrementing }
  987. asm
  988. .LDecLockedLoop:
  989. lwarx r10,0,r3
  990. subi r10,r10,1
  991. stwcx. r10,0,r3
  992. bne- .LDecLockedLoop
  993. cntlzw r3,r10
  994. srwi r3,r3,5
  995. end;
  996. {$define FPC_SYSTEM_HAS_INCLOCKED_LONGINT}
  997. procedure inclocked(var l : longint);assembler;nostackframe;
  998. asm
  999. .LIncLockedLoop:
  1000. lwarx r10,0,r3
  1001. addi r10,r10,1
  1002. stwcx. r10,0,r3
  1003. bne- .LIncLockedLoop
  1004. end;
  1005. function InterLockedDecrement (var Target: longint) : longint; assembler; nostackframe;
  1006. { input: address of target in r3 }
  1007. { output: target-1 in r3 }
  1008. { side-effect: target := target-1 }
  1009. asm
  1010. .LInterLockedDecLoop:
  1011. lwarx r10,0,r3
  1012. subi r10,r10,1
  1013. stwcx. r10,0,r3
  1014. bne .LInterLockedDecLoop
  1015. mr r3,r10
  1016. end;
  1017. function InterLockedIncrement (var Target: longint) : longint; assembler; nostackframe;
  1018. { input: address of target in r3 }
  1019. { output: target+1 in r3 }
  1020. { side-effect: target := target+1 }
  1021. asm
  1022. .LInterLockedIncLoop:
  1023. lwarx r10,0,r3
  1024. addi r10,r10,1
  1025. stwcx. r10,0,r3
  1026. bne .LInterLockedIncLoop
  1027. mr r3,r10
  1028. end;
  1029. function InterLockedExchange (var Target: longint;Source : longint) : longint; assembler; nostackframe;
  1030. { input: address of target in r3, source in r4 }
  1031. { output: target in r3 }
  1032. { side-effect: target := source }
  1033. asm
  1034. .LInterLockedXchgLoop:
  1035. lwarx r10,0,r3
  1036. stwcx. r4,0,r3
  1037. bne .LInterLockedXchgLoop
  1038. mr r3,r10
  1039. end;
  1040. function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; assembler; nostackframe;
  1041. asm
  1042. .LInterLockedXchgAddLoop:
  1043. lwarx r10,0,r3
  1044. add r10,r10,r4
  1045. stwcx. r10,0,r3
  1046. bne .LInterLockedXchgAddLoop
  1047. sub r3,r10,r4
  1048. end;
  1049. function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; assembler; nostackframe;
  1050. { input: address of target in r3, newvalue in r4, comparand in r5 }
  1051. { output: value stored in target before entry of the function }
  1052. { side-effect: NewValue stored in target if (target = comparand) }
  1053. asm
  1054. .LInterlockedCompareExchangeLoop:
  1055. lwarx r10,0,r3
  1056. sub r9,r10,r5
  1057. addic r9,r9,-1
  1058. subfe r9,r9,r9
  1059. and r8,r4,r9
  1060. andc r7,r10,r9
  1061. or r6,r7,r8
  1062. stwcx. r6,0,r3
  1063. bne .LInterlockedCompareExchangeLoop
  1064. mr r3, r10
  1065. end;
  1066. {$ifndef FPC_SYSTEM_HAS_MEM_BARRIER}
  1067. {$define FPC_SYSTEM_HAS_MEM_BARRIER}
  1068. procedure ReadBarrier;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
  1069. asm
  1070. isync
  1071. end;
  1072. procedure ReadDependencyBarrier;{$ifdef SYSTEMINLINE}inline;{$endif}
  1073. begin
  1074. { reads imply barrier on earlier reads depended on }
  1075. end;
  1076. procedure ReadWriteBarrier;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
  1077. asm
  1078. isync
  1079. eieio
  1080. end;
  1081. procedure WriteBarrier;assembler;nostackframe;{$ifdef SYSTEMINLINE}inline;{$endif}
  1082. asm
  1083. eieio
  1084. end;
  1085. {$endif}