Bug 103336 - [arm64] operations on long double generate calls to libgcc
Summary: [arm64] operations on long double generate calls to libgcc
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-19 17:39 UTC by sebpop@gmail.com
Modified: 2021-11-19 19:29 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sebpop@gmail.com 2021-11-19 17:39:14 UTC
On testsuite/gcc.target/i386/long-double-64-1.c, gcc produces a call to __multf3 on arm64 and the test checks that such a call is not generated on x86_64.

$ cat a.c
long double
foo (long double x)
{
  return x * x;
}

On arm64:
$  gcc -O2 -S -o- a.c
foo:
	stp	x29, x30, [sp, -16]!
	mov	v1.16b, v0.16b
	mov	x29, sp
	bl	__multf3
	ldp	x29, x30, [sp], 16
	ret

On x64:
$ gcc -O2 -S -o- a.c 
foo:
	endbr64
	fldt	8(%rsp)
	fmul	%st(0), %st
	ret

Why GCC does not generate an fmul on arm64 instead of calling libgcc?

There is a related performance issue in libGeos: https://github.com/libgeos/geos/issues/509
Comment 1 Andrew Pinski 2021-11-19 18:04:24 UTC
Arm64 does not have native higher than 644bit floating point. That is why it is a libcall. X86_64's long double is 80bit fp too.
Comment 2 Andrew Pinski 2021-11-19 19:29:16 UTC
If you want to have a consistency between platforms, it might be best if you use _Float128 instead of long double but _Float128 is not supported on all targets really.  It is only supported on targets which have support for IEEE 128bit FP which includes x86_64, arm64 and PowerPC.
Again this is not really a bug or anything GCC can do better unless the newer hardware comes out which has native support.

See https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html for more details on this.