[Numpy-discussion] Problems testing the floating point flags

Mark Wiebe mwwiebe@gmail....
Sun Nov 14 14:09:22 CST 2010


On Sun, Nov 14, 2010 at 7:07 AM, Charles R Harris <charlesr.harris@gmail.com
> wrote:

>
> Another possible solution is like so:
>
> static __attribute__ ((noinline)) int
> fpecheck(int *status)
> {
>     *status = PyUFunc_getfperr();
>     return 0;
> }
>
> static __attribute__ ((noinline)) int
> fpeclear(int *status)
> {
>     PyUFunc_clearfperr();
>     return 0;
> }
>
> int myfunc(void)
> {
>     int status;
>
>    fpeclear(&status);
>     do {
>         stuff;
>     } while (fpecheck(&status));
>     return status;
> }
>
>
While this may work in this particular case because of compiler specifics, I
don't think this creates a reliable ordering dependency because of the form
of 'stuff'. It will be loop invariant, so the compiler may do as follows:

    do {
        result = arg1 / arg2;
    } while (fpecheck(&status));

Pulling out the loop-invariant statement:

    result = arg1 / arg2;
    do {
    } while (fpecheck(&status));

Since the loop doesn't use result, it may feel free to reorder:

    do {
    } while (fpecheck(&status));
    result = arg1 / arg2;

producing the bug again.

-Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101114/d2baf649/attachment.html 


More information about the NumPy-Discussion mailing list