This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: Need help on FPU division on 64 bit RHEL


On Fri, 2009-03-20 at 12:33 +0530, Halesh S wrote:
> Hi,
> 
> I am writing assembly level code for dividing two numbers.
> 
> The assembly function i used is
> 
> float  assm_div(float a1, float b1)
> {
>  float res;
>  __asm__ ("fld 8(%%ebp)"
>           :
>           :"a"(a1)
>          );
>  __asm__ ("fld 12(%%ebp)"
>          :
>          :"b"(b1)
>          );
>  __asm__ ("fdiv %st(1), %st");
>  __asm__ ("fstp -8(%ebp)"
>          );
>  __asm__ ("fstp -12(%ebp)"
>          );
>  return res;
> }
> 
> It works fine in Red hat 32 bit Linux, for the same its not working
> Red hat 64 bit Linux, on same hardware.
> 
> Is there any changes required for code to make work??
> 
> Thanks,
> Halesh

The first thing to know is that the default for floating point is x87 in
32-bit and it's SSE2 in 64-bit.

When I use the command:
   gcc -O1 -S -fno-asynchronous-unwind-tables divide.c

for the C source file:

double asm_div(double a, double b) { 
  return a / b;
}

I get:

	.file	"divide.c"
	.text
.globl asm_div
	.type	asm_div, @function
asm_div:
	divsd	%xmm1, %xmm0
	ret
	.size	asm_div, .-asm_div
	.ident	"GCC: (Ubuntu 4.3.2-1ubuntu12) 4.3.2"
	.section	.note.GNU-stack,"",@progbits

Floating point arguments are passed in the xmm registers, not on the
stack, in 64-bit. And the return value is in the xmm0 register. So the
assembly language is only one instruction.

For more complicated C functions, try the command:
   gcc -O1 -c -g -Wa,-adhl -fno-asynchronous-unwind-tables divide.c >
divide.lst

As an aside, you should probably use "double" instead of "float" to get
better precision. If you use float, the instruction is divss instead of
divsd.


--Bob



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