PageRenderTime 189ms CodeModel.GetById 60ms app.highlight 95ms RepoModel.GetById 26ms 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
  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/**********************************************************************
 38 * Included Files
 39 **********************************************************************/
 40
 41#include <stdint.h>
 42#include <stdio.h>
 43
 44#include "keywords.h"
 45#include "pdefs.h"
 46#include "pinsn32.h"
 47
 48#include "paslib.h"
 49#include "popt.h"
 50#include "polocal.h"
 51#include "pcopt.h"
 52
 53/**********************************************************************/
 54
 55int unaryOptimize(void)
 56{
 57  register uint32_t temp;
 58  register int i;
 59  int nchanges = 0;
 60
 61  TRACE(stderr, "[unaryOptimize]");
 62
 63  /* At least two pcodes are need to perform unary optimizations */
 64
 65  i = 0;
 66  while (i < nops-1)
 67    {
 68      /* Check for a constant value being pushed onto the stack */
 69
 70      if (GETOP(pptr[i]) == oPUSH)
 71        {
 72          switch (GETOP(pptr[i+1]))
 73            {
 74              /* Delete unary operators on constants */
 75            case oNEG   :
 76              PUTARG(pptr[i], -GETARG(pptr[i]));
 77              deletePcode(i+1);
 78              nchanges++;
 79              break;
 80
 81            case oABS   :
 82              if ((int32_t)GETARG(pptr[i]) < 0)
 83                PUTARG(pptr[i], -(int32_t)GETARG(pptr[i]));
 84              deletePcode(i+1);
 85              nchanges++;
 86              break;
 87
 88            case oINC   :
 89              PUTARG(pptr[i], GETARG(pptr[i]) + 1);
 90              deletePcode(i+1);
 91              nchanges++;
 92              break;
 93
 94            case oDEC   :
 95              PUTARG(pptr[i], GETARG(pptr[i]) - 1);
 96              deletePcode(i+1);
 97              nchanges++;
 98              break;
 99
100            case oNOT   :
101              PUTARG(pptr[i], ~GETARG(pptr[i]));
102              PUTARG(pptr[i], ~(GETARG(pptr[i])));
103              deletePcode(i+1);
104              nchanges++;
105              break;
106
107              /* Simplify binary operations on constants */
108
109            case oADD :
110              if (GETARG(pptr[i]) == 0)
111                {
112                  deletePcodePair(i, (i+1));
113                  nchanges++;
114                } /* end if */
115              else if (GETARG(pptr[i]) == 1)
116                {
117                  PUTOP(pptr[i+1], oINC);
118                  deletePcode(i);
119                  nchanges++;
120                } /* end else if */
121              else if (GETARG(pptr[i]) == ARGONES)
122                {
123                  PUTOP(pptr[i+1], oDEC);
124                  deletePcode(i);
125                  nchanges++;
126                } /* end else if */
127              else i++;
128              break;
129
130            case oSUB :
131              if (GETARG(pptr[i]) == 0)
132                {
133                  deletePcodePair(i, (i+1));
134                  nchanges++;
135                } /* end if */
136              else if (GETARG(pptr[i]) == 1)
137                {
138                  PUTOP(pptr[i+1], oDEC);
139                  deletePcode(i);
140                  nchanges++;
141                } /* end else if */
142              else if (GETARG(pptr[i]) == ARGONES)
143                {
144                  PUTOP(pptr[i+1], oINC);
145                  deletePcode(i);
146                  nchanges++;
147                } /* end else if */
148              else i++;
149              break;
150
151            case oMUL :
152            case oDIV :
153              temp = 0;
154              switch (GETARG(pptr[i]))
155                {
156                case 1 :
157                  deletePcodePair(i, (i+1));
158                  nchanges++;
159                  break;
160                case 16384 : temp++;
161                case  8192 : temp++;
162                case  4096 : temp++;
163                case  2048 : temp++;
164                case  1024 : temp++;
165                case   512 : temp++;
166                case   256 : temp++;
167                case   128 : temp++;
168                case    64 : temp++;
169                case    32 : temp++;
170                case    16 : temp++;
171                case     8 : temp++;
172                case     4 : temp++;
173                case     2 : temp++;
174                  PUTARG(pptr[i], temp);
175                  if (GETOP(pptr[i+1]) == oMUL)
176                    PUTOP(pptr[i+1], oSLL);
177                  else
178                    PUTOP(pptr[i+1], oSRA);
179                  nchanges++;
180                  i++;
181                  break;
182
183                default :
184                  i++;
185                  break;
186                } /* end switch */
187              break;
188
189            case oSLL :
190            case oSRL :
191            case oSRA :
192            case oOR  :
193              if (GETARG(pptr[i]) == 0)
194                {
195                  deletePcodePair(i, (i+1));
196                  nchanges++;
197                } /* end if */
198              else i++;
199              break;
200
201            case oAND :
202              if (GETARG(pptr[i]) == ARGONES)
203                {
204                  deletePcodePair(i, (i+1));
205                  nchanges++;
206                } /* end if */
207              else i++;
208              break;
209
210              /* Delete comparisons of constants to zero */
211
212            case oEQUZ  :
213              if (GETARG(pptr[i]) == 0)
214                PUTARG(pptr[i], -1);
215              else
216                PUTARG(pptr[i], 0);
217              deletePcode(i+1);
218              nchanges++;
219              break;
220
221            case oNEQZ  :
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
230            case oLTZ   :
231              if ((int32_t)GETARG(pptr[i]) < 0)
232                PUTARG(pptr[i], -1);
233              else
234                PUTARG(pptr[i], 0);
235              deletePcode(i+1);
236              nchanges++;
237              break;
238                              
239            case oGTEZ  :
240              if ((int32_t)GETARG(pptr[i]) >= 0)
241                PUTARG(pptr[i], -1);
242              else
243                PUTARG(pptr[i], 0);
244              deletePcode(i+1);
245              nchanges++;
246              break;
247
248            case oGTZ   :
249              if (GETARG(pptr[i]) > 0)
250                PUTARG(pptr[i], -1);
251              else
252                PUTARG(pptr[i], 0);
253              deletePcode(i+1);
254              nchanges++;
255              break;
256                                                                                         
257            case oLTEZ :
258              if (GETARG(pptr[i]) <= 0)
259                PUTARG(pptr[i], -1);
260              else
261                PUTARG(pptr[i], 0);
262              deletePcode(i+1);
263              nchanges++;
264              break;
265
266              /*  Simplify comparisons with certain constants */
267
268            case oEQU   :
269              if (GETARG(pptr[i]) == 0)
270                {
271                  PUTOP(pptr[i+1],oEQUZ);
272                  deletePcode(i);
273                  nchanges++;
274                } /* end if */
275              else if (GETARG(pptr[i]) == 1)
276                {
277                  PUTOP(pptr[i], oDEC);
278                  PUTARG(pptr[i], 0);
279                  PUTOP(pptr[i+1], oEQUZ);
280                  nchanges++;
281                } /* end else if */
282              else if ((int32_t)GETARG(pptr[i]) == -1)
283                {
284                  PUTOP(pptr[i], oINC);
285                  PUTARG(pptr[i], 0);
286                  PUTOP(pptr[i+1], oEQUZ);
287                  nchanges++;
288                } /* end else if */
289              else i++;
290              break;
291
292            case oNEQ   :
293              if (GETARG(pptr[i]) == 0)
294                {
295                  PUTOP(pptr[i+1], oNEQZ);
296                  deletePcode(i);
297                  nchanges++;
298                } /* end if */
299              else if (GETARG(pptr[i]) == 1)
300                {
301                  PUTOP(pptr[i], oDEC);
302                  PUTARG(pptr[i], 0);
303                  PUTOP(pptr[i+1], oNEQZ);
304                  nchanges++;
305                } /* end else if */
306              else if ((int32_t)GETARG(pptr[i]) == -1)
307                {
308                  PUTOP(pptr[i], oINC);
309                  PUTARG(pptr[i], 0);
310                  PUTOP(pptr[i+1], oNEQZ);
311                  nchanges++;
312                } /* end else if */
313              else i++;
314              break;
315
316            case oLT    :
317              if (GETARG(pptr[i]) == 0)
318                {
319                  PUTOP(pptr[i+1], oLTZ);
320                  deletePcode(i);
321                  nchanges++;
322                } /* end if */
323              else if (GETARG(pptr[i]) == 1)
324                {
325                  PUTOP(pptr[i], oDEC);
326                  PUTARG(pptr[i], 0);
327                  PUTOP(pptr[i+1], oLTZ);
328                  nchanges++;
329                } /* end else if */
330              else if ((int32_t)GETARG(pptr[i]) == -1)
331                {
332                  PUTOP(pptr[i], oINC);
333                  PUTARG(pptr[i], 0);
334                  PUTOP(pptr[i+1], oLTZ);
335                  nchanges++;
336                } /* end else if */
337              else i++;
338              break;
339
340            case oGTE   :
341              if (GETARG(pptr[i]) == 0)
342                {
343                  PUTOP(pptr[i+1], oGTEZ);
344                  deletePcode(i);
345                  nchanges++;
346                } /* end if */
347              else if (GETARG(pptr[i]) == 1)
348                {
349                  PUTOP(pptr[i], oDEC);
350                  PUTARG(pptr[i], 0);
351                  PUTOP(pptr[i+1], oGTEZ);
352                  nchanges++;
353                } /* end else if */
354              else if ((int32_t)GETARG(pptr[i]) == -1)
355                {
356                  PUTOP(pptr[i], oINC);
357                  PUTARG(pptr[i], 0);
358                  PUTOP(pptr[i+1], oGTEZ);
359                  nchanges++;
360                } /* end else if */
361              else i++;
362              break;
363
364            case oGT    :
365              if (GETARG(pptr[i]) == 0)
366                {
367                  PUTOP(pptr[i+1], oGTZ);
368                  deletePcode(i);
369                  nchanges++;
370                } /* end if */
371              else if (GETARG(pptr[i]) == 1)
372                {
373                  PUTOP(pptr[i], oDEC);
374                  PUTARG(pptr[i], 0);
375                  PUTOP(pptr[i+1], oGTZ);
376                  nchanges++;
377                } /* end else if */
378              else if ((int32_t)GETARG(pptr[i]) == -1)
379                {
380                  PUTOP(pptr[i], oINC);
381                  PUTARG(pptr[i], 0);
382                  PUTOP(pptr[i+1], oGTZ);
383                  nchanges++;
384                } /* end else if */
385              else i++;
386              break;
387
388            case oLTE   :
389              if (GETARG(pptr[i]) == 0)
390                {
391                  PUTOP(pptr[i+1], oLTEZ);
392                  deletePcode(i);
393                  nchanges++;
394                } /* end if */
395              else if (GETARG(pptr[i]) == 1)
396                {
397                  PUTOP(pptr[i], oDEC);
398                  PUTARG(pptr[i], 0);
399                  PUTOP(pptr[i+1], oLTEZ);
400                  nchanges++;
401                } /* end else if */
402              else if ((int32_t)GETARG(pptr[i]) == -1)
403                {
404                  PUTOP(pptr[i], oINC);
405                  PUTARG(pptr[i], 0);
406                  PUTOP(pptr[i+1], oLTEZ);
407                  nchanges++;
408                } /* end else if */
409              else i++;
410              break;
411
412              /* Simplify or delete condition branches on constants */
413
414            case oJEQUZ :
415              if (GETARG(pptr[i]) == 0)
416                {
417                  PUTOP(pptr[i+1], oJMP);
418                  deletePcode(i);
419                } /* end if */
420              else 
421                deletePcodePair(i, (i+1));
422              nchanges++;
423              break;
424
425            case oJNEQZ :
426              if (GETARG(pptr[i]) != 0)
427                {
428                  PUTOP(pptr[i+1], oJMP);
429                  deletePcode(i);
430                } /* end if */
431              else 
432                deletePcodePair(i, (i+1));
433              nchanges++;
434              break;
435
436            case oJLTZ  :
437              if ((int32_t)GETARG(pptr[i]) < 0)
438                {
439                  PUTOP(pptr[i+1], oJMP);
440                  deletePcode(i);
441                } /* end if */
442              else 
443                deletePcodePair(i, (i+1));
444              nchanges++;
445              break;
446
447            case oJGTEZ :
448              if ((int32_t)GETARG(pptr[i]) >= 0)
449                {
450                  PUTOP(pptr[i+1], oJMP);
451                  deletePcode(i);
452                } /* end if */
453              else 
454                deletePcodePair(i, (i+1));
455              nchanges++;
456              break;
457
458            case oJGTZ  :
459              if (GETARG(pptr[i]) > 0)
460                {
461                  PUTOP(pptr[i+1], oJMP);
462                  deletePcode(i);
463                } /* end if */
464              else 
465                deletePcodePair(i, (i+1));
466              nchanges++;
467              break;
468
469            case oJLTEZ :
470              if (GETARG(pptr[i]) <= 0)
471                {
472                  PUTOP(pptr[i+1], oJMP);
473                  deletePcode(i);
474                } /* end if */
475              else 
476                deletePcodePair(i, (i+1));
477              nchanges++;
478              break;
479
480            default     :
481              i++;
482              break;
483            } /* end switch */
484        } /* end if */
485
486          /* Delete multiple modifications of DSEG pointer */
487
488      else if (GETOP(pptr[i]) == oINDS)
489        {
490          if (GETOP(pptr[i+1]) == oINDS)
491            {
492              PUTARG(pptr[i], GETARG(pptr[i] + GETARG(pptr[i+1])));
493              deletePcode(i+1);
494            } /* end if */
495          else i++;
496        } /* end else if */
497      else i++;
498    } /* end while */
499
500  return (nchanges);
501
502} /* end unaryOptimize */
503
504/**********************************************************************/
505
506int binaryOptimize(void)
507{
508  register int i;
509  int nchanges = 0;
510
511  TRACE(stderr, "[binaryOptimize]");
512
513  /* At least two pcodes are needed to perform the following binary */
514  /* operator optimizations */
515
516  i = 0;
517  while (i < nops-2)
518    {
519      if (GETOP(pptr[i]) == oPUSH)
520        {
521          if (GETOP(pptr[i+1]) == oPUSH)
522            {
523              switch (GETOP(pptr[i+2]))
524                {
525                case oADD :
526                  PUTARG(pptr[i], GETARG(pptr[i]) + GETARG(pptr[i+1]));
527                  deletePcodePair((i+1), (i+2));
528                  nchanges++;
529                  break;
530
531                case oSUB :
532                  PUTARG(pptr[i], GETARG(pptr[i]) - GETARG(pptr[i+1]));
533                  deletePcodePair((i+1), (i+2));
534                  nchanges++;
535                  break;
536
537                case oMUL :
538                  PUTARG(pptr[i], GETARG(pptr[i]) * GETARG(pptr[i+1]));
539                  deletePcodePair((i+1), (i+2));
540                  nchanges++;
541                  break;
542
543                case oDIV :
544                  PUTARG(pptr[i], GETARG(pptr[i]) / (int32_t)GETARG(pptr[i+1]));
545                  deletePcodePair((i+1), (i+2));
546                  nchanges++;
547                  break;
548
549                case oMOD :
550                  PUTARG(pptr[i], GETARG(pptr[i]) % GETARG(pptr[i+1]));
551                  deletePcodePair((i+1), (i+2));
552                  nchanges++;
553                  break;
554
555                case oSLL :
556                  PUTARG(pptr[i], GETARG(pptr[i]) << GETARG(pptr[i+1]));
557                  deletePcodePair((i+1), (i+2));
558                  nchanges++;
559                  break;
560
561                case oSRL :
562                  PUTARG(pptr[i], GETARG(pptr[i]) >> GETARG(pptr[i+1]));
563                  deletePcodePair((i+1), (i+2));
564                  nchanges++;
565                  break;
566
567                case oSRA :
568                  PUTARG(pptr[i], (int32_t)GETARG(pptr[i]) >> GETARG(pptr[i+1]));
569                  deletePcodePair((i+1), (i+2));
570                  nchanges++;
571                  break;
572
573                case oOR  :
574                  PUTARG(pptr[i], GETARG(pptr[i]) | GETARG(pptr[i+1]));
575                  deletePcodePair((i+1), (i+2));
576                  nchanges++;
577                  break;
578
579                case oAND :
580                  PUTARG(pptr[i], GETARG(pptr[i]) & GETARG(pptr[i+1]));
581                  deletePcodePair((i+1), (i+2));
582                  nchanges++;
583                  break;
584
585                case oEQU :
586                  if (GETARG(pptr[i]) == GETARG(pptr[i+1]))
587                    PUTARG(pptr[i], -1);
588                  else
589                    PUTARG(pptr[i], 0);
590                  deletePcodePair((i+1), (i+2));
591                  nchanges++;
592                  break;
593
594                case oNEQ :
595                  if (GETARG(pptr[i]) != GETARG(pptr[i+1]))
596                    PUTARG(pptr[i], -1);
597                  else
598                    PUTARG(pptr[i], 0);
599                  deletePcodePair((i+1), (i+2));
600                  nchanges++;
601                  break;
602
603                case oLT  :
604                  if ((int32_t)GETARG(pptr[i]) < (int32_t)GETARG(pptr[i+1]))
605                    PUTARG(pptr[i], -1);
606                  else
607                    PUTARG(pptr[i], 0);
608                  deletePcodePair((i+1), (i+2));
609                  nchanges++;
610                  break;
611
612                case oGTE :
613                  if ((int32_t)GETARG(pptr[i]) >= (int32_t)GETARG(pptr[i+1]))
614                    PUTARG(pptr[i], -1);
615                  else
616                    PUTARG(pptr[i], 0);
617                  deletePcodePair((i+1), (i+2));
618                  nchanges++;
619                  break;
620
621                case oGT  :
622                  if ((int32_t)GETARG(pptr[i]) > (int32_t)GETARG(pptr[i+1]))
623                    PUTARG(pptr[i], -1);
624                  else
625                    PUTARG(pptr[i], 0);
626                  deletePcodePair((i+1), (i+2));
627                  nchanges++;
628                  break;
629
630                case oLTE :
631                  if ((int32_t)GETARG(pptr[i]) <= (int32_t)GETARG(pptr[i+1]))
632                    PUTARG(pptr[i], -1);
633                  else
634                    PUTARG(pptr[i], 0);
635                  deletePcodePair((i+1), (i+2));
636                  nchanges++;
637                  break;
638
639                default   :
640                  i++;
641                  break;
642                } /* end switch */
643            } /* end if */
644
645          /* A single (constant) pcode is sufficient to perform the */
646          /* following binary operator optimizations */
647
648          else if ((GETOP(pptr[i+1]) == oLDSH) || (GETOP(pptr[i+1]) == oLDSB) ||
649                   (GETOP(pptr[i+1]) == oLAS)  || (GETOP(pptr[i+1]) == oLAC))
650            {
651              switch (GETOP(pptr[i+2]))
652                {
653                case oADD :
654                  if (GETARG(pptr[i]) == 0)
655                    {
656                      deletePcodePair(i, (i+2));
657                      nchanges++;
658                    } /* end if */
659                  else if (GETARG(pptr[i]) == 1)
660                    {
661                      PUTOP(pptr[i+2], oINC);
662                      deletePcode(i);
663                      nchanges++;
664                    } /* end else if */
665                  else if (GETARG(pptr[i]) == ARGONES)
666                    {
667                      PUTOP(pptr[i+2], oDEC);
668                      deletePcode(i);
669                      nchanges++;
670                    } /* end else if */
671                  else i++;
672                  break;
673
674                case oSUB :
675                  if (GETARG(pptr[i]) == 0)
676                    {
677                      PUTOP(pptr[i], oNEG);
678                      deletePcode(i);
679                      nchanges++;
680                    } /* end if */
681                  else i++;
682                  break;
683
684                case oMUL :
685                  {
686                    int32_t stmp32 = 0;
687                    switch (GETARG(pptr[i]))
688                      {
689                      case 1 :
690                        deletePcodePair(i, (i+2));
691                        nchanges++;
692                        break;
693                      case 16384 : stmp32++;
694                      case  8192 : stmp32++;
695                      case  4096 : stmp32++;
696                      case  2048 : stmp32++;
697                      case  1024 : stmp32++;
698                      case   512 : stmp32++;
699                      case   256 : stmp32++;
700                      case   128 : stmp32++;
701                      case    64 : stmp32++;
702                      case    32 : stmp32++;
703                      case    16 : stmp32++;
704                      case     8 : stmp32++;
705                      case     4 : stmp32++;
706                      case     2 : stmp32++;
707                        PUTOP(pptr[i],    GETOP(pptr[i+1]));
708                        PUTARG(pptr[i],   GETARG(pptr[i+1]));
709                        PUTOP(pptr[i+1],  oPUSH);
710                        PUTARG(pptr[i+1], stmp32);
711                        PUTOP(pptr[i+2],  oSLL);
712                        nchanges++;
713                        i++;
714                        break;
715
716                      default :
717                        i++;
718                        break;
719                      }
720                  }
721                  break;
722
723                case oOR  :
724                  if (GETARG(pptr[i]) == 0)
725                    {
726                      deletePcodePair(i, (i+2));
727                      nchanges++;
728                    } /* end if */
729                  else i++;
730                  break;
731
732                case oAND :
733                  if (GETARG(pptr[i]) == ARGONES)
734                    {
735                      deletePcodePair(i, (i+2));
736                      nchanges++;
737                    } /* end if */
738                  else i++;
739                  break;
740
741                case oEQU :
742                  if (GETARG(pptr[i]) == 0)
743                    {
744                      PUTOP(pptr[i+2], oEQUZ);
745                      deletePcode(i);
746                      nchanges++;
747                    } /* end if */
748                  else i++;
749                  break;
750
751                case oNEQ :
752                  if (GETARG(pptr[i]) == 0)
753                    {
754                      PUTOP(pptr[i+2], oNEQZ);
755                      deletePcode(i);
756                      nchanges++;
757                    } /* end if */
758                  else i++;
759                  break;
760
761                case oLT  :
762                  if (GETARG(pptr[i]) == 0)
763                    {
764                      PUTOP(pptr[i+2], oGTEZ);
765                      deletePcode(i);
766                      nchanges++;
767                    } /* end if */
768                  else i++;
769                  break;
770
771                case oGTE :
772                  if (GETARG(pptr[i]) == 0)
773                    {
774                      PUTOP(pptr[i+2], oLTZ);
775                      deletePcode(i);
776                      nchanges++;
777                    } /* end if */
778                  else i++;
779                  break;
780
781                case oGT  :
782                  if (GETARG(pptr[i]) == 0)
783                    {
784                      PUTOP(pptr[i+2], oLTEZ);
785                      deletePcode(i);
786                      nchanges++;
787                    } /* end if */
788                  else i++;
789                  break;
790
791                case oLTE :
792                  if (GETARG(pptr[i]) == 0)
793                    {
794                      PUTOP(pptr[i+2], oGTZ);
795                      deletePcode(i);
796                      nchanges++;
797                    } /* end if */
798                  else i++;
799                  break;
800
801                default   :
802                  i++;
803                  break;
804
805                } /* end switch */
806            } /* end else if */
807          else i++;
808        } /* end if */
809
810      /* Misc improvements on binary operators */
811
812      else if (GETOP(pptr[i]) == oNEG)
813        {
814          /* Negation followed by add is subtraction */
815
816          if (GETOP(pptr[i+1]) == oADD)
817            {
818              PUTOP(pptr[i+1], oSUB);
819              deletePcode(i);
820              nchanges++;
821            }
822
823          /* Negation followed by subtraction is addition */
824
825          else if (GETOP(pptr[i]) == oSUB)
826            {
827              PUTOP(pptr[i+1], oADD);
828              deletePcode(i);
829              nchanges++;
830            }
831          else i++;
832        }
833      else i++;
834    } /* end while */
835
836  return (nchanges);
837
838} /* end binaryOptimize */
839
840/**********************************************************************/