News for hackers. Stuff that matters.
Re:Mugo, a toy compiler for a subset of Go that can compile ... by thysultan on Monday April 12, 2021 @08:07AM (#26778445)
NodeJs and Go can and probably are optimizing the loop away, the authors attempt to assign the sum to result does not prevent this from happening.
Re:Mugo, a toy compiler for a subset of Go that can compile ... by benhoyt on Monday April 12, 2021 @03:00PM (#26783606)
> can and probably are optimizing the loop away

Why do you think that, and how would it do that and still do the calculation? My timing tests showed that Go didn't optimize the loop away (if I counted to 10 billion it took about 10 times as long), and godbolt.org also shows the loop in Go's assembly output: https://www.godbolt.org/z/d38xfGYr6

Re:Mugo, a toy compiler for a subset of Go that can compile ... by makapuf on Monday April 12, 2021 @03:54PM (#26784318)
Fun fact: in C, gcc and clang can(and will) replace the sum of n first integers with a loop (and slight variations) with Euler formula n(n+1)/2. Impressive.
Re:Mugo, a toy compiler for a subset of Go that can compile ... by benhoyt on Monday April 12, 2021 @04:24PM (#26784676)
Wow, that is impressive, thanks. I confirmed this with godbolt.org at -O2.