🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Dennis Ferguson Mon, 11 Jan 1993 06:14
ffs() with gcc 2.3.3
#1626
Author: Dennis Ferguson
Date: Mon, 11 Jan 1993 06:14
100 lines
3367 bytes
There is at least one bug report in here, and perhaps a second unless I
am missing something.  I am using gcc 2.3.3 configured for i386-bsd and
sparc-sun-sunos4.1 (I am running both versions on a Sun, if this matters).
My understanding is that gcc should recognize ffs() as a builtin under
certain conditions, and that if the machine has an instruction to do this
gcc will generate code which uses it.  In addition gcc should almost always
recognize references to __builtin_ffs() as referring to the built in
version of the routine.

The 386 CPU has an ffs() instruction, and a template using this is included
in config/i386.md.  Using __builtin_ffs() to reference this seems to work 
fine:

  azilda.ans.net> cat myffs_builtin.c
  int
  myffs(int i)
  {
	return __builtin_ffs(i);
  }
  azilda.ans.net> gcc386 -O -S -Wall myffs_builtin.c
  azilda.ans.net> cat myffs_builtin.s
	.file   "myffs_builtin.c"
  gcc2_compiled.:
  .text
	.align 2
  .globl _myffs
  _myffs:
	pushl %ebp
	movl %esp,%ebp
	movl $-1,%eax
	bsfl 8(%ebp),%eax
	incl %eax
	leave
	ret
  azilda.ans.net> 

Unfortunately I have yet to be able to find a set of options which will
compile a reference to ffs() the same way as __builtin_ffs().  Neither
the Sun nor the i386 compiler seems to recognize ffs() as a built-in,
so both always generate external calls:

  azilda.ans.net> cat myffs.c
  int
  myffs(int i)
  {
	return ffs(i);
  }
  azilda.ans.net> gcc386 -O -S -Wall myffs.c
  myffs.c: In function `myffs':
  myffs.c:4: warning: implicit declaration of function `ffs'
  azilda.ans.net> cat myffs.s
	.file   "myffs.c"
  gcc2_compiled.:
  .text
	.align 2
  .globl _myffs
  _myffs:
	pushl %ebp
	movl %esp,%ebp
	pushl 8(%ebp)
	call _ffs
	leave
	ret
  azilda.ans.net> 

It hence appears that the only way to get ffs() to compile to an instruction
on machines which have one is to include a -Dffs=__builtin_ffs somewhere.
The problem with this is that with the sparc compiler, whose machine
description does not define an ffs() instruction, __builtin_ffs()
compiles as a call to __ffssi2().  The latter routine, which looks
like it should be part of libgcc?.c, does not exist.

  azilda.ans.net> gcc -O -S -Wall myffs_builtin.c
  azilda.ans.net> cat myffs_builtin.s
  gcc2_compiled.:
  .text
	.align 4
	.global _myffs
	.proc   04
  _myffs:
	!#PROLOGUE# 0
	save %sp,-136,%sp
	!#PROLOGUE# 1
	call ___ffssi2,0
	mov %i0,%o0
	ret
	restore %g0,%o0,%o0
  azilda.ans.net> gcc -O -o mymain mymain.c myffs_builtin.c
  ld: Undefined symbol 
     ___ffssi2 
  collect: /usr/bin/ld returned 2 exit status
  azilda.ans.net> 

Ideally I would like gcc to recognize ffs() as a builtin function the
way it does other builtin's, certainly on machines where there is some
benefit to this.  Failing this I would at least like __builtin_ffs()
to compile and load correctly on all target machines.

Thanks,
Dennis Ferguson
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads