powerpc.inc 37 KB

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