[PATCH] x86-64: Add sinf with FMA

H.J. Lu hjl.tools@gmail.com
Tue Dec 5 19:03:00 GMT 2017


On Tue, Dec 5, 2017 at 9:09 AM, Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
> On 05/12/2017 14:56, H.J. Lu wrote:
>> On Tue, Dec 5, 2017 at 5:47 AM, Adhemerval Zanella
>> <adhemerval.zanella@linaro.org> wrote:
>>
>>> And with a simple modification to avoid int to fp conversion:
>>>
>>> ---
>>> diff --git a/sysdeps/ieee754/flt-32/s_sinf.c b/sysdeps/ieee754/flt-32/s_sinf.c
>>> index 40d3d19..a2fd3cf 100644
>>> --- a/sysdeps/ieee754/flt-32/s_sinf.c
>>> +++ b/sysdeps/ieee754/flt-32/s_sinf.c
>>> @@ -75,7 +75,7 @@ static const double invpio4_table[] = {
>>>    0x1.0e4107cp-169
>>>  };
>>>
>>> -static const int ones[] = { +1, -1 };
>>> +static const double ones[] = { 1.0, -1.0 };
>>>
>>>  /* Compute the sine value using Chebyshev polynomials where
>>>     THETA is the range reduced absolute value of the input
>>> @@ -92,7 +92,7 @@ reduced (const double theta, const unsigned long int n,
>>>    const double theta2 = theta * theta;
>>>    /* We are operating on |x|, so we need to add back the original
>>>       signbit for sinf.  */
>>> -  int sign;
>>> +  double sign;
>>>    /* Determine positive or negative primary interval.  */
>>>    sign = ones[((n >> 2) & 1) ^ signbit];
>>>    /* Are we in the primary interval of sin or cos?  */
>>> ---
>>>
>>> I get:
>>>
>>>   "sinf": {
>>>    "": {
>>>     "duration": 4.0015e+10,
>>>     "iterations": 1.4535e+09,
>>>     "max": 640.456,
>>>     "min": 11.437,
>>>     "mean": 27.5301
>>>    }
>>>
>>> Which is roughly 3% on mean and 11.5% on min. I think we can improve it
>>> even more by avoiding the int to fp conversion to get the sign right
>>> and try operate with sign as double argument.
>>
>> I tried it on Skylake with the current master.  Before:
>>
>>   "sinf": {
>>    "": {
>>     "duration": 3.4044e+10,
>>     "iterations": 1.9942e+09,
>>     "max": 141.106,
>>     "min": 7.704,
>>     "mean": 17.0715
>>    }
>>   }
>>
>> After:
>>
>>   "sinf": {
>>    "": {
>>     "duration": 3.40665e+10,
>>     "iterations": 2.03199e+09,
>>     "max": 95.994,
>>     "min": 7.704,
>>     "mean": 16.765
>>    }
>>   }
>>
>> Generic is faster than asm now:
>>
>>   "sinf": {
>>    "": {
>>     "duration": 3.40417e+10,
>>     "iterations": 1.87792e+09,
>>     "max": 138.868,
>>     "min": 8.546,
>>     "mean": 18.1273
>>    }
>>   }
>>
>> Can you submit your patch?
>
> I will do it, thanks for checking this out.

Here is the patch to add sinf with FMA using s_sinf.c for SSE2.
I posted a separate patch to remove sysdeps/x86_64/fpu/s_sinf.S:

https://sourceware.org/ml/libc-alpha/2017-12/msg00146.html

OK for master?

-- 
H.J.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-x86-64-Add-sinf-with-FMA.patch
Type: text/x-patch
Size: 3441 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20171205/8bdb3f42/attachment.bin>


More information about the Libc-alpha mailing list