A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-October/029645.html below:

[Python-Dev] Memory size overflows

[Python-Dev] Memory size overflowsTim Peters tim.one@comcast.net
Wed, 16 Oct 2002 12:31:44 -0400
[Tim]
> BTW, if we know we're not interested in anything other than
> 32-bit products,
>
>     double _prod = (double)src1 * (double)src2;
>     if (_prod < 4294967296.0) /* 2**32 */
>         result = (size_t)_prod;
>     else
>         overflow;

[Oren Tirosh]
> s/_prod;/src1 * src2;/
>
> Re-calculating the product with integer multiplication is probably faster
> than converting a double to integer on any sane CPU.

This is so.  Better, because it allows more instruction-level parallelism:

    double dprod = (double)src1 * (double)src2;
    size_t iprod = src1 * src2;
    if (dprod <  4294967296.0) /* 2**32 */
        result = iprod;
    else
        /* overflow */

> I wonder if the old SPARCs that don't have an integer multiply
> instruction actually have a floating point to integer conversion
> that is faster than integer mul.

I'll let someone with an old SPARC worry about that.

> Wasting "expensive" multiplications this way still feels blasphemous :)

Well, we could simulate multiplication by hand, with a bit-at-a-time
shift-and-add loop.  This reduces the detect-mul-overflow case to the
detect-add-overflow case.  Bonus:  on some odd boxes, it would be faster
<wink/sigh>.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4