🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #5941

GCC 2.7.2/MIPS/Why not use NOR instruction when possible

#5941
From: Martin Eli Erhardsen
Date: Wed, 08 Jan 1997 00:00
133 lines
4176 bytes
I am not satisfied with the code qualite from the gcc compiler,
because this piece of code : 

     res1=~(arg1|arg2);

gets translated into these instructions

        or      $5,$16,$2
        nor     $5,$0,$5

The native SGI compiler uses just one instruction like this

        nor     $5,$16,$2

The code generated by GCC first uses a or and then a not, when
it is possible to evaluate the expression with a NOR.
This would be tvice as fast as the code generated by gcc for this
statement. It shouldn't be too difficult to fully support a
simple instruction like NOR. 


~> gcc -v
Reading specs from
/usr/local/gnu/lib/gcc-lib/mips-sgi-irix5.3/2.7.2/specs
gcc version 2.7.2
~> cat test.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{ 
  int arg1,arg2,res1,res2;
  if (argc==3) 
    {
      arg1=atoi(argv[1]);arg2=atoi(argv[2]);
      res1=~(arg1|arg2);
      res2=(~arg1)&(~arg2);
      printf("%d %d\n",res1,res2);
    }
  return 0;
}
~> gcc -O2 test.c -S
~> cat test.s
        .file   1 "test.c"
        .option pic2

 # GNU C 2.7.2 [AL 1.1, MM 40] SGI running IRIX 5.x compiled by GNU C

 # Cc1 defaults:
 # -mabicalls

 # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1):
 # -quiet -dumpbase -O2 -o

gcc2_compiled.:
__gnu_compiled_c:
        .rdata

        .byte   0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
        .byte   0x6e,0x3a,0x20,0x31,0x2e,0x36,0x35,0x20
        .byte   0x24,0x0

        .byte   0x24,0x49,0x64,0x3a,0x20,0x73,0x74,0x61
        .byte   0x6e,0x64,0x61,0x72,0x64,0x73,0x2e,0x68
        .byte   0x2c,0x76,0x20,0x31,0x2e,0x37,0x20,0x31
        .byte   0x39,0x39,0x35,0x2f,0x31,0x32,0x2f,0x33
        .byte   0x30,0x20,0x30,0x32,0x3a,0x34,0x39,0x3a
        .byte   0x31,0x38,0x20,0x6a,0x77,0x61,0x67,0x20
        .byte   0x45,0x78,0x70,0x20,0x24,0x0

        .byte   0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
        .byte   0x6e,0x3a,0x20,0x31,0x2e,0x31,0x31,0x20
        .byte   0x24,0x0

        .byte   0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
        .byte   0x6e,0x3a,0x20,0x31,0x2e,0x31,0x31,0x20
        .byte   0x24,0x0

        .byte   0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
        .byte   0x6e,0x3a,0x20,0x31,0x2e,0x35,0x37,0x20
        .byte   0x24,0x0
        .align  2
$LC0:

        .byte   0x25,0x64,0x20,0x25,0x64,0xa,0x0
        .text
        .align  2
        .globl  main
        .ent    main
main:
        .frame  $sp,40,$31              # vars= 0, regs= 3/0, args= 16,
extra= 8
        .mask   0x90010000,-8
        .fmask  0x00000000,0
        .set    noreorder
        .cpload $25
        .set    reorder
        subu    $sp,$sp,40
        .cprestore 16
        sw      $16,24($sp)
        move    $16,$5
        li      $2,0x00000003           # 3
        sw      $31,32($sp)
        .set    noreorder
        .set    nomacro
        bne     $4,$2,$L2
        sw      $28,28($sp)
        .set    macro
        .set    reorder

        lw      $4,4($16)
        jal     atoi
        lw      $4,8($16)
        move    $16,$2
        jal     atoi
        la      $4,$LC0
        or      $5,$16,$2
        or      $2,$2,$16
        nor     $5,$0,$5
        nor     $6,$0,$2
        jal     printf
$L2:
        move    $2,$0
        lw      $31,32($sp)
        lw      $16,24($sp)
        addu    $sp,$sp,40
        j       $31
        .end    main

        .globl printf .text
        .globl atoi .text
~>
Technical Details
Message-ID: <32D3847F.50C7@daimi.aau.dk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,7a4ae9bb690c5284,start
X-Google-Attributes: gid113d02,public
From: u930534@daimi.aau.dk (Martin Eli Erhardsen)
Subject: GCC 2.7.2/MIPS/Why not use NOR instruction when possible
Date: 1997/01/08
Message-ID: <32D3847F.50C7@daimi.aau.dk>
X-Deja-AN: 208518730
sender: bug-gcc-request@prep.ai.mit.edu
content-type: text/plain; charset=us-ascii
organization: DAIMI, Computer Science Dept. at Aarhus University
x-gateway: relay6.UU.NET from bug-gcc to gnu.gcc.bug; Wed, 8 Jan 1997 06:28:01 EST
mime-version: 1.0
newsgroups: gnu.gcc.bug
x-mailer: Mozilla 3.0 (X11; I; SunOS 5.5 sun4m)