public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marc.glisse at normalesup dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/47913] [C++0x] improve ratio_add to overflow less often
Date: Wed, 02 Mar 2011 11:50:00 -0000	[thread overview]
Message-ID: <bug-47913-4-RBiAEvh0rG@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47913-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47913

--- Comment #9 from Marc Glisse <marc.glisse at normalesup dot org> 2011-03-02 11:50:41 UTC ---
(In reply to comment #8)
> Right. Mine was sort of a general comment: the comments in ratio_less are also
> rather terse ;)

I'll try to expand a bit on them.

> I don't think you should really handcode something, just pick the right
> __builtin_* depending on the actual type of uintmax_t (after all it's just a
> typedef for one of the builtin types). Thus, if we aim for something really
> general here, use just a bit of templates to pick the best match among the
> various available __builtin_*, via make_signed on uintmax_t and then three
> special cases for int, long, long long. Granted, probably on widespread 32-bit
> and 64-bit machines, long long it's indeed a safe bet.

If intmax_t is guaranteed to be one of int/long/long long, then it seems that
it has to be equivalent to long long. I was more afraid that it might be a
bigger type than long long.

(by the way, __builtin_clz takes an unsigned argument)

> Understood. Since 4.6.0 is approaching, do you think it would make sense for
> this release series to modify only a bit the GCC code, to the point that we are
> as good or even slightly better, if possible, than Boost, without requiring too
> much new code? I fear regressions, as you of course can easily understand.
> Ideally, we should add, mano a mano, testcases for each "subclass" of inputs
> which we are able to process without overflowing.

I think there is nothing wrong with the implementation of ratio_add currently
in libstdc++ (shipping it as it is seems fine), but we could indeed easily
avoid all unnecessary denominator overflows (attachment in a minute). The
factorization of the gcd of numerators is a heuristic that sometimes helps but
doesn't really close a category of overflow, so I am more reluctant to add it,
but it is really easy if you think it should be done.


  parent reply	other threads:[~2011-03-02 11:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27 13:23 [Bug libstdc++/47913] New: " marc.glisse at normalesup dot org
2011-02-27 14:13 ` [Bug libstdc++/47913] " paolo.carlini at oracle dot com
2011-02-27 19:33 ` marc.glisse at normalesup dot org
2011-02-27 23:38 ` paolo.carlini at oracle dot com
2011-02-28  1:33 ` paolo.carlini at oracle dot com
2011-03-01 22:16 ` marc.glisse at normalesup dot org
2011-03-01 23:00 ` paolo.carlini at oracle dot com
2011-03-02 10:00 ` marc.glisse at normalesup dot org
2011-03-02 10:59 ` paolo.carlini at oracle dot com
2011-03-02 11:50 ` marc.glisse at normalesup dot org [this message]
2011-03-02 11:54 ` marc.glisse at normalesup dot org
2011-03-02 11:59 ` paolo.carlini at oracle dot com
2011-03-02 12:07 ` paolo.carlini at oracle dot com
2011-03-02 14:05 ` marc.glisse at normalesup dot org
2011-03-02 14:15 ` paolo.carlini at oracle dot com
2011-03-02 14:58 ` paolo at gcc dot gnu.org
2011-03-02 14:59 ` paolo.carlini at oracle dot com
2011-03-02 20:50 ` marc.glisse at normalesup dot org
2011-03-02 23:21 ` paolo.carlini at oracle dot com
2011-03-03  6:41 ` marc.glisse at normalesup dot org
2011-03-03  9:51 ` paolo.carlini at oracle dot com
2011-05-04 16:35 ` marc.glisse at normalesup dot org
2011-05-04 17:05 ` paolo.carlini at oracle dot com
2011-05-04 18:08 ` paolo.carlini at oracle dot com
2011-05-04 23:28 ` paolo at gcc dot gnu.org
2011-05-04 23:36 ` paolo.carlini at oracle dot com

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-47913-4-RBiAEvh0rG@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: link
Be 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).