nwasminl.pas 22 KB

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