1
0

asm-nseel-ppc-gcc.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. #define FUNCTION_MARKER "mr r0, r0\n" \
  2. "mr r1, r1\n" \
  3. "mr r2, r2\n"
  4. #if EEL_F_SIZE == 8
  5. void nseel_asm_1pdd(void)
  6. {
  7. __asm__(
  8. FUNCTION_MARKER
  9. "addis r5, 0, 0xdead\n"
  10. "ori r5, r5, 0xbeef\n"
  11. "mtctr r5\n"
  12. "subi r1, r1, 64\n"
  13. "bctrl\n"
  14. "addi r1, r1, 64\n"
  15. FUNCTION_MARKER
  16. :: );
  17. }
  18. void nseel_asm_1pdd_end(void){}
  19. void nseel_asm_2pdd(void)
  20. {
  21. __asm__(
  22. FUNCTION_MARKER
  23. "addis r7, 0, 0xdead\n"
  24. "ori r7, r7, 0xbeef\n"
  25. "fmr f2, f1\n"
  26. "lfd f1, 0(r14)\n"
  27. "mtctr r7\n"
  28. "subi r1, r1, 64\n"
  29. "bctrl\n"
  30. "addi r1, r1, 64\n"
  31. FUNCTION_MARKER
  32. :: );
  33. };
  34. void nseel_asm_2pdd_end(void){}
  35. void nseel_asm_2pdds(void)
  36. {
  37. __asm__(
  38. FUNCTION_MARKER
  39. "addis r5, 0, 0xdead\n"
  40. "ori r5, r5, 0xbeef\n"
  41. "fmr f2, f1\n"
  42. "lfd f1, 0(r14)\n"
  43. "mtctr r5\n"
  44. "subi r1, r1, 64\n"
  45. "bctrl\n"
  46. "addi r1, r1, 64\n"
  47. "stfd f1, 0(r14)\n"
  48. "mr r3, r14\n"
  49. FUNCTION_MARKER
  50. :: );
  51. }
  52. void nseel_asm_2pdds_end(void){}
  53. #else // 32 bit floating point calls
  54. #error no 32 bit float support
  55. #endif
  56. //---------------------------------------------------------------------------------------------------------------
  57. // do nothing, eh
  58. void nseel_asm_exec2(void)
  59. {
  60. __asm__(
  61. FUNCTION_MARKER
  62. FUNCTION_MARKER
  63. );
  64. }
  65. void nseel_asm_exec2_end(void) { }
  66. void nseel_asm_invsqrt(void)
  67. {
  68. __asm__(
  69. FUNCTION_MARKER
  70. "frsqrte f1, f1\n" // less accurate than our x86 equivilent, but invsqrt() is inherently inaccurate anyway
  71. FUNCTION_MARKER
  72. );
  73. }
  74. void nseel_asm_invsqrt_end(void) {}
  75. void nseel_asm_dbg_getstackptr(void)
  76. {
  77. __asm__(
  78. FUNCTION_MARKER
  79. "addis r11, 0, 0x4330\n"
  80. "xoris r10, r1, 0x8000\n"
  81. "stw r11, -8(r1)\n" // 0x43300000
  82. "stw r10, -4(r1)\n" // our integer sign flipped
  83. "lfd f1, -8(r1)\n"
  84. "fsub f1, f1, f30\n"
  85. FUNCTION_MARKER
  86. );
  87. }
  88. void nseel_asm_dbg_getstackptr_end(void) {}
  89. //---------------------------------------------------------------------------------------------------------------
  90. void nseel_asm_sqr(void)
  91. {
  92. __asm__(
  93. FUNCTION_MARKER
  94. "fmul f1, f1, f1\n"
  95. FUNCTION_MARKER
  96. );
  97. }
  98. void nseel_asm_sqr_end(void) {}
  99. //---------------------------------------------------------------------------------------------------------------
  100. void nseel_asm_abs(void)
  101. {
  102. __asm__(
  103. FUNCTION_MARKER
  104. "fabs f1, f1\n"
  105. FUNCTION_MARKER
  106. );
  107. }
  108. void nseel_asm_abs_end(void) {}
  109. //---------------------------------------------------------------------------------------------------------------
  110. void nseel_asm_assign(void)
  111. {
  112. __asm__(
  113. FUNCTION_MARKER
  114. "lfd f1, 0(r3)\n"
  115. "mr r3, r14\n"
  116. "stfd f1, 0(r14)\n"
  117. FUNCTION_MARKER
  118. );
  119. }
  120. void nseel_asm_assign_end(void) {}
  121. //
  122. //---------------------------------------------------------------------------------------------------------------
  123. void nseel_asm_assign_fromfp(void)
  124. {
  125. __asm__(
  126. FUNCTION_MARKER
  127. "mr r3, r14\n"
  128. "stfd f1, 0(r14)\n"
  129. FUNCTION_MARKER
  130. );
  131. }
  132. void nseel_asm_assign_fromfp_end(void) {}
  133. //---------------------------------------------------------------------------------------------------------------
  134. void nseel_asm_assign_fast(void)
  135. {
  136. __asm__(
  137. FUNCTION_MARKER
  138. "lfd f1, 0(r3)\n"
  139. "mr r3, r14\n"
  140. "stfd f1, 0(r14)\n"
  141. FUNCTION_MARKER
  142. );
  143. }
  144. void nseel_asm_assign_fast_end(void) {}
  145. //
  146. //---------------------------------------------------------------------------------------------------------------
  147. void nseel_asm_assign_fast_fromfp(void)
  148. {
  149. __asm__(
  150. FUNCTION_MARKER
  151. "mr r3, r14\n"
  152. "stfd f1, 0(r14)\n"
  153. FUNCTION_MARKER
  154. );
  155. }
  156. void nseel_asm_assign_fast_fromfp_end(void) {}
  157. //---------------------------------------------------------------------------------------------------------------
  158. void nseel_asm_add(void)
  159. {
  160. __asm__(
  161. FUNCTION_MARKER
  162. "lfd f2, 0(r14)\n"
  163. "fadd f1, f1, f2\n"
  164. FUNCTION_MARKER
  165. );
  166. }
  167. void nseel_asm_add_end(void) {}
  168. void nseel_asm_add_op(void)
  169. {
  170. __asm__(
  171. FUNCTION_MARKER
  172. "lfd f2, 0(r14)\n"
  173. "fadd f1, f1, f2\n"
  174. "mr r3, r14\n"
  175. "stfd f1, 0(r14)\n"
  176. FUNCTION_MARKER
  177. );
  178. }
  179. void nseel_asm_add_op_end(void) {}
  180. void nseel_asm_add_op_fast(void)
  181. {
  182. __asm__(
  183. FUNCTION_MARKER
  184. "lfd f2, 0(r14)\n"
  185. "fadd f1, f1, f2\n"
  186. "mr r3, r14\n"
  187. "stfd f1, 0(r14)\n"
  188. FUNCTION_MARKER
  189. );
  190. }
  191. void nseel_asm_add_op_fast_end(void) {}
  192. //---------------------------------------------------------------------------------------------------------------
  193. void nseel_asm_sub(void)
  194. {
  195. __asm__(
  196. FUNCTION_MARKER
  197. "lfd f2, 0(r14)\n"
  198. "fsub f1, f2, f1\n"
  199. FUNCTION_MARKER
  200. );
  201. }
  202. void nseel_asm_sub_end(void) {}
  203. void nseel_asm_sub_op(void)
  204. {
  205. __asm__(
  206. FUNCTION_MARKER
  207. "lfd f2, 0(r14)\n"
  208. "fsub f1, f2, f1\n"
  209. "mr r3, r14\n"
  210. "stfd f1, 0(r14)\n"
  211. FUNCTION_MARKER
  212. );
  213. }
  214. void nseel_asm_sub_op_end(void) {}
  215. void nseel_asm_sub_op_fast(void)
  216. {
  217. __asm__(
  218. FUNCTION_MARKER
  219. "lfd f2, 0(r14)\n"
  220. "fsub f1, f2, f1\n"
  221. "mr r3, r14\n"
  222. "stfd f1, 0(r14)\n"
  223. FUNCTION_MARKER
  224. );
  225. }
  226. void nseel_asm_sub_op_fast_end(void) {}
  227. //---------------------------------------------------------------------------------------------------------------
  228. void nseel_asm_mul(void)
  229. {
  230. __asm__(
  231. FUNCTION_MARKER
  232. "lfd f2, 0(r14)\n"
  233. "fmul f1, f2, f1\n"
  234. FUNCTION_MARKER
  235. );
  236. }
  237. void nseel_asm_mul_end(void) {}
  238. void nseel_asm_mul_op(void)
  239. {
  240. __asm__(
  241. FUNCTION_MARKER
  242. "lfd f2, 0(r14)\n"
  243. "fmul f1, f2, f1\n"
  244. "mr r3, r14\n"
  245. "stfd f1, 0(r14)\n"
  246. FUNCTION_MARKER
  247. );
  248. }
  249. void nseel_asm_mul_op_end(void) {}
  250. void nseel_asm_mul_op_fast(void)
  251. {
  252. __asm__(
  253. FUNCTION_MARKER
  254. "lfd f2, 0(r14)\n"
  255. "fmul f1, f2, f1\n"
  256. "mr r3, r14\n"
  257. "stfd f1, 0(r14)\n"
  258. FUNCTION_MARKER
  259. );
  260. }
  261. void nseel_asm_mul_op_fast_end(void) {}
  262. //---------------------------------------------------------------------------------------------------------------
  263. void nseel_asm_div(void)
  264. {
  265. __asm__(
  266. FUNCTION_MARKER
  267. "lfd f2, 0(r14)\n"
  268. "fdiv f1, f2, f1\n"
  269. FUNCTION_MARKER
  270. );
  271. }
  272. void nseel_asm_div_end(void) {}
  273. void nseel_asm_div_op(void)
  274. {
  275. __asm__(
  276. FUNCTION_MARKER
  277. "lfd f2, 0(r14)\n"
  278. "fdiv f1, f2, f1\n"
  279. "mr r3, r14\n"
  280. "stfd f1, 0(r14)\n"
  281. FUNCTION_MARKER
  282. );
  283. }
  284. void nseel_asm_div_op_end(void) {}
  285. void nseel_asm_div_op_fast(void)
  286. {
  287. __asm__(
  288. FUNCTION_MARKER
  289. "lfd f2, 0(r14)\n"
  290. "fdiv f1, f2, f1\n"
  291. "mr r3, r14\n"
  292. "stfd f1, 0(r14)\n"
  293. FUNCTION_MARKER
  294. );
  295. }
  296. void nseel_asm_div_op_fast_end(void) {}
  297. //---------------------------------------------------------------------------------------------------------------
  298. void nseel_asm_mod(void)
  299. {
  300. __asm__(
  301. FUNCTION_MARKER
  302. "lfd f2, 0(r14)\n"
  303. "fabs f1, f1\n"
  304. "fabs f2, f2\n"
  305. "fctiwz f1, f1\n"
  306. "fctiwz f2, f2\n"
  307. "stfd f1, -8(r1)\n"
  308. "stfd f2, -16(r1)\n"
  309. "lwz r10, -4(r1)\n"
  310. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  311. "divw r12, r11, r10\n"
  312. "mullw r12, r12, r10\n"
  313. "subf r10, r12, r11\n"
  314. "addis r11, 0, 0x4330\n"
  315. "xoris r10, r10, 0x8000\n"
  316. "stw r11, -8(r1)\n" // 0x43300000
  317. "stw r10, -4(r1)\n" // our integer sign flipped
  318. "lfd f1, -8(r1)\n"
  319. "fsub f1, f1, f30\n"
  320. FUNCTION_MARKER
  321. );
  322. }
  323. void nseel_asm_mod_end(void) {}
  324. void nseel_asm_shl(void)
  325. {
  326. __asm__(
  327. FUNCTION_MARKER
  328. "lfd f2, 0(r14)\n"
  329. "fctiwz f1, f1\n"
  330. "fctiwz f2, f2\n"
  331. "stfd f1, -8(r1)\n"
  332. "stfd f2, -16(r1)\n"
  333. "lwz r10, -4(r1)\n"
  334. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  335. "slw r10, r11, r10\n" // r10 has the result
  336. "addis r11, 0, 0x4330\n"
  337. "xoris r10, r10, 0x8000\n"
  338. "stw r11, -8(r1)\n" // 0x43300000
  339. "stw r10, -4(r1)\n" // our integer sign flipped
  340. "lfd f1, -8(r1)\n"
  341. "fsub f1, f1, f30\n"
  342. FUNCTION_MARKER
  343. );
  344. }
  345. void nseel_asm_shl_end(void) {}
  346. void nseel_asm_shr(void)
  347. {
  348. __asm__(
  349. FUNCTION_MARKER
  350. "lfd f2, 0(r14)\n"
  351. "fctiwz f1, f1\n"
  352. "fctiwz f2, f2\n"
  353. "stfd f1, -8(r1)\n"
  354. "stfd f2, -16(r1)\n"
  355. "lwz r10, -4(r1)\n"
  356. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  357. "sraw r10, r11, r10\n" // r10 has the result
  358. "addis r11, 0, 0x4330\n"
  359. "xoris r10, r10, 0x8000\n"
  360. "stw r11, -8(r1)\n" // 0x43300000
  361. "stw r10, -4(r1)\n" // our integer sign flipped
  362. "lfd f1, -8(r1)\n"
  363. "fsub f1, f1, f30\n"
  364. FUNCTION_MARKER
  365. );
  366. }
  367. void nseel_asm_shr_end(void) {}
  368. void nseel_asm_mod_op(void)
  369. {
  370. __asm__(
  371. FUNCTION_MARKER
  372. "lfd f2, 0(r14)\n"
  373. "fabs f1, f1\n"
  374. "fabs f2, f2\n"
  375. "fctiwz f1, f1\n"
  376. "fctiwz f2, f2\n"
  377. "stfd f1, -8(r1)\n"
  378. "stfd f2, -16(r1)\n"
  379. "lwz r10, -4(r1)\n"
  380. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  381. "divw r12, r11, r10\n"
  382. "mullw r12, r12, r10\n"
  383. "subf r10, r12, r11\n"
  384. "addis r11, 0, 0x4330\n"
  385. "xoris r10, r10, 0x8000\n"
  386. "stw r11, -8(r1)\n" // 0x43300000
  387. "stw r10, -4(r1)\n" // our integer sign flipped
  388. "lfd f1, -8(r1)\n"
  389. "fsub f1, f1, f30\n"
  390. "mr r3, r14\n"
  391. "stfd f1, 0(r14)\n"
  392. FUNCTION_MARKER
  393. );
  394. }
  395. void nseel_asm_mod_op_end(void) {}
  396. //---------------------------------------------------------------------------------------------------------------
  397. void nseel_asm_or(void)
  398. {
  399. __asm__(
  400. FUNCTION_MARKER
  401. "lfd f2, 0(r14)\n"
  402. "fctiwz f1, f1\n"
  403. "fctiwz f2, f2\n"
  404. "stfd f1, -8(r1)\n"
  405. "stfd f2, -16(r1)\n"
  406. "lwz r10, -4(r1)\n"
  407. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  408. "or r10, r10, r11\n" // r10 has the result
  409. "addis r11, 0, 0x4330\n"
  410. "xoris r10, r10, 0x8000\n"
  411. "stw r11, -8(r1)\n" // 0x43300000
  412. "stw r10, -4(r1)\n" // our integer sign flipped
  413. "lfd f1, -8(r1)\n"
  414. "fsub f1, f1, f30\n"
  415. FUNCTION_MARKER
  416. );
  417. }
  418. void nseel_asm_or_end(void) {}
  419. void nseel_asm_or0(void)
  420. {
  421. __asm__(
  422. FUNCTION_MARKER
  423. "fctiwz f1, f1\n"
  424. "addis r11, 0, 0x4330\n"
  425. "stfd f1, -8(r1)\n"
  426. "lwz r10, -4(r1)\n"
  427. "xoris r10, r10, 0x8000\n"
  428. "stw r11, -8(r1)\n" // 0x43300000
  429. "stw r10, -4(r1)\n" // our integer sign flipped
  430. "lfd f1, -8(r1)\n"
  431. "fsub f1, f1, f30\n"
  432. FUNCTION_MARKER
  433. );
  434. }
  435. void nseel_asm_or0_end(void) {}
  436. void nseel_asm_or_op(void)
  437. {
  438. __asm__(
  439. FUNCTION_MARKER
  440. "lfd f2, 0(r14)\n"
  441. "fctiwz f1, f1\n"
  442. "fctiwz f2, f2\n"
  443. "stfd f1, -8(r1)\n"
  444. "stfd f2, -16(r1)\n"
  445. "lwz r10, -4(r1)\n"
  446. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  447. "or r10, r10, r11\n" // r10 has the result
  448. "addis r11, 0, 0x4330\n"
  449. "xoris r10, r10, 0x8000\n"
  450. "stw r11, -8(r1)\n" // 0x43300000
  451. "stw r10, -4(r1)\n" // our integer sign flipped
  452. "lfd f1, -8(r1)\n"
  453. "fsub f1, f1, f30\n"
  454. "mr r3, r14\n"
  455. "stfd f1, 0(r14)\n"
  456. FUNCTION_MARKER
  457. );
  458. }
  459. void nseel_asm_or_op_end(void) {}
  460. //---------------------------------------------------------------------------------------------------------------
  461. void nseel_asm_xor(void)
  462. {
  463. __asm__(
  464. FUNCTION_MARKER
  465. "lfd f2, 0(r14)\n"
  466. "fctiwz f1, f1\n"
  467. "fctiwz f2, f2\n"
  468. "stfd f1, -8(r1)\n"
  469. "stfd f2, -16(r1)\n"
  470. "lwz r10, -4(r1)\n"
  471. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  472. "xor r10, r10, r11\n" // r10 has the result
  473. "addis r11, 0, 0x4330\n"
  474. "xoris r10, r10, 0x8000\n"
  475. "stw r11, -8(r1)\n" // 0x43300000
  476. "stw r10, -4(r1)\n" // our integer sign flipped
  477. "lfd f1, -8(r1)\n"
  478. "fsub f1, f1, f30\n"
  479. FUNCTION_MARKER
  480. );
  481. }
  482. void nseel_asm_xor_end(void) {}
  483. void nseel_asm_xor_op(void)
  484. {
  485. __asm__(
  486. FUNCTION_MARKER
  487. "lfd f2, 0(r14)\n"
  488. "fctiwz f1, f1\n"
  489. "fctiwz f2, f2\n"
  490. "stfd f1, -8(r1)\n"
  491. "stfd f2, -16(r1)\n"
  492. "lwz r10, -4(r1)\n"
  493. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  494. "xor r10, r10, r11\n" // r10 has the result
  495. "addis r11, 0, 0x4330\n"
  496. "xoris r10, r10, 0x8000\n"
  497. "stw r11, -8(r1)\n" // 0x43300000
  498. "stw r10, -4(r1)\n" // our integer sign flipped
  499. "lfd f1, -8(r1)\n"
  500. "fsub f1, f1, f30\n"
  501. "mr r3, r14\n"
  502. "stfd f1, 0(r14)\n"
  503. FUNCTION_MARKER
  504. );
  505. }
  506. void nseel_asm_xor_op_end(void) {}
  507. //---------------------------------------------------------------------------------------------------------------
  508. void nseel_asm_and(void)
  509. {
  510. __asm__(
  511. FUNCTION_MARKER
  512. "lfd f2, 0(r14)\n"
  513. "fctiwz f1, f1\n"
  514. "fctiwz f2, f2\n"
  515. "stfd f1, -8(r1)\n"
  516. "stfd f2, -16(r1)\n"
  517. "lwz r10, -4(r1)\n"
  518. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  519. "and r10, r10, r11\n" // r10 has the result
  520. "addis r11, 0, 0x4330\n"
  521. "xoris r10, r10, 0x8000\n"
  522. "stw r11, -8(r1)\n" // 0x43300000
  523. "stw r10, -4(r1)\n" // our integer sign flipped
  524. "lfd f1, -8(r1)\n"
  525. "fsub f1, f1, f30\n"
  526. FUNCTION_MARKER
  527. );}
  528. void nseel_asm_and_end(void) {}
  529. void nseel_asm_and_op(void)
  530. {
  531. __asm__(
  532. FUNCTION_MARKER
  533. "lfd f2, 0(r14)\n"
  534. "fctiwz f1, f1\n"
  535. "fctiwz f2, f2\n"
  536. "stfd f1, -8(r1)\n"
  537. "stfd f2, -16(r1)\n"
  538. "lwz r10, -4(r1)\n"
  539. "lwz r11, -12(r1)\n" //r11 and r12 have the integers
  540. "and r10, r10, r11\n" // r10 has the result
  541. "addis r11, 0, 0x4330\n"
  542. "xoris r10, r10, 0x8000\n"
  543. "stw r11, -8(r1)\n" // 0x43300000
  544. "stw r10, -4(r1)\n" // our integer sign flipped
  545. "lfd f1, -8(r1)\n"
  546. "fsub f1, f1, f30\n"
  547. "mr r3, r14\n"
  548. "stfd f1, 0(r14)\n"
  549. FUNCTION_MARKER
  550. );
  551. }
  552. void nseel_asm_and_op_end(void) {}
  553. //---------------------------------------------------------------------------------------------------------------
  554. void nseel_asm_uplus(void) // this is the same as doing nothing, it seems
  555. {
  556. __asm__(
  557. FUNCTION_MARKER
  558. FUNCTION_MARKER
  559. );
  560. }
  561. void nseel_asm_uplus_end(void) {}
  562. //---------------------------------------------------------------------------------------------------------------
  563. void nseel_asm_uminus(void)
  564. {
  565. __asm__(
  566. FUNCTION_MARKER
  567. "fneg f1, f1\n"
  568. FUNCTION_MARKER
  569. );
  570. }
  571. void nseel_asm_uminus_end(void) {}
  572. //---------------------------------------------------------------------------------------------------------------
  573. void nseel_asm_sign(void)
  574. {
  575. __asm__(
  576. FUNCTION_MARKER
  577. "li r9, 0\n"
  578. "stw r9, -4(r1)\n"
  579. "lis r9, 0xbf80\n" // -1 in float
  580. "lfs f2, -4(r1)\n"
  581. "fcmpu cr7, f1, f2\n"
  582. "blt- cr7, 0f\n"
  583. "ble- cr7, 1f\n"
  584. " lis r9, 0x3f80\n" // 1 in float
  585. "0:\n"
  586. " stw r9, -4(r1)\n"
  587. " lfs f1, -4(r1)\n"
  588. "1:\n"
  589. FUNCTION_MARKER
  590. ::
  591. );
  592. }
  593. void nseel_asm_sign_end(void) {}
  594. //---------------------------------------------------------------------------------------------------------------
  595. void nseel_asm_bnot(void)
  596. {
  597. __asm__(
  598. FUNCTION_MARKER
  599. "cmpwi cr0, r3, 0\n"
  600. "addis r3, 0, 0\n"
  601. "bne cr0, 0f\n"
  602. "addis r3, 0, 1\n"
  603. "0:\n"
  604. FUNCTION_MARKER
  605. );
  606. }
  607. void nseel_asm_bnot_end(void) {}
  608. //---------------------------------------------------------------------------------------------------------------
  609. void nseel_asm_if(void)
  610. {
  611. __asm__(
  612. FUNCTION_MARKER
  613. "cmpwi cr0, r3, 0\n"
  614. "beq cr0, 0f\n"
  615. " addis r6, 0, 0xdead\n"
  616. " ori r6, r6, 0xbeef\n"
  617. " mtctr r6\n"
  618. " bctrl\n"
  619. "b 1f\n"
  620. "0:\n"
  621. " addis r6, 0, 0xdead\n"
  622. " ori r6, r6, 0xbeef\n"
  623. " mtctr r6\n"
  624. " bctrl\n"
  625. "1:\n"
  626. FUNCTION_MARKER
  627. :: );
  628. }
  629. void nseel_asm_if_end(void) {}
  630. //---------------------------------------------------------------------------------------------------------------
  631. void nseel_asm_repeat(void)
  632. {
  633. #if NSEEL_LOOPFUNC_SUPPORT_MAXLEN > 0
  634. __asm__(
  635. FUNCTION_MARKER
  636. "fctiwz f1, f1\n"
  637. "stfd f1, -8(r1)\n"
  638. "lwz r5, -4(r1)\n" // r5 has count now
  639. "cmpwi cr0, r5, 0\n"
  640. "ble cr0, 1f\n" // skip the loop
  641. "addis r7, 0, ha16(%0)\n"
  642. "addi r7, r7, lo16(%0)\n"
  643. "stwu r16, -16(r1)\n" // set up the stack for the loop, save r16
  644. "cmpw cr0, r7, r5\n"
  645. "bge cr0, 0f\n"
  646. "mr r5, r7\n" // set r5 to max if we have to
  647. "0:\n"
  648. "addis r6, 0, 0xdead\n"
  649. "ori r6, r6, 0xbeef\n"
  650. "addi r5, r5, -1\n"
  651. "stw r5, 4(r1)\n"
  652. "mtctr r6\n"
  653. "bctrl\n"
  654. "lwz r16, 0(r1)\n"
  655. "lwz r5, 4(r1)\n"
  656. "cmpwi cr0, r5, 0\n"
  657. "bgt cr0, 0b\n"
  658. "addi r1, r1, 16\n" // restore old stack
  659. "1:\n"
  660. FUNCTION_MARKER
  661. ::"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN)
  662. );
  663. #else
  664. __asm__(
  665. FUNCTION_MARKER
  666. "fctiwz f1, f1\n"
  667. "stfd f1, -8(r1)\n"
  668. "lwz r5, -4(r1)\n" // r5 has count now
  669. "cmpwi cr0, r5, 0\n"
  670. "ble cr0, 1f\n" // skip the loop
  671. "stwu r16, -16(r1)\n" // set up the stack for the loop, save r16
  672. "0:\n"
  673. "addis r6, 0, 0xdead\n"
  674. "ori r6, r6, 0xbeef\n"
  675. "addi r5, r5, -1\n"
  676. "stw r5, 4(r1)\n"
  677. "mtctr r6\n"
  678. "bctrl\n"
  679. "lwz r16, 0(r1)\n"
  680. "lwz r5, 4(r1)\n"
  681. "cmpwi cr0, r5, 0\n"
  682. "bgt cr0, 0b\n"
  683. "addi r1, r1, 16\n" // restore old stack
  684. "1:\n"
  685. FUNCTION_MARKER
  686. ::
  687. );
  688. #endif
  689. }
  690. void nseel_asm_repeat_end(void) {}
  691. void nseel_asm_repeatwhile(void)
  692. {
  693. #if NSEEL_LOOPFUNC_SUPPORT_MAXLEN > 0
  694. __asm__(
  695. FUNCTION_MARKER
  696. "stwu r16, -16(r1)\n" // save r16 to stack, update stack
  697. "addis r5, 0, ha16(%0)\n"
  698. "addi r5, r5, lo16(%0)\n"
  699. "0:\n"
  700. "addis r6, 0, 0xdead\n"
  701. "ori r6, r6, 0xbeef\n"
  702. "stw r5, 4(r1)\n" // save maxcnt
  703. "mtctr r6\n"
  704. "bctrl\n"
  705. "lwz r16, 0(r1)\n" // restore r16
  706. "lwz r5, 4(r1)\n" // restore, check maxcnt
  707. "cmpwi cr7, r3, 0\n" // check return value
  708. "addi r5, r5, -1\n"
  709. "beq cr7, 1f\n"
  710. "cmpwi cr0, r5, 0\n"
  711. "bgt cr0, 0b\n"
  712. "1:\n"
  713. "addi r1, r1, 16\n" // restore stack
  714. FUNCTION_MARKER
  715. ::"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN)
  716. );
  717. #else
  718. __asm__(
  719. FUNCTION_MARKER
  720. "stwu r16, -16(r1)\n" // save r16 to stack, update stack
  721. "0:\n"
  722. "addis r6, 0, 0xdead\n"
  723. "ori r6, r6, 0xbeef\n"
  724. "mtctr r6\n"
  725. "bctrl\n"
  726. "lwz r16, 0(r1)\n" // restore r16
  727. "cmpwi cr7, r3, 0\n" // check return value
  728. "bne cr7, 0b\n"
  729. "addi r1, r1, 16\n" // restore stack
  730. FUNCTION_MARKER
  731. ::
  732. );
  733. #endif
  734. }
  735. void nseel_asm_repeatwhile_end(void) {}
  736. void nseel_asm_band(void)
  737. {
  738. __asm__(
  739. FUNCTION_MARKER
  740. "cmpwi cr7, r3, 0\n"
  741. "beq cr7, 0f\n"
  742. " addis r6, 0, 0xdead\n"
  743. " ori r6, r6, 0xbeef\n"
  744. " mtctr r6\n"
  745. " bctrl\n"
  746. "0:\n"
  747. FUNCTION_MARKER
  748. :: );
  749. }
  750. void nseel_asm_band_end(void) {}
  751. void nseel_asm_bor(void)
  752. {
  753. __asm__(
  754. FUNCTION_MARKER
  755. "cmpwi cr7, r3, 0\n"
  756. "bne cr7, 0f\n"
  757. " addis r6, 0, 0xdead\n"
  758. " ori r6, r6, 0xbeef\n"
  759. " mtctr r6\n"
  760. " bctrl\n"
  761. "0:\n"
  762. FUNCTION_MARKER
  763. :: );
  764. }
  765. void nseel_asm_bor_end(void) {}
  766. //---------------------------------------------------------------------------------------------------------------
  767. void nseel_asm_equal(void)
  768. {
  769. __asm__(
  770. FUNCTION_MARKER
  771. "lfd f2, 0(r14)\n"
  772. "fsub f1, f1, f2\n"
  773. "fabs f1, f1\n"
  774. "fcmpu cr7, f1, f31\n"
  775. "addis r3, 0, 0\n"
  776. "bge cr7, 0f\n"
  777. "addis r3, 0, 1\n"
  778. "0:\n"
  779. FUNCTION_MARKER
  780. ::
  781. );
  782. }
  783. void nseel_asm_equal_end(void) {}
  784. //---------------------------------------------------------------------------------------------------------------
  785. void nseel_asm_equal_exact(void)
  786. {
  787. __asm__(
  788. FUNCTION_MARKER
  789. "lfd f2, 0(r14)\n"
  790. "fcmpu cr7, f1, f2\n"
  791. "addis r3, 0, 0\n"
  792. "bne cr7, 0f\n"
  793. "addis r3, 0, 1\n"
  794. "0:\n"
  795. FUNCTION_MARKER
  796. ::
  797. );
  798. }
  799. void nseel_asm_equal_exact_end(void) {}
  800. //
  801. //---------------------------------------------------------------------------------------------------------------
  802. void nseel_asm_notequal_exact(void)
  803. {
  804. __asm__(
  805. FUNCTION_MARKER
  806. "lfd f2, 0(r14)\n"
  807. "fcmpu cr7, f1, f2\n"
  808. "addis r3, 0, 0\n"
  809. "beq cr7, 0f\n"
  810. "addis r3, 0, 1\n"
  811. "0:\n"
  812. FUNCTION_MARKER
  813. ::
  814. );
  815. }
  816. void nseel_asm_notequal_exact_end(void) {}
  817. //
  818. //
  819. //
  820. //---------------------------------------------------------------------------------------------------------------
  821. void nseel_asm_notequal(void)
  822. {
  823. __asm__(
  824. FUNCTION_MARKER
  825. "lfd f2, 0(r14)\n"
  826. "fsub f1, f1, f2\n"
  827. "fabs f1, f1\n"
  828. "fcmpu cr7, f1, f31\n"
  829. "addis r3, 0, 0\n"
  830. "blt cr7, 0f\n"
  831. " addis r3, 0, 1\n"
  832. "0:\n"
  833. FUNCTION_MARKER
  834. ::
  835. );
  836. }
  837. void nseel_asm_notequal_end(void) {}
  838. //---------------------------------------------------------------------------------------------------------------
  839. void nseel_asm_below(void)
  840. {
  841. __asm__(
  842. FUNCTION_MARKER
  843. "lfd f2, 0(r14)\n"
  844. "fcmpu cr7, f1, f2\n"
  845. "addis r3, 0, 0\n"
  846. "ble cr7, 0f\n"
  847. "addis r3, 0, 1\n"
  848. "0:\n"
  849. FUNCTION_MARKER
  850. ::
  851. );
  852. }
  853. void nseel_asm_below_end(void) {}
  854. //---------------------------------------------------------------------------------------------------------------
  855. void nseel_asm_beloweq(void)
  856. {
  857. __asm__(
  858. FUNCTION_MARKER
  859. "lfd f2, 0(r14)\n"
  860. "fcmpu cr7, f1, f2\n"
  861. "addis r3, 0, 0\n"
  862. "blt cr7, 0f\n"
  863. " addis r3, 0, 1\n"
  864. "0:\n"
  865. FUNCTION_MARKER
  866. ::
  867. );
  868. }
  869. void nseel_asm_beloweq_end(void) {}
  870. //---------------------------------------------------------------------------------------------------------------
  871. void nseel_asm_above(void)
  872. {
  873. __asm__(
  874. FUNCTION_MARKER
  875. "lfd f2, 0(r14)\n"
  876. "fcmpu cr7, f1, f2\n"
  877. "addis r3, 0, 0\n"
  878. "bge cr7, 0f\n"
  879. "addis r3, 0, 1\n"
  880. "0:\n"
  881. FUNCTION_MARKER
  882. ::
  883. );
  884. }
  885. void nseel_asm_above_end(void) {}
  886. void nseel_asm_aboveeq(void)
  887. {
  888. __asm__(
  889. FUNCTION_MARKER
  890. "lfd f2, 0(r14)\n"
  891. "fcmpu cr7, f1, f2\n"
  892. "addis r3, 0, 0\n"
  893. "bgt cr7, 0f\n"
  894. "addis r3, 0, 1\n"
  895. "0:\n"
  896. FUNCTION_MARKER
  897. ::
  898. );
  899. }
  900. void nseel_asm_aboveeq_end(void) {}
  901. void nseel_asm_min(void)
  902. {
  903. __asm__(
  904. FUNCTION_MARKER
  905. "lfd f1, 0(r3)\n"
  906. "lfd f2, 0(r14)\n"
  907. "fcmpu cr7, f2, f1\n"
  908. "bgt cr7, 0f\n"
  909. "mr r3, r14\n"
  910. "0:\n"
  911. FUNCTION_MARKER
  912. );
  913. }
  914. void nseel_asm_min_end(void) {}
  915. void nseel_asm_max(void)
  916. {
  917. __asm__(
  918. FUNCTION_MARKER
  919. "lfd f1, 0(r3)\n"
  920. "lfd f2, 0(r14)\n"
  921. "fcmpu cr7, f2, f1\n"
  922. "blt cr7, 0f\n"
  923. "mr r3, r14\n"
  924. "0:\n"
  925. FUNCTION_MARKER
  926. );
  927. }
  928. void nseel_asm_max_end(void) {}
  929. void nseel_asm_min_fp(void)
  930. {
  931. __asm__(
  932. FUNCTION_MARKER
  933. "lfd f2, 0(r14)\n"
  934. "fcmpu cr7, f2, f1\n"
  935. "bgt cr7, 0f\n"
  936. "fmr f1, f2\n"
  937. "0:\n"
  938. FUNCTION_MARKER
  939. );
  940. }
  941. void nseel_asm_min_fp_end(void) {}
  942. void nseel_asm_max_fp(void)
  943. {
  944. __asm__(
  945. FUNCTION_MARKER
  946. "lfd f2, 0(r14)\n"
  947. "fcmpu cr7, f2, f1\n"
  948. "blt cr7, 0f\n"
  949. "fmr f1, f2\n"
  950. "0:\n"
  951. FUNCTION_MARKER
  952. );
  953. }
  954. void nseel_asm_max_fp_end(void) {}
  955. void _asm_generic3parm(void)
  956. {
  957. __asm__(
  958. FUNCTION_MARKER
  959. "mr r6, r3\n"
  960. "addis r3, 0, 0xdead\n"
  961. "ori r3, r3, 0xbeef\n"
  962. "addis r7, 0, 0xdead\n"
  963. "ori r7, r7, 0xbeef\n"
  964. "mr r4, r15\n"
  965. "mr r5, r14\n"
  966. "mtctr r7\n"
  967. "subi r1, r1, 64\n"
  968. "bctrl\n"
  969. "addi r1, r1, 64\n"
  970. FUNCTION_MARKER
  971. ::
  972. );
  973. }
  974. void _asm_generic3parm_end(void) {}
  975. void _asm_generic3parm_retd(void)
  976. {
  977. __asm__(
  978. FUNCTION_MARKER
  979. "mr r6, r3\n"
  980. "addis r3, 0, 0xdead\n"
  981. "ori r3, r3, 0xbeef\n"
  982. "addis r7, 0, 0xdead\n"
  983. "ori r7, r7, 0xbeef\n"
  984. "mr r4, r15\n"
  985. "mr r5, r14\n"
  986. "mtctr r7\n"
  987. "subi r1, r1, 64\n"
  988. "bctrl\n"
  989. "addi r1, r1, 64\n"
  990. FUNCTION_MARKER
  991. ::
  992. );
  993. }
  994. void _asm_generic3parm_retd_end(void) {}
  995. void _asm_generic2parm(void) // this prob neds to be fixed for ppc
  996. {
  997. __asm__(
  998. FUNCTION_MARKER
  999. "mr r5, r3\n"
  1000. "addis r3, 0, 0xdead\n"
  1001. "ori r3, r3, 0xbeef\n"
  1002. "addis r7, 0, 0xdead\n"
  1003. "ori r7, r7, 0xbeef\n"
  1004. "mr r4, r14\n"
  1005. "mtctr r7\n"
  1006. "subi r1, r1, 64\n"
  1007. "bctrl\n"
  1008. "addi r1, r1, 64\n"
  1009. FUNCTION_MARKER
  1010. ::
  1011. );
  1012. }
  1013. void _asm_generic2parm_end(void) {}
  1014. void _asm_generic2parm_retd(void)
  1015. {
  1016. __asm__(
  1017. FUNCTION_MARKER
  1018. "mr r5, r3\n"
  1019. "addis r3, 0, 0xdead\n"
  1020. "ori r3, r3, 0xbeef\n"
  1021. "addis r7, 0, 0xdead\n"
  1022. "ori r7, r7, 0xbeef\n"
  1023. "mr r4, r14\n"
  1024. "mtctr r7\n"
  1025. "subi r1, r1, 64\n"
  1026. "bctrl\n"
  1027. "addi r1, r1, 64\n"
  1028. FUNCTION_MARKER
  1029. ::
  1030. );
  1031. }
  1032. void _asm_generic2parm_retd_end(void) {}
  1033. void _asm_generic1parm(void) // this prob neds to be fixed for ppc
  1034. {
  1035. __asm__(
  1036. FUNCTION_MARKER
  1037. "mr r4, r3\n"
  1038. "addis r3, 0, 0xdead\n"
  1039. "ori r3, r3, 0xbeef\n"
  1040. "addis r7, 0, 0xdead\n"
  1041. "ori r7, r7, 0xbeef\n"
  1042. "mtctr r7\n"
  1043. "subi r1, r1, 64\n"
  1044. "bctrl\n"
  1045. "addi r1, r1, 64\n"
  1046. FUNCTION_MARKER
  1047. ::
  1048. );
  1049. }
  1050. void _asm_generic1parm_end(void) {}
  1051. void _asm_generic1parm_retd(void)
  1052. {
  1053. __asm__(
  1054. FUNCTION_MARKER
  1055. "mr r4, r3\n"
  1056. "addis r3, 0, 0xdead\n"
  1057. "ori r3, r3, 0xbeef\n"
  1058. "addis r7, 0, 0xdead\n"
  1059. "ori r7, r7, 0xbeef\n"
  1060. "mtctr r7\n"
  1061. "subi r1, r1, 64\n"
  1062. "bctrl\n"
  1063. "addi r1, r1, 64\n"
  1064. FUNCTION_MARKER
  1065. ::
  1066. );
  1067. }
  1068. void _asm_generic1parm_retd_end(void) {}
  1069. void _asm_megabuf(void)
  1070. {
  1071. __asm__(
  1072. FUNCTION_MARKER
  1073. "lfd f2, -8(r13)\n"
  1074. "mr r3, r13\n"
  1075. "fadd f1, f2, f1\n"
  1076. // f1 has (float) index of array, r3 has EEL_F **
  1077. "fctiwz f1, f1\n"
  1078. "stfd f1, -8(r1)\n"
  1079. "lwz r4, -4(r1)\n" // r4 is index of array
  1080. "andis. r15, r4, %0\n" // check to see if it has any bits in 0xFF800000, which is 0xFFFFFFFF - (NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK - 1)
  1081. "bne cr0, 0f\n" // out of range, jump to error
  1082. // shr 14 (16 for NSEEL_RAM_ITEMSPERBLOCK, minus two for pointer size), which is rotate 18
  1083. // mask 7 bits (NSEEL_RAM_BLOCKS), but leave two empty bits (pointer size)
  1084. "rlwinm r15, r4, %1, %2, 29\n"
  1085. "lwzx r15, r3, r15\n" // r15 = (r3+r15)
  1086. "cmpi cr0, r15, 0\n"
  1087. "bne cr0, 1f\n" // if nonzero, jump to final calculation
  1088. "0:\n"
  1089. // set up function call
  1090. "addis r7, 0, 0xdead\n"
  1091. "ori r7, r7, 0xbeef\n"
  1092. "mtctr r7\n"
  1093. "subi r1, r1, 64\n"
  1094. "bctrl\n"
  1095. "addi r1, r1, 64\n"
  1096. "b 2f\n"
  1097. "1:\n"
  1098. // good news: we can do a direct addr return
  1099. // bad news: more rlwinm ugliness!
  1100. // shift left by 3 (sizeof(EEL_F)), mask off lower 3 bits, only allow 16 bits (NSEEL_RAM_ITEMSPERBLOCK) through
  1101. "rlwinm r3, r4, 3, %3, 28\n"
  1102. // add offset of loaded block
  1103. "add r3, r3, r15\n"
  1104. "2:\n"
  1105. FUNCTION_MARKER
  1106. ::
  1107. "i" ((0xFFFFFFFF - (NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK - 1))>>16),
  1108. "i" (32 - NSEEL_RAM_ITEMSPERBLOCK_LOG2 + 2),
  1109. "i" (30 - NSEEL_RAM_BLOCKS_LOG2),
  1110. "i" (28 - NSEEL_RAM_ITEMSPERBLOCK_LOG2 + 1)
  1111. );
  1112. }
  1113. void _asm_megabuf_end(void) {}
  1114. void _asm_gmegabuf(void)
  1115. {
  1116. __asm__(
  1117. FUNCTION_MARKER
  1118. "fadd f1, f31, f1\n"
  1119. "addis r3, 0, 0xdead\n" // set up context pointer
  1120. "ori r3, r3, 0xbeef\n"
  1121. "fctiwz f1, f1\n"
  1122. "subi r1, r1, 64\n"
  1123. "addis r7, 0, 0xdead\n"
  1124. "ori r7, r7, 0xbeef\n"
  1125. "stfd f1, 8(r1)\n"
  1126. "mtctr r7\n"
  1127. "lwz r4, 12(r1)\n"
  1128. "bctrl\n"
  1129. "addi r1, r1, 64\n"
  1130. FUNCTION_MARKER
  1131. ::
  1132. );
  1133. }
  1134. void _asm_gmegabuf_end(void) {}
  1135. void nseel_asm_fcall(void)
  1136. {
  1137. __asm__(
  1138. FUNCTION_MARKER
  1139. "addis r6, 0, 0xdead\n"
  1140. "ori r6, r6, 0xbeef\n"
  1141. "mtctr r6\n"
  1142. "bctrl\n"
  1143. FUNCTION_MARKER
  1144. );
  1145. }
  1146. void nseel_asm_fcall_end(void) {}
  1147. void nseel_asm_stack_push(void)
  1148. {
  1149. __asm__(
  1150. FUNCTION_MARKER
  1151. "addis r6, 0, 0xdead\n"
  1152. "ori r6, r6, 0xbeef\n" // r6 is stack
  1153. "lfd f1, 0(r3)\n" // f1 is value to copy to stack
  1154. "lwz r3, 0(r6)\n"
  1155. "addis r14, 0, 0xdead\n"
  1156. "ori r14, r14, 0xbeef\n"
  1157. "addi r3, r3, 0x8\n"
  1158. "and r3, r3, r14\n"
  1159. "addis r14, 0, 0xdead\n"
  1160. "ori r14, r14, 0xbeef\n"
  1161. "or r3, r3, r14\n"
  1162. "stfd f1, 0(r3)\n" // copy parameter to stack
  1163. "stw r3, 0(r6)\n" // update stack state
  1164. FUNCTION_MARKER
  1165. );
  1166. }
  1167. void nseel_asm_stack_push_end(void) {}
  1168. void nseel_asm_stack_pop(void)
  1169. {
  1170. __asm__(
  1171. FUNCTION_MARKER
  1172. "addis r6, 0, 0xdead\n"
  1173. "ori r6, r6, 0xbeef\n" // r6 is stack
  1174. "lwz r15, 0(r6)\n" // return the old stack pointer
  1175. "lfd f1, 0(r15)\n"
  1176. "subi r15, r15, 0x8\n"
  1177. "addis r14, 0, 0xdead\n"
  1178. "ori r14, r14, 0xbeef\n"
  1179. "and r15, r15, r14\n"
  1180. "addis r14, 0, 0xdead\n"
  1181. "ori r14, r14, 0xbeef\n"
  1182. "or r15, r15, r14\n"
  1183. "stw r15, 0(r6)\n"
  1184. "stfd f1, 0(r3)\n"
  1185. FUNCTION_MARKER
  1186. );
  1187. }
  1188. void nseel_asm_stack_pop_end(void) {}
  1189. void nseel_asm_stack_pop_fast(void)
  1190. {
  1191. __asm__(
  1192. FUNCTION_MARKER
  1193. "addis r6, 0, 0xdead\n"
  1194. "ori r6, r6, 0xbeef\n" // r6 is stack
  1195. "lwz r3, 0(r6)\n" // return the old stack pointer
  1196. "mr r15, r3\n" // update stack pointer
  1197. "subi r15, r15, 0x8\n"
  1198. "addis r14, 0, 0xdead\n"
  1199. "ori r14, r14, 0xbeef\n"
  1200. "and r15, r15, r14\n"
  1201. "addis r14, 0, 0xdead\n"
  1202. "ori r14, r14, 0xbeef\n"
  1203. "or r15, r15, r14\n"
  1204. "stw r15, 0(r6)\n"
  1205. FUNCTION_MARKER
  1206. );
  1207. }
  1208. void nseel_asm_stack_pop_fast_end(void) {}
  1209. void nseel_asm_stack_peek(void)
  1210. {
  1211. __asm__(
  1212. FUNCTION_MARKER
  1213. "fctiwz f1, f1\n"
  1214. "stfd f1, -8(r1)\n"
  1215. "addis r6, 0, 0xdead\n"
  1216. "ori r6, r6, 0xbeef\n" // r6 is stack
  1217. "lwz r14, -4(r1)\n"
  1218. "rlwinm r14, r14, 3, 0, 28\n" // slwi r14, r14, 3 -- 3 is log2(sizeof(EEL_F)) -- 28 represents 31-3
  1219. "lwz r3, 0(r6)\n" // return the old stack pointer
  1220. "sub r3, r3, r14\n"
  1221. "addis r14, 0, 0xdead\n"
  1222. "ori r14, r14, 0xbeef\n"
  1223. "and r3, r3, r14\n"
  1224. "addis r14, 0, 0xdead\n"
  1225. "ori r14, r14, 0xbeef\n"
  1226. "or r3, r3, r14\n"
  1227. FUNCTION_MARKER
  1228. );
  1229. }
  1230. void nseel_asm_stack_peek_end(void) {}
  1231. void nseel_asm_stack_peek_top(void)
  1232. {
  1233. __asm__(
  1234. FUNCTION_MARKER
  1235. "addis r6, 0, 0xdead\n"
  1236. "ori r6, r6, 0xbeef\n" // r6 is stack
  1237. "lwz r3, 0(r6)\n" // return the old stack pointer
  1238. FUNCTION_MARKER
  1239. );
  1240. }
  1241. void nseel_asm_stack_peek_top_end(void) {}
  1242. void nseel_asm_stack_peek_int(void)
  1243. {
  1244. __asm__(
  1245. FUNCTION_MARKER
  1246. "addis r6, 0, 0xdead\n"
  1247. "ori r6, r6, 0xbeef\n" // r6 is stack
  1248. "lwz r3, 0(r6)\n" // return the old stack pointer
  1249. "addis r14, 0, 0xdead\n" // add manual offset
  1250. "ori r14, r14, 0xbeef\n"
  1251. "sub r3, r3, r14\n"
  1252. "addis r14, 0, 0xdead\n"
  1253. "ori r14, r14, 0xbeef\n"
  1254. "and r3, r3, r14\n"
  1255. "addis r14, 0, 0xdead\n"
  1256. "ori r14, r14, 0xbeef\n"
  1257. "or r3, r3, r14\n"
  1258. FUNCTION_MARKER
  1259. );
  1260. }
  1261. void nseel_asm_stack_peek_int_end(void) {}
  1262. void nseel_asm_stack_exch(void)
  1263. {
  1264. __asm__(
  1265. FUNCTION_MARKER
  1266. "addis r6, 0, 0xdead\n"
  1267. "ori r6, r6, 0xbeef\n" // r6 is stack
  1268. "lfd f1, 0(r3)\n"
  1269. "lwz r14, 0(r6)\n"
  1270. "lfd f2, 0(r14)\n"
  1271. "stfd f1, 0(r14)\n"
  1272. "stfd f2, 0(r3)\n"
  1273. FUNCTION_MARKER
  1274. );
  1275. }
  1276. void nseel_asm_stack_exch_end(void) {}
  1277. void nseel_asm_booltofp(void)
  1278. {
  1279. __asm__(
  1280. FUNCTION_MARKER
  1281. "cmpwi cr7, r3, 0\n"
  1282. "li r14, 0\n"
  1283. "beq cr7, 0f\n"
  1284. "addis r14, 0, 0x3f80\n"
  1285. "0:\n"
  1286. "stw r14, -8(r1)\n"
  1287. "lfs f1, -8(r1)\n"
  1288. FUNCTION_MARKER
  1289. );
  1290. }
  1291. void nseel_asm_booltofp_end(void){ }
  1292. void nseel_asm_fptobool(void)
  1293. {
  1294. __asm__(
  1295. FUNCTION_MARKER
  1296. "fabs f1, f1\n"
  1297. "fcmpu cr7, f1, f31\n"
  1298. "addis r3, 0, 1\n"
  1299. "bge cr7, 0f\n"
  1300. " addis r3, 0, 0\n"
  1301. "0:\n"
  1302. FUNCTION_MARKER
  1303. ::
  1304. );
  1305. }
  1306. void nseel_asm_fptobool_end(void){ }
  1307. void nseel_asm_fptobool_rev(void)
  1308. {
  1309. __asm__(
  1310. FUNCTION_MARKER
  1311. "fabs f1, f1\n"
  1312. "fcmpu cr7, f1, f31\n"
  1313. "addis r3, 0, 0\n"
  1314. "bge cr7, 0f\n"
  1315. " addis r3, 0, 1\n"
  1316. "0:\n"
  1317. FUNCTION_MARKER
  1318. ::
  1319. );
  1320. }
  1321. void nseel_asm_fptobool_rev_end(void){ }