This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why is floor() only compiled to roundsd when using -funsafe-math-optimizations?
- From: Jay Foad <jay dot foad at gmail dot com>
- To: Fredrik Tolf <fredrik at dolda2000 dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 28 Jan 2015 11:40:52 +0000
- Subject: Re: Why is floor() only compiled to roundsd when using -funsafe-math-optimizations?
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 11 dot 1501270040340 dot 7734 at shack dot dolda2000 dot com>
On 26 January 2015 at 23:50, Fredrik Tolf <fredrik@dolda2000.com> wrote:
> Dear list,
>
> Consider the following small program:
>
> #include <math.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char **argv)
> {
> double a;
>
> a = strtod(argv[0], NULL);
> printf("%f\n", floor(a));
> return(0);
> }
>
> When compiling this with a -march that supports the roundsd instruction, the
> floor() call seems to only be compiled to such an instruction if
> -funsafe-math-optimizations is specified.
>
> Why is this? I notice the glibc's floor() implementation (for SSE4.1-enabled
> processors) consists of only this instruction, so barring a bug in glibc,
> that would seem to imply to me the roundsd is IEEE-compliant and safe. Why
> does GCC consider it unsafe?
I asked the same thing: https://gcc.gnu.org/ml/gcc-help/2014-01/msg00051.html
Jay.