nwasminl.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. {
  2. Copyright (c) 1998-2002, 2021 by Florian Klaempfl and Nikolay Nikolov
  3. Generate WebAssembly inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nwasminl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncginl;
  22. type
  23. { twasminlinenode }
  24. twasminlinenode = class(tcginlinenode)
  25. private
  26. function first_abs_real:tnode;override;
  27. function first_int_real:tnode;override;
  28. function first_sqrt_real:tnode;override;
  29. function first_trunc_real:tnode;override;
  30. function first_round_real:tnode;override;
  31. procedure second_abs_real;override;
  32. procedure second_int_real;override;
  33. procedure second_sqrt_real;override;
  34. procedure second_trunc_real;override;
  35. procedure second_round_real;override;
  36. procedure second_high; override;
  37. procedure second_memory_size;
  38. procedure second_memory_grow;
  39. procedure second_memory_fill;
  40. procedure second_memory_copy;
  41. procedure second_unreachable;
  42. procedure second_throw_fpcexception;
  43. protected
  44. function first_sqr_real: tnode; override;
  45. public
  46. function pass_typecheck_cpu: tnode; override;
  47. function first_cpu: tnode; override;
  48. procedure pass_generate_code_cpu; override;
  49. procedure second_length;override;
  50. procedure second_sqr_real; override;
  51. end;
  52. implementation
  53. uses
  54. ninl,ncal,compinnr,
  55. cpubase,
  56. aasmbase,aasmdata,aasmcpu,
  57. cgbase,cgutils,
  58. hlcgobj,hlcgcpu,
  59. defutil,pass_2,verbose,
  60. symtype,symdef;
  61. {*****************************************************************************
  62. twasminlinenode
  63. *****************************************************************************}
  64. function twasminlinenode.first_abs_real: tnode;
  65. begin
  66. expectloc:=LOC_FPUREGISTER;
  67. result:=nil;
  68. end;
  69. function twasminlinenode.first_int_real: tnode;
  70. begin
  71. expectloc:=LOC_FPUREGISTER;
  72. result:=nil;
  73. end;
  74. function twasminlinenode.first_sqrt_real: tnode;
  75. begin
  76. expectloc:=LOC_FPUREGISTER;
  77. result:=nil;
  78. end;
  79. function twasminlinenode.first_trunc_real: tnode;
  80. begin
  81. expectloc:=LOC_REGISTER;
  82. result:=nil;
  83. end;
  84. function twasminlinenode.first_round_real: tnode;
  85. begin
  86. expectloc:=LOC_REGISTER;
  87. result:=nil;
  88. end;
  89. procedure twasminlinenode.second_abs_real;
  90. begin
  91. secondpass(left);
  92. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  93. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  94. case left.location.size of
  95. OS_F32:
  96. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_abs));
  97. OS_F64:
  98. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_abs));
  99. else
  100. internalerror(2021092902);
  101. end;
  102. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  103. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  104. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  105. end;
  106. procedure twasminlinenode.second_int_real;
  107. begin
  108. secondpass(left);
  109. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  110. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  111. case left.location.size of
  112. OS_F32:
  113. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_trunc));
  114. OS_F64:
  115. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_trunc));
  116. else
  117. internalerror(2021092903);
  118. end;
  119. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  120. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  121. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  122. end;
  123. procedure twasminlinenode.second_sqrt_real;
  124. begin
  125. secondpass(left);
  126. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  127. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  128. case left.location.size of
  129. OS_F32:
  130. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_sqrt));
  131. OS_F64:
  132. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_sqrt));
  133. else
  134. internalerror(2021092901);
  135. end;
  136. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  137. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  138. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  139. end;
  140. procedure twasminlinenode.second_trunc_real;
  141. begin
  142. secondpass(left);
  143. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  144. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  145. case left.location.size of
  146. OS_F32:
  147. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f32_s));
  148. OS_F64:
  149. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f64_s));
  150. else
  151. internalerror(2021092904);
  152. end;
  153. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  154. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  155. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  156. end;
  157. procedure twasminlinenode.second_round_real;
  158. begin
  159. secondpass(left);
  160. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  161. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  162. case left.location.size of
  163. OS_F32:
  164. begin
  165. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_nearest));
  166. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f32_s));
  167. end;
  168. OS_F64:
  169. begin
  170. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_nearest));
  171. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f64_s));
  172. end
  173. else
  174. internalerror(2021092905);
  175. end;
  176. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  177. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  178. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  179. end;
  180. procedure twasminlinenode.second_high;
  181. var
  182. hightype: TWasmBasicType;
  183. begin
  184. secondpass(left);
  185. if not(is_dynamic_array(left.resultdef)) then
  186. Internalerror(2019122801);
  187. { determine the WasmBasicType of the result }
  188. if is_64bit(resultdef) then
  189. hightype:=wbt_i64
  190. else
  191. hightype:=wbt_i32;
  192. { length in dynamic arrays is at offset -sizeof(pint) }
  193. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  194. { 64-bit pointer values need a <>0 comparison to produce a 32-bit int on the stack (0 or 1) for the 'if' instruction.
  195. 32-bit pointer values don't need it, because 'if' already expects and pops a 32-bit int and checks for <>0. }
  196. if is_64bit(left.resultdef) then
  197. begin
  198. thlcgwasm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,left.resultdef,0,R_INTREGISTER);
  199. thlcgwasm(hlcg).a_cmp_stack_stack(current_asmdata.CurrAsmList,left.resultdef,OC_NE);
  200. end;
  201. { if not nil }
  202. current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[hightype])));
  203. thlcgwasm(hlcg).incblock;
  204. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  205. { volatility of the dyn. array refers to the volatility of the
  206. string pointer, not of the string data }
  207. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  208. { length in dynamic arrays is at offset -ossinttype.size }
  209. thlcgwasm(hlcg).a_op_const_stack(current_asmdata.CurrAsmList,OP_SUB,left.resultdef,ossinttype.size);
  210. { load length }
  211. if ossinttype.size=8 then
  212. current_asmdata.CurrAsmList.Concat(taicpu.op_const(a_i64_load,0))
  213. else
  214. current_asmdata.CurrAsmList.Concat(taicpu.op_const(a_i32_load,0));
  215. { else }
  216. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_else));
  217. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  218. { high=-1 }
  219. thlcgwasm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,resultdef,-1,R_INTREGISTER);
  220. { endif }
  221. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_end_if));
  222. thlcgwasm(hlcg).decblock;
  223. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  224. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  225. if location.size in [OS_64,OS_S64] then
  226. begin
  227. location.register64.reglo := cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  228. location.register64.reghi := cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  229. end
  230. else
  231. {$endif}
  232. location.register := hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  233. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  234. end;
  235. procedure twasminlinenode.second_memory_size;
  236. begin
  237. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_size));
  238. thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  239. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  240. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  241. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  242. end;
  243. procedure twasminlinenode.second_memory_grow;
  244. begin
  245. secondpass(left);
  246. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  247. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,left.resultdef,left.location.register);
  248. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_grow));
  249. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  250. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  251. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  252. end;
  253. procedure twasminlinenode.second_memory_fill;
  254. begin
  255. location_reset(location,LOC_VOID,OS_NO);
  256. secondpass(tcallparanode(tcallparanode(tcallparanode(left).right).right).left);
  257. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  258. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location,
  259. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  260. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,false);
  261. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  262. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  263. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location.register);
  264. secondpass(tcallparanode(tcallparanode(left).right).left);
  265. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  266. tcallparanode(tcallparanode(left).right).left.location,
  267. tcallparanode(tcallparanode(left).right).left.resultdef,
  268. tcallparanode(tcallparanode(left).right).left.resultdef,false);
  269. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  270. tcallparanode(tcallparanode(left).right).left.resultdef,
  271. tcallparanode(tcallparanode(left).right).left.location.register);
  272. secondpass(tcallparanode(left).left);
  273. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  274. tcallparanode(left).left.location,
  275. tcallparanode(left).left.resultdef,
  276. tcallparanode(left).left.resultdef,false);
  277. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  278. tcallparanode(left).left.resultdef,
  279. tcallparanode(left).left.location.register);
  280. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_fill));
  281. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,3);
  282. end;
  283. procedure twasminlinenode.second_memory_copy;
  284. begin
  285. location_reset(location,LOC_VOID,OS_NO);
  286. secondpass(tcallparanode(tcallparanode(tcallparanode(left).right).right).left);
  287. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  288. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location,
  289. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  290. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,false);
  291. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  292. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  293. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location.register);
  294. secondpass(tcallparanode(tcallparanode(left).right).left);
  295. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  296. tcallparanode(tcallparanode(left).right).left.location,
  297. tcallparanode(tcallparanode(left).right).left.resultdef,
  298. tcallparanode(tcallparanode(left).right).left.resultdef,false);
  299. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  300. tcallparanode(tcallparanode(left).right).left.resultdef,
  301. tcallparanode(tcallparanode(left).right).left.location.register);
  302. secondpass(tcallparanode(left).left);
  303. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  304. tcallparanode(left).left.location,
  305. tcallparanode(left).left.resultdef,
  306. tcallparanode(left).left.resultdef,false);
  307. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  308. tcallparanode(left).left.resultdef,
  309. tcallparanode(left).left.location.register);
  310. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_copy));
  311. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,3);
  312. end;
  313. procedure twasminlinenode.second_unreachable;
  314. begin
  315. location_reset(location,LOC_VOID,OS_NO);
  316. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_unreachable));
  317. end;
  318. procedure twasminlinenode.second_throw_fpcexception;
  319. begin
  320. location_reset(location,LOC_VOID,OS_NO);
  321. current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
  322. end;
  323. function twasminlinenode.first_sqr_real: tnode;
  324. begin
  325. expectloc:=LOC_FPUREGISTER;
  326. first_sqr_real:=nil;
  327. end;
  328. function twasminlinenode.pass_typecheck_cpu: tnode;
  329. begin
  330. Result:=nil;
  331. case inlinenumber of
  332. in_wasm32_memory_size:
  333. begin
  334. CheckParameters(0);
  335. resultdef:=u32inttype;
  336. end;
  337. in_wasm32_memory_grow:
  338. begin
  339. CheckParameters(1);
  340. resultdef:=u32inttype;
  341. end;
  342. in_wasm32_unreachable:
  343. begin
  344. CheckParameters(0);
  345. resultdef:=voidtype;
  346. end;
  347. in_wasm32_throw_fpcexception:
  348. begin
  349. CheckParameters(0);
  350. resultdef:=voidtype;
  351. end;
  352. in_wasm32_memory_fill:
  353. begin
  354. CheckParameters(3);
  355. resultdef:=voidtype;
  356. end;
  357. in_wasm32_memory_copy:
  358. begin
  359. CheckParameters(3);
  360. resultdef:=voidtype;
  361. end;
  362. else
  363. Result:=inherited pass_typecheck_cpu;
  364. end;
  365. end;
  366. function twasminlinenode.first_cpu: tnode;
  367. begin
  368. Result:=nil;
  369. case inlinenumber of
  370. in_wasm32_memory_size,
  371. in_wasm32_memory_grow:
  372. expectloc:=LOC_REGISTER;
  373. in_wasm32_memory_fill,
  374. in_wasm32_memory_copy,
  375. in_wasm32_unreachable,
  376. in_wasm32_throw_fpcexception:
  377. expectloc:=LOC_VOID;
  378. else
  379. Result:=inherited first_cpu;
  380. end;
  381. end;
  382. procedure twasminlinenode.pass_generate_code_cpu;
  383. begin
  384. case inlinenumber of
  385. in_wasm32_memory_size:
  386. second_memory_size;
  387. in_wasm32_memory_grow:
  388. second_memory_grow;
  389. in_wasm32_memory_fill:
  390. second_memory_fill;
  391. in_wasm32_memory_copy:
  392. second_memory_copy;
  393. in_wasm32_unreachable:
  394. second_unreachable;
  395. in_wasm32_throw_fpcexception:
  396. second_throw_fpcexception;
  397. else
  398. inherited pass_generate_code_cpu;
  399. end;
  400. end;
  401. procedure twasminlinenode.second_length;
  402. var
  403. lendef : tdef;
  404. href : treference;
  405. extra_slots: LongInt;
  406. begin
  407. secondpass(left);
  408. if is_shortstring(left.resultdef) then
  409. begin
  410. location_copy(location,left.location);
  411. location.size:=OS_8;
  412. end
  413. else
  414. begin
  415. { length in ansi/wide strings and high in dynamic arrays is at offset -sizeof(pint) }
  416. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  417. thlcgwasm(hlcg).a_cmp_const_reg_stack(current_asmdata.CurrAsmList,left.resultdef,OC_EQ,0,left.location.register);
  418. current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i32])));
  419. thlcgwasm(hlcg).incblock;
  420. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  421. current_asmdata.CurrAsmList.Concat(taicpu.op_const(a_i32_const,0));
  422. thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  423. current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_else) );
  424. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  425. { the length of a widestring is a 32 bit unsigned int. Since every
  426. character occupies 2 bytes, on a 32 bit platform you can express
  427. the maximum length using 31 bits. On a 64 bit platform, it may be
  428. 32 bits. This means that regardless of the platform, a location
  429. with size OS_SINT/ossinttype can hold the length without
  430. overflowing (this code returns an ossinttype value) }
  431. if is_widestring(left.resultdef) then
  432. lendef:=u32inttype
  433. else
  434. lendef:=ossinttype;
  435. { volatility of the ansistring/widestring refers to the volatility of the
  436. string pointer, not of the string data }
  437. hlcg.reference_reset_base(href,left.resultdef,left.location.register,-lendef.size,ctempposinvalid,lendef.alignment,[]);
  438. extra_slots:=thlcgwasm(hlcg).prepare_stack_for_ref(current_asmdata.CurrAsmList,href,false);
  439. thlcgwasm(hlcg).a_load_ref_stack(current_asmdata.CurrAsmList,lendef,href,extra_slots);
  440. if is_widestring(left.resultdef) then
  441. thlcgwasm(hlcg).a_op_const_stack(current_asmdata.CurrAsmList,OP_SHR,resultdef,1);
  442. { Dynamic arrays do not have their length attached but their maximum index }
  443. if is_dynamic_array(left.resultdef) then
  444. thlcgwasm(hlcg).a_op_const_stack(current_asmdata.CurrAsmList,OP_ADD,resultdef,1);
  445. current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_end_if) );
  446. thlcgwasm(hlcg).decblock;
  447. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  448. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  449. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  450. end;
  451. end;
  452. procedure twasminlinenode.second_sqr_real;
  453. begin
  454. secondpass(left);
  455. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  456. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  457. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  458. case left.location.size of
  459. OS_F32:
  460. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_mul));
  461. OS_F64:
  462. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_mul));
  463. else
  464. internalerror(2021060102);
  465. end;
  466. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  467. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  468. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  469. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  470. end;
  471. begin
  472. cinlinenode:=twasminlinenode;
  473. end.