nx86set.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate x86 assembler for in/case 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 nx86set;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. node,nset,pass_1,ncgset;
  23. type
  24. tx86innode = class(tinnode)
  25. procedure pass_generate_code;override;
  26. function pass_1 : tnode;override;
  27. end;
  28. tx86casenode = class(tcgcasenode)
  29. function has_jumptable : boolean;override;
  30. procedure genjumptable(hp : pcaselabel;min_,max_ : aint);override;
  31. procedure genlinearlist(hp : pcaselabel);override;
  32. end;
  33. implementation
  34. uses
  35. systems,constexp,
  36. verbose,globals,
  37. symconst,symdef,defutil,
  38. aasmbase,aasmtai,aasmdata,aasmcpu,
  39. cgbase,pass_2,tgobj,
  40. ncon,
  41. cpubase,
  42. cga,cgobj,cgutils,ncgutil,
  43. cgx86,
  44. procinfo;
  45. {*****************************************************************************
  46. TX86CASENODE
  47. *****************************************************************************}
  48. function tx86casenode.has_jumptable : boolean;
  49. begin
  50. {$ifdef i386}
  51. has_jumptable:=true;
  52. {$else}
  53. has_jumptable:=false;
  54. {$endif}
  55. end;
  56. procedure tx86casenode.genjumptable(hp : pcaselabel;min_,max_ : aint);
  57. var
  58. table : tasmlabel;
  59. last : TConstExprInt;
  60. indexreg : tregister;
  61. href : treference;
  62. jtlist: tasmlist;
  63. sectype: TAsmSectiontype;
  64. procedure genitem(list:TAsmList;t : pcaselabel);
  65. var
  66. i : aint;
  67. begin
  68. if assigned(t^.less) then
  69. genitem(list,t^.less);
  70. { fill possible hole }
  71. i:=last.svalue+1;
  72. while i<=t^._low.svalue-1 do
  73. begin
  74. list.concat(Tai_const.Create_sym(elselabel));
  75. inc(i);
  76. end;
  77. i:=t^._low.svalue;
  78. while i<=t^._high.svalue do
  79. begin
  80. list.concat(Tai_const.Create_sym(blocklabel(t^.blockid)));
  81. inc(i);
  82. end;
  83. last:=t^._high;
  84. if assigned(t^.greater) then
  85. genitem(list,t^.greater);
  86. end;
  87. begin
  88. last:=min_;
  89. if not(jumptable_no_range) then
  90. begin
  91. { a <= x <= b <-> unsigned(x-a) <= (b-a) }
  92. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opsize,aint(min_),hregister);
  93. { case expr greater than max_ => goto elselabel }
  94. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_A,aint(max_)-aint(min_),hregister,elselabel);
  95. min_:=0;
  96. end;
  97. current_asmdata.getdatalabel(table);
  98. { make it a 32bit register }
  99. indexreg:=cg.makeregsize(current_asmdata.CurrAsmList,hregister,OS_INT);
  100. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,OS_INT,hregister,indexreg);
  101. { create reference }
  102. reference_reset_symbol(href,table,0,sizeof(pint));
  103. href.offset:=(-aint(min_))*sizeof(aint);
  104. href.index:=indexreg;
  105. href.scalefactor:=sizeof(aint);
  106. emit_ref(A_JMP,S_NO,href);
  107. { generate jump table }
  108. if (target_info.system in [system_i386_darwin,system_i386_iphonesim]) then
  109. begin
  110. jtlist:=current_asmdata.asmlists[al_const];
  111. sectype:=sec_rodata;
  112. end
  113. else
  114. begin
  115. jtlist:=current_procinfo.aktlocaldata;
  116. sectype:=sec_data;
  117. end;
  118. new_section(jtlist,sectype,current_procinfo.procdef.mangledname,sizeof(aint));
  119. jtlist.concat(Tai_label.Create(table));
  120. genitem(jtlist,hp);
  121. end;
  122. procedure tx86casenode.genlinearlist(hp : pcaselabel);
  123. var
  124. first : boolean;
  125. lastrange : boolean;
  126. last : TConstExprInt;
  127. cond_lt,cond_le : tresflags;
  128. procedure genitem(t : pcaselabel);
  129. begin
  130. if assigned(t^.less) then
  131. genitem(t^.less);
  132. { need we to test the first value }
  133. if first and (t^._low>get_min_value(left.resultdef)) then
  134. begin
  135. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,jmp_lt,aint(t^._low.svalue),hregister,elselabel);
  136. end;
  137. if t^._low=t^._high then
  138. begin
  139. if t^._low-last=0 then
  140. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_EQ,0,hregister,blocklabel(t^.blockid))
  141. else
  142. begin
  143. cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low.svalue-last.svalue), hregister);
  144. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,blocklabel(t^.blockid));
  145. end;
  146. last:=t^._low;
  147. lastrange:=false;
  148. end
  149. else
  150. begin
  151. { it begins with the smallest label, if the value }
  152. { is even smaller then jump immediately to the }
  153. { ELSE-label }
  154. if first then
  155. begin
  156. { have we to ajust the first value ? }
  157. if (t^._low>get_min_value(left.resultdef)) or (get_min_value(left.resultdef)<>0) then
  158. cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low.svalue), hregister);
  159. end
  160. else
  161. begin
  162. { if there is no unused label between the last and the }
  163. { present label then the lower limit can be checked }
  164. { immediately. else check the range in between: }
  165. cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opsize, aint(t^._low.svalue-last.svalue), hregister);
  166. { no jump necessary here if the new range starts at }
  167. { at the value following the previous one }
  168. if ((t^._low-last) <> 1) or
  169. (not lastrange) then
  170. cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_lt,elselabel);
  171. end;
  172. {we need to use A_SUB, because A_DEC does not set the correct flags, therefor
  173. using a_op_const_reg(OP_SUB) is not possible }
  174. emit_const_reg(A_SUB,TCGSize2OpSize[opsize],aint(t^._high.svalue-t^._low.svalue),hregister);
  175. cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_le,blocklabel(t^.blockid));
  176. last:=t^._high;
  177. lastrange:=true;
  178. end;
  179. first:=false;
  180. if assigned(t^.greater) then
  181. genitem(t^.greater);
  182. end;
  183. begin
  184. if with_sign then
  185. begin
  186. cond_lt:=F_L;
  187. cond_le:=F_LE;
  188. end
  189. else
  190. begin
  191. cond_lt:=F_B;
  192. cond_le:=F_BE;
  193. end;
  194. { do we need to generate cmps? }
  195. if (with_sign and (min_label<0)) then
  196. genlinearcmplist(hp)
  197. else
  198. begin
  199. last:=0;
  200. lastrange:=false;
  201. first:=true;
  202. genitem(hp);
  203. cg.a_jmp_always(current_asmdata.CurrAsmList,elselabel);
  204. end;
  205. end;
  206. {*****************************************************************************
  207. TX86INNODE
  208. *****************************************************************************}
  209. function tx86innode.pass_1 : tnode;
  210. begin
  211. result:=nil;
  212. { this is the only difference from the generic version }
  213. expectloc:=LOC_FLAGS;
  214. firstpass(right);
  215. firstpass(left);
  216. if codegenerror then
  217. exit;
  218. end;
  219. procedure tx86innode.pass_generate_code;
  220. type
  221. Tsetpart=record
  222. range : boolean; {Part is a range.}
  223. start,stop : byte; {Start/stop when range; Stop=element when an element.}
  224. end;
  225. var
  226. hreg,hreg2,
  227. pleftreg : tregister;
  228. opsize : tcgsize;
  229. orgopsize : tcgsize;
  230. setparts : array[1..8] of Tsetpart;
  231. setbase : aint;
  232. adjustment : longint;
  233. l,l2 : tasmlabel;
  234. i,numparts : byte;
  235. genjumps,
  236. use_small,
  237. ranges : boolean;
  238. {$ifdef CORRECT_SET_IN_FPC}
  239. AM : tasmop;
  240. {$endif CORRECT_SET_IN_FPC}
  241. function analizeset(Aset:pconstset;is_small:boolean):boolean;
  242. var
  243. compares,maxcompares:word;
  244. i:byte;
  245. begin
  246. if tnormalset(Aset^)=[] then
  247. {The expression...
  248. if expr in []
  249. ...is allways false. It should be optimized away in the
  250. resultdef pass, and thus never occur here. Since we
  251. do generate wrong code for it, do internalerror.}
  252. internalerror(2002072301);
  253. analizeset:=false;
  254. ranges:=false;
  255. numparts:=0;
  256. compares:=0;
  257. { Lots of comparisions take a lot of time, so do not allow
  258. too much comparisions. 8 comparisions are, however, still
  259. smalller than emitting the set }
  260. if cs_opt_size in current_settings.optimizerswitches then
  261. maxcompares:=8
  262. else
  263. maxcompares:=5;
  264. { when smallset is possible allow only 3 compares the smallset
  265. code is for littlesize also smaller when more compares are used }
  266. if is_small then
  267. maxcompares:=3;
  268. for i:=0 to 255 do
  269. if i in tnormalset(Aset^) then
  270. begin
  271. if (numparts=0) or (i<>setparts[numparts].stop+1) then
  272. begin
  273. {Set element is a separate element.}
  274. inc(compares);
  275. if compares>maxcompares then
  276. exit;
  277. inc(numparts);
  278. setparts[numparts].range:=false;
  279. setparts[numparts].stop:=i;
  280. end
  281. else
  282. {Set element is part of a range.}
  283. if not setparts[numparts].range then
  284. begin
  285. {Transform an element into a range.}
  286. setparts[numparts].range:=true;
  287. setparts[numparts].start:=setparts[numparts].stop;
  288. setparts[numparts].stop:=i;
  289. ranges := true;
  290. end
  291. else
  292. begin
  293. {Extend a range.}
  294. setparts[numparts].stop:=i;
  295. end;
  296. end;
  297. analizeset:=true;
  298. end;
  299. begin
  300. { We check first if we can generate jumps, this can be done
  301. because the resultdef is already set in firstpass }
  302. { check if we can use smallset operation using btl which is limited
  303. to 32 bits, the left side may also not contain higher values or be signed !! }
  304. use_small:=is_smallset(right.resultdef) and
  305. not is_signed(left.resultdef) and
  306. ((left.resultdef.typ=orddef) and (torddef(left.resultdef).high.svalue<32) or
  307. (left.resultdef.typ=enumdef) and (tenumdef(left.resultdef).max<32));
  308. { Can we generate jumps? Possible for all types of sets }
  309. genjumps:=(right.nodetype=setconstn) and
  310. analizeset(tsetconstnode(right).value_set,use_small);
  311. { calculate both operators }
  312. { the complex one first }
  313. { not in case of genjumps, because then we don't secondpass }
  314. { right at all (so we have to make sure that "right" really is }
  315. { "right" and not "swapped left" in that case) }
  316. if not(genjumps) then
  317. firstcomplex(self);
  318. secondpass(left);
  319. { Only process the right if we are not generating jumps }
  320. if not genjumps then
  321. begin
  322. secondpass(right);
  323. end;
  324. if codegenerror then
  325. exit;
  326. { ofcourse not commutative }
  327. if nf_swapped in flags then
  328. swapleftright;
  329. orgopsize := def_cgsize(left.resultdef);
  330. opsize := OS_32;
  331. if is_signed(left.resultdef) then
  332. opsize := tcgsize(ord(opsize)+(ord(OS_S8)-ord(OS_8)));
  333. if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE,LOC_CONSTANT]) then
  334. location_force_reg(current_asmdata.CurrAsmList,left.location,opsize,true);
  335. if (right.location.loc in [LOC_SUBSETREG,LOC_CSUBSETREG]) then
  336. location_force_reg(current_asmdata.CurrAsmList,right.location,opsize,true);
  337. if genjumps then
  338. begin
  339. { It gives us advantage to check for the set elements
  340. separately instead of using the SET_IN_BYTE procedure.
  341. To do: Build in support for LOC_JUMP }
  342. { load and zero or sign extend as necessary }
  343. location_force_reg(current_asmdata.CurrAsmList,left.location,opsize,false);
  344. pleftreg:=left.location.register;
  345. { Get a label to jump to the end }
  346. location_reset(location,LOC_FLAGS,OS_NO);
  347. { It's better to use the zero flag when there are
  348. no ranges }
  349. if ranges then
  350. location.resflags:=F_C
  351. else
  352. location.resflags:=F_E;
  353. current_asmdata.getjumplabel(l);
  354. { how much have we already substracted from the x in the }
  355. { "x in [y..z]" expression }
  356. adjustment := 0;
  357. for i:=1 to numparts do
  358. if setparts[i].range then
  359. { use fact that a <= x <= b <=> cardinal(x-a) <= cardinal(b-a) }
  360. begin
  361. { is the range different from all legal values? }
  362. if (setparts[i].stop-setparts[i].start <> 255) or not (orgopsize = OS_8) then
  363. begin
  364. { yes, is the lower bound <> 0? }
  365. if (setparts[i].start <> 0) then
  366. begin
  367. location_force_reg(current_asmdata.CurrAsmList,left.location,opsize,false);
  368. hreg:=left.location.register;
  369. pleftreg:=hreg;
  370. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,opsize,setparts[i].start-adjustment,pleftreg);
  371. end;
  372. { new total value substracted from x: }
  373. { adjustment + (setparts[i].start - adjustment) }
  374. adjustment := setparts[i].start;
  375. { check if result < b-a+1 (not "result <= b-a", since }
  376. { we need a carry in case the element is in the range }
  377. { (this will never overflow since we check at the }
  378. { beginning whether stop-start <> 255) }
  379. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_B,setparts[i].stop-setparts[i].start+1,pleftreg,l);
  380. end
  381. else
  382. { if setparts[i].start = 0 and setparts[i].stop = 255, }
  383. { it's always true since "in" is only allowed for bytes }
  384. begin
  385. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_STC,S_NO));
  386. cg.a_jmp_always(current_asmdata.CurrAsmList,l);
  387. end;
  388. end
  389. else
  390. begin
  391. { Emit code to check if left is an element }
  392. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,TCGSize2OpSize[opsize],setparts[i].stop-adjustment,
  393. pleftreg));
  394. { Result should be in carry flag when ranges are used }
  395. if ranges then
  396. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_STC,S_NO));
  397. { If found, jump to end }
  398. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,l);
  399. end;
  400. if ranges and
  401. { if the last one was a range, the carry flag is already }
  402. { set appropriately }
  403. not(setparts[numparts].range) then
  404. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLC,S_NO));
  405. { To compensate for not doing a second pass }
  406. right.location.reference.symbol:=nil;
  407. { Now place the end label }
  408. cg.a_label(current_asmdata.CurrAsmList,l);
  409. end
  410. else
  411. begin
  412. location_reset(location,LOC_FLAGS,OS_NO);
  413. setbase:=tsetdef(right.resultdef).setbase;
  414. { We will now generated code to check the set itself, no jmps,
  415. handle smallsets separate, because it allows faster checks }
  416. if use_small then
  417. begin
  418. if left.location.loc=LOC_CONSTANT then
  419. begin
  420. location.resflags:=F_NE;
  421. case right.location.loc of
  422. LOC_REGISTER,
  423. LOC_CREGISTER:
  424. begin
  425. emit_const_reg(A_TEST,TCGSize2OpSize[right.location.size],
  426. 1 shl ((left.location.value-setbase) and 31),right.location.register);
  427. end;
  428. LOC_REFERENCE,
  429. LOC_CREFERENCE :
  430. begin
  431. emit_const_ref(A_TEST,TCGSize2OpSize[right.location.size],1 shl ((left.location.value-setbase) and 31),
  432. right.location.reference);
  433. end;
  434. else
  435. internalerror(200203312);
  436. end;
  437. end
  438. else
  439. begin
  440. location_force_reg(current_asmdata.CurrAsmList,left.location,OS_32,true);
  441. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,left.location,setbase);
  442. if (tcgsize2size[right.location.size] < 4) or
  443. (right.location.loc = LOC_CONSTANT) then
  444. location_force_reg(current_asmdata.CurrAsmList,right.location,OS_32,true);
  445. hreg:=left.location.register;
  446. case right.location.loc of
  447. LOC_REGISTER,
  448. LOC_CREGISTER :
  449. begin
  450. emit_reg_reg(A_BT,S_L,hreg,right.location.register);
  451. end;
  452. LOC_CREFERENCE,
  453. LOC_REFERENCE :
  454. begin
  455. emit_reg_ref(A_BT,S_L,hreg,right.location.reference);
  456. end;
  457. else
  458. internalerror(2002032210);
  459. end;
  460. location.resflags:=F_C;
  461. end;
  462. end
  463. else
  464. begin
  465. if right.location.loc=LOC_CONSTANT then
  466. begin
  467. location.resflags:=F_C;
  468. current_asmdata.getjumplabel(l);
  469. current_asmdata.getjumplabel(l2);
  470. { load constants to a register }
  471. if (left.location.loc=LOC_CONSTANT) or
  472. (setbase<>0) then
  473. begin
  474. location_force_reg(current_asmdata.CurrAsmList,left.location,opsize,true);
  475. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,left.location,setbase);
  476. end;
  477. case left.location.loc of
  478. LOC_REGISTER,
  479. LOC_CREGISTER:
  480. begin
  481. hreg:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,opsize);
  482. cg.a_load_reg_reg(current_asmdata.CurrAsmList,left.location.size,opsize,left.location.register,hreg);
  483. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_BE,31,hreg,l);
  484. { reset carry flag }
  485. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLC,S_NO));
  486. cg.a_jmp_always(current_asmdata.CurrAsmList,l2);
  487. cg.a_label(current_asmdata.CurrAsmList,l);
  488. { We have to load the value into a register because
  489. btl does not accept values only refs or regs (PFV) }
  490. hreg2:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  491. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,right.location.value,hreg2);
  492. emit_reg_reg(A_BT,S_L,hreg,hreg2);
  493. end;
  494. else
  495. begin
  496. emit_const_ref(A_CMP,TCGSize2OpSize[orgopsize],31,left.location.reference);
  497. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_BE,l);
  498. { reset carry flag }
  499. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLC,S_NO));
  500. cg.a_jmp_always(current_asmdata.CurrAsmList,l2);
  501. cg.a_label(current_asmdata.CurrAsmList,l);
  502. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  503. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_32,left.location.reference,hreg);
  504. { We have to load the value into a register because
  505. btl does not accept values only refs or regs (PFV) }
  506. hreg2:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  507. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_32,right.location.value,hreg2);
  508. emit_reg_reg(A_BT,S_L,hreg,hreg2);
  509. end;
  510. end;
  511. cg.a_label(current_asmdata.CurrAsmList,l2);
  512. end { of right.location.loc=LOC_CONSTANT }
  513. { do search in a normal set which could have >32 elementsm
  514. but also used if the left side contains values > 32 or < 0 }
  515. else if left.location.loc=LOC_CONSTANT then
  516. begin
  517. if (left.location.value<setbase) or (((left.location.value-setbase) shr 3) >= right.resultdef.size) then
  518. {should be caught earlier }
  519. internalerror(2007020201);
  520. location.resflags:=F_NE;
  521. case right.location.loc of
  522. LOC_REFERENCE,LOC_CREFERENCE:
  523. begin
  524. inc(right.location.reference.offset,(left.location.value-setbase) shr 3);
  525. emit_const_ref(A_TEST,S_B,1 shl (left.location.value and 7),right.location.reference);
  526. end;
  527. LOC_REGISTER,LOC_CREGISTER:
  528. begin
  529. emit_const_reg(A_TEST,TCGSize2OpSize[right.location.size],1 shl (left.location.value-setbase),right.location.register);
  530. end;
  531. else
  532. internalerror(2007051901);
  533. end;
  534. end
  535. else
  536. begin
  537. location_force_reg(current_asmdata.CurrAsmList,left.location,opsize,false);
  538. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,left.location,setbase);
  539. if (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  540. location_force_reg(current_asmdata.CurrAsmList,right.location,opsize,true);
  541. pleftreg:=left.location.register;
  542. if (opsize >= OS_S8) or { = if signed }
  543. ((left.resultdef.typ=orddef) and
  544. ((torddef(left.resultdef).low < int64(tsetdef(right.resultdef).setbase)) or
  545. (torddef(left.resultdef).high > int64(tsetdef(right.resultdef).setmax)))) or
  546. ((left.resultdef.typ=enumdef) and
  547. ((tenumdef(left.resultdef).min < aint(tsetdef(right.resultdef).setbase)) or
  548. (tenumdef(left.resultdef).max > aint(tsetdef(right.resultdef).setmax)))) then
  549. begin
  550. { we have to check if the value is < 0 or > setmax }
  551. current_asmdata.getjumplabel(l);
  552. current_asmdata.getjumplabel(l2);
  553. { BE will be false for negative values }
  554. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,opsize,OC_BE,tsetdef(right.resultdef).setmax-tsetdef(right.resultdef).setbase,pleftreg,l);
  555. { reset carry flag }
  556. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_CLC,S_NO));
  557. cg.a_jmp_always(current_asmdata.CurrAsmList,l2);
  558. cg.a_label(current_asmdata.CurrAsmList,l);
  559. pleftreg:=left.location.register;
  560. case right.location.loc of
  561. LOC_REGISTER, LOC_CREGISTER :
  562. emit_reg_reg(A_BT,S_L,pleftreg,right.location.register);
  563. LOC_CREFERENCE, LOC_REFERENCE :
  564. emit_reg_ref(A_BT,S_L,pleftreg,right.location.reference);
  565. else
  566. internalerror(2007020301);
  567. end;
  568. cg.a_label(current_asmdata.CurrAsmList,l2);
  569. location.resflags:=F_C;
  570. end
  571. else
  572. begin
  573. case right.location.loc of
  574. LOC_REGISTER, LOC_CREGISTER :
  575. emit_reg_reg(A_BT,S_L,pleftreg,right.location.register);
  576. LOC_CREFERENCE, LOC_REFERENCE :
  577. emit_reg_ref(A_BT,S_L,pleftreg,right.location.reference);
  578. else
  579. internalerror(2007020302);
  580. end;
  581. location.resflags:=F_C;
  582. end;
  583. end;
  584. end;
  585. end;
  586. if not genjumps then
  587. location_freetemp(current_asmdata.CurrAsmList,right.location);
  588. end;
  589. begin
  590. cinnode:=tx86innode;
  591. ccasenode:=tx86casenode;
  592. end.