2
0

ncgset.pas 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Carl Eric Codere
  3. Generate generic assembler for in set/case labels
  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 ncgset;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,globals,constexp,symtype,
  22. node,nset,cpubase,cgbase,cgutils,cgobj,aasmbase,aasmtai,aasmdata;
  23. type
  24. tcgsetelementnode = class(tsetelementnode)
  25. procedure pass_generate_code;override;
  26. end;
  27. Tsetpart=record
  28. range : boolean; {Part is a range.}
  29. start,stop : byte; {Start/stop when range; Stop=element when an element.}
  30. end;
  31. Tsetparts=array[1..8] of Tsetpart;
  32. { tcginnode }
  33. tcginnode = class(tinnode)
  34. procedure in_smallset(opdef: tdef; setbase: aint); virtual;
  35. function pass_1: tnode;override;
  36. procedure pass_generate_code;override;
  37. protected
  38. function checkgenjumps(out setparts: Tsetparts; out numparts: byte; out use_small: boolean): boolean; virtual;
  39. function analizeset(const Aset:Tconstset;out setparts: Tsetparts; out numparts: byte;is_small:boolean):boolean;virtual;
  40. procedure in_reg_const(uopdef: tdef; opsize: tcgsize);virtual;
  41. end;
  42. tcgcasenode = class(tcasenode)
  43. {
  44. Emits the case node statement. Contrary to the intel
  45. 80x86 version, this version does not emit jump tables,
  46. because of portability problems.
  47. }
  48. procedure pass_generate_code;override;
  49. protected
  50. with_sign : boolean;
  51. opsize : tdef;
  52. jmp_gt,jmp_lt,jmp_le : topcmp;
  53. { register with case expression }
  54. hregister,hregister2 : tregister;
  55. endlabel,elselabel : tasmlabel;
  56. { true, if we can omit the range check of the jump table }
  57. jumptable_no_range : boolean;
  58. { has the implementation jumptable support }
  59. min_label : tconstexprint;
  60. function GetBranchLabel(Block: TNode; out _Label: TAsmLabel): Boolean;
  61. function blocklabel(id:longint):tasmlabel;
  62. procedure optimizevalues(var max_linear_list:int64;var max_dist:qword);virtual;
  63. function has_jumptable : boolean;virtual;
  64. procedure genjumptable(hp : pcaselabel;min_,max_ : int64); virtual;
  65. procedure genlinearlist(hp : pcaselabel); virtual;
  66. procedure genlinearcmplist(hp : pcaselabel); virtual;
  67. procedure genjmptreeentry(p : pcaselabel;parentvalue : TConstExprInt); virtual;
  68. procedure genjmptree(root : pcaselabel); virtual;
  69. end;
  70. implementation
  71. uses
  72. verbose,
  73. cutils,
  74. symconst,symdef,symsym,defutil,
  75. pass_2,tgobj,
  76. nbas,ncon,ncgflw,
  77. {$ifdef WASM}
  78. hlcgcpu,aasmcpu,
  79. {$endif WASM}
  80. ncgutil,hlcgobj;
  81. {*****************************************************************************
  82. TCGSETELEMENTNODE
  83. *****************************************************************************}
  84. procedure tcgsetelementnode.pass_generate_code;
  85. begin
  86. { load the set element's value }
  87. secondpass(left);
  88. { also a second value ? }
  89. if assigned(right) then
  90. internalerror(2015111106);
  91. { we don't modify the left side, we only check the location type; our
  92. parent node (an add-node) will use the resulting location to perform
  93. the set operation without creating an intermediate set }
  94. location_copy(location,left.location);
  95. end;
  96. {*****************************************************************************
  97. *****************************************************************************}
  98. function tcginnode.analizeset(const Aset:Tconstset; out setparts:tsetparts; out numparts: byte; is_small:boolean):boolean;
  99. var
  100. compares,maxcompares:word;
  101. i:byte;
  102. begin
  103. analizeset:=false;
  104. fillchar(setparts,sizeof(setparts),0);
  105. numparts:=0;
  106. compares:=0;
  107. { Lots of comparisions take a lot of time, so do not allow
  108. too much comparisions. 8 comparisions are, however, still
  109. smalller than emitting the set }
  110. if cs_opt_size in current_settings.optimizerswitches then
  111. maxcompares:=8
  112. else
  113. maxcompares:=5;
  114. { when smallset is possible allow only 3 compares the smallset
  115. code is for littlesize also smaller when more compares are used }
  116. if is_small then
  117. maxcompares:=3;
  118. for i:=0 to 255 do
  119. if i in Aset then
  120. begin
  121. if (numparts=0) or (i<>setparts[numparts].stop+1) then
  122. begin
  123. {Set element is a separate element.}
  124. inc(compares);
  125. if compares>maxcompares then
  126. exit;
  127. inc(numparts);
  128. setparts[numparts].range:=false;
  129. setparts[numparts].stop:=i;
  130. end
  131. else
  132. {Set element is part of a range.}
  133. if not setparts[numparts].range then
  134. begin
  135. {Transform an element into a range.}
  136. setparts[numparts].range:=true;
  137. setparts[numparts].start:=setparts[numparts].stop;
  138. setparts[numparts].stop:=i;
  139. { there's only one compare per range anymore. Only a }
  140. { sub is added, but that's much faster than a }
  141. { cmp/jcc combo so neglect its effect }
  142. { inc(compares);
  143. if compares>maxcompares then
  144. exit; }
  145. end
  146. else
  147. begin
  148. {Extend a range.}
  149. setparts[numparts].stop:=i;
  150. end;
  151. end;
  152. analizeset:=true;
  153. end;
  154. procedure tcginnode.in_reg_const(uopdef: tdef; opsize: tcgsize);
  155. var
  156. hr: tregister;
  157. begin
  158. { emit bit test operation -- warning: do not use
  159. location_force_reg() to force a set into a register, except
  160. to a register of the same size as the set. The reason is
  161. that on big endian systems, this would require moving the
  162. set to the most significant part of the new register,
  163. and location_force_register can't do that (it does not
  164. know the type).
  165. a_bit_test_reg_loc_reg() properly takes into account the
  166. size of the set to adjust the register index to test }
  167. hlcg.a_bit_test_reg_loc_reg(current_asmdata.CurrAsmList,
  168. uopdef, right.resultdef, uopdef,
  169. left.location.register, right.location, location.register);
  170. { this may have resulted in an undefined value if left.location.register
  171. was >= size of right.location, but we'll mask the value to zero below
  172. in that case -> okay }
  173. hlcg.g_undefined_ok(current_asmdata.CurrAsmList,uopdef,location.register);
  174. { now zero the result if left > nr_of_bits_in_right_register }
  175. hr := hlcg.getintregister(current_asmdata.CurrAsmList, uopdef);
  176. { if left > tcgsize2size[opsize]*8 then hr := 0 else hr := $ffffffff }
  177. { (left.location.size = location.size at this point) }
  178. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SUB, uopdef,
  179. tcgsize2size[opsize]*8, left.location.register, hr);
  180. hlcg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SAR, uopdef, (tcgsize2size
  181. [opsize]*8)-1, hr);
  182. { if left > tcgsize2size[opsize]*8-1, then result := 0 else result := result of bit test }
  183. hlcg.a_op_reg_reg(current_asmdata.CurrAsmList, OP_AND, uopdef, hr,
  184. location.register);
  185. end;
  186. procedure tcginnode.in_smallset(opdef: tdef; setbase: aint);
  187. begin
  188. { location is always LOC_REGISTER }
  189. location_reset(location, LOC_REGISTER, def_cgsize(resultdef));
  190. { allocate a register for the result }
  191. location.register := hlcg.getintregister(current_asmdata.CurrAsmList, resultdef);
  192. {**************************** SMALL SET **********************}
  193. if left.location.loc=LOC_CONSTANT then
  194. begin
  195. hlcg.a_bit_test_const_loc_reg(current_asmdata.CurrAsmList,
  196. right.resultdef, resultdef,
  197. left.location.value-setbase, right.location,
  198. location.register);
  199. end
  200. else
  201. begin
  202. hlcg.location_force_reg(current_asmdata.CurrAsmList, left.location,
  203. left.resultdef, opdef, true);
  204. register_maybe_adjust_setbase(current_asmdata.CurrAsmList, opdef, left.location,
  205. setbase);
  206. hlcg.a_bit_test_reg_loc_reg(current_asmdata.CurrAsmList, opdef,
  207. right.resultdef, resultdef, left.location.register, right.location,
  208. location.register);
  209. end;
  210. end;
  211. function tcginnode.checkgenjumps(out setparts: Tsetparts; out numparts: byte;out use_small: boolean): boolean;
  212. begin
  213. { check if we can use smallset operation using btl which is limited
  214. to 32 bits, the left side may also not contain higher values !! }
  215. use_small:=is_smallset(right.resultdef) and
  216. not is_signed(left.resultdef) and
  217. ((left.resultdef.typ=orddef) and (torddef(left.resultdef).high<32) or
  218. (left.resultdef.typ=enumdef) and (tenumdef(left.resultdef).max<32));
  219. { Can we generate jumps? Possible for all types of sets }
  220. checkgenjumps:=(right.nodetype=setconstn) and
  221. analizeset(Tsetconstnode(right).value_set^,setparts,numparts,use_small);
  222. end;
  223. function tcginnode.pass_1: tnode;
  224. var
  225. setparts: Tsetparts;
  226. numparts: byte;
  227. use_small: boolean;
  228. begin
  229. result := inherited pass_1;
  230. if not(assigned(result)) and
  231. checkgenjumps(setparts,numparts,use_small) then
  232. expectloc := LOC_JUMP;
  233. end;
  234. procedure tcginnode.pass_generate_code;
  235. var
  236. adjustment,
  237. setbase : {$ifdef CPU8BITALU}smallint{$else}aint{$endif};
  238. l, l2 : tasmlabel;
  239. hr,
  240. pleftreg : tregister;
  241. setparts : Tsetparts;
  242. opsize : tcgsize;
  243. opdef : tdef;
  244. uopsize : tcgsize;
  245. uopdef : tdef;
  246. orgopsize : tcgsize;
  247. genjumps,
  248. use_small : boolean;
  249. i,numparts : byte;
  250. needslabel : Boolean;
  251. begin
  252. l2:=nil;
  253. { We check first if we can generate jumps, this can be done
  254. because the resultdef is already set in firstpass }
  255. genjumps := checkgenjumps(setparts,numparts,use_small);
  256. orgopsize := def_cgsize(left.resultdef);
  257. {$if defined(cpu8bitalu)}
  258. if (tsetdef(right.resultdef).setbase>=-128) and
  259. (tsetdef(right.resultdef).setmax-tsetdef(right.resultdef).setbase+1<=256) then
  260. begin
  261. uopsize := OS_8;
  262. uopdef := u8inttype;
  263. if is_signed(left.resultdef) then
  264. begin
  265. opsize := OS_S8;
  266. opdef := s8inttype;
  267. end
  268. else
  269. begin
  270. opsize := uopsize;
  271. opdef := uopdef;
  272. end;
  273. end
  274. {$endif defined(cpu8bitalu)}
  275. {$if defined(cpu8bitalu)}
  276. { this should be also enabled for 16 bit CPUs, however, I have no proper testing facility for 16 bit, my
  277. testing results using Dosbox are no reliable }
  278. { $if defined(cpu8bitalu) or defined(cpu16bitalu)}
  279. else if (tsetdef(right.resultdef).setbase>=-32768) and
  280. (tsetdef(right.resultdef).setmax-tsetdef(right.resultdef).setbase+1<=65536) then
  281. begin
  282. uopsize := OS_16;
  283. uopdef := u16inttype;
  284. if is_signed(left.resultdef) then
  285. begin
  286. opsize := OS_S16;
  287. opdef := s16inttype;
  288. end
  289. else
  290. begin
  291. opsize := uopsize;
  292. opdef := uopdef;
  293. end;
  294. end
  295. else
  296. {$endif defined(cpu8bitalu)}
  297. begin
  298. uopsize := OS_32;
  299. uopdef := u32inttype;
  300. if is_signed(left.resultdef) then
  301. begin
  302. opsize := OS_S32;
  303. opdef := s32inttype;
  304. end
  305. else
  306. begin
  307. opsize := uopsize;
  308. opdef := uopdef;
  309. end;
  310. end;
  311. needslabel := false;
  312. if not genjumps then
  313. { calculate both operators }
  314. { the complex one first }
  315. { not in case of genjumps, because then we don't secondpass }
  316. { right at all (so we have to make sure that "right" really is }
  317. { "right" and not "swapped left" in that case) }
  318. firstcomplex(self);
  319. secondpass(left);
  320. if (left.expectloc=LOC_JUMP)<>
  321. (left.location.loc=LOC_JUMP) then
  322. internalerror(2007070101);
  323. { Only process the right if we are not generating jumps }
  324. if not genjumps then
  325. secondpass(right);
  326. if codegenerror then
  327. exit;
  328. { ofcourse not commutative }
  329. if nf_swapped in flags then
  330. swapleftright;
  331. setbase:=tsetdef(right.resultdef).setbase;
  332. if genjumps then
  333. begin
  334. { location is always LOC_JUMP }
  335. current_asmdata.getjumplabel(l);
  336. current_asmdata.getjumplabel(l2);
  337. location_reset_jump(location,l,l2);
  338. { If register is used, use only lower 8 bits }
  339. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,opdef,false);
  340. pleftreg := left.location.register;
  341. { how much have we already substracted from the x in the }
  342. { "x in [y..z]" expression }
  343. adjustment := 0;
  344. hr:=NR_NO;
  345. for i:=1 to numparts do
  346. if setparts[i].range then
  347. { use fact that a <= x <= b <=> aword(x-a) <= aword(b-a) }
  348. begin
  349. { is the range different from all legal values? }
  350. if (setparts[i].stop-setparts[i].start <> 255) or not (orgopsize = OS_8) then
  351. begin
  352. { yes, is the lower bound <> 0? }
  353. if (setparts[i].start <> 0) then
  354. { we're going to substract from the left register, }
  355. { so in case of a LOC_CREGISTER first move the value }
  356. { to edi (not done before because now we can do the }
  357. { move and substract in one instruction with LEA) }
  358. if (left.location.loc = LOC_CREGISTER) and
  359. (hr<>pleftreg) then
  360. begin
  361. { don't change this back to a_op_const_reg/a_load_reg_reg, since pleftreg must not be modified }
  362. hr:=hlcg.getintregister(current_asmdata.CurrAsmList,opdef);
  363. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,opdef,setparts[i].start,pleftreg,hr);
  364. pleftreg:=hr;
  365. end
  366. else
  367. begin
  368. { otherwise, the value is already in a register }
  369. { that can be modified }
  370. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opdef,
  371. setparts[i].start-adjustment,pleftreg)
  372. end;
  373. { new total value substracted from x: }
  374. { adjustment + (setparts[i].start - adjustment) }
  375. adjustment := setparts[i].start;
  376. { check if result < b-a+1 (not "result <= b-a", since }
  377. { we need a carry in case the element is in the range }
  378. { (this will never overflow since we check at the }
  379. { beginning whether stop-start <> 255) }
  380. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, uopdef, OC_B,
  381. setparts[i].stop-setparts[i].start+1,pleftreg,location.truelabel);
  382. end
  383. else
  384. { if setparts[i].start = 0 and setparts[i].stop = 255, }
  385. { it's always true since "in" is only allowed for bytes }
  386. begin
  387. hlcg.a_jmp_always(current_asmdata.CurrAsmList,location.truelabel);
  388. end;
  389. end
  390. else
  391. begin
  392. { Emit code to check if left is an element }
  393. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opdef, OC_EQ,
  394. setparts[i].stop-adjustment,pleftreg,location.truelabel);
  395. end;
  396. { To compensate for not doing a second pass }
  397. right.location.reference.symbol:=nil;
  398. hlcg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  399. end
  400. else
  401. {*****************************************************************}
  402. { NO JUMP TABLE GENERATION }
  403. {*****************************************************************}
  404. begin
  405. { We will now generated code to check the set itself, no jmps,
  406. handle smallsets separate, because it allows faster checks }
  407. if use_small then
  408. begin
  409. in_smallset(opdef, setbase);
  410. end
  411. else
  412. {************************** NOT SMALL SET ********************}
  413. begin
  414. { location is always LOC_REGISTER }
  415. location_reset(location, LOC_REGISTER, uopsize{def_cgsize(resultdef)});
  416. { allocate a register for the result }
  417. location.register := hlcg.getintregister(current_asmdata.CurrAsmList, uopdef);
  418. if (right.location.loc=LOC_CONSTANT) and
  419. (opsize < OS_S8) and { = if unsigned }
  420. (((left.resultdef.typ=orddef) and
  421. (torddef(left.resultdef).low >= int64(tsetdef(right.resultdef).setbase))) or
  422. ((left.resultdef.typ=enumdef) and
  423. (tenumdef(left.resultdef).min >= aint(tsetdef(right.resultdef).setbase)))) then
  424. begin
  425. { can it actually occur currently? CEC }
  426. { yes: "if bytevar in [1,3,5,7,9,11,13,15]" (JM) }
  427. { note: this code assumes that left in [0..255], which is a valid }
  428. { assumption (other cases will be caught by range checking) (JM) }
  429. { load left in register }
  430. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,uopdef,true);
  431. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,uopdef,left.location,setbase);
  432. in_reg_const(uopdef, opsize);
  433. end { of right.location.loc=LOC_CONSTANT }
  434. { do search in a normal set which could have >32 elements
  435. but also used if the left side contains higher values > 32 }
  436. else if (left.location.loc=LOC_CONSTANT) then
  437. begin
  438. if (left.location.value < setbase) or (((left.location.value-setbase) shr 3) >= right.resultdef.size) then
  439. {should be caught earlier }
  440. internalerror(2007020402);
  441. hlcg.a_bit_test_const_loc_reg(current_asmdata.CurrAsmList,right.resultdef,uopdef,left.location.value-setbase,
  442. right.location,location.register);
  443. end
  444. else
  445. begin
  446. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,opdef,true);
  447. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,opdef,left.location,setbase);
  448. pleftreg := left.location.register;
  449. if (opsize >= OS_S8) or { = if signed }
  450. ((left.resultdef.typ=orddef) and
  451. ((torddef(left.resultdef).low < int64(tsetdef(right.resultdef).setbase)) or
  452. (torddef(left.resultdef).high > int64(tsetdef(right.resultdef).setmax)))) or
  453. ((left.resultdef.typ=enumdef) and
  454. ((tenumdef(left.resultdef).min < aint(tsetdef(right.resultdef).setbase)) or
  455. (tenumdef(left.resultdef).max > aint(tsetdef(right.resultdef).setmax)))) then
  456. begin
  457. {$ifdef WASM}
  458. needslabel := True;
  459. thlcgwasm(hlcg).a_cmp_const_reg_stack(current_asmdata.CurrAsmList, opdef, OC_A, tsetdef(right.resultdef).setmax-tsetdef(right.resultdef).setbase, pleftreg);
  460. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_if));
  461. thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  462. hlcg.a_load_const_reg(current_asmdata.CurrAsmList, uopdef, 0, location.register);
  463. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_else));
  464. {$else WASM}
  465. current_asmdata.getjumplabel(l);
  466. current_asmdata.getjumplabel(l2);
  467. needslabel := True;
  468. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opdef, OC_BE, tsetdef(right.resultdef).setmax-tsetdef(right.resultdef).setbase, pleftreg, l);
  469. hlcg.a_load_const_reg(current_asmdata.CurrAsmList, uopdef, 0, location.register);
  470. hlcg.a_jmp_always(current_asmdata.CurrAsmList, l2);
  471. hlcg.a_label(current_asmdata.CurrAsmList, l);
  472. {$endif WASM}
  473. end;
  474. hlcg.a_bit_test_reg_loc_reg(current_asmdata.CurrAsmList,opdef,right.resultdef,uopdef,
  475. pleftreg,right.location,location.register);
  476. if needslabel then
  477. begin
  478. {$ifdef WASM}
  479. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_if));
  480. {$else WASM}
  481. hlcg.a_label(current_asmdata.CurrAsmList, l2);
  482. {$endif WASM}
  483. end
  484. end;
  485. {$ifndef cpuhighleveltarget}
  486. location.size := def_cgsize(resultdef);
  487. location.register := cg.makeregsize(current_asmdata.CurrAsmList, location.register, location.size);
  488. {$else not cpuhighleveltarget}
  489. hr:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  490. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,uopdef,resultdef,location.register,hr);
  491. location.register:=hr;
  492. location.size := def_cgsize(resultdef);
  493. {$endif not cpuhighleveltarget}
  494. end;
  495. end;
  496. location_freetemp(current_asmdata.CurrAsmList, right.location);
  497. end;
  498. {*****************************************************************************
  499. TCGCASENODE
  500. *****************************************************************************}
  501. { Analyse the nodes following the else label - if empty, change to end label }
  502. function tcgcasenode.GetBranchLabel(Block: TNode; out _Label: TAsmLabel): Boolean;
  503. var
  504. LabelSym: TLabelSym;
  505. begin
  506. Result := True;
  507. if not Assigned(Block) then
  508. begin
  509. { Block doesn't exist / is empty }
  510. _Label := endlabel;
  511. Exit;
  512. end;
  513. { These optimisations aren't particularly debugger friendly }
  514. if not (cs_opt_level2 in current_settings.optimizerswitches) then
  515. begin
  516. Result := False;
  517. current_asmdata.getjumplabel(_Label);
  518. Exit;
  519. end;
  520. while Assigned(Block) do
  521. begin
  522. case Block.nodetype of
  523. nothingn:
  524. begin
  525. _Label := endlabel;
  526. Exit;
  527. end;
  528. goton:
  529. begin
  530. LabelSym := TCGGotoNode(Block).labelsym;
  531. if not Assigned(LabelSym) then
  532. InternalError(2018121131);
  533. _Label := TCGLabelNode(TCGGotoNode(Block).labelnode).getasmlabel;
  534. if Assigned(_Label) then
  535. { Keep tabs on the fact that an actual 'goto' was used }
  536. Include(flowcontrol,fc_gotolabel)
  537. else
  538. Break;
  539. Exit;
  540. end;
  541. blockn:
  542. begin
  543. Block := TBlockNode(Block).Left;
  544. Continue;
  545. end;
  546. statementn:
  547. begin
  548. { If the right node is assigned, then it's a compound block
  549. that can't be simplified, so fall through, set Result to
  550. False and make a new label }
  551. if Assigned(TStatementNode(Block).right) then
  552. Break;
  553. Block := TStatementNode(Block).Left;
  554. Continue;
  555. end;
  556. else
  557. ;
  558. end;
  559. Break;
  560. end;
  561. { Create unique label }
  562. Result := False;
  563. current_asmdata.getjumplabel(_Label);
  564. end;
  565. function tcgcasenode.blocklabel(id:longint):tasmlabel;
  566. begin
  567. if not assigned(blocks[id]) then
  568. internalerror(200411301);
  569. result:=pcaseblock(blocks[id])^.blocklabel;
  570. end;
  571. procedure tcgcasenode.optimizevalues(var max_linear_list:int64;var max_dist:qword);
  572. begin
  573. { no changes by default }
  574. end;
  575. function tcgcasenode.has_jumptable : boolean;
  576. begin
  577. { No jumptable support in the default implementation }
  578. has_jumptable:=false;
  579. end;
  580. procedure tcgcasenode.genjumptable(hp : pcaselabel;min_,max_ : int64);
  581. begin
  582. internalerror(200209161);
  583. end;
  584. procedure tcgcasenode.genlinearlist(hp : pcaselabel);
  585. var
  586. first : boolean;
  587. last : TConstExprInt;
  588. scratch_reg: tregister;
  589. newsize: tcgsize;
  590. newdef: tdef;
  591. procedure gensub(value:tcgint);
  592. begin
  593. { here, since the sub and cmp are separate we need
  594. to move the result before subtract to help
  595. the register allocator
  596. }
  597. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList, opsize, opsize, hregister, scratch_reg);
  598. hlcg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, value, hregister);
  599. end;
  600. procedure genitem(t : pcaselabel);
  601. begin
  602. if assigned(t^.less) then
  603. genitem(t^.less);
  604. { do we need to test the first value? }
  605. if first and (t^._low>get_min_value(left.resultdef)) then
  606. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,tcgint(t^._low.svalue),hregister,elselabel);
  607. if t^._low=t^._high then
  608. begin
  609. if t^._low-last=0 then
  610. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_EQ,0,hregister,blocklabel(t^.blockid))
  611. else
  612. begin
  613. gensub(tcgint(t^._low.svalue-last.svalue));
  614. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,
  615. OC_EQ,tcgint(t^._low.svalue-last.svalue),scratch_reg,blocklabel(t^.blockid));
  616. end;
  617. last:=t^._low;
  618. end
  619. else
  620. begin
  621. { it begins with the smallest label, if the value }
  622. { is even smaller then jump immediately to the }
  623. { ELSE-label }
  624. if first then
  625. begin
  626. { have we to ajust the first value ? }
  627. if (t^._low>get_min_value(left.resultdef)) or (get_min_value(left.resultdef)<>0) then
  628. gensub(tcgint(t^._low.svalue));
  629. end
  630. else
  631. begin
  632. { if there is no unused label between the last and the }
  633. { present label then the lower limit can be checked }
  634. { immediately. else check the range in between: }
  635. gensub(tcgint(t^._low.svalue-last.svalue));
  636. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize,jmp_lt,tcgint(t^._low.svalue-last.svalue),scratch_reg,elselabel);
  637. end;
  638. gensub(tcgint(t^._high.svalue-t^._low.svalue));
  639. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_le,tcgint(t^._high.svalue-t^._low.svalue),scratch_reg,blocklabel(t^.blockid));
  640. last:=t^._high;
  641. end;
  642. first:=false;
  643. if assigned(t^.greater) then
  644. genitem(t^.greater);
  645. end;
  646. begin
  647. { do we need to generate cmps? }
  648. if (with_sign and (min_label<0)) then
  649. genlinearcmplist(hp)
  650. else
  651. begin
  652. { sign/zero extend the value to a full register before starting to
  653. subtract values, so that on platforms that don't have
  654. subregisters of the same size as the value we don't generate
  655. sign/zero-extensions after every subtraction
  656. make newsize always signed, since we only do this if the size in
  657. bytes of the register is larger than the original opsize, so
  658. the value can always be represented by a larger signed type }
  659. newsize:=tcgsize2signed[reg_cgsize(hregister)];
  660. if tcgsize2size[newsize]>opsize.size then
  661. begin
  662. newdef:=cgsize_orddef(newsize);
  663. scratch_reg:=hlcg.getintregister(current_asmdata.CurrAsmList,newdef);
  664. hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,newdef,hregister,scratch_reg);
  665. hregister:=scratch_reg;
  666. opsize:=newdef;
  667. end;
  668. if (labelcnt>1) or not(cs_opt_level1 in current_settings.optimizerswitches) then
  669. begin
  670. last:=0;
  671. first:=true;
  672. scratch_reg:=hlcg.getintregister(current_asmdata.CurrAsmList,opsize);
  673. genitem(hp);
  674. end
  675. else
  676. begin
  677. { If only one label exists, we can greatly simplify the checks to a simple comparison }
  678. if hp^._low=hp^._high then
  679. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ, tcgint(hp^._low.svalue), hregister, blocklabel(hp^.blockid))
  680. else
  681. begin
  682. scratch_reg:=hlcg.getintregister(current_asmdata.CurrAsmList,opsize);
  683. gensub(tcgint(hp^._low.svalue));
  684. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_BE, tcgint(hp^._high.svalue-hp^._low.svalue), hregister, blocklabel(hp^.blockid))
  685. end;
  686. end;
  687. hlcg.a_jmp_always(current_asmdata.CurrAsmList,elselabel);
  688. end;
  689. end;
  690. procedure tcgcasenode.genlinearcmplist(hp : pcaselabel);
  691. var
  692. last : TConstExprInt;
  693. lastwasrange: boolean;
  694. procedure genitem(t : pcaselabel);
  695. {$if not defined(cpu64bitalu) and not defined(cpuhighleveltarget)}
  696. var
  697. l1 : tasmlabel;
  698. {$endif not cpu64bitalu and not cpuhighleveltarget}
  699. begin
  700. if assigned(t^.less) then
  701. genitem(t^.less);
  702. if t^._low=t^._high then
  703. begin
  704. {$ifndef cpuhighleveltarget}
  705. {$if defined(cpu32bitalu)}
  706. if def_cgsize(opsize) in [OS_S64,OS_64] then
  707. begin
  708. current_asmdata.getjumplabel(l1);
  709. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_NE, aint(hi(int64(t^._low.svalue))),hregister2,l1);
  710. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_EQ, aint(lo(int64(t^._low.svalue))),hregister, blocklabel(t^.blockid));
  711. cg.a_label(current_asmdata.CurrAsmList,l1);
  712. end
  713. else
  714. {$elseif defined(cpu16bitalu)}
  715. if def_cgsize(opsize) in [OS_S64,OS_64] then
  716. begin
  717. current_asmdata.getjumplabel(l1);
  718. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_NE, aint(hi(hi(int64(t^._low.svalue)))),cg.GetNextReg(hregister2),l1);
  719. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_NE, aint(lo(hi(int64(t^._low.svalue)))),hregister2,l1);
  720. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_NE, aint(hi(lo(int64(t^._low.svalue)))),cg.GetNextReg(hregister),l1);
  721. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_EQ, aint(lo(lo(int64(t^._low.svalue)))),hregister, blocklabel(t^.blockid));
  722. cg.a_label(current_asmdata.CurrAsmList,l1);
  723. end
  724. else if def_cgsize(opsize) in [OS_S32,OS_32] then
  725. begin
  726. current_asmdata.getjumplabel(l1);
  727. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_NE, aint(hi(int32(t^._low.svalue))),cg.GetNextReg(hregister),l1);
  728. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_EQ, aint(lo(int32(t^._low.svalue))),hregister, blocklabel(t^.blockid));
  729. cg.a_label(current_asmdata.CurrAsmList,l1);
  730. end
  731. else
  732. {$elseif defined(cpu8bitalu)}
  733. if def_cgsize(opsize) in [OS_S64,OS_64] then
  734. begin
  735. current_asmdata.getjumplabel(l1);
  736. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(hi(hi(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister2))),l1);
  737. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(lo(hi(hi(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister2)),l1);
  738. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(lo(hi(int64(t^._low.svalue))))),cg.GetNextReg(hregister2),l1);
  739. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(lo(lo(hi(int64(t^._low.svalue))))),hregister2,l1);
  740. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(hi(lo(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),l1);
  741. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(lo(hi(lo(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister)),l1);
  742. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(lo(lo(int64(t^._low.svalue))))),cg.GetNextReg(hregister),l1);
  743. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_EQ, aint(lo(lo(lo(int64(t^._low.svalue))))),hregister,blocklabel(t^.blockid));
  744. cg.a_label(current_asmdata.CurrAsmList,l1);
  745. end
  746. else if def_cgsize(opsize) in [OS_S32,OS_32] then
  747. begin
  748. current_asmdata.getjumplabel(l1);
  749. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(hi(int32(t^._low.svalue)))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),l1);
  750. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(lo(hi(int32(t^._low.svalue)))),cg.GetNextReg(cg.GetNextReg(hregister)),l1);
  751. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(lo(int32(t^._low.svalue)))),cg.GetNextReg(hregister),l1);
  752. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_EQ, aint(lo(lo(int32(t^._low.svalue)))),hregister, blocklabel(t^.blockid));
  753. cg.a_label(current_asmdata.CurrAsmList,l1);
  754. end
  755. else if def_cgsize(opsize) in [OS_S16,OS_16] then
  756. begin
  757. current_asmdata.getjumplabel(l1);
  758. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_NE, aint(hi(int16(t^._low.svalue))),cg.GetNextReg(hregister),l1);
  759. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8, OC_EQ, aint(lo(int16(t^._low.svalue))),hregister, blocklabel(t^.blockid));
  760. cg.a_label(current_asmdata.CurrAsmList,l1);
  761. end
  762. else
  763. {$endif}
  764. {$endif cpuhighleveltarget}
  765. begin
  766. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ, tcgint(t^._low.svalue),hregister, blocklabel(t^.blockid));
  767. end;
  768. { Reset last here, because we've only checked for one value and need to compare
  769. for the next range both the lower and upper bound }
  770. lastwasrange := false;
  771. end
  772. else
  773. begin
  774. { it begins with the smallest label, if the value }
  775. { is even smaller then jump immediately to the }
  776. { ELSE-label }
  777. if not lastwasrange or (t^._low-last>1) then
  778. begin
  779. {$ifndef cpuhighleveltarget}
  780. {$if defined(cpu32bitalu)}
  781. if def_cgsize(opsize) in [OS_64,OS_S64] then
  782. begin
  783. current_asmdata.getjumplabel(l1);
  784. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_lt, aint(hi(int64(t^._low.svalue))),
  785. hregister2, elselabel);
  786. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_gt, aint(hi(int64(t^._low.svalue))),
  787. hregister2, l1);
  788. { the comparisation of the low dword must be always unsigned! }
  789. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_B, aint(lo(int64(t^._low.svalue))), hregister, elselabel);
  790. cg.a_label(current_asmdata.CurrAsmList,l1);
  791. end
  792. else
  793. {$elseif defined(cpu16bitalu)}
  794. if def_cgsize(opsize) in [OS_64,OS_S64] then
  795. begin
  796. current_asmdata.getjumplabel(l1);
  797. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_lt, aint(hi(hi(int64(t^._low.svalue)))),
  798. cg.GetNextReg(hregister2), elselabel);
  799. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_gt, aint(hi(hi(int64(t^._low.svalue)))),
  800. cg.GetNextReg(hregister2), l1);
  801. { the comparison of the low words must be always unsigned! }
  802. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_B, aint(lo(hi(int64(t^._low.svalue)))),
  803. hregister2, elselabel);
  804. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_A, aint(lo(hi(int64(t^._low.svalue)))),
  805. hregister2, l1);
  806. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_B, aint(hi(lo(int64(t^._low.svalue)))),
  807. cg.GetNextReg(hregister), elselabel);
  808. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_A, aint(hi(lo(int64(t^._low.svalue)))),
  809. cg.GetNextReg(hregister), l1);
  810. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_B, aint(lo(lo(int64(t^._low.svalue)))), hregister, elselabel);
  811. cg.a_label(current_asmdata.CurrAsmList,l1);
  812. end
  813. else if def_cgsize(opsize) in [OS_32,OS_S32] then
  814. begin
  815. current_asmdata.getjumplabel(l1);
  816. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_lt, aint(hi(int32(t^._low.svalue))),
  817. cg.GetNextReg(hregister), elselabel);
  818. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_gt, aint(hi(int32(t^._low.svalue))),
  819. cg.GetNextReg(hregister), l1);
  820. { the comparisation of the low dword must be always unsigned! }
  821. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_B, aint(lo(int32(t^._low.svalue))), hregister, elselabel);
  822. cg.a_label(current_asmdata.CurrAsmList,l1);
  823. end
  824. else
  825. {$elseif defined(cpu8bitalu)}
  826. if def_cgsize(opsize) in [OS_64,OS_S64] then
  827. begin
  828. current_asmdata.getjumplabel(l1);
  829. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_lt,aint(hi(hi(hi(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister2))),elselabel);
  830. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_gt,aint(hi(hi(hi(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister2))),l1);
  831. { the comparison of the low words must be always unsigned! }
  832. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(hi(hi(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister2)),elselabel);
  833. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(hi(hi(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister2)),l1);
  834. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(lo(hi(int64(t^._low.svalue))))),cg.GetNextReg(hregister2),elselabel);
  835. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(lo(hi(int64(t^._low.svalue))))),cg.GetNextReg(hregister2),l1);
  836. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(lo(hi(int64(t^._low.svalue))))),hregister2,elselabel);
  837. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(lo(hi(int64(t^._low.svalue))))),hregister2,l1);
  838. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(hi(lo(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),elselabel);
  839. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(hi(lo(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),l1);
  840. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(hi(lo(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister)),elselabel);
  841. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(hi(lo(int64(t^._low.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister)),l1);
  842. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(lo(lo(int64(t^._low.svalue))))),cg.GetNextReg(hregister),elselabel);
  843. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(lo(lo(int64(t^._low.svalue))))),cg.GetNextReg(hregister),l1);
  844. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(lo(lo(int64(t^._low.svalue))))),hregister,elselabel);
  845. cg.a_label(current_asmdata.CurrAsmList,l1);
  846. end
  847. else if def_cgsize(opsize) in [OS_32,OS_S32] then
  848. begin
  849. current_asmdata.getjumplabel(l1);
  850. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_lt,aint(hi(hi(int32(t^._low.svalue)))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),elselabel);
  851. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_8,jmp_gt,aint(hi(hi(int32(t^._low.svalue)))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),l1);
  852. { the comparison of the low words must be always unsigned! }
  853. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(hi(int32(t^._low.svalue)))),cg.GetNextReg(cg.GetNextReg(hregister)),elselabel);
  854. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(hi(int32(t^._low.svalue)))),cg.GetNextReg(cg.GetNextReg(hregister)),l1);
  855. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(lo(int32(t^._low.svalue)))),cg.GetNextReg(hregister),elselabel);
  856. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(lo(int32(t^._low.svalue)))),cg.GetNextReg(hregister),l1);
  857. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(lo(int32(t^._low.svalue)))),hregister,elselabel);
  858. cg.a_label(current_asmdata.CurrAsmList,l1);
  859. end
  860. else if def_cgsize(opsize) in [OS_16,OS_S16] then
  861. begin
  862. current_asmdata.getjumplabel(l1);
  863. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_lt,aint(hi(int16(t^._low.svalue))),cg.GetNextReg(hregister),elselabel);
  864. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_gt,aint(hi(int16(t^._low.svalue))),cg.GetNextReg(hregister),l1);
  865. { the comparisation of the low dword must be always unsigned! }
  866. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(int16(t^._low.svalue))),hregister,elselabel);
  867. cg.a_label(current_asmdata.CurrAsmList,l1);
  868. end
  869. else
  870. {$endif}
  871. {$endif cpuhighleveltarget}
  872. begin
  873. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_lt, tcgint(t^._low.svalue), hregister,
  874. elselabel);
  875. end;
  876. end;
  877. {$ifndef cpuhighleveltarget}
  878. {$if defined(cpu32bitalu)}
  879. if def_cgsize(opsize) in [OS_S64,OS_64] then
  880. begin
  881. current_asmdata.getjumplabel(l1);
  882. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_lt, aint(hi(int64(t^._high.svalue))), hregister2,
  883. blocklabel(t^.blockid));
  884. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, jmp_gt, aint(hi(int64(t^._high.svalue))), hregister2,
  885. l1);
  886. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_32, OC_BE, aint(lo(int64(t^._high.svalue))), hregister, blocklabel(t^.blockid));
  887. cg.a_label(current_asmdata.CurrAsmList,l1);
  888. end
  889. else
  890. {$elseif defined(cpu16bitalu)}
  891. if def_cgsize(opsize) in [OS_S64,OS_64] then
  892. begin
  893. current_asmdata.getjumplabel(l1);
  894. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_lt, aint(hi(hi(int64(t^._high.svalue)))), cg.GetNextReg(hregister2),
  895. blocklabel(t^.blockid));
  896. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_gt, aint(hi(hi(int64(t^._high.svalue)))), cg.GetNextReg(hregister2),
  897. l1);
  898. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_B, aint(lo(hi(int64(t^._high.svalue)))), hregister2,
  899. blocklabel(t^.blockid));
  900. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_A, aint(lo(hi(int64(t^._high.svalue)))), hregister2,
  901. l1);
  902. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_B, aint(hi(lo(int64(t^._high.svalue)))), cg.GetNextReg(hregister),
  903. blocklabel(t^.blockid));
  904. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_A, aint(hi(lo(int64(t^._high.svalue)))), cg.GetNextReg(hregister),
  905. l1);
  906. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_BE, aint(lo(lo(int64(t^._high.svalue)))), hregister, blocklabel(t^.blockid));
  907. cg.a_label(current_asmdata.CurrAsmList,l1);
  908. end
  909. else if def_cgsize(opsize) in [OS_S32,OS_32] then
  910. begin
  911. current_asmdata.getjumplabel(l1);
  912. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_lt, aint(hi(int32(t^._high.svalue))), cg.GetNextReg(hregister),
  913. blocklabel(t^.blockid));
  914. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, jmp_gt, aint(hi(int32(t^._high.svalue))), cg.GetNextReg(hregister),
  915. l1);
  916. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, OS_16, OC_BE, aint(lo(int32(t^._high.svalue))), hregister, blocklabel(t^.blockid));
  917. cg.a_label(current_asmdata.CurrAsmList,l1);
  918. end
  919. else
  920. {$elseif defined(cpu8bitalu)}
  921. if def_cgsize(opsize) in [OS_S64,OS_64] then
  922. begin
  923. current_asmdata.getjumplabel(l1);
  924. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_lt,aint(hi(hi(hi(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister2))),blocklabel(t^.blockid));
  925. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_gt,aint(hi(hi(hi(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister2))),l1);
  926. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(hi(hi(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister2)),blocklabel(t^.blockid));
  927. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(hi(hi(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister2)),l1);
  928. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(lo(hi(int64(t^._high.svalue))))),cg.GetNextReg(hregister2),blocklabel(t^.blockid));
  929. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(lo(hi(int64(t^._high.svalue))))),cg.GetNextReg(hregister2),l1);
  930. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(lo(hi(int64(t^._high.svalue))))),hregister2,blocklabel(t^.blockid));
  931. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(lo(hi(int64(t^._high.svalue))))),hregister2,l1);
  932. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(hi(lo(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),blocklabel(t^.blockid));
  933. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(hi(lo(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),l1);
  934. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(hi(lo(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister)),blocklabel(t^.blockid));
  935. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(hi(lo(int64(t^._high.svalue))))),cg.GetNextReg(cg.GetNextReg(hregister)),l1);
  936. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(lo(lo(int64(t^._high.svalue))))),cg.GetNextReg(hregister),blocklabel(t^.blockid));
  937. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(lo(lo(int64(t^._high.svalue))))),cg.GetNextReg(hregister),l1);
  938. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_BE,aint(lo(lo(lo(int64(t^._high.svalue))))),hregister,blocklabel(t^.blockid));
  939. cg.a_label(current_asmdata.CurrAsmList,l1);
  940. end
  941. else if def_cgsize(opsize) in [OS_S32,OS_32] then
  942. begin
  943. current_asmdata.getjumplabel(l1);
  944. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_lt,aint(hi(hi(int32(t^._high.svalue)))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),blocklabel(t^.blockid));
  945. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_gt,aint(hi(hi(int32(t^._high.svalue)))),cg.GetNextReg(cg.GetNextReg(cg.GetNextReg(hregister))),l1);
  946. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(lo(hi(int32(t^._high.svalue)))),cg.GetNextReg(cg.GetNextReg(hregister)),blocklabel(t^.blockid));
  947. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(lo(hi(int32(t^._high.svalue)))),cg.GetNextReg(cg.GetNextReg(hregister)),l1);
  948. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_B,aint(hi(lo(int32(t^._high.svalue)))),cg.GetNextReg(hregister),blocklabel(t^.blockid));
  949. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_A,aint(hi(lo(int32(t^._high.svalue)))),cg.GetNextReg(hregister),l1);
  950. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_BE,aint(lo(lo(int32(t^._high.svalue)))),hregister,blocklabel(t^.blockid));
  951. cg.a_label(current_asmdata.CurrAsmList,l1);
  952. end
  953. else if def_cgsize(opsize) in [OS_S16,OS_16] then
  954. begin
  955. current_asmdata.getjumplabel(l1);
  956. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_lt,aint(hi(int16(t^._high.svalue))),cg.GetNextReg(hregister),blocklabel(t^.blockid));
  957. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,jmp_gt,aint(hi(int16(t^._high.svalue))),cg.GetNextReg(hregister),l1);
  958. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_8,OC_BE,aint(lo(int16(t^._high.svalue))),hregister,blocklabel(t^.blockid));
  959. cg.a_label(current_asmdata.CurrAsmList,l1);
  960. end
  961. else
  962. {$endif}
  963. {$endif cpuhighleveltarget}
  964. begin
  965. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_le, tcgint(t^._high.svalue), hregister, blocklabel(t^.blockid));
  966. end;
  967. last:=t^._high;
  968. lastwasrange := true;
  969. end;
  970. if assigned(t^.greater) then
  971. genitem(t^.greater);
  972. end;
  973. begin
  974. last:=0;
  975. lastwasrange:=false;
  976. genitem(hp);
  977. hlcg.a_jmp_always(current_asmdata.CurrAsmList,elselabel);
  978. end;
  979. procedure tcgcasenode.genjmptreeentry(p : pcaselabel;parentvalue : TConstExprInt);
  980. var
  981. lesslabel,greaterlabel : tasmlabel;
  982. begin
  983. current_asmdata.CurrAsmList.concat(cai_align.Create(current_settings.alignment.jumpalign));
  984. cg.a_label(current_asmdata.CurrAsmList,p^.labellabel);
  985. { calculate labels for left and right }
  986. if p^.less=nil then
  987. lesslabel:=elselabel
  988. else
  989. lesslabel:=p^.less^.labellabel;
  990. if p^.greater=nil then
  991. greaterlabel:=elselabel
  992. else
  993. greaterlabel:=p^.greater^.labellabel;
  994. { calculate labels for left and right }
  995. { no range label: }
  996. if p^._low=p^._high then
  997. begin
  998. if greaterlabel=lesslabel then
  999. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_NE,p^._low,hregister, lesslabel)
  1000. else
  1001. begin
  1002. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize, jmp_lt,p^._low,hregister, lesslabel);
  1003. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize, jmp_gt,p^._low,hregister, greaterlabel);
  1004. end;
  1005. hlcg.a_jmp_always(current_asmdata.CurrAsmList,blocklabel(p^.blockid));
  1006. end
  1007. else
  1008. begin
  1009. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,p^._low, hregister, lesslabel);
  1010. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_gt,p^._high,hregister, greaterlabel);
  1011. hlcg.a_jmp_always(current_asmdata.CurrAsmList,blocklabel(p^.blockid));
  1012. end;
  1013. if assigned(p^.less) then
  1014. genjmptreeentry(p^.less,p^._low);
  1015. if assigned(p^.greater) then
  1016. genjmptreeentry(p^.greater,p^._high);
  1017. end;
  1018. procedure tcgcasenode.genjmptree(root : pcaselabel);
  1019. type
  1020. tlabelarrayentry = record
  1021. caselabel : pcaselabel;
  1022. asmlabel : TAsmLabel;
  1023. end;
  1024. tlabelarray = array of tlabelarrayentry;
  1025. var
  1026. labelarray : tlabelarray;
  1027. var
  1028. nextarrayentry : int64;
  1029. i : longint;
  1030. procedure addarrayentry(entry : pcaselabel);
  1031. begin
  1032. if assigned(entry^.less) then
  1033. addarrayentry(entry^.less);
  1034. with labelarray[nextarrayentry] do
  1035. begin
  1036. caselabel:=entry;
  1037. current_asmdata.getjumplabel(asmlabel);
  1038. end;
  1039. inc(nextarrayentry);
  1040. if assigned(entry^.greater) then
  1041. addarrayentry(entry^.greater);
  1042. end;
  1043. { rebuild the label tree balanced }
  1044. procedure rebuild(first,last : int64;var p : pcaselabel);
  1045. var
  1046. current : int64;
  1047. begin
  1048. current:=(first+last) div 2;
  1049. p:=labelarray[current].caselabel;
  1050. if first<current then
  1051. rebuild(first,current-1,p^.less)
  1052. else
  1053. p^.less:=nil;
  1054. if last>current then
  1055. rebuild(current+1,last,p^.greater)
  1056. else
  1057. p^.greater:=nil;
  1058. end;
  1059. begin
  1060. labelarray:=nil;
  1061. SetLength(labelarray,labelcnt);
  1062. nextarrayentry:=0;
  1063. addarrayentry(root);
  1064. rebuild(0,high(labelarray),root);
  1065. for i:=0 to high(labelarray) do
  1066. current_asmdata.getjumplabel(labelarray[i].caselabel^.labellabel);
  1067. genjmptreeentry(root,root^._high+10);
  1068. end;
  1069. procedure tcgcasenode.pass_generate_code;
  1070. var
  1071. oldflowcontrol: tflowcontrol;
  1072. i : longint;
  1073. dist : asizeuint;
  1074. distv,
  1075. lv,hv,
  1076. max_label: tconstexprint;
  1077. max_linear_list : int64;
  1078. max_dist : qword;
  1079. ShortcutElse: Boolean;
  1080. begin
  1081. location_reset(location,LOC_VOID,OS_NO);
  1082. oldflowcontrol := flowcontrol;
  1083. include(flowcontrol,fc_inflowcontrol);
  1084. { Allocate labels }
  1085. current_asmdata.getjumplabel(endlabel);
  1086. { Do some optimisation to deal with empty else blocks }
  1087. ShortcutElse := GetBranchLabel(elseblock, elselabel);
  1088. for i:=0 to blocks.count-1 do
  1089. with pcaseblock(blocks[i])^ do
  1090. shortcut := GetBranchLabel(statement, blocklabel);
  1091. with_sign:=is_signed(left.resultdef);
  1092. if with_sign then
  1093. begin
  1094. jmp_gt:=OC_GT;
  1095. jmp_lt:=OC_LT;
  1096. jmp_le:=OC_LTE;
  1097. end
  1098. else
  1099. begin
  1100. jmp_gt:=OC_A;
  1101. jmp_lt:=OC_B;
  1102. jmp_le:=OC_BE;
  1103. end;
  1104. secondpass(left);
  1105. if (left.expectloc=LOC_JUMP)<>
  1106. (left.location.loc=LOC_JUMP) then
  1107. internalerror(2006050501);
  1108. { determines the size of the operand }
  1109. opsize:=left.resultdef;
  1110. { copy the case expression to a register }
  1111. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,opsize,false);
  1112. {$if not defined(cpu64bitalu)}
  1113. if def_cgsize(opsize) in [OS_S64,OS_64] then
  1114. begin
  1115. hregister:=left.location.register64.reglo;
  1116. hregister2:=left.location.register64.reghi;
  1117. end
  1118. else
  1119. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1120. hregister:=left.location.register;
  1121. { we need the min_label always to choose between }
  1122. { cmps and subs/decs }
  1123. min_label:=case_get_min(labels);
  1124. { Generate the jumps }
  1125. {$if not defined(cpu64bitalu)}
  1126. if def_cgsize(opsize) in [OS_64,OS_S64] then
  1127. genlinearcmplist(labels)
  1128. else
  1129. {$endif not cpu64bitalu and not cpuhighleveltarget}
  1130. begin
  1131. if cs_opt_level1 in current_settings.optimizerswitches then
  1132. begin
  1133. { procedures are empirically passed on }
  1134. { consumption can also be calculated }
  1135. { but does it pay on the different }
  1136. { processors? }
  1137. { moreover can the size only be appro- }
  1138. { ximated as it is not known if rel8, }
  1139. { rel16 or rel32 jumps are used }
  1140. max_label := case_get_max(labels);
  1141. { can we omit the range check of the jump table ? }
  1142. getrange(left.resultdef,lv,hv);
  1143. jumptable_no_range:=(lv=min_label) and (hv=max_label);
  1144. distv:=max_label-min_label;
  1145. if distv>=0 then
  1146. dist:=min(distv.uvalue,high(dist))
  1147. else
  1148. dist:=min(asizeuint(-distv.svalue),high(dist));
  1149. { optimize for size ? }
  1150. if cs_opt_size in current_settings.optimizerswitches then
  1151. begin
  1152. if has_jumptable and
  1153. (min_label>=int64(low(aint))) and
  1154. (max_label<=high(aint)) and
  1155. not((labelcnt<=2) or
  1156. (distv.svalue<0) or
  1157. (dist>3*labelcnt)) then
  1158. begin
  1159. { if the labels less or more a continuum then }
  1160. genjumptable(labels,min_label.svalue,max_label.svalue);
  1161. end
  1162. else
  1163. begin
  1164. { a linear list is always smaller than a jump tree }
  1165. genlinearlist(labels);
  1166. end;
  1167. end
  1168. else
  1169. begin
  1170. max_dist:=4*labelcoverage;
  1171. { Don't allow jump tables to get too large }
  1172. if max_dist>4*labelcnt then
  1173. max_dist:=min(max_dist,2048);
  1174. if jumptable_no_range then
  1175. max_linear_list:=4
  1176. else
  1177. max_linear_list:=2;
  1178. { allow processor specific values }
  1179. optimizevalues(max_linear_list,max_dist);
  1180. if (labelcnt<=max_linear_list) then
  1181. genlinearlist(labels)
  1182. else
  1183. begin
  1184. if (has_jumptable) and
  1185. (dist<max_dist) and
  1186. (min_label>=int64(low(aint))) and
  1187. (max_label<=high(aint)) then
  1188. genjumptable(labels,min_label.svalue,max_label.svalue)
  1189. { value has been determined on an i7-4770 using a random case with random values
  1190. if more values are known, this can be handled depending on the target CPU
  1191. Testing on a Core 2 Duo E6850 as well as on a Raspi3 showed also, that 64 is
  1192. a good value }
  1193. else if labelcnt>=64 then
  1194. genjmptree(labels)
  1195. else
  1196. genlinearlist(labels);
  1197. end;
  1198. end;
  1199. end
  1200. else
  1201. { it's always not bad }
  1202. genlinearlist(labels);
  1203. end;
  1204. { generate the instruction blocks }
  1205. for i:=0 to blocks.count-1 do with pcaseblock(blocks[i])^ do
  1206. begin
  1207. { If the labels are not equal, then the block label has been shortcut to point elsewhere,
  1208. so there's no need to implement it }
  1209. if not shortcut then
  1210. begin
  1211. current_asmdata.CurrAsmList.concat(cai_align.create(current_settings.alignment.jumpalign));
  1212. cg.a_label(current_asmdata.CurrAsmList,blocklabel);
  1213. secondpass(statement);
  1214. { don't come back to case line }
  1215. current_filepos:=current_asmdata.CurrAsmList.getlasttaifilepos^;
  1216. hlcg.a_jmp_always(current_asmdata.CurrAsmList,endlabel);
  1217. end;
  1218. end;
  1219. { ...and the else block }
  1220. if not ShortcutElse then
  1221. begin
  1222. current_asmdata.CurrAsmList.concat(cai_align.create(current_settings.alignment.jumpalign));
  1223. hlcg.a_label(current_asmdata.CurrAsmList,elselabel);
  1224. end;
  1225. if Assigned(elseblock) then
  1226. begin
  1227. secondpass(elseblock);
  1228. end;
  1229. current_asmdata.CurrAsmList.concat(cai_align.create(current_settings.alignment.jumpalign));
  1230. hlcg.a_label(current_asmdata.CurrAsmList,endlabel);
  1231. { Reset labels }
  1232. for i:=0 to blocks.count-1 do
  1233. pcaseblock(blocks[i])^.blocklabel:=nil;
  1234. flowcontrol := oldflowcontrol + (flowcontrol - [fc_inflowcontrol]);
  1235. end;
  1236. begin
  1237. csetelementnode:=tcgsetelementnode;
  1238. cinnode:=tcginnode;
  1239. ccasenode:=tcgcasenode;
  1240. end.