Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-29 Thread Roman Leshchinskiy
On 29/03/2010, at 02:27, Lennart Augustsson wrote:

 Does anything change if you swap the first two rhss?

No, not as far as I can tell.

 
 On Sun, Mar 28, 2010 at 1:28 AM, Roman Leshchinskiy r...@cse.unsw.edu.au 
 wrote:
 On 28/03/2010, at 09:47, Lennart Augustsson wrote:
 
 It's important to switch from mod to rem.  This can be done by a
 simple abstract interpretation.
 
 Also, changing the definition of rem from
 
a `rem` b
 | b == 0 = divZeroError
 | a == minBound  b == (-1) = overflowError
 | otherwise  =  a `remInt` b
 
 to
 
a `rem` b
 | b == 0 = divZeroError
 | b == (-1)  a == minBound = overflowError
 | otherwise  =  a `remInt` b
 
 speeds up the GHC version by about 20%. Figuring out why is left as an 
 exercise to the reader :-)
 
 Roman
 
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-28 Thread Lennart Augustsson
Does anything change if you swap the first two rhss?

On Sun, Mar 28, 2010 at 1:28 AM, Roman Leshchinskiy r...@cse.unsw.edu.au 
wrote:
 On 28/03/2010, at 09:47, Lennart Augustsson wrote:

 It's important to switch from mod to rem.  This can be done by a
 simple abstract interpretation.

 Also, changing the definition of rem from

    a `rem` b
     | b == 0                     = divZeroError
     | a == minBound  b == (-1) = overflowError
     | otherwise                  =  a `remInt` b

 to

    a `rem` b
     | b == 0                     = divZeroError
     | b == (-1)  a == minBound = overflowError
     | otherwise                  =  a `remInt` b

 speeds up the GHC version by about 20%. Figuring out why is left as an 
 exercise to the reader :-)

 Roman


 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Neil Mitchell
Hi John,

Any chance of seeing the benchmark? You're not the only one with an
optimising compiler tucked away somewhere :-)

I have one benchmark where I outperform GHC by 21 times, although
saying it's artificial is a bit of an understatement...

Thanks, Neil

On Fri, Mar 26, 2010 at 6:27 PM, John Meacham j...@repetae.net wrote:
 Here are jhc's timings for the same programs on my machine. gcc and ghc
 both used -O3 and jhc had its full standard optimizations turned on.

 jhc:
 ./hs.out  5.12s user 0.07s system 96% cpu 5.380 total

 gcc:
 ./a.out  5.58s user 0.00s system 97% cpu 5.710 total

 ghc:
 ./try  31.11s user 0.00s system 96% cpu 32.200 total


 As you can see, jhc shines at this example, actually beating gcc -O3. It
 isn't too surprising, this is exactly the sort of haskell code that jhc
 excels at.

        John


 --
 John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Jason Dagit
On Sat, Mar 27, 2010 at 3:25 AM, Neil Mitchell ndmitch...@gmail.com wrote:

 Hi John,

 Any chance of seeing the benchmark? You're not the only one with an
 optimising compiler tucked away somewhere :-)


Neil, for some reason John's reply didn't thread with the rest of the
thread.  Probably because he changed the subject.  He was referring to this
thread:
http://www.haskell.org/pipermail/haskell-cafe/2010-March/075151.html

Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Rafael Cunha de Almeida
John Meacham wrote:
 Here are jhc's timings for the same programs on my machine. gcc and ghc
 both used -O3 and jhc had its full standard optimizations turned on.
 
 jhc:
 ./hs.out  5.12s user 0.07s system 96% cpu 5.380 total
 
 gcc:
 ./a.out  5.58s user 0.00s system 97% cpu 5.710 total
 
 ghc:
 ./try  31.11s user 0.00s system 96% cpu 32.200 total
 
 
 As you can see, jhc shines at this example, actually beating gcc -O3. It
 isn't too surprising, this is exactly the sort of haskell code that jhc
 excels at.

What's the property of that code which makes jhc excels in it? What
makes ghc perform so poorly in comparison?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Lennart Augustsson
It's important to switch from mod to rem.  This can be done by a
simple abstract interpretation.
I'm nore sure if it's jhc or gcc that does this for jhc.

  -- Lennart

On Sat, Mar 27, 2010 at 10:30 PM, Rafael Cunha de Almeida
almeida...@gmail.com wrote:
 John Meacham wrote:
 Here are jhc's timings for the same programs on my machine. gcc and ghc
 both used -O3 and jhc had its full standard optimizations turned on.

 jhc:
 ./hs.out  5.12s user 0.07s system 96% cpu 5.380 total

 gcc:
 ./a.out  5.58s user 0.00s system 97% cpu 5.710 total

 ghc:
 ./try  31.11s user 0.00s system 96% cpu 32.200 total


 As you can see, jhc shines at this example, actually beating gcc -O3. It
 isn't too surprising, this is exactly the sort of haskell code that jhc
 excels at.

 What's the property of that code which makes jhc excels in it? What
 makes ghc perform so poorly in comparison?
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Rafael Cunha de Almeida
Lennart Augustsson wrote:
 It's important to switch from mod to rem.  This can be done by a
 simple abstract interpretation.
 I'm nore sure if it's jhc or gcc that does this for jhc.
 

It's not just adding rem. Ghc still runs much slower using rem. It's
only when switching to -fvia-C and using rem that ghc gets close to gcc
speed (even though, still slower). Now jhc seems to get it fast right
away. What's going on here? Is ghc backend wrose than using gcc as a
backend (which is what via-C seems to accomplish)? Are there cases when
one way is preferred over the other? What are the tradeoffs here?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread John Meacham
On Sat, Mar 27, 2010 at 07:30:30PM -0300, Rafael Cunha de Almeida wrote:
 John Meacham wrote:
  Here are jhc's timings for the same programs on my machine. gcc and ghc
  both used -O3 and jhc had its full standard optimizations turned on.
  
  jhc:
  ./hs.out  5.12s user 0.07s system 96% cpu 5.380 total
  
  gcc:
  ./a.out  5.58s user 0.00s system 97% cpu 5.710 total
  
  ghc:
  ./try  31.11s user 0.00s system 96% cpu 32.200 total
  
  
  As you can see, jhc shines at this example, actually beating gcc -O3. It
  isn't too surprising, this is exactly the sort of haskell code that jhc
  excels at.

I have not thoroughly checked it, but I think there are a couple things
going on here:

jhc is able to determine that all the arguments to the various functions
are strict, so it can avoid all heap allocations and evaluations. ghc
also benefits from this optimization.

jhc sees that all the functions are fully applied to all their
arguments, this means that they can always be directly called with
optimized calling conventions as they will never have to represent
generic 'eval' thunks or partial applications.

it sees that all the functions are local to 'main' and not exported, so
it can actually translate them to local functions in main in grin,
allowing some more useful optimizations.

Now the most important one, after optimizing the local functions, jhc
sees that they are only called in tail-call position, so jhc is able to
turn the function calls into direct jumps, turning them
directly into C while/for loops operating fully on automatic variables
on the stack.

These last two optimizations are enabled by an incredibly useful
extension to boquist's GRIN which is to allow a form of local function
definitions, which solve a number of issues raised in his paper. Via a
series of Grin-Grin transformations I am able to turn these local
funciton definitions into direct conditional jumps in the resulting
code. (which translate to looping constructs, if's and goto's in C)

John


-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Roman Leshchinskiy
On 27/03/2010, at 05:27, John Meacham wrote:

 Here are jhc's timings for the same programs on my machine. gcc and ghc
 both used -O3 and jhc had its full standard optimizations turned on.
 
 jhc:
 ./hs.out  5.12s user 0.07s system 96% cpu 5.380 total
 
 gcc:
 ./a.out  5.58s user 0.00s system 97% cpu 5.710 total
 
 ghc:
 ./try  31.11s user 0.00s system 96% cpu 32.200 total

I really don't understand these GHC numbers. I get about 3s for the C version, 
about 5s for GHC with rem and about 7.5s for GHC with mod. Is this perhaps on a 
64-bit system? What is sizeof(int) in C and sizeOf (undefined :: Int) in 
Haskell?

That said, I suspect the only thing this benchmark really measures is how fast 
the various compilers can compute i * i + j * j + k * k `mod` 7.

Roman


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Roman Leshchinskiy
On 28/03/2010, at 11:07, John Meacham wrote:

 I have not thoroughly checked it, but I think there are a couple things
 going on here:

It could also be worthwhile to float out (i*i + j*j) in rangeK instead of 
computing it in every loop iteration. Neither ghc nor gcc can do this; if jhc 
can then that might explain the performance difference (although I would expect 
it to be larger in this case).

Roman


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Roman Leshchinskiy
On 28/03/2010, at 09:47, Lennart Augustsson wrote:

 It's important to switch from mod to rem.  This can be done by a
 simple abstract interpretation.

Also, changing the definition of rem from

a `rem` b
 | b == 0 = divZeroError
 | a == minBound  b == (-1) = overflowError
 | otherwise  =  a `remInt` b

to

a `rem` b
 | b == 0 = divZeroError
 | b == (-1)  a == minBound = overflowError
 | otherwise  =  a `remInt` b

speeds up the GHC version by about 20%. Figuring out why is left as an exercise 
to the reader :-)

Roman 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-26 Thread John Meacham
Here are jhc's timings for the same programs on my machine. gcc and ghc
both used -O3 and jhc had its full standard optimizations turned on.

jhc:
./hs.out  5.12s user 0.07s system 96% cpu 5.380 total

gcc:
./a.out  5.58s user 0.00s system 97% cpu 5.710 total

ghc:
./try  31.11s user 0.00s system 96% cpu 32.200 total


As you can see, jhc shines at this example, actually beating gcc -O3. It
isn't too surprising, this is exactly the sort of haskell code that jhc
excels at.

John


-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe