Please rid me of this goto
Seb via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 23 15:08:20 PDT 2016
On Thursday, 23 June 2016 at 21:03:08 UTC, Andrei Alexandrescu
wrote:
> On 06/23/2016 02:37 PM, Seb wrote:
>> On Thursday, 23 June 2016 at 18:05:07 UTC, Andrei Alexandrescu
>> wrote:
>>> On 06/23/2016 01:34 PM, H. S. Teoh via Digitalmars-d wrote:
>>>> I don't understand why that goto is necessary.
>>>
>>> Eh, thank you all who set me straight! I've been in my head
>>> for too
>>> long. So where is the current implementation of "^^"? If it's
>>> not as
>>> fast as this, we should replace it. -- Andrei
>>
>> ^^ seems to be lowered here
>> https://github.com/dlang/dmd/blob/9903aba3b1d39bf499a54edbc81c7d9f08711f3e/src/constfold.d#L506
>>
>>
>> and std.math.pow is defined here:
>> https://github.com/dlang/phobos/blob/master/std/math.d#L6028
>
> I see, thanks. Both seem to be ripe for the optimized version
> (they do more testing than necessary).
>
>> However you should test how it performs against the LLVM
>> intrinsics
>> available in LDC, e.g.:
>>
>> llvm.intrinsincs.llvm_pow and llvm_powi (i = integer).
>
> Cool! Is that a CPU operation?
Depends on the target
http://llvm.org/docs/LangRef.html#llvm-pow-intrinsic
You should definitely benchmark between compilers. I gave it a
quick for floating point and integer power (see [1, 2]). Please
take the numbers with _great_ care, but I hope they show the
point about the importance of benchmarking between compilers ;-)
Floating-point
--------------
dmd -inline -release -O -boundscheck=off test_pow.d
-ofbin/dmd/test_pow
ldc -release -O3 -boundscheck=off test_pow.d -ofbin/ldc/test_pow
gdc -finline-functions -frelease -O3 test_pow.d -o
bin/gdc/test_pow
>dmd
math.pow 3 secs, 463 ms, 379 μs, and 6 hnsecs
^^ 7 secs, 295 ms, 984 μs, and 3 hnsecs
>ldc
llvm_pow 125 ms, 673 μs, and 2 hnsecs
^^ 6 secs, 380 ms, 104 μs, and 2 hnsecs
>gdc
math.pow 0 secs 125 ms
^^ 2 secs 2161 ms
Integer power
-------------
dmd -inline -release -O -boundscheck=off test_powi.d
-ofbin/dmd/test_powi
ldc -release -O3 -boundscheck=off test_powi.d -ofbin/ldc/test_powi
gdc -finline-functions -frelease -O3 test_powi.d -o
bin/gdc/test_powi
>dmd
math.pow 978 ms, 961 μs, and 8 hnsecs
^^ 1 sec, 15 ms, 177 μs, and 6 hnsecs
>ldc
math.pow 556 ms, 366 μs, and 8 hnsecs
^^ 507 ms, 3 μs, and 1 hnsec
>gdc
math.pow 0 secs 125 ms
^^ 0 secs 42 ms
[1] https://github.com/wilzbach/perf-d/blob/master/test_pow.d
[2] https://github.com/wilzbach/perf-d/blob/master/test_powi.d
More information about the Digitalmars-d
mailing list