PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/misc/pascal/insn32/popt/pcopt.c

https://github.com/markangelo/PX4NuttX
C | 840 lines | 693 code | 91 blank | 56 comment | 186 complexity | 45f7ebe6a6853ced3cae01a4c70bd82c MD5 | raw file
Possible License(s): GPL-2.0, 0BSD
  1. /**********************************************************************
  2. * pcopt.c
  3. * Constant Expression Optimizations
  4. *
  5. * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
  6. * Author: Gregory Nutt <gnutt@nuttx.org>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. **********************************************************************/
  36. /**********************************************************************
  37. * Included Files
  38. **********************************************************************/
  39. #include <stdint.h>
  40. #include <stdio.h>
  41. #include "keywords.h"
  42. #include "pdefs.h"
  43. #include "pinsn32.h"
  44. #include "paslib.h"
  45. #include "popt.h"
  46. #include "polocal.h"
  47. #include "pcopt.h"
  48. /**********************************************************************/
  49. int unaryOptimize(void)
  50. {
  51. register uint32_t temp;
  52. register int i;
  53. int nchanges = 0;
  54. TRACE(stderr, "[unaryOptimize]");
  55. /* At least two pcodes are need to perform unary optimizations */
  56. i = 0;
  57. while (i < nops-1)
  58. {
  59. /* Check for a constant value being pushed onto the stack */
  60. if (GETOP(pptr[i]) == oPUSH)
  61. {
  62. switch (GETOP(pptr[i+1]))
  63. {
  64. /* Delete unary operators on constants */
  65. case oNEG :
  66. PUTARG(pptr[i], -GETARG(pptr[i]));
  67. deletePcode(i+1);
  68. nchanges++;
  69. break;
  70. case oABS :
  71. if ((int32_t)GETARG(pptr[i]) < 0)
  72. PUTARG(pptr[i], -(int32_t)GETARG(pptr[i]));
  73. deletePcode(i+1);
  74. nchanges++;
  75. break;
  76. case oINC :
  77. PUTARG(pptr[i], GETARG(pptr[i]) + 1);
  78. deletePcode(i+1);
  79. nchanges++;
  80. break;
  81. case oDEC :
  82. PUTARG(pptr[i], GETARG(pptr[i]) - 1);
  83. deletePcode(i+1);
  84. nchanges++;
  85. break;
  86. case oNOT :
  87. PUTARG(pptr[i], ~GETARG(pptr[i]));
  88. PUTARG(pptr[i], ~(GETARG(pptr[i])));
  89. deletePcode(i+1);
  90. nchanges++;
  91. break;
  92. /* Simplify binary operations on constants */
  93. case oADD :
  94. if (GETARG(pptr[i]) == 0)
  95. {
  96. deletePcodePair(i, (i+1));
  97. nchanges++;
  98. } /* end if */
  99. else if (GETARG(pptr[i]) == 1)
  100. {
  101. PUTOP(pptr[i+1], oINC);
  102. deletePcode(i);
  103. nchanges++;
  104. } /* end else if */
  105. else if (GETARG(pptr[i]) == ARGONES)
  106. {
  107. PUTOP(pptr[i+1], oDEC);
  108. deletePcode(i);
  109. nchanges++;
  110. } /* end else if */
  111. else i++;
  112. break;
  113. case oSUB :
  114. if (GETARG(pptr[i]) == 0)
  115. {
  116. deletePcodePair(i, (i+1));
  117. nchanges++;
  118. } /* end if */
  119. else if (GETARG(pptr[i]) == 1)
  120. {
  121. PUTOP(pptr[i+1], oDEC);
  122. deletePcode(i);
  123. nchanges++;
  124. } /* end else if */
  125. else if (GETARG(pptr[i]) == ARGONES)
  126. {
  127. PUTOP(pptr[i+1], oINC);
  128. deletePcode(i);
  129. nchanges++;
  130. } /* end else if */
  131. else i++;
  132. break;
  133. case oMUL :
  134. case oDIV :
  135. temp = 0;
  136. switch (GETARG(pptr[i]))
  137. {
  138. case 1 :
  139. deletePcodePair(i, (i+1));
  140. nchanges++;
  141. break;
  142. case 16384 : temp++;
  143. case 8192 : temp++;
  144. case 4096 : temp++;
  145. case 2048 : temp++;
  146. case 1024 : temp++;
  147. case 512 : temp++;
  148. case 256 : temp++;
  149. case 128 : temp++;
  150. case 64 : temp++;
  151. case 32 : temp++;
  152. case 16 : temp++;
  153. case 8 : temp++;
  154. case 4 : temp++;
  155. case 2 : temp++;
  156. PUTARG(pptr[i], temp);
  157. if (GETOP(pptr[i+1]) == oMUL)
  158. PUTOP(pptr[i+1], oSLL);
  159. else
  160. PUTOP(pptr[i+1], oSRA);
  161. nchanges++;
  162. i++;
  163. break;
  164. default :
  165. i++;
  166. break;
  167. } /* end switch */
  168. break;
  169. case oSLL :
  170. case oSRL :
  171. case oSRA :
  172. case oOR :
  173. if (GETARG(pptr[i]) == 0)
  174. {
  175. deletePcodePair(i, (i+1));
  176. nchanges++;
  177. } /* end if */
  178. else i++;
  179. break;
  180. case oAND :
  181. if (GETARG(pptr[i]) == ARGONES)
  182. {
  183. deletePcodePair(i, (i+1));
  184. nchanges++;
  185. } /* end if */
  186. else i++;
  187. break;
  188. /* Delete comparisons of constants to zero */
  189. case oEQUZ :
  190. if (GETARG(pptr[i]) == 0)
  191. PUTARG(pptr[i], -1);
  192. else
  193. PUTARG(pptr[i], 0);
  194. deletePcode(i+1);
  195. nchanges++;
  196. break;
  197. case oNEQZ :
  198. if (GETARG(pptr[i]) != 0)
  199. PUTARG(pptr[i], -1);
  200. else
  201. PUTARG(pptr[i], 0);
  202. deletePcode(i+1);
  203. nchanges++;
  204. break;
  205. case oLTZ :
  206. if ((int32_t)GETARG(pptr[i]) < 0)
  207. PUTARG(pptr[i], -1);
  208. else
  209. PUTARG(pptr[i], 0);
  210. deletePcode(i+1);
  211. nchanges++;
  212. break;
  213. case oGTEZ :
  214. if ((int32_t)GETARG(pptr[i]) >= 0)
  215. PUTARG(pptr[i], -1);
  216. else
  217. PUTARG(pptr[i], 0);
  218. deletePcode(i+1);
  219. nchanges++;
  220. break;
  221. case oGTZ :
  222. if (GETARG(pptr[i]) > 0)
  223. PUTARG(pptr[i], -1);
  224. else
  225. PUTARG(pptr[i], 0);
  226. deletePcode(i+1);
  227. nchanges++;
  228. break;
  229. case oLTEZ :
  230. if (GETARG(pptr[i]) <= 0)
  231. PUTARG(pptr[i], -1);
  232. else
  233. PUTARG(pptr[i], 0);
  234. deletePcode(i+1);
  235. nchanges++;
  236. break;
  237. /* Simplify comparisons with certain constants */
  238. case oEQU :
  239. if (GETARG(pptr[i]) == 0)
  240. {
  241. PUTOP(pptr[i+1],oEQUZ);
  242. deletePcode(i);
  243. nchanges++;
  244. } /* end if */
  245. else if (GETARG(pptr[i]) == 1)
  246. {
  247. PUTOP(pptr[i], oDEC);
  248. PUTARG(pptr[i], 0);
  249. PUTOP(pptr[i+1], oEQUZ);
  250. nchanges++;
  251. } /* end else if */
  252. else if ((int32_t)GETARG(pptr[i]) == -1)
  253. {
  254. PUTOP(pptr[i], oINC);
  255. PUTARG(pptr[i], 0);
  256. PUTOP(pptr[i+1], oEQUZ);
  257. nchanges++;
  258. } /* end else if */
  259. else i++;
  260. break;
  261. case oNEQ :
  262. if (GETARG(pptr[i]) == 0)
  263. {
  264. PUTOP(pptr[i+1], oNEQZ);
  265. deletePcode(i);
  266. nchanges++;
  267. } /* end if */
  268. else if (GETARG(pptr[i]) == 1)
  269. {
  270. PUTOP(pptr[i], oDEC);
  271. PUTARG(pptr[i], 0);
  272. PUTOP(pptr[i+1], oNEQZ);
  273. nchanges++;
  274. } /* end else if */
  275. else if ((int32_t)GETARG(pptr[i]) == -1)
  276. {
  277. PUTOP(pptr[i], oINC);
  278. PUTARG(pptr[i], 0);
  279. PUTOP(pptr[i+1], oNEQZ);
  280. nchanges++;
  281. } /* end else if */
  282. else i++;
  283. break;
  284. case oLT :
  285. if (GETARG(pptr[i]) == 0)
  286. {
  287. PUTOP(pptr[i+1], oLTZ);
  288. deletePcode(i);
  289. nchanges++;
  290. } /* end if */
  291. else if (GETARG(pptr[i]) == 1)
  292. {
  293. PUTOP(pptr[i], oDEC);
  294. PUTARG(pptr[i], 0);
  295. PUTOP(pptr[i+1], oLTZ);
  296. nchanges++;
  297. } /* end else if */
  298. else if ((int32_t)GETARG(pptr[i]) == -1)
  299. {
  300. PUTOP(pptr[i], oINC);
  301. PUTARG(pptr[i], 0);
  302. PUTOP(pptr[i+1], oLTZ);
  303. nchanges++;
  304. } /* end else if */
  305. else i++;
  306. break;
  307. case oGTE :
  308. if (GETARG(pptr[i]) == 0)
  309. {
  310. PUTOP(pptr[i+1], oGTEZ);
  311. deletePcode(i);
  312. nchanges++;
  313. } /* end if */
  314. else if (GETARG(pptr[i]) == 1)
  315. {
  316. PUTOP(pptr[i], oDEC);
  317. PUTARG(pptr[i], 0);
  318. PUTOP(pptr[i+1], oGTEZ);
  319. nchanges++;
  320. } /* end else if */
  321. else if ((int32_t)GETARG(pptr[i]) == -1)
  322. {
  323. PUTOP(pptr[i], oINC);
  324. PUTARG(pptr[i], 0);
  325. PUTOP(pptr[i+1], oGTEZ);
  326. nchanges++;
  327. } /* end else if */
  328. else i++;
  329. break;
  330. case oGT :
  331. if (GETARG(pptr[i]) == 0)
  332. {
  333. PUTOP(pptr[i+1], oGTZ);
  334. deletePcode(i);
  335. nchanges++;
  336. } /* end if */
  337. else if (GETARG(pptr[i]) == 1)
  338. {
  339. PUTOP(pptr[i], oDEC);
  340. PUTARG(pptr[i], 0);
  341. PUTOP(pptr[i+1], oGTZ);
  342. nchanges++;
  343. } /* end else if */
  344. else if ((int32_t)GETARG(pptr[i]) == -1)
  345. {
  346. PUTOP(pptr[i], oINC);
  347. PUTARG(pptr[i], 0);
  348. PUTOP(pptr[i+1], oGTZ);
  349. nchanges++;
  350. } /* end else if */
  351. else i++;
  352. break;
  353. case oLTE :
  354. if (GETARG(pptr[i]) == 0)
  355. {
  356. PUTOP(pptr[i+1], oLTEZ);
  357. deletePcode(i);
  358. nchanges++;
  359. } /* end if */
  360. else if (GETARG(pptr[i]) == 1)
  361. {
  362. PUTOP(pptr[i], oDEC);
  363. PUTARG(pptr[i], 0);
  364. PUTOP(pptr[i+1], oLTEZ);
  365. nchanges++;
  366. } /* end else if */
  367. else if ((int32_t)GETARG(pptr[i]) == -1)
  368. {
  369. PUTOP(pptr[i], oINC);
  370. PUTARG(pptr[i], 0);
  371. PUTOP(pptr[i+1], oLTEZ);
  372. nchanges++;
  373. } /* end else if */
  374. else i++;
  375. break;
  376. /* Simplify or delete condition branches on constants */
  377. case oJEQUZ :
  378. if (GETARG(pptr[i]) == 0)
  379. {
  380. PUTOP(pptr[i+1], oJMP);
  381. deletePcode(i);
  382. } /* end if */
  383. else
  384. deletePcodePair(i, (i+1));
  385. nchanges++;
  386. break;
  387. case oJNEQZ :
  388. if (GETARG(pptr[i]) != 0)
  389. {
  390. PUTOP(pptr[i+1], oJMP);
  391. deletePcode(i);
  392. } /* end if */
  393. else
  394. deletePcodePair(i, (i+1));
  395. nchanges++;
  396. break;
  397. case oJLTZ :
  398. if ((int32_t)GETARG(pptr[i]) < 0)
  399. {
  400. PUTOP(pptr[i+1], oJMP);
  401. deletePcode(i);
  402. } /* end if */
  403. else
  404. deletePcodePair(i, (i+1));
  405. nchanges++;
  406. break;
  407. case oJGTEZ :
  408. if ((int32_t)GETARG(pptr[i]) >= 0)
  409. {
  410. PUTOP(pptr[i+1], oJMP);
  411. deletePcode(i);
  412. } /* end if */
  413. else
  414. deletePcodePair(i, (i+1));
  415. nchanges++;
  416. break;
  417. case oJGTZ :
  418. if (GETARG(pptr[i]) > 0)
  419. {
  420. PUTOP(pptr[i+1], oJMP);
  421. deletePcode(i);
  422. } /* end if */
  423. else
  424. deletePcodePair(i, (i+1));
  425. nchanges++;
  426. break;
  427. case oJLTEZ :
  428. if (GETARG(pptr[i]) <= 0)
  429. {
  430. PUTOP(pptr[i+1], oJMP);
  431. deletePcode(i);
  432. } /* end if */
  433. else
  434. deletePcodePair(i, (i+1));
  435. nchanges++;
  436. break;
  437. default :
  438. i++;
  439. break;
  440. } /* end switch */
  441. } /* end if */
  442. /* Delete multiple modifications of DSEG pointer */
  443. else if (GETOP(pptr[i]) == oINDS)
  444. {
  445. if (GETOP(pptr[i+1]) == oINDS)
  446. {
  447. PUTARG(pptr[i], GETARG(pptr[i] + GETARG(pptr[i+1])));
  448. deletePcode(i+1);
  449. } /* end if */
  450. else i++;
  451. } /* end else if */
  452. else i++;
  453. } /* end while */
  454. return (nchanges);
  455. } /* end unaryOptimize */
  456. /**********************************************************************/
  457. int binaryOptimize(void)
  458. {
  459. register int i;
  460. int nchanges = 0;
  461. TRACE(stderr, "[binaryOptimize]");
  462. /* At least two pcodes are needed to perform the following binary */
  463. /* operator optimizations */
  464. i = 0;
  465. while (i < nops-2)
  466. {
  467. if (GETOP(pptr[i]) == oPUSH)
  468. {
  469. if (GETOP(pptr[i+1]) == oPUSH)
  470. {
  471. switch (GETOP(pptr[i+2]))
  472. {
  473. case oADD :
  474. PUTARG(pptr[i], GETARG(pptr[i]) + GETARG(pptr[i+1]));
  475. deletePcodePair((i+1), (i+2));
  476. nchanges++;
  477. break;
  478. case oSUB :
  479. PUTARG(pptr[i], GETARG(pptr[i]) - GETARG(pptr[i+1]));
  480. deletePcodePair((i+1), (i+2));
  481. nchanges++;
  482. break;
  483. case oMUL :
  484. PUTARG(pptr[i], GETARG(pptr[i]) * GETARG(pptr[i+1]));
  485. deletePcodePair((i+1), (i+2));
  486. nchanges++;
  487. break;
  488. case oDIV :
  489. PUTARG(pptr[i], GETARG(pptr[i]) / (int32_t)GETARG(pptr[i+1]));
  490. deletePcodePair((i+1), (i+2));
  491. nchanges++;
  492. break;
  493. case oMOD :
  494. PUTARG(pptr[i], GETARG(pptr[i]) % GETARG(pptr[i+1]));
  495. deletePcodePair((i+1), (i+2));
  496. nchanges++;
  497. break;
  498. case oSLL :
  499. PUTARG(pptr[i], GETARG(pptr[i]) << GETARG(pptr[i+1]));
  500. deletePcodePair((i+1), (i+2));
  501. nchanges++;
  502. break;
  503. case oSRL :
  504. PUTARG(pptr[i], GETARG(pptr[i]) >> GETARG(pptr[i+1]));
  505. deletePcodePair((i+1), (i+2));
  506. nchanges++;
  507. break;
  508. case oSRA :
  509. PUTARG(pptr[i], (int32_t)GETARG(pptr[i]) >> GETARG(pptr[i+1]));
  510. deletePcodePair((i+1), (i+2));
  511. nchanges++;
  512. break;
  513. case oOR :
  514. PUTARG(pptr[i], GETARG(pptr[i]) | GETARG(pptr[i+1]));
  515. deletePcodePair((i+1), (i+2));
  516. nchanges++;
  517. break;
  518. case oAND :
  519. PUTARG(pptr[i], GETARG(pptr[i]) & GETARG(pptr[i+1]));
  520. deletePcodePair((i+1), (i+2));
  521. nchanges++;
  522. break;
  523. case oEQU :
  524. if (GETARG(pptr[i]) == GETARG(pptr[i+1]))
  525. PUTARG(pptr[i], -1);
  526. else
  527. PUTARG(pptr[i], 0);
  528. deletePcodePair((i+1), (i+2));
  529. nchanges++;
  530. break;
  531. case oNEQ :
  532. if (GETARG(pptr[i]) != GETARG(pptr[i+1]))
  533. PUTARG(pptr[i], -1);
  534. else
  535. PUTARG(pptr[i], 0);
  536. deletePcodePair((i+1), (i+2));
  537. nchanges++;
  538. break;
  539. case oLT :
  540. if ((int32_t)GETARG(pptr[i]) < (int32_t)GETARG(pptr[i+1]))
  541. PUTARG(pptr[i], -1);
  542. else
  543. PUTARG(pptr[i], 0);
  544. deletePcodePair((i+1), (i+2));
  545. nchanges++;
  546. break;
  547. case oGTE :
  548. if ((int32_t)GETARG(pptr[i]) >= (int32_t)GETARG(pptr[i+1]))
  549. PUTARG(pptr[i], -1);
  550. else
  551. PUTARG(pptr[i], 0);
  552. deletePcodePair((i+1), (i+2));
  553. nchanges++;
  554. break;
  555. case oGT :
  556. if ((int32_t)GETARG(pptr[i]) > (int32_t)GETARG(pptr[i+1]))
  557. PUTARG(pptr[i], -1);
  558. else
  559. PUTARG(pptr[i], 0);
  560. deletePcodePair((i+1), (i+2));
  561. nchanges++;
  562. break;
  563. case oLTE :
  564. if ((int32_t)GETARG(pptr[i]) <= (int32_t)GETARG(pptr[i+1]))
  565. PUTARG(pptr[i], -1);
  566. else
  567. PUTARG(pptr[i], 0);
  568. deletePcodePair((i+1), (i+2));
  569. nchanges++;
  570. break;
  571. default :
  572. i++;
  573. break;
  574. } /* end switch */
  575. } /* end if */
  576. /* A single (constant) pcode is sufficient to perform the */
  577. /* following binary operator optimizations */
  578. else if ((GETOP(pptr[i+1]) == oLDSH) || (GETOP(pptr[i+1]) == oLDSB) ||
  579. (GETOP(pptr[i+1]) == oLAS) || (GETOP(pptr[i+1]) == oLAC))
  580. {
  581. switch (GETOP(pptr[i+2]))
  582. {
  583. case oADD :
  584. if (GETARG(pptr[i]) == 0)
  585. {
  586. deletePcodePair(i, (i+2));
  587. nchanges++;
  588. } /* end if */
  589. else if (GETARG(pptr[i]) == 1)
  590. {
  591. PUTOP(pptr[i+2], oINC);
  592. deletePcode(i);
  593. nchanges++;
  594. } /* end else if */
  595. else if (GETARG(pptr[i]) == ARGONES)
  596. {
  597. PUTOP(pptr[i+2], oDEC);
  598. deletePcode(i);
  599. nchanges++;
  600. } /* end else if */
  601. else i++;
  602. break;
  603. case oSUB :
  604. if (GETARG(pptr[i]) == 0)
  605. {
  606. PUTOP(pptr[i], oNEG);
  607. deletePcode(i);
  608. nchanges++;
  609. } /* end if */
  610. else i++;
  611. break;
  612. case oMUL :
  613. {
  614. int32_t stmp32 = 0;
  615. switch (GETARG(pptr[i]))
  616. {
  617. case 1 :
  618. deletePcodePair(i, (i+2));
  619. nchanges++;
  620. break;
  621. case 16384 : stmp32++;
  622. case 8192 : stmp32++;
  623. case 4096 : stmp32++;
  624. case 2048 : stmp32++;
  625. case 1024 : stmp32++;
  626. case 512 : stmp32++;
  627. case 256 : stmp32++;
  628. case 128 : stmp32++;
  629. case 64 : stmp32++;
  630. case 32 : stmp32++;
  631. case 16 : stmp32++;
  632. case 8 : stmp32++;
  633. case 4 : stmp32++;
  634. case 2 : stmp32++;
  635. PUTOP(pptr[i], GETOP(pptr[i+1]));
  636. PUTARG(pptr[i], GETARG(pptr[i+1]));
  637. PUTOP(pptr[i+1], oPUSH);
  638. PUTARG(pptr[i+1], stmp32);
  639. PUTOP(pptr[i+2], oSLL);
  640. nchanges++;
  641. i++;
  642. break;
  643. default :
  644. i++;
  645. break;
  646. }
  647. }
  648. break;
  649. case oOR :
  650. if (GETARG(pptr[i]) == 0)
  651. {
  652. deletePcodePair(i, (i+2));
  653. nchanges++;
  654. } /* end if */
  655. else i++;
  656. break;
  657. case oAND :
  658. if (GETARG(pptr[i]) == ARGONES)
  659. {
  660. deletePcodePair(i, (i+2));
  661. nchanges++;
  662. } /* end if */
  663. else i++;
  664. break;
  665. case oEQU :
  666. if (GETARG(pptr[i]) == 0)
  667. {
  668. PUTOP(pptr[i+2], oEQUZ);
  669. deletePcode(i);
  670. nchanges++;
  671. } /* end if */
  672. else i++;
  673. break;
  674. case oNEQ :
  675. if (GETARG(pptr[i]) == 0)
  676. {
  677. PUTOP(pptr[i+2], oNEQZ);
  678. deletePcode(i);
  679. nchanges++;
  680. } /* end if */
  681. else i++;
  682. break;
  683. case oLT :
  684. if (GETARG(pptr[i]) == 0)
  685. {
  686. PUTOP(pptr[i+2], oGTEZ);
  687. deletePcode(i);
  688. nchanges++;
  689. } /* end if */
  690. else i++;
  691. break;
  692. case oGTE :
  693. if (GETARG(pptr[i]) == 0)
  694. {
  695. PUTOP(pptr[i+2], oLTZ);
  696. deletePcode(i);
  697. nchanges++;
  698. } /* end if */
  699. else i++;
  700. break;
  701. case oGT :
  702. if (GETARG(pptr[i]) == 0)
  703. {
  704. PUTOP(pptr[i+2], oLTEZ);
  705. deletePcode(i);
  706. nchanges++;
  707. } /* end if */
  708. else i++;
  709. break;
  710. case oLTE :
  711. if (GETARG(pptr[i]) == 0)
  712. {
  713. PUTOP(pptr[i+2], oGTZ);
  714. deletePcode(i);
  715. nchanges++;
  716. } /* end if */
  717. else i++;
  718. break;
  719. default :
  720. i++;
  721. break;
  722. } /* end switch */
  723. } /* end else if */
  724. else i++;
  725. } /* end if */
  726. /* Misc improvements on binary operators */
  727. else if (GETOP(pptr[i]) == oNEG)
  728. {
  729. /* Negation followed by add is subtraction */
  730. if (GETOP(pptr[i+1]) == oADD)
  731. {
  732. PUTOP(pptr[i+1], oSUB);
  733. deletePcode(i);
  734. nchanges++;
  735. }
  736. /* Negation followed by subtraction is addition */
  737. else if (GETOP(pptr[i]) == oSUB)
  738. {
  739. PUTOP(pptr[i+1], oADD);
  740. deletePcode(i);
  741. nchanges++;
  742. }
  743. else i++;
  744. }
  745. else i++;
  746. } /* end while */
  747. return (nchanges);
  748. } /* end binaryOptimize */
  749. /**********************************************************************/