Thread overview | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 21, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu wrote:
> https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
>
> https://www.facebook.com/dlang.org/posts/1192267587453587
>
> https://twitter.com/D_Programming/status/678989872367988741
>
>
> Andrei
In the future, you should put your name in the title as it will probably get more votes that way.
|
December 22, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu wrote:
> https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
Great motivation as always! Thx!
|
December 22, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu wrote:
> https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
By the way, even though I wholeheartedly share your sentiment regarding those "functional" examples, I found it to be an interesting example for the power of modern optimizers that LDC manages to compile this
---
ulong factorial(this n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}
---
to this:
---
__D4test9factorialFkZm:
mov eax, 1
cmp edi, 2
jb LBB0_7
mov ecx, edi
lea edx, [rdi + 7]
add edi, -2
mov eax, 1
test dl, 7
je LBB0_4
and edx, 7
neg edx
mov eax, 1
.align 4, 0x90
LBB0_3:
imul rax, rcx
dec rcx
inc edx
jne LBB0_3
LBB0_4:
cmp edi, 7
jb LBB0_7
add rcx, -3
.align 4, 0x90
LBB0_6:
lea rdx, [rcx + 3]
imul rdx, rax
lea rax, [rcx + 2]
lea rsi, [rcx + 1]
imul rax, rsi
imul rax, rdx
lea rdx, [rcx - 1]
imul rdx, rcx
lea rsi, [rcx - 2]
imul rsi, rdx
imul rsi, rax
lea rax, [rcx - 3]
lea rdx, [rcx - 4]
imul rax, rdx
imul rax, rsi
add rcx, -8
lea edx, [rcx + 3]
cmp edx, 1
ja LBB0_6
LBB0_7:
ret
---
Not sure about how it arrives at the crazily unrolled loop, but no recursion in sight anymore.
— David
|
December 22, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 12/22/15 1:29 PM, David Nadlinger wrote:
> ---
> ulong factorial(this n) {
> return n <= 1 ? 1 : n * factorial(n - 1);
> }
> ---
Am I missing some new feature here? What does the 'this' mean?
-Steve
|
December 22, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 22 December 2015 at 19:07:55 UTC, Steven Schveighoffer wrote:
> Am I missing some new feature here? What does the 'this' mean?
I have no idea, this must have been some sort of weird copy/paste or auto-correct mistake on my side. It's supposed to be "uint", as in Andrei's talk.
— David
|
December 22, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 12/22/2015 10:29 AM, David Nadlinger wrote:
> Not sure about how it arrives at the crazily unrolled loop, but no recursion in
> sight anymore.
It's doing tail recursion optimization, which turns the recursion into a loop.
Then the loop is unrolled 8 times.
|
December 22, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 12/21/2015 09:28 AM, Andrei Alexandrescu wrote:
> https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
>
>
> https://www.facebook.com/dlang.org/posts/1192267587453587
>
> https://twitter.com/D_Programming/status/678989872367988741
>
>
> Andrei
Two unnecessary pedantic corrections:
- One of the earlier slides has "Voldermort" with an extra 'r'. It should be Voldemort.
- At the end of one of the optimization presentations you said that the behaviour of unsigned integer overflow and *underflow* are well defined. Although what you meant is clear and that I've been using "underflow" in the same meaning until very recently, I now know that underflow is a condition only for floating point types.
Copying from Wikipedia, "Arithmetic underflow can occur when the true result of a floating point operation is smaller in magnitude (that is, closer to zero) than the smallest value representable as a normal floating point number in the target datatype."
Ali
|
December 23, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Wednesday, 23 December 2015 at 01:07:57 UTC, Walter Bright wrote: > On 12/22/2015 10:29 AM, David Nadlinger wrote: >> Not sure about how it arrives at the crazily unrolled loop, but no recursion in >> sight anymore. > > It's doing tail recursion optimization, which turns the recursion into a loop. The recursive call is not quite a tail call by itself, which is what Andrei pointed out using that example. But yes, that's what happens. > Then the loop is unrolled 8 times. Sure thing. I was rather surprised to see that happen given that I only compiled with -O1, though, as it seems to be quite an aggressive optimization. — David |
December 23, 2015 Re: Three Cool Things about D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 21 December 2015 at 17:28:51 UTC, Andrei Alexandrescu wrote:
> https://www.reddit.com/r/programming/comments/3xq2ul/codedive_2015_talk_three_cool_things_about_d/
>
> https://www.facebook.com/dlang.org/posts/1192267587453587
>
> https://twitter.com/D_Programming/status/678989872367988741
>
>
> Andrei
Interesting talk :-) Watched it while cooking.
|
Copyright © 1999-2021 by the D Language Foundation