This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Strange output code


Per Lundberg wrote:
> The following is a code sample of code generated by gcc version 2.95.2
> 19990906 (prerelease):
> 
>  800072b:       9a 00 00 00 00 50 01    lcall  $0x150,$0x0
>  8000732:       89 c0                   mov    %eax,%eax
>  8000734:       89 c2                   mov    %eax,%edx
>  8000736:       89 51 fc                mov    %edx,0xfffffffc(%ecx)
>  8000739:       8b 51 fc                mov    0xfffffffc(%ecx),%edx
>  800073c:       8b 51 fc                mov    0xfffffffc(%ecx),%edx
>  800073f:       89 d1                   mov    %edx,%ecx
> 
> Not very effective, to say the least. :-)
...

I modified your example function enough to compile it:

int
getpidbyname (char *name)
{
  volatile int r;
  asm volatile ("pushl\t%0" : : "dN" (name));
  asm volatile ("lcall\t%0, $0" : : "n" (0x150));
  asm volatile ("movl\t%%eax, %0": "=a" (r) :);
  return r;
}

and got this assembly output with the 19991001 snapshot:

getpidbyname:
	subl	$28, %esp
	movl	32(%esp), %edx
	pushl	%edx
	lcall	$336, $0
	movl	%eax, %eax
	movl	%eax, 12(%esp)
	movl	12(%esp), %eax
	movl	12(%esp), %eax
	addl	$28, %esp
	ret

I believe your problem is that you are not letting the compiler do its
job.  Your asm constraints make no sense, and you used volatile all
over the place.  If you rewrite the function like this:

int
getpidbyname (char *name)
{
   int r;
   asm ("pushl\t%1\n\t"
	"lcall\t%2, $0"
	: "=a" (r)
	: "g" (name), "n" (0x150));
   return r;
}

you get the much more reasonable

getpidbyname:
	pushl	4(%esp)
	lcall	$336, $0
	ret

[What platform is this, what happens if the syscall fails, and why
can't you use the stub in the standard library for this call?]

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]