home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / gnu / gcc / bug / 3159 < prev    next >
Encoding:
Text File  |  1993-01-11  |  3.2 KB  |  114 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ans.net!dennis
  3. From: dennis@ans.net (Dennis Ferguson)
  4. Subject: ffs() with gcc 2.3.3
  5. Message-ID: <199301111614.AA52547@foo.ans.net>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Mon, 11 Jan 1993 06:14:32 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 101
  12.  
  13. There is at least one bug report in here, and perhaps a second unless I
  14. am missing something.  I am using gcc 2.3.3 configured for i386-bsd and
  15. sparc-sun-sunos4.1 (I am running both versions on a Sun, if this matters).
  16. My understanding is that gcc should recognize ffs() as a builtin under
  17. certain conditions, and that if the machine has an instruction to do this
  18. gcc will generate code which uses it.  In addition gcc should almost always
  19. recognize references to __builtin_ffs() as referring to the built in
  20. version of the routine.
  21.  
  22. The 386 CPU has an ffs() instruction, and a template using this is included
  23. in config/i386.md.  Using __builtin_ffs() to reference this seems to work 
  24. fine:
  25.  
  26.   azilda.ans.net> cat myffs_builtin.c
  27.   int
  28.   myffs(int i)
  29.   {
  30.     return __builtin_ffs(i);
  31.   }
  32.   azilda.ans.net> gcc386 -O -S -Wall myffs_builtin.c
  33.   azilda.ans.net> cat myffs_builtin.s
  34.     .file   "myffs_builtin.c"
  35.   gcc2_compiled.:
  36.   .text
  37.     .align 2
  38.   .globl _myffs
  39.   _myffs:
  40.     pushl %ebp
  41.     movl %esp,%ebp
  42.     movl $-1,%eax
  43.     bsfl 8(%ebp),%eax
  44.     incl %eax
  45.     leave
  46.     ret
  47.   azilda.ans.net> 
  48.  
  49. Unfortunately I have yet to be able to find a set of options which will
  50. compile a reference to ffs() the same way as __builtin_ffs().  Neither
  51. the Sun nor the i386 compiler seems to recognize ffs() as a built-in,
  52. so both always generate external calls:
  53.  
  54.   azilda.ans.net> cat myffs.c
  55.   int
  56.   myffs(int i)
  57.   {
  58.     return ffs(i);
  59.   }
  60.   azilda.ans.net> gcc386 -O -S -Wall myffs.c
  61.   myffs.c: In function `myffs':
  62.   myffs.c:4: warning: implicit declaration of function `ffs'
  63.   azilda.ans.net> cat myffs.s
  64.     .file   "myffs.c"
  65.   gcc2_compiled.:
  66.   .text
  67.     .align 2
  68.   .globl _myffs
  69.   _myffs:
  70.     pushl %ebp
  71.     movl %esp,%ebp
  72.     pushl 8(%ebp)
  73.     call _ffs
  74.     leave
  75.     ret
  76.   azilda.ans.net> 
  77.  
  78. It hence appears that the only way to get ffs() to compile to an instruction
  79. on machines which have one is to include a -Dffs=__builtin_ffs somewhere.
  80. The problem with this is that with the sparc compiler, whose machine
  81. description does not define an ffs() instruction, __builtin_ffs()
  82. compiles as a call to __ffssi2().  The latter routine, which looks
  83. like it should be part of libgcc?.c, does not exist.
  84.  
  85.   azilda.ans.net> gcc -O -S -Wall myffs_builtin.c
  86.   azilda.ans.net> cat myffs_builtin.s
  87.   gcc2_compiled.:
  88.   .text
  89.     .align 4
  90.     .global _myffs
  91.     .proc   04
  92.   _myffs:
  93.     !#PROLOGUE# 0
  94.     save %sp,-136,%sp
  95.     !#PROLOGUE# 1
  96.     call ___ffssi2,0
  97.     mov %i0,%o0
  98.     ret
  99.     restore %g0,%o0,%o0
  100.   azilda.ans.net> gcc -O -o mymain mymain.c myffs_builtin.c
  101.   ld: Undefined symbol 
  102.      ___ffssi2 
  103.   collect: /usr/bin/ld returned 2 exit status
  104.   azilda.ans.net> 
  105.  
  106. Ideally I would like gcc to recognize ffs() as a builtin function the
  107. way it does other builtin's, certainly on machines where there is some
  108. benefit to this.  Failing this I would at least like __builtin_ffs()
  109. to compile and load correctly on all target machines.
  110.  
  111. Thanks,
  112. Dennis Ferguson
  113.  
  114.