mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: bobodog <8192542@qq.com>
Cc: musl <musl@lists.openwall.com>
Subject: Re: RE:[BUG][math]build musl with optimizing flags, some math functions are broken.
Date: Tue, 14 Oct 2014 11:12:12 -0400	[thread overview]
Message-ID: <20141014151212.GO32028@brightrain.aerifal.cx> (raw)
In-Reply-To: <tencent_07C7708762DD414A5A757808@qq.com>

On Tue, Oct 14, 2014 at 03:09:45PM +0800, bobodog wrote:
> Further confirmation, the problem is -ffast-math flag, just remove
> this flag, all tests passed, please fix this bug, the openbsd's msun
> math library, have not any problem with this flags.

This is not a bug. The documented purpose of the -ffast-math flag is
to unconstrain the compiler from having to provide correct results for
floating point math operation, in hopes of producing faster code. It
is documented as:

    Sets -fno-math-errno, -funsafe-math-optimizations,
    -ffinite-math-only, -fno-rounding-math, -fno-signaling-nans and
    -fcx-limited-range. This option causes the preprocessor macro
    __FAST_MATH__ to be defined.

    This option is not turned on by any -O option besides -Ofast since
    it can result in incorrect output for programs that depend on an
    exact implementation of IEEE or ISO rules/specifications for math
    functions. It may, however, yield faster code for programs that do
    not require the guarantees of these specifications.

(Source: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html)

The patches you provided are not valid; they simply cause
perturbations in the compiler's output that makes the functions happen
to work for your particular version of GCC and CFLAGS. But there is no
reason they should make it work. The problem is -ffast-math. The only
way to implement the math part of the standard library that's
compatible with -ffast-math would be to write the whole thing using
explicit soft-float, which would be very slow.

Just remove -ffast-math and the problem should go away.

Note that -mfpu=neon may also break some things in the standard
library, and it will not help. There are no functions in the standard
library which benefit from vectorization of floating point math. The
breakage from using neon should be much smaller (probably limited to
cases of denormal arguments) but you're not gaining anything by using
it, so it would make sense to remove that too.

There is nothing wrong with using -ffast-math or -mfpu=neon to compile
your _applications_ as long as those applications don't need
rigorously correct math results. But these options should not be used
for compiling the standard library.

Rich


  parent reply	other threads:[~2014-10-14 15:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-14  2:17 [math] The math library have some bug for ceil,floor,round functioin, in arm mode bobodog
2014-10-14  2:42 ` Rich Felker
2014-10-14  2:51   ` 回复: [musl] [math] The math library have some bug forceil,floor,round " bobodog
2014-10-14  3:03     ` Rich Felker
2014-10-14  4:11       ` 回复: [musl] 回复: [musl ] [math] The math library have some bugforceil,floor,round " bobodog
2014-10-14  6:26         ` RE:[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains bobodog
2014-10-14  6:43           ` [BUG][math]build musl with optimizing flags, some math functions are broken bobodog
     [not found]             ` <tencent_07C7708762DD414A5A757808@qq.com>
2014-10-14 15:12               ` Rich Felker [this message]
2014-10-14 15:33               ` RE???[BUG][math]build " Szabolcs Nagy
2014-10-14  8:06           ` RE???[musl ] [math] I Found math library's bug in ceil, floor, round functions, Using arm toolchains Szabolcs Nagy
2014-10-14  3:04     ` 回复: [musl] The math library have some bug forceil,floor,round functioin, in arm mode bobodog

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141014151212.GO32028@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=8192542@qq.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).