public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103008] poor inlined builtin_fmod on x86_64 Date: Fri, 11 Feb 2022 07:59:40 +0000 [thread overview] Message-ID: <bug-103008-4-N5DsCLgg0x@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103008-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103008 --- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> --- Just as data-point on znver2 Uros testcase shows rguenther@ryzen:/tmp> gcc-11 t.c -Ofast -lm -march=znver2 rguenther@ryzen:/tmp> numactl --physcpubind=3 /usr/bin/time ./a.out 19.18user 0.00system 0:19.18elapsed 99%CPU (0avgtext+0avgdata 1528maxresident)k 0inputs+0outputs (0major+76minor)pagefaults 0swaps rguenther@ryzen:/tmp> gcc-11 t.c -Ofast -lm -march=znver2 -fno-builtin-fmod rguenther@ryzen:/tmp> numactl --physcpubind=3 /usr/bin/time ./a.out 19.26user 0.00system 0:19.26elapsed 99%CPU (0avgtext+0avgdata 1528maxresident)k 0inputs+0outputs (0major+76minor)pagefaults 0swaps rguenther@ryzen:/tmp> gcc-11 t.c -Ofast -lm -march=znver2 -Dfmodf=_fmodf rguenther@ryzen:/tmp> numactl --physcpubind=3 /usr/bin/time ./a.out 4.40user 0.00system 0:04.40elapsed 100%CPU (0avgtext+0avgdata 1528maxresident)k 0inputs+0outputs (0major+76minor)pagefaults 0swaps that's with glibc 2.31. So the _fmodf variant is very much faster. But as Joseph says a general expansion like that is probably a bad idea. The specific case of blender using doubles and fmod (x, 1.) shows that glibc is very much slower than x87 in the test below on znver2 but the proposed inline is very very much faster. Note that using modf(x, &tem) is more than three times as fast as using fmod (x, 1.) with glibc 2.31. While we have an optab for fmod we don't have one for modf (which has an unfortunate pointer output API). I'm not sure whether fmod (x, 1.) == modf (x, &tem). #include <math.h> double __attribute__((noinline)) _fmod (double x, double) { return x - trunc (x); } int main () { double a, b; volatile double z; for (a = -1000.0; a < 1000.0; a += 0.01) for (b = -1000.0; b < 1000.0; b += 0.1) { volatile double tem = a; z = fmod (tem, 1.); } return 0; } Note that replacing a call of fmod (x, 1.) with x - trunc (x) would not be a simplifcation on GIMPLE so that should be possibly done by RTL expansion? Replacing it with modf (x, &tem) would be OK I think (unfortunately modf doesn't seem to accept a NULL arg). Both functions are part of C99 / POSIX so replacing one with the other should be generally OK. Maybe there's a function that does not compute the integer part as well.
next prev parent reply other threads:[~2022-02-11 7:59 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-10-30 18:51 [Bug target/103008] New: " fx at gnu dot org 2021-10-30 18:52 ` [Bug target/103008] " fx at gnu dot org 2021-10-30 18:55 ` fx at gnu dot org 2021-10-30 18:56 ` fx at gnu dot org 2021-10-30 20:15 ` fx at gnu dot org 2021-10-30 20:39 ` anlauf at gcc dot gnu.org 2021-10-31 20:05 ` ubizjak at gmail dot com 2021-11-01 8:23 ` ubizjak at gmail dot com 2022-02-10 14:18 ` rguenth at gcc dot gnu.org 2022-02-10 14:22 ` rguenth at gcc dot gnu.org 2022-02-10 18:09 ` ubizjak at gmail dot com 2022-02-10 20:50 ` joseph at codesourcery dot com 2022-02-11 7:59 ` rguenth at gcc dot gnu.org [this message] 2022-02-11 15:47 ` ubizjak at gmail dot com 2022-02-12 22:07 ` ubizjak at gmail dot com 2022-02-13 21:00 ` Dave.Love at manchester dot ac.uk 2022-02-14 7:12 ` rguenther at suse dot de 2022-02-14 7:35 ` rguenth at gcc dot gnu.org
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=bug-103008-4-N5DsCLgg0x@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).