nx86set.pas 27 KB

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