pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Eisentraut <peter_e@gmx.net>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Noah Misch <noah@leadboat.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: [COMMITTERS] pgsql: Add trigonometric functions that work in degrees.
Date: Mon, 25 Apr 2016 23:25:54 -0400
Message-ID: <7978.1461641154@sss.pgh.pa.us> (raw)
In-Reply-To: <21507.1461625996@sss.pgh.pa.us>
References: <570311F1.6020902@gmx.net>
	<31479.1460152130@sss.pgh.pa.us>
	<CA+Tgmoa1fig2OV0Mam3dPmAOhaf6T_E8CXvQsDunvDV9vYEhwg@mail.gmail.com>
	<5714552B.5030001@gmx.net>
	<CAB7nPqSvocAX1n9Wbozo8nfdOAZaA0MAxvkpwSKTFjc-0NxadQ@mail.gmail.com>
	<12238.1460985466@sss.pgh.pa.us>
	<20160419021144.GA1984253@tornado.leadboat.com>
	<20830.1461032579@sss.pgh.pa.us>
	<20160419024950.GB1983345@tornado.leadboat.com>
	<32425.1461038215@sss.pgh.pa.us>
	<20160419041631.GC1983345@tornado.leadboat.com>
	<CAEZATCXxdf0ZG4Vbd-6ZrE8g-VYfFpGQpHBi1tFoi3S+TKn=VQ@mail.gmail.com>
	<18241.1461073100@sss.pgh.pa.us>
	<CAEZATCX-vpywtAFpkdir52Hqp-+xnM8Nwr7pU6XOCAeELDPuWA@mail.gmail.com>
	<12182.1461098908@sss.pgh.pa.us>
	<57192E3C.9040109@gmx.net>
	<9748.1461284311@sss.pgh.pa.us>
	<571D8415.3050109@gmx.net>
	<7284.1461552992@sss.pgh.pa.us>
	<12552.1461611379@sss.pgh.pa.us>
	<571E8379.7070802@gmx.net>
	<21507.1461625996@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

I wrote:
> Evidently, asin() is returning an 80-bit result, and that's not
> getting rounded to double width before we divide by asin_0_5.

I found that I could reproduce this type of assembly-code behavior
on dromedary (gcc version 4.2.1) by using -mfpmath=387.  That box
doesn't show the visible regression-test failure, but that must be
down to its version of asin() not producing the same low-order bits
that yours does.  It's clear from the assembly output that the code
*would* misbehave given an appropriate asin() library function.

With that version of gcc, just casting the function output to double
changes nothing.  The local-variable solution likewise.  I do get
a useful fix if I declare the asin_x local variable volatile:

        .loc 1 1873 0
        fstpl   (%esp)
        call    _asin
+       fstpl   -16(%ebp)
+ LVL107:
+       fldl    -16(%ebp)
        fdivl   _asin_0_5-"L00000000019$pb"(%ebx)
        fmuls   LC21-"L00000000019$pb"(%ebx)

Interestingly, declaring asin_x as global is not enough to fix it,
because it stores into the global but doesn't fetch back:

        .loc 1 1873 0
        fstpl   (%esp)
        call    _asin
+       movl    L_asin_x$non_lazy_ptr-"L00000000019$pb"(%ebx), %eax
+       fstl    (%eax)
        fdivl   _asin_0_5-"L00000000019$pb"(%ebx)
        fmuls   LC21-"L00000000019$pb"(%ebx)

Declaring asin_x as a volatile global does fix it:

        .loc 1 1873 0
        fstpl   (%esp)
        call    _asin
+       movl    L_asin_x$non_lazy_ptr-"L00000000019$pb"(%ebx), %eax
+       fstpl   (%eax)
+       fldl    (%eax)
        fdivl   _asin_0_5-"L00000000019$pb"(%ebx)
        fmuls   LC21-"L00000000019$pb"(%ebx)

but that seems like just being uglier without much redeeming value.

In short, these tests suggest that we need a coding pattern like
this:

	volatile float8 asin_x = asin(x);
	return (asin_x / asin_0_5) * 30.0;

We could drop the "volatile" by adopting -ffloat-store, but that
doesn't seem like a better answer, because -ffloat-store would
pessimize a lot of code elsewhere.  (It causes a whole lot of
changes in float.c, for sure.)

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (35+ messages)  latest in thread

Message-ID: <7978.1461641154@sss.pgh.pa.us>
Permalink:  ../7978.1461641154@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/7978.1461641154@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, peter_e@gmx.net, dean.a.rasheed@gmail.com, noah@leadboat.com, michael.paquier@gmail.com, robertmhaas@gmail.com, pgsql-hackers@postgresql.org
  Subject: Re: [COMMITTERS] pgsql: Add trigonometric functions that work in degrees.
  In-Reply-To: <7978.1461641154@sss.pgh.pa.us>
  References: <570311F1.6020902@gmx.net> <31479.1460152130@sss.pgh.pa.us> <CA+Tgmoa1fig2OV0Mam3dPmAOhaf6T_E8CXvQsDunvDV9vYEhwg@mail.gmail.com> <5714552B.5030001@gmx.net> <CAB7nPqSvocAX1n9Wbozo8nfdOAZaA0MAxvkpwSKTFjc-0NxadQ@mail.gmail.com> <12238.1460985466@sss.pgh.pa.us> <20160419021144.GA1984253@tornado.leadboat.com> <20830.1461032579@sss.pgh.pa.us> <20160419024950.GB1983345@tornado.leadboat.com> <32425.1461038215@sss.pgh.pa.us> <20160419041631.GC1983345@tornado.leadboat.com> <CAEZATCXxdf0ZG4Vbd-6ZrE8g-VYfFpGQpHBi1tFoi3S+TKn=VQ@mail.gmail.com> <18241.1461073100@sss.pgh.pa.us> <CAEZATCX-vpywtAFpkdir52Hqp-+xnM8Nwr7pU6XOCAeELDPuWA@mail.gmail.com> <12182.1461098908@sss.pgh.pa.us> <57192E3C.9040109@gmx.net> <9748.1461284311@sss.pgh.pa.us> <571D8415.3050109@gmx.net> <7284.1461552992@sss.pgh.pa.us> <12552.1461611379@sss.pgh.pa.us> <571E8379.7070802@gmx.net> <21507.1461625996@sss.pgh.pa.us> <7978.1461641154@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox