[Numpy-discussion] Problems testing the floating point flags
Charles R Harris
charlesr.harris at gmail.com
Sun Nov 14 15:21:31 EST 2010
On Sun, Nov 14, 2010 at 1:09 PM, Mark Wiebe <mwwiebe at gmail.com> wrote:
>
>
> On Sun, Nov 14, 2010 at 7:07 AM, Charles R Harris <
> charlesr.harris at 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.
>
>
Good point. I was trying to keep the fpeclear in front of the code to be
tested.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20101114/b5352bfb/attachment.html>
More information about the NumPy-Discussion
mailing list