nwasminl.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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).decstack(current_asmdata.CurrAsmList,1);
  204. { volatility of the dyn. array refers to the volatility of the
  205. string pointer, not of the string data }
  206. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  207. { length in dynamic arrays is at offset -ossinttype.size }
  208. thlcgwasm(hlcg).a_op_const_stack(current_asmdata.CurrAsmList,OP_SUB,left.resultdef,ossinttype.size);
  209. { load length }
  210. if ossinttype.size=8 then
  211. current_asmdata.CurrAsmList.Concat(taicpu.op_const(a_i64_load,0))
  212. else
  213. current_asmdata.CurrAsmList.Concat(taicpu.op_const(a_i32_load,0));
  214. { else }
  215. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_else));
  216. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  217. { high=-1 }
  218. thlcgwasm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,resultdef,-1,R_INTREGISTER);
  219. { endif }
  220. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_end_if));
  221. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  222. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  223. if location.size in [OS_64,OS_S64] then
  224. begin
  225. location.register64.reglo := cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  226. location.register64.reghi := cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  227. end
  228. else
  229. {$endif}
  230. location.register := hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  231. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  232. end;
  233. procedure twasminlinenode.second_memory_size;
  234. begin
  235. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_size));
  236. thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  237. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  238. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  239. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  240. end;
  241. procedure twasminlinenode.second_memory_grow;
  242. begin
  243. secondpass(left);
  244. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  245. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,left.resultdef,left.location.register);
  246. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_grow));
  247. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  248. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  249. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  250. end;
  251. procedure twasminlinenode.second_memory_fill;
  252. begin
  253. location_reset(location,LOC_VOID,OS_NO);
  254. secondpass(tcallparanode(tcallparanode(tcallparanode(left).right).right).left);
  255. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  256. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location,
  257. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  258. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,false);
  259. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  260. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  261. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location.register);
  262. secondpass(tcallparanode(tcallparanode(left).right).left);
  263. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  264. tcallparanode(tcallparanode(left).right).left.location,
  265. tcallparanode(tcallparanode(left).right).left.resultdef,
  266. tcallparanode(tcallparanode(left).right).left.resultdef,false);
  267. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  268. tcallparanode(tcallparanode(left).right).left.resultdef,
  269. tcallparanode(tcallparanode(left).right).left.location.register);
  270. secondpass(tcallparanode(left).left);
  271. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  272. tcallparanode(left).left.location,
  273. tcallparanode(left).left.resultdef,
  274. tcallparanode(left).left.resultdef,false);
  275. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  276. tcallparanode(left).left.resultdef,
  277. tcallparanode(left).left.location.register);
  278. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_fill));
  279. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,3);
  280. end;
  281. procedure twasminlinenode.second_memory_copy;
  282. begin
  283. location_reset(location,LOC_VOID,OS_NO);
  284. secondpass(tcallparanode(tcallparanode(tcallparanode(left).right).right).left);
  285. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  286. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location,
  287. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  288. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,false);
  289. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  290. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.resultdef,
  291. tcallparanode(tcallparanode(tcallparanode(left).right).right).left.location.register);
  292. secondpass(tcallparanode(tcallparanode(left).right).left);
  293. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  294. tcallparanode(tcallparanode(left).right).left.location,
  295. tcallparanode(tcallparanode(left).right).left.resultdef,
  296. tcallparanode(tcallparanode(left).right).left.resultdef,false);
  297. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  298. tcallparanode(tcallparanode(left).right).left.resultdef,
  299. tcallparanode(tcallparanode(left).right).left.location.register);
  300. secondpass(tcallparanode(left).left);
  301. hlcg.location_force_reg(current_asmdata.CurrAsmList,
  302. tcallparanode(left).left.location,
  303. tcallparanode(left).left.resultdef,
  304. tcallparanode(left).left.resultdef,false);
  305. thlcgwasm(hlcg).a_load_reg_stack(current_asmdata.CurrAsmList,
  306. tcallparanode(left).left.resultdef,
  307. tcallparanode(left).left.location.register);
  308. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_memory_copy));
  309. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,3);
  310. end;
  311. procedure twasminlinenode.second_unreachable;
  312. begin
  313. location_reset(location,LOC_VOID,OS_NO);
  314. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_unreachable));
  315. end;
  316. procedure twasminlinenode.second_throw_fpcexception;
  317. begin
  318. location_reset(location,LOC_VOID,OS_NO);
  319. current_asmdata.CurrAsmList.Concat(taicpu.op_sym(a_throw,current_asmdata.WeakRefAsmSymbol(FPC_EXCEPTION_TAG_SYM,AT_WASM_EXCEPTION_TAG)));
  320. end;
  321. function twasminlinenode.first_sqr_real: tnode;
  322. begin
  323. expectloc:=LOC_FPUREGISTER;
  324. first_sqr_real:=nil;
  325. end;
  326. function twasminlinenode.pass_typecheck_cpu: tnode;
  327. begin
  328. Result:=nil;
  329. case inlinenumber of
  330. in_wasm32_memory_size:
  331. begin
  332. CheckParameters(0);
  333. resultdef:=u32inttype;
  334. end;
  335. in_wasm32_memory_grow:
  336. begin
  337. CheckParameters(1);
  338. resultdef:=u32inttype;
  339. end;
  340. in_wasm32_unreachable:
  341. begin
  342. CheckParameters(0);
  343. resultdef:=voidtype;
  344. end;
  345. in_wasm32_throw_fpcexception:
  346. begin
  347. CheckParameters(0);
  348. resultdef:=voidtype;
  349. end;
  350. in_wasm32_memory_fill:
  351. begin
  352. CheckParameters(3);
  353. resultdef:=voidtype;
  354. end;
  355. in_wasm32_memory_copy:
  356. begin
  357. CheckParameters(3);
  358. resultdef:=voidtype;
  359. end;
  360. else
  361. Result:=inherited pass_typecheck_cpu;
  362. end;
  363. end;
  364. function twasminlinenode.first_cpu: tnode;
  365. begin
  366. Result:=nil;
  367. case inlinenumber of
  368. in_wasm32_memory_size,
  369. in_wasm32_memory_grow:
  370. expectloc:=LOC_REGISTER;
  371. in_wasm32_memory_fill,
  372. in_wasm32_memory_copy,
  373. in_wasm32_unreachable,
  374. in_wasm32_throw_fpcexception:
  375. expectloc:=LOC_VOID;
  376. else
  377. Result:=inherited first_cpu;
  378. end;
  379. end;
  380. procedure twasminlinenode.pass_generate_code_cpu;
  381. begin
  382. case inlinenumber of
  383. in_wasm32_memory_size:
  384. second_memory_size;
  385. in_wasm32_memory_grow:
  386. second_memory_grow;
  387. in_wasm32_memory_fill:
  388. second_memory_fill;
  389. in_wasm32_memory_copy:
  390. second_memory_copy;
  391. in_wasm32_unreachable:
  392. second_unreachable;
  393. in_wasm32_throw_fpcexception:
  394. second_throw_fpcexception;
  395. else
  396. inherited pass_generate_code_cpu;
  397. end;
  398. end;
  399. procedure twasminlinenode.second_length;
  400. var
  401. lendef : tdef;
  402. href : treference;
  403. extra_slots: LongInt;
  404. begin
  405. secondpass(left);
  406. if is_shortstring(left.resultdef) then
  407. begin
  408. location_copy(location,left.location);
  409. location.size:=OS_8;
  410. end
  411. else
  412. begin
  413. { length in ansi/wide strings and high in dynamic arrays is at offset -sizeof(pint) }
  414. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  415. thlcgwasm(hlcg).a_cmp_const_reg_stack(current_asmdata.CurrAsmList,left.resultdef,OC_EQ,0,left.location.register);
  416. current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i32])));
  417. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  418. current_asmdata.CurrAsmList.Concat(taicpu.op_const(a_i32_const,0));
  419. thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  420. current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_else) );
  421. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  422. { the length of a widestring is a 32 bit unsigned int. Since every
  423. character occupies 2 bytes, on a 32 bit platform you can express
  424. the maximum length using 31 bits. On a 64 bit platform, it may be
  425. 32 bits. This means that regardless of the platform, a location
  426. with size OS_SINT/ossinttype can hold the length without
  427. overflowing (this code returns an ossinttype value) }
  428. if is_widestring(left.resultdef) then
  429. lendef:=u32inttype
  430. else
  431. lendef:=ossinttype;
  432. { volatility of the ansistring/widestring refers to the volatility of the
  433. string pointer, not of the string data }
  434. hlcg.reference_reset_base(href,left.resultdef,left.location.register,-lendef.size,ctempposinvalid,lendef.alignment,[]);
  435. extra_slots:=thlcgwasm(hlcg).prepare_stack_for_ref(current_asmdata.CurrAsmList,href,false);
  436. thlcgwasm(hlcg).a_load_ref_stack(current_asmdata.CurrAsmList,lendef,href,extra_slots);
  437. if is_widestring(left.resultdef) then
  438. thlcgwasm(hlcg).a_op_const_stack(current_asmdata.CurrAsmList,OP_SHR,resultdef,1);
  439. { Dynamic arrays do not have their length attached but their maximum index }
  440. if is_dynamic_array(left.resultdef) then
  441. thlcgwasm(hlcg).a_op_const_stack(current_asmdata.CurrAsmList,OP_ADD,resultdef,1);
  442. current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_end_if) );
  443. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  444. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  445. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  446. end;
  447. end;
  448. procedure twasminlinenode.second_sqr_real;
  449. begin
  450. secondpass(left);
  451. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  452. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  453. thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  454. case left.location.size of
  455. OS_F32:
  456. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_mul));
  457. OS_F64:
  458. current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_mul));
  459. else
  460. internalerror(2021060102);
  461. end;
  462. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  463. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  464. location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
  465. thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
  466. end;
  467. begin
  468. cinlinenode:=twasminlinenode;
  469. end.