cgen.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. #include "gc.h"
  2. void
  3. cgen(Node *n, int result, Node *nn)
  4. {
  5. Node *l, *r, nod;
  6. int lg, rg, xg, yg, g, o;
  7. long v;
  8. Prog *p1;
  9. if(n == Z || n->type == T)
  10. return;
  11. if(typesuv[n->type->etype]) {
  12. sugen(n, result, nn, n->type->width);
  13. return;
  14. }
  15. if(debug['g']) {
  16. if(result == D_TREE)
  17. prtree(nn, "result");
  18. else
  19. print("result = %R\n", result);
  20. prtree(n, "cgen");
  21. }
  22. l = n->left;
  23. r = n->right;
  24. o = n->op;
  25. if(n->addable >= INDEXED) {
  26. if(result == D_NONE) {
  27. if(nn == Z)
  28. switch(o) {
  29. default:
  30. nullwarn(Z, Z);
  31. break;
  32. case OINDEX:
  33. nullwarn(l, r);
  34. break;
  35. }
  36. return;
  37. }
  38. gmove(n->type, nn->type, D_TREE, n, result, nn);
  39. return;
  40. }
  41. v = 0; /* set */
  42. switch(o) {
  43. default:
  44. diag(n, "unknown op in cgen: %O", o);
  45. break;
  46. case OAS:
  47. if(l->op == OBIT)
  48. goto bitas;
  49. /*
  50. * recursive use of result
  51. */
  52. if(result == D_NONE)
  53. if(l->addable > INDEXED)
  54. if(l->complex < FNX) {
  55. cgen(r, D_TREE, l);
  56. break;
  57. }
  58. /*
  59. * function calls on both sides
  60. */
  61. if(l->complex >= FNX && r->complex >= FNX) {
  62. cgen(r, D_TOS, r);
  63. v = argoff;
  64. lg = regaddr(result);
  65. lcgen(l, lg, Z);
  66. lg |= I_INDIR;
  67. adjsp(v - argoff);
  68. gmove(r->type, l->type, D_TOS, r, lg, l);
  69. if(result != D_NONE)
  70. gmove(l->type, nn->type, lg, l, result, nn);
  71. regfree(lg);
  72. break;
  73. }
  74. rg = D_TREE;
  75. lg = D_TREE;
  76. if(r->complex >= l->complex) {
  77. /*
  78. * right side before left
  79. */
  80. if(result != D_NONE) {
  81. rg = regalloc(n->type, result);
  82. cgen(r, rg, n);
  83. } else
  84. if(r->complex >= FNX || r->addable < INDEXED) {
  85. rg = regalloc(r->type, result);
  86. cgen(r, rg, r);
  87. }
  88. if(l->addable < INDEXED) {
  89. lg = regaddr(lg);
  90. lcgen(l, lg, Z);
  91. lg |= I_INDIR;
  92. }
  93. } else {
  94. /*
  95. * left before right
  96. */
  97. if(l->complex >= FNX || l->addable < INDEXED) {
  98. lg = regaddr(lg);
  99. lcgen(l, lg, Z);
  100. lg |= I_INDIR;
  101. }
  102. if(result != D_NONE) {
  103. rg = regalloc(n->type, result);
  104. cgen(r, rg, n);
  105. } else
  106. if(r->addable < INDEXED) {
  107. rg = regalloc(r->type, result);
  108. cgen(r, rg, r);
  109. }
  110. }
  111. if(result != D_NONE) {
  112. gmove(n->type, l->type, rg, r, lg, l);
  113. gmove(n->type, nn->type, rg, r, result, nn);
  114. } else
  115. gmove(r->type, l->type, rg, r, lg, l);
  116. regfree(lg);
  117. regfree(rg);
  118. break;
  119. bitas:
  120. n = l->left;
  121. rg = regalloc(tfield, result);
  122. if(l->complex >= r->complex) {
  123. lg = regaddr(D_NONE);
  124. lcgen(n, lg, Z);
  125. lg |= I_INDIR;
  126. cgen(r, rg, r);
  127. } else {
  128. cgen(r, rg, r);
  129. lg = regaddr(D_NONE);
  130. lcgen(n, lg, Z);
  131. lg |= I_INDIR;
  132. }
  133. g = regalloc(n->type, D_NONE);
  134. gmove(l->type, l->type, lg, l, g, l);
  135. bitstore(l, rg, lg, g, result, nn);
  136. break;
  137. case OBIT:
  138. if(result == D_NONE) {
  139. nullwarn(l, Z);
  140. break;
  141. }
  142. g = bitload(n, D_NONE, D_NONE, result, nn);
  143. gopcode(OAS, nn->type, g, n, result, nn);
  144. regfree(g);
  145. break;
  146. case ODOT:
  147. sugen(l, D_TREE, nodrat, l->type->width);
  148. if(result != D_NONE) {
  149. warn(n, "non-interruptable temporary");
  150. nod = *nodrat;
  151. if(!r || r->op != OCONST) {
  152. diag(n, "DOT and no offset");
  153. break;
  154. }
  155. nod.xoffset += r->vconst;
  156. nod.type = n->type;
  157. cgen(&nod, result, nn);
  158. }
  159. break;
  160. case OASLDIV:
  161. case OASLMOD:
  162. case OASDIV:
  163. case OASMOD:
  164. if(l->op == OBIT)
  165. goto asbitop;
  166. if(typefd[n->type->etype])
  167. goto asbinop;
  168. rg = D_TREE;
  169. if(l->complex >= FNX || r->complex >= FNX) {
  170. rg = D_TOS;
  171. cgen(r, rg, r);
  172. v = argoff;
  173. } else
  174. if(r->addable < INDEXED) {
  175. rg = regalloc(n->type, D_NONE);
  176. cgen(r, rg, r);
  177. }
  178. lg = D_TREE;
  179. if(!simplv(l)) {
  180. lg = regaddr(D_NONE);
  181. lcgen(l, lg, Z); /* destroys register optimization */
  182. lg |= I_INDIR;
  183. }
  184. g = regpair(result);
  185. gmove(l->type, n->type, lg, l, g, n);
  186. if(rg == D_TOS)
  187. adjsp(v - argoff);
  188. gopcode(o, n->type, rg, r, g, n);
  189. if(o == OASLMOD || o == OASMOD)
  190. gmove(n->type, l->type, g+1, n, lg, l);
  191. else
  192. gmove(n->type, l->type, g, n, lg, l);
  193. if(result != D_NONE)
  194. if(o == OASLMOD || o == OASMOD)
  195. gmove(n->type, nn->type, g+1, n, result, nn);
  196. else
  197. gmove(n->type, nn->type, g, n, result, nn);
  198. regfree(g);
  199. regfree(g+1);
  200. regfree(lg);
  201. regfree(rg);
  202. break;
  203. case OASXOR:
  204. case OASAND:
  205. case OASOR:
  206. if(l->op == OBIT)
  207. goto asbitop;
  208. if(l->complex >= FNX ||
  209. l->addable < INDEXED ||
  210. result != D_NONE ||
  211. typefd[n->type->etype])
  212. goto asbinop;
  213. rg = D_TREE;
  214. if(r->op != OCONST) {
  215. rg = regalloc(n->type, D_NONE);
  216. cgen(r, rg, r);
  217. }
  218. gopcode(o, l->type, rg, r, D_TREE, l);
  219. regfree(rg);
  220. break;
  221. case OASADD:
  222. case OASSUB:
  223. if(l->op == OBIT ||
  224. l->complex >= FNX ||
  225. l->addable < INDEXED ||
  226. result != D_NONE ||
  227. typefd[n->type->etype])
  228. goto asbinop;
  229. v = vconst(r);
  230. if(v > 0 && v <= 8) {
  231. gopcode(o, n->type, D_TREE, r, D_TREE, l);
  232. break;
  233. }
  234. rg = regalloc(n->type, D_NONE);
  235. cgen(r, rg, r);
  236. gopcode(o, n->type, rg, r, D_TREE, l);
  237. regfree(rg);
  238. break;
  239. case OASLSHR:
  240. case OASASHR:
  241. case OASASHL:
  242. if(l->op == OBIT ||
  243. l->complex >= FNX ||
  244. l->addable < INDEXED ||
  245. result != D_NONE ||
  246. typefd[n->type->etype])
  247. goto asbinop;
  248. rg = D_TREE;
  249. v = vconst(r);
  250. if(v <= 0 || v > 8) {
  251. rg = regalloc(n->type, D_NONE);
  252. cgen(r, rg, r);
  253. }
  254. lg = regalloc(n->type, D_NONE);
  255. cgen(l, lg, l);
  256. gopcode(o, n->type, rg, r, lg, l);
  257. gmove(n->type, n->type, lg, l, D_TREE, l);
  258. regfree(lg);
  259. regfree(rg);
  260. break;
  261. case OASLMUL:
  262. case OASMUL:
  263. asbinop:
  264. if(l->op == OBIT)
  265. goto asbitop;
  266. rg = D_TREE;
  267. if(l->complex >= FNX || r->complex >= FNX) {
  268. rg = D_TOS;
  269. cgen(r, rg, r);
  270. v = argoff;
  271. } else
  272. if(r->addable < INDEXED) {
  273. rg = regalloc(n->type, D_NONE);
  274. cgen(r, rg, r);
  275. } else {
  276. if(o == OASLSHR || o == OASASHR || o == OASASHL) {
  277. v = vconst(r);
  278. if(v <= 0 || v > 8) {
  279. rg = regalloc(n->type, D_NONE);
  280. cgen(r, rg, r);
  281. }
  282. }
  283. }
  284. lg = D_TREE;
  285. if(!simplv(l)) {
  286. lg = regaddr(D_NONE);
  287. lcgen(l, lg, Z); /* destroys register optimization */
  288. lg |= I_INDIR;
  289. }
  290. g = regalloc(n->type, result);
  291. gmove(l->type, n->type, lg, l, g, n);
  292. if(rg == D_TOS)
  293. adjsp(v - argoff);
  294. if(o == OASXOR)
  295. if(rg == D_TREE) {
  296. rg = regalloc(n->type, D_NONE);
  297. cgen(r, rg, r);
  298. }
  299. if(o == OASXOR || o == OASLSHR || o == OASASHR || o == OASASHL)
  300. if(rg == D_TOS) {
  301. rg = regalloc(n->type, D_NONE);
  302. gmove(n->type, n->type, D_TOS, n, rg, n);
  303. }
  304. gopcode(o, n->type, rg, r, g, n);
  305. gmove(n->type, l->type, g, n, lg, l);
  306. if(result != D_NONE)
  307. gmove(n->type, nn->type, g, n, result, nn);
  308. regfree(g);
  309. regfree(lg);
  310. regfree(rg);
  311. break;
  312. asbitop:
  313. rg = regaddr(D_NONE);
  314. lg = regalloc(tfield, D_NONE);
  315. if(l->complex >= r->complex) {
  316. g = bitload(l, lg, rg, result, nn);
  317. xg = regalloc(r->type, D_NONE);
  318. cgen(r, xg, nn);
  319. } else {
  320. xg = regalloc(r->type, D_NONE);
  321. cgen(r, xg, nn);
  322. g = bitload(l, lg, rg, result, nn);
  323. }
  324. if(!typefd[n->type->etype]) {
  325. if(o == OASLDIV || o == OASDIV) {
  326. yg = regpair(result);
  327. gmove(tfield, n->type, g, l, yg, n);
  328. gopcode(o, n->type, xg, r, yg, n);
  329. gmove(n->type, tfield, yg, n, g, l);
  330. regfree(yg);
  331. regfree(yg+1);
  332. regfree(xg);
  333. bitstore(l, g, rg, lg, D_NONE, nn);
  334. break;
  335. }
  336. if(o == OASLMOD || o == OASMOD) {
  337. yg = regpair(result);
  338. gmove(tfield, n->type, g, l, yg, n);
  339. gopcode(o, n->type, xg, r, yg, n);
  340. gmove(n->type, tfield, yg+1, n, g, l);
  341. regfree(yg);
  342. regfree(yg+1);
  343. regfree(xg);
  344. bitstore(l, g, rg, lg, D_NONE, nn);
  345. break;
  346. }
  347. }
  348. yg = regalloc(n->type, result);
  349. gmove(tfield, n->type, g, l, yg, n);
  350. gopcode(o, n->type, xg, r, yg, n);
  351. gmove(n->type, tfield, yg, n, g, l);
  352. regfree(yg);
  353. regfree(xg);
  354. bitstore(l, g, rg, lg, D_NONE, nn);
  355. break;
  356. case OCAST:
  357. if(result == D_NONE) {
  358. nullwarn(l, Z);
  359. break;
  360. }
  361. lg = result;
  362. if(l->complex >= FNX)
  363. lg = regret(l->type);
  364. lg = eval(l, lg);
  365. if(nocast(l->type, n->type)) {
  366. gmove(n->type, nn->type, lg, l, result, nn);
  367. regfree(lg);
  368. break;
  369. }
  370. if(nocast(n->type, nn->type)) {
  371. gmove(l->type, n->type, lg, l, result, nn);
  372. regfree(lg);
  373. break;
  374. }
  375. rg = regalloc(n->type, result);
  376. gmove(l->type, n->type, lg, l, rg, n);
  377. gmove(n->type, nn->type, rg, n, result, nn);
  378. regfree(rg);
  379. regfree(lg);
  380. break;
  381. case OCOND:
  382. doinc(l, PRE);
  383. boolgen(l, 1, D_NONE, Z, l);
  384. p1 = p;
  385. inargs++;
  386. doinc(r->left, PRE);
  387. cgen(r->left, result, nn);
  388. doinc(r->left, POST);
  389. gbranch(OGOTO);
  390. patch(p1, pc);
  391. p1 = p;
  392. doinc(r->right, PRE);
  393. cgen(r->right, result, nn);
  394. doinc(r->right, POST);
  395. patch(p1, pc);
  396. inargs--;
  397. break;
  398. case OIND:
  399. if(result == D_NONE) {
  400. nullwarn(l, Z);
  401. break;
  402. }
  403. lg = nodalloc(types[TIND], result, &nod);
  404. nod.lineno = n->lineno;
  405. if(l->op == OADD) {
  406. if(l->left->op == OCONST) {
  407. nod.xoffset += l->left->vconst;
  408. l = l->right;
  409. } else
  410. if(l->right->op == OCONST) {
  411. nod.xoffset += l->right->vconst;
  412. l = l->left;
  413. }
  414. }
  415. cgen(l, lg, l);
  416. gmove(n->type, nn->type, D_TREE, &nod, result, nn);
  417. regfree(lg);
  418. break;
  419. case OFUNC:
  420. v = argoff;
  421. inargs++;
  422. gargs(r);
  423. lg = D_TREE;
  424. if(l->addable < INDEXED) {
  425. lg = regaddr(result);
  426. lcgen(l, lg, Z);
  427. lg |= I_INDIR;
  428. }
  429. inargs--;
  430. doinc(r, POST);
  431. doinc(l, POST);
  432. gopcode(OFUNC, types[TCHAR], D_NONE, Z, lg, l);
  433. regfree(lg);
  434. if(inargs)
  435. adjsp(v - argoff);
  436. if(result != D_NONE) {
  437. lg = regret(n->type);
  438. gmove(n->type, nn->type, lg, n, result, nn);
  439. }
  440. break;
  441. case OLDIV:
  442. case OLMOD:
  443. case ODIV:
  444. case OMOD:
  445. if(result == D_NONE) {
  446. nullwarn(l, r);
  447. break;
  448. }
  449. if(typefd[n->type->etype])
  450. goto binop;
  451. if(r->addable >= INDEXED && r->complex < FNX) {
  452. lg = regpair(result);
  453. cgen(l, lg, l);
  454. rg = D_TREE;
  455. } else {
  456. cgen(r, D_TOS, r);
  457. v = argoff;
  458. lg = regpair(result);
  459. cgen(l, lg, l);
  460. adjsp(v - argoff);
  461. rg = D_TOS;
  462. }
  463. gopcode(o, n->type, rg, r, lg, l);
  464. if(o == OMOD || o == OLMOD)
  465. gmove(l->type, nn->type, lg+1, l, result, nn);
  466. else
  467. gmove(l->type, nn->type, lg, l, result, nn);
  468. regfree(lg);
  469. regfree(lg+1);
  470. break;
  471. case OMUL:
  472. case OLMUL:
  473. if(l->op == OCONST)
  474. if(mulcon(r, l, result, nn))
  475. break;
  476. if(r->op == OCONST)
  477. if(mulcon(l, r, result, nn))
  478. break;
  479. if(debug['M'])
  480. print("%L multiply\n", n->lineno);
  481. goto binop;
  482. case OAND:
  483. if(r->op == OCONST)
  484. if(typeil[n->type->etype])
  485. if(l->op == OCAST) {
  486. if(typec[l->left->type->etype])
  487. if(!(r->vconst & ~0xff)) {
  488. l = l->left;
  489. goto binop;
  490. }
  491. if(typeh[l->left->type->etype])
  492. if(!(r->vconst & ~0xffff)) {
  493. l = l->left;
  494. goto binop;
  495. }
  496. }
  497. goto binop;
  498. case OADD:
  499. if(result == D_TOS)
  500. if(r->addable >= INDEXED)
  501. if(l->op == OCONST)
  502. if(typeil[l->type->etype]) {
  503. v = l->vconst;
  504. if(v > -32768 && v < 32768) {
  505. rg = regaddr(D_NONE);
  506. gmove(r->type, r->type, D_TREE, r, rg, r);
  507. gopcode(OADDR, types[TSHORT], D_NONE, Z, rg, r);
  508. p->to.offset = v;
  509. p->to.type |= I_INDIR;
  510. regfree(rg);
  511. break;
  512. }
  513. }
  514. case OSUB:
  515. if(result == D_TOS)
  516. if(l->addable >= INDEXED)
  517. if(r->op == OCONST)
  518. if(typeil[r->type->etype]) {
  519. v = r->vconst;
  520. if(v > -32768 && v < 32768) {
  521. if(n->op == OSUB)
  522. v = -v;
  523. lg = regaddr(D_NONE);
  524. gmove(l->type, l->type, D_TREE, l, lg, l);
  525. gopcode(OADDR, types[TSHORT], D_NONE, Z, lg, l);
  526. p->to.offset = v;
  527. p->to.type |= I_INDIR;
  528. regfree(lg);
  529. break;
  530. }
  531. }
  532. goto binop;
  533. case OOR:
  534. case OXOR:
  535. binop:
  536. if(result == D_NONE) {
  537. nullwarn(l, r);
  538. break;
  539. }
  540. if(l->complex >= FNX && r->complex >= FNX) {
  541. cgen(r, D_TOS, r);
  542. v = argoff;
  543. lg = regalloc(l->type, result);
  544. cgen(l, lg, l);
  545. adjsp(v - argoff);
  546. if(o == OXOR) {
  547. rg = regalloc(r->type, D_NONE);
  548. gmove(r->type, r->type, D_TOS, r, rg, r);
  549. gopcode(o, n->type, rg, r, lg, l);
  550. regfree(rg);
  551. } else
  552. gopcode(o, n->type, D_TOS, r, lg, l);
  553. gmove(n->type, nn->type, lg, l, result, nn);
  554. regfree(lg);
  555. break;
  556. }
  557. if(l->complex >= r->complex) {
  558. if(l->op == OADDR && (o == OADD || o == OSUB))
  559. lg = regaddr(result);
  560. else
  561. lg = regalloc(l->type, result);
  562. cgen(l, lg, l);
  563. rg = eval(r, D_NONE);
  564. } else {
  565. rg = regalloc(r->type, D_NONE);
  566. cgen(r, rg, r);
  567. lg = regalloc(l->type, result);
  568. cgen(l, lg, l);
  569. }
  570. if(o == OXOR) {
  571. if(rg == D_TREE) {
  572. rg = regalloc(r->type, D_NONE);
  573. cgen(r, rg, r);
  574. }
  575. if(rg == D_TOS) {
  576. rg = regalloc(r->type, D_NONE);
  577. gmove(r->type, r->type, D_TOS, r, rg, r);
  578. }
  579. }
  580. gopcode(o, n->type, rg, r, lg, l);
  581. gmove(n->type, nn->type, lg, l, result, nn);
  582. regfree(lg);
  583. regfree(rg);
  584. break;
  585. case OASHL:
  586. if(r->op == OCONST)
  587. if(shlcon(l, r, result, nn))
  588. break;
  589. case OLSHR:
  590. case OASHR:
  591. if(result == D_NONE) {
  592. nullwarn(l, r);
  593. break;
  594. }
  595. if(l->complex >= FNX && r->complex >= FNX) {
  596. cgen(r, D_TOS, r);
  597. v = argoff;
  598. lg = regalloc(l->type, result);
  599. cgen(l, lg, l);
  600. adjsp(v - argoff);
  601. rg = regalloc(r->type, D_NONE);
  602. gopcode(OAS, r->type, D_TOS, r, rg, r);
  603. gopcode(n->op, n->type, rg, r, lg, l);
  604. gmove(n->type, nn->type, lg, l, result, nn);
  605. regfree(lg);
  606. regfree(rg);
  607. break;
  608. }
  609. if(l->complex >= r->complex) {
  610. lg = regalloc(l->type, result);
  611. cgen(l, lg, l);
  612. v = vconst(r);
  613. if(v <= 0 || v > 8) {
  614. rg = regalloc(r->type, D_NONE);
  615. cgen(r, rg, r);
  616. } else
  617. rg = eval(r, D_NONE);
  618. } else {
  619. rg = regalloc(r->type, D_NONE);
  620. cgen(r, rg, r);
  621. lg = regalloc(l->type, result);
  622. cgen(l, lg, l);
  623. }
  624. gopcode(o, n->type, rg, r, lg, l);
  625. gmove(n->type, nn->type, lg, l, result, nn);
  626. regfree(lg);
  627. regfree(rg);
  628. break;
  629. case ONEG:
  630. case OCOM:
  631. if(result == D_NONE) {
  632. nullwarn(l, Z);
  633. break;
  634. }
  635. lg = regalloc(l->type, result);
  636. cgen(l, lg, l);
  637. gopcode(o, l->type, D_NONE, Z, lg, l);
  638. gmove(n->type, nn->type, lg, l, result, nn);
  639. regfree(lg);
  640. break;
  641. case OADDR:
  642. if(result == D_NONE) {
  643. nullwarn(l, Z);
  644. break;
  645. }
  646. if(l->op == OINDEX && l->scale == 4 && result != D_TOS) {
  647. /* index scaled by 1, add is better */
  648. nod = *l;
  649. nod.op = OADD;
  650. nod.addable = 0;
  651. cgen(&nod, result, nn);
  652. break;
  653. }
  654. lcgen(l, result, nn);
  655. break;
  656. case OEQ:
  657. case ONE:
  658. case OLE:
  659. case OLT:
  660. case OGE:
  661. case OGT:
  662. case OLO:
  663. case OLS:
  664. case OHI:
  665. case OHS:
  666. if(result == D_NONE) {
  667. nullwarn(l, r);
  668. break;
  669. }
  670. boolgen(n, 1, result, nn, Z);
  671. break;
  672. case OANDAND:
  673. case OOROR:
  674. boolgen(n, 1, result, nn, Z);
  675. if(result == D_NONE)
  676. patch(p, pc);
  677. break;
  678. case OCOMMA:
  679. cgen(l, D_NONE, l);
  680. doinc(l, POST);
  681. doinc(r, PRE);
  682. cgen(r, result, nn);
  683. break;
  684. case ONOT:
  685. if(result == D_NONE) {
  686. nullwarn(l, Z);
  687. break;
  688. }
  689. boolgen(n, 1, result, nn, Z);
  690. break;
  691. case OPOSTINC:
  692. case OPOSTDEC:
  693. v = 1;
  694. if(l->type->etype == TIND)
  695. v = l->type->link->width;
  696. if(o == OPOSTDEC)
  697. v = -v;
  698. if(l->op == OBIT)
  699. goto bitinc;
  700. if(nn == Z)
  701. goto pre;
  702. lg = D_TREE;
  703. if(l->addable < INDEXED) {
  704. lg = regaddr(D_NONE);
  705. lcgen(l, lg, Z);
  706. lg |= I_INDIR;
  707. }
  708. if(result != D_NONE)
  709. gmove(l->type, nn->type, lg, l, result, nn);
  710. if(typefd[n->type->etype]) {
  711. rg = regalloc(n->type, D_NONE);
  712. gmove(l->type, l->type, lg, l, rg, l);
  713. gopcode(o, n->type, D_CONST, nodconst(1), rg, l);
  714. gmove(l->type, l->type, rg, l, lg, l);
  715. regfree(rg);
  716. } else {
  717. if(v < 0)
  718. gopcode(o, n->type, D_CONST, nodconst(-v), lg, l);
  719. else
  720. gopcode(o, n->type, D_CONST, nodconst(v), lg, l);
  721. }
  722. regfree(lg);
  723. break;
  724. case OPREINC:
  725. case OPREDEC:
  726. v = 1;
  727. if(l->type->etype == TIND)
  728. v = l->type->link->width;
  729. if(o == OPREDEC)
  730. v = -v;
  731. if(l->op == OBIT)
  732. goto bitinc;
  733. pre:
  734. lg = D_TREE;
  735. if(l->addable < INDEXED) {
  736. lg = regaddr(D_NONE);
  737. lcgen(l, lg, Z);
  738. lg |= I_INDIR;
  739. }
  740. if(typefd[n->type->etype]) {
  741. rg = regalloc(n->type, D_NONE);
  742. gmove(l->type, l->type, lg, l, rg, l);
  743. gopcode(o, n->type, D_CONST, nodconst(1), rg, l);
  744. gmove(l->type, l->type, rg, l, lg, l);
  745. regfree(rg);
  746. } else {
  747. if(v < 0)
  748. gopcode(o, n->type, D_CONST, nodconst(-v), lg, l);
  749. else
  750. gopcode(o, n->type, D_CONST, nodconst(v), lg, l);
  751. }
  752. if(result != D_NONE)
  753. gmove(l->type, nn->type, lg, l, result, nn);
  754. regfree(lg);
  755. break;
  756. bitinc:
  757. rg = regaddr(D_NONE);
  758. lg = regalloc(tfield, D_NONE);
  759. if(result != D_NONE && (o == OPOSTINC || o == OPOSTDEC)) {
  760. g = bitload(l, lg, rg, D_NONE, nn);
  761. if(nn != Z)
  762. gmove(l->type, nn->type, g, l, result, nn);
  763. if(v < 0)
  764. gopcode(o, n->type, D_CONST, nodconst(-v), g, n);
  765. else
  766. gopcode(o, n->type, D_CONST, nodconst(v), g, n);
  767. bitstore(l, g, rg, lg, D_NONE, nn);
  768. break;
  769. }
  770. g = bitload(l, lg, rg, result, nn);
  771. if(v < 0)
  772. gopcode(o, n->type, D_CONST, nodconst(-v), g, n);
  773. else
  774. gopcode(o, n->type, D_CONST, nodconst(v), g, n);
  775. if(result != D_NONE)
  776. gmove(l->type, nn->type, g, l, result, nn);
  777. bitstore(l, g, rg, lg, D_NONE, nn);
  778. break;
  779. }
  780. }
  781. void
  782. lcgen(Node *n, int result, Node *nn)
  783. {
  784. Node rn;
  785. Prog *p1;
  786. int lg;
  787. if(n == Z || n->type == T)
  788. return;
  789. if(debug['g']) {
  790. if(result == D_TREE)
  791. prtree(nn, "result");
  792. else
  793. print("result = %R\n", result);
  794. prtree(n, "lcgen");
  795. }
  796. if(nn == Z) {
  797. nn = &rn;
  798. nn->type = types[TIND];
  799. }
  800. switch(n->op) {
  801. case OCOMMA:
  802. cgen(n->left, D_NONE, n->left);
  803. doinc(n->left, POST);
  804. doinc(n->right, PRE);
  805. lcgen(n->right, result, nn);
  806. break;
  807. case OCOND:
  808. doinc(n->left, PRE);
  809. boolgen(n->left, 1, D_NONE, Z, n->left);
  810. p1 = p;
  811. inargs++;
  812. doinc(n->right->left, PRE);
  813. lcgen(n->right->left, result, nn);
  814. doinc(n->right->left, POST);
  815. gbranch(OGOTO);
  816. patch(p1, pc);
  817. p1 = p;
  818. doinc(n->right->right, PRE);
  819. lcgen(n->right->right, result, nn);
  820. doinc(n->right->right, POST);
  821. patch(p1, pc);
  822. inargs--;
  823. break;
  824. case OIND:
  825. if(n->addable >= INDEXED) {
  826. if(result >= D_A0 && result < D_A0+NREG) {
  827. gopcode(OADDR, types[TLONG], D_TREE, n, result, nn);
  828. break;
  829. }
  830. if(result == D_TOS) {
  831. gopcode(OADDR, types[TSHORT], D_NONE, nn, D_TREE, n);
  832. break;
  833. }
  834. }
  835. cgen(n->left, result, nn);
  836. break;
  837. default:
  838. if(n->addable < INDEXED) {
  839. diag(n, "unknown op in lcgen: %O", n->op);
  840. break;
  841. }
  842. if(result >= D_A0 && result < D_A0+NREG) {
  843. gopcode(OADDR, types[TLONG], D_TREE, n, result, nn);
  844. break;
  845. }
  846. if(result == D_TOS) {
  847. gopcode(OADDR, types[TSHORT], D_NONE, nn, D_TREE, n);
  848. break;
  849. }
  850. lg = regaddr(result);
  851. gopcode(OADDR, types[TLONG], D_TREE, n, lg, nn);
  852. gopcode(OAS, nn->type, lg, nn, result, nn);
  853. regfree(lg);
  854. break;
  855. }
  856. }
  857. void
  858. bcgen(Node *n, int true)
  859. {
  860. boolgen(n, true, D_NONE, Z, Z);
  861. }
  862. void
  863. boolgen(Node *n, int true, int result, Node *nn, Node *post)
  864. {
  865. Prog *p1, *p2;
  866. Node *l, *r;
  867. int lg, rg, fp, o;
  868. long v;
  869. if(debug['g']) {
  870. if(result == D_TREE)
  871. prtree(nn, "result");
  872. else
  873. print("result = %R\n", result);
  874. prtree(n, "boolgen");
  875. }
  876. l = n->left;
  877. r = n->right;
  878. switch(n->op) {
  879. default:
  880. lg = eval(n, result);
  881. if(lg >= D_A0 && lg < D_A0+NREG) {
  882. rg = regalloc(types[TLONG], D_NONE);
  883. gopcode(OAS, types[TLONG], lg, n, rg, Z);
  884. regfree(rg);
  885. } else
  886. gopcode(OTST, n->type, D_NONE, Z, lg, n);
  887. regfree(lg);
  888. o = ONE;
  889. fp = typefd[n->type->etype];
  890. goto genbool;
  891. case OCONST:
  892. fp = vconst(n);
  893. if(!true)
  894. fp = !fp;
  895. gbranch(OGOTO);
  896. if(fp) {
  897. p1 = p;
  898. gbranch(OGOTO);
  899. patch(p1, pc);
  900. }
  901. goto com;
  902. case ONOT:
  903. boolgen(l, !true, result, nn, post);
  904. break;
  905. case OCOND:
  906. doinc(l, PRE);
  907. boolgen(l, 1, D_NONE, Z, l);
  908. p1 = p;
  909. inargs++;
  910. doinc(r->left, PRE);
  911. boolgen(r->left, true, result, nn, r->left);
  912. if(result != D_NONE) {
  913. doinc(r->left, POST);
  914. gbranch(OGOTO);
  915. patch(p1, pc);
  916. p1 = p;
  917. doinc(r->right, PRE);
  918. boolgen(r->right, !true, result, nn, r->right);
  919. doinc(r->right, POST);
  920. patch(p1, pc);
  921. inargs--;
  922. break;
  923. }
  924. p2 = p;
  925. gbranch(OGOTO);
  926. patch(p1, pc);
  927. p1 = p;
  928. doinc(r->right, PRE);
  929. boolgen(r->right, !true, result, nn, r->right);
  930. patch(p2, pc);
  931. p2 = p;
  932. if(doinc(post, POST|TEST)) {
  933. lg = regalloc(types[TSHORT], D_NONE);
  934. gopcode(OAS, types[TSHORT], D_CCR, Z, lg, Z);
  935. doinc(post, POST);
  936. gopcode(OAS, types[TSHORT], lg, Z, D_CCR, Z);
  937. regfree(lg);
  938. }
  939. gbranch(OGOTO);
  940. patch(p1, pc);
  941. patch(p2, pc);
  942. inargs--;
  943. goto com;
  944. case OANDAND:
  945. if(!true)
  946. goto caseor;
  947. caseand:
  948. doinc(l, PRE);
  949. boolgen(l, true, D_NONE, Z, l);
  950. p1 = p;
  951. inargs++;
  952. doinc(r, PRE);
  953. boolgen(r, !true, D_NONE, Z, r);
  954. p2 = p;
  955. patch(p1, pc);
  956. gbranch(OGOTO);
  957. patch(p2, pc);
  958. inargs--;
  959. goto com;
  960. case OOROR:
  961. if(!true)
  962. goto caseand;
  963. caseor:
  964. doinc(l, PRE);
  965. boolgen(l, !true, D_NONE, Z, l);
  966. p1 = p;
  967. inargs++;
  968. doinc(r, PRE);
  969. boolgen(r, !true, D_NONE, Z, r);
  970. p2 = p;
  971. gbranch(OGOTO);
  972. patch(p1, pc);
  973. patch(p2, pc);
  974. inargs--;
  975. goto com;
  976. case OEQ:
  977. case ONE:
  978. if(vconst(l) == 0) {
  979. if(n->op == ONE) {
  980. boolgen(r, true, result, nn, post);
  981. break;
  982. }
  983. boolgen(r, !true, result, nn, post);
  984. break;
  985. }
  986. case OLE:
  987. case OLT:
  988. case OGE:
  989. case OGT:
  990. case OHI:
  991. case OHS:
  992. case OLO:
  993. case OLS:
  994. fp = typefd[r->type->etype];
  995. if(l->op == OCONST) {
  996. v = vconst(l);
  997. if(v == 0) { /* tst instruction */
  998. o = invrel[relindex(n->op)];
  999. rg = eval(r, result);
  1000. gopcode(OTST, r->type, D_NONE, Z, rg, r);
  1001. regfree(rg);
  1002. goto genbool;
  1003. }
  1004. if(!fp) { /* cmpi and movq, saves about .5% both time and space */
  1005. if(v < 128 && v >= -128 &&
  1006. ewidth[r->type->etype] == SZ_LONG) {
  1007. rg = eval(r, result);
  1008. lg = regalloc(l->type, D_NONE);
  1009. cgen(l, lg, l);
  1010. o = n->op;
  1011. gopcode(o, l->type, lg, l, rg, r);
  1012. regfree(lg);
  1013. regfree(rg);
  1014. goto genbool;
  1015. }
  1016. o = invrel[relindex(n->op)];
  1017. rg = eval(r, result);
  1018. gopcode(o, r->type, rg, r, D_TREE, l);
  1019. regfree(rg);
  1020. goto genbool;
  1021. }
  1022. }
  1023. lg = D_TOS;
  1024. if(r->complex < FNX)
  1025. lg = regalloc(l->type, lg);
  1026. cgen(l, lg, l);
  1027. v = argoff;
  1028. rg = eval(r, result);
  1029. if(lg == D_TOS) {
  1030. adjsp(v - argoff);
  1031. lg = regalloc(l->type, lg);
  1032. gopcode(OAS, l->type, D_TOS, l, lg, l);
  1033. }
  1034. o = n->op;
  1035. gopcode(o, l->type, lg, l, rg, r);
  1036. regfree(lg);
  1037. regfree(rg);
  1038. genbool:
  1039. if(true)
  1040. o = comrel[relindex(o)];
  1041. if(doinc(post, POST|TEST)) {
  1042. lg = regalloc(types[TSHORT], D_NONE);
  1043. gopcode(OAS, types[TSHORT], D_CCR, Z, lg, Z);
  1044. doinc(post, POST);
  1045. gopcode(OAS, types[TSHORT], lg, Z, D_CCR, Z);
  1046. regfree(lg);
  1047. }
  1048. gbranch(o);
  1049. if(fp)
  1050. fpbranch();
  1051. com:
  1052. if(result == D_NONE)
  1053. break;
  1054. p1 = p;
  1055. gopcode(OAS, nn->type, D_CONST, nodconst(1), result, nn);
  1056. gbranch(OGOTO);
  1057. p2 = p;
  1058. patch(p1, pc);
  1059. gopcode(OAS, nn->type, D_CONST, nodconst(0), result, nn);
  1060. patch(p2, pc);
  1061. break;
  1062. }
  1063. }
  1064. void
  1065. sugen(Node *n, int result, Node *nn, long w)
  1066. {
  1067. long s, v, o;
  1068. int lg, rg, ng;
  1069. Prog *p1;
  1070. Node *l, *r, nod;
  1071. Type *t;
  1072. if(n == Z || n->type == T)
  1073. return;
  1074. if(debug['g']) {
  1075. if(result == D_TREE)
  1076. prtree(nn, "result");
  1077. else
  1078. print("result = %R width = %ld\n", result, w);
  1079. prtree(n, "sugen");
  1080. }
  1081. s = argoff;
  1082. if(result == D_TREE) {
  1083. if(nn == nodrat)
  1084. if(w > nrathole)
  1085. nrathole = w;
  1086. }
  1087. if(n->addable >= INDEXED && n->op != OCONST)
  1088. goto copy;
  1089. switch(n->op) {
  1090. default:
  1091. diag(n, "unknown op in sugen: %O", n->op);
  1092. break;
  1093. case OCONST:
  1094. if(n->type && typev[n->type->etype]) {
  1095. if(result == D_NONE) {
  1096. nullwarn(n->left, Z);
  1097. break;
  1098. }
  1099. lg = regaddr(D_NONE);
  1100. if(result == D_TOS) {
  1101. adjsp(s - argoff + w);
  1102. gopcode(OADDR, types[TIND], result, nn, lg, n);
  1103. } else
  1104. if(result == D_TREE) {
  1105. lcgen(nn, lg, Z);
  1106. } else
  1107. diag(n, "unknown su result: %R", result);
  1108. gopcode(OAS, types[TLONG], D_CONST, nodconst((long)(n->vconst>>32)),
  1109. lg|I_INDINC, n);
  1110. gopcode(OAS, types[TLONG], D_CONST, nodconst((long)(n->vconst)),
  1111. lg|I_INDINC, n);
  1112. regfree(lg);
  1113. break;
  1114. }
  1115. goto copy;
  1116. case ODOT:
  1117. l = n->left;
  1118. sugen(l, D_TREE, nodrat, l->type->width);
  1119. if(result != D_NONE) {
  1120. warn(n, "non-interruptable temporary");
  1121. nod = *nodrat;
  1122. r = n->right;
  1123. if(!r || r->op != OCONST) {
  1124. diag(n, "DOT and no offset");
  1125. break;
  1126. }
  1127. nod.xoffset += r->vconst;
  1128. nod.type = n->type;
  1129. sugen(&nod, result, nn, w);
  1130. }
  1131. break;
  1132. case OIND:
  1133. if(result == D_NONE) {
  1134. nullwarn(n->left, Z);
  1135. break;
  1136. }
  1137. goto copy;
  1138. case OSTRUCT:
  1139. lg = nodalloc(types[TIND], result, &nod);
  1140. nod.lineno = n->lineno;
  1141. if(result == D_TREE)
  1142. lcgen(nn, lg, Z);
  1143. else
  1144. if(result == D_TOS) {
  1145. adjsp(s - argoff + w);
  1146. gopcode(OADDR, types[TIND], result, nn, lg, n);
  1147. } else
  1148. diag(n, "unknown su result: %R", result);
  1149. o = 0;
  1150. r = n->left;
  1151. for(t = n->type->link; t != T; t = t->down) {
  1152. l = r;
  1153. if(r->op == OLIST) {
  1154. l = r->left;
  1155. r = r->right;
  1156. }
  1157. nod.type = t;
  1158. if(l->complex < FNX) {
  1159. nod.xoffset = 0;
  1160. if(o != t->offset) {
  1161. gopcode(OADD, types[TIND], D_CONST,
  1162. nodconst(t->offset-o), lg, Z);
  1163. o = t->offset;
  1164. }
  1165. cgen(l, D_TREE, &nod);
  1166. continue;
  1167. }
  1168. nod.xoffset = t->offset - o;
  1169. gopcode(OAS, types[TIND], lg, Z, D_TOS, Z);
  1170. s = argoff;
  1171. if(typesuv[t->etype]) {
  1172. sugen(l, D_TREE, nodrat, t->width);
  1173. adjsp(s - argoff);
  1174. gopcode(OAS, types[TIND], D_TOS, Z, lg, Z);
  1175. warn(n, "non-interruptable temporary");
  1176. sugen(nodrat, D_TREE, &nod, t->width);
  1177. continue;
  1178. }
  1179. rg = regalloc(t, D_NONE);
  1180. cgen(l, rg, l);
  1181. adjsp(s - argoff);
  1182. gopcode(OAS, types[TIND], D_TOS, Z, lg, Z);
  1183. gopcode(OAS, t, rg, Z, D_TREE, &nod);
  1184. regfree(rg);
  1185. }
  1186. regfree(lg);
  1187. break;
  1188. case OAS:
  1189. if(result == D_NONE) {
  1190. sugen(n->right, D_TREE, n->left, w);
  1191. break;
  1192. }
  1193. sugen(n->right, D_TREE, nodrat, w); /* could do better */
  1194. warn(n, "non-interruptable temporary");
  1195. sugen(nodrat, D_TREE, n->left, w);
  1196. sugen(nodrat, result, nn, w);
  1197. break;
  1198. case OFUNC:
  1199. if(result == D_NONE) {
  1200. sugen(n, D_TREE, nodrat, w);
  1201. break;
  1202. }
  1203. inargs++;
  1204. /* prepare zero-th arg: address of result */
  1205. if(result == D_TOS) {
  1206. adjsp(s - argoff + w);
  1207. v = argoff;
  1208. gargs(n->right);
  1209. gopcode(OADDR, types[TSHORT], D_NONE, nn, result, nn);
  1210. p->to.type = D_STACK;
  1211. p->to.offset = argoff - v;
  1212. } else
  1213. if(result == D_TREE) {
  1214. v = argoff;
  1215. gargs(n->right);
  1216. if(nn->complex >= FNX) {
  1217. rg = regalloc(types[TIND], regret(types[TIND]));
  1218. lcgen(nn, rg, Z);
  1219. gopcode(OAS, types[TIND], rg, Z, D_TOS, Z);
  1220. regfree(rg);
  1221. } else
  1222. lcgen(nn, D_TOS, Z);
  1223. } else {
  1224. diag(n, "unknown result in FUNC sugen");
  1225. break;
  1226. }
  1227. argoff += types[TIND]->width;
  1228. l = n->left;
  1229. lg = D_TREE;
  1230. if(l->addable < INDEXED) {
  1231. lg = regaddr(result);
  1232. lcgen(l, lg, Z);
  1233. lg |= I_INDIR;
  1234. }
  1235. inargs--;
  1236. doinc(n->right, POST);
  1237. doinc(n->left, POST);
  1238. gopcode(OFUNC, types[TCHAR], D_NONE, Z, lg, l);
  1239. regfree(lg);
  1240. if(inargs)
  1241. adjsp(v - argoff);
  1242. break;
  1243. case OCOND:
  1244. doinc(n->left, PRE);
  1245. boolgen(n->left, 1, D_NONE, Z, n->left);
  1246. p1 = p;
  1247. inargs++;
  1248. doinc(n->right->left, PRE);
  1249. sugen(n->right->left, result, nn, w);
  1250. doinc(n->right->left, POST);
  1251. gbranch(OGOTO);
  1252. patch(p1, pc);
  1253. p1 = p;
  1254. doinc(n->right->right, PRE);
  1255. sugen(n->right->right, result, nn, w);
  1256. doinc(n->right->right, POST);
  1257. patch(p1, pc);
  1258. inargs--;
  1259. break;
  1260. case OCOMMA:
  1261. cgen(n->left, D_NONE, n->left);
  1262. doinc(n->left, POST);
  1263. doinc(n->right, PRE);
  1264. sugen(n->right, result, nn, w);
  1265. break;
  1266. }
  1267. return;
  1268. copy:
  1269. if(result == D_NONE)
  1270. return;
  1271. rg = regaddr(D_NONE);
  1272. lcgen(n, rg, Z);
  1273. lg = regaddr(D_NONE);
  1274. if(result == D_TOS) {
  1275. adjsp(s - argoff + w);
  1276. gopcode(OADDR, types[TIND], result, nn, lg, n);
  1277. } else
  1278. if(result == D_TREE) {
  1279. if(nn->complex >= FNX) {
  1280. gopcode(OAS, types[TIND], rg, n, D_TOS, n);
  1281. s = argoff;
  1282. lcgen(nn, lg, Z);
  1283. adjsp(s - argoff);
  1284. gopcode(OAS, types[TIND], D_TOS, n, rg, n);
  1285. } else
  1286. lcgen(nn, lg, Z);
  1287. } else
  1288. diag(n, "unknown su result: %R", result);
  1289. if(w % SZ_LONG)
  1290. diag(Z, "sucopy width not 0%%%d", SZ_LONG);
  1291. v = w / SZ_LONG;
  1292. if(v & 1) {
  1293. gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
  1294. v--;
  1295. }
  1296. if(v > 6) {
  1297. ng = regalloc(types[TLONG], D_NONE);
  1298. gopcode(OAS, types[TLONG], D_CONST, nodconst(v/2-1), ng, n);
  1299. v = pc;
  1300. gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
  1301. gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
  1302. gbranch(OGT);
  1303. patch(p, v);
  1304. p->from.type = ng;
  1305. p->as = ADBF;
  1306. regfree(ng);
  1307. } else
  1308. while(v > 0) {
  1309. gopcode(OAS, types[TLONG], rg|I_INDINC, n, lg|I_INDINC, n);
  1310. v--;
  1311. }
  1312. regfree(lg);
  1313. regfree(rg);
  1314. }