Re: [Haskell-cafe] x86 code generation going wrong?

2006-01-08 Thread Branimir Maksimovic





From: [EMAIL PROTECTED] (Donald Bruce Stewart)
To: Branimir Maksimovic <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED], 
[EMAIL PROTECTED],haskell-cafe@haskell.org

Subject: Re: [Haskell-cafe] x86 code generation going wrong?
Date: Mon, 9 Jan 2006 11:15:51 +1100

bmaxa:
>
>
>
> >From: Chris Kuklewicz <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED], Haskell Cafe 
> >Subject: Re: [Haskell-cafe] x86 code generation going wrong?
> >Date: Sun, 08 Jan 2006 20:33:57 +
> >
> >Brian Sniffen wrote:
> >> The first couldn't even complete on my 2.26 GHz Celeron! It's only 
got

> >> 512 MB of RAM,  which may be part of the problem.
> >
> >I should not leak memory but it may be an optimization problem.
> >
> >Try explicitly using "ghc -O2 -funbox-strict-fields".
> >
> On p4. 2.4 ghz 512mb first example takes about 2.5 mb of ram.
> I've compiled explicitelly with -O2, because without optimisations it 
takes

> ridicilously large amount of RAM.
> I've changed {# OPTIONS to OPTIONS_GHC as Bulat sugested
> but still no effect. Options have to be specified on command line in
> order to work.

Ensure that the {-# OPTIONS ... #-} lines is the *first* line of the
file, and that no comments precede it.



Aaah, I didn't knew that. Now this works, thanks!


Greetings, Bane.

_
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


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


Re: [Haskell-cafe] x86 code generation going wrong?

2006-01-08 Thread Donald Bruce Stewart
bmaxa:
> 
> 
> 
> >From: Chris Kuklewicz <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED], Haskell Cafe 
> >Subject: Re: [Haskell-cafe] x86 code generation going wrong?
> >Date: Sun, 08 Jan 2006 20:33:57 +
> >
> >Brian Sniffen wrote:
> >> The first couldn't even complete on my 2.26 GHz Celeron! It's only got
> >> 512 MB of RAM,  which may be part of the problem.
> >
> >I should not leak memory but it may be an optimization problem.
> >
> >Try explicitly using "ghc -O2 -funbox-strict-fields".
> >
> On p4. 2.4 ghz 512mb first example takes about 2.5 mb of ram.
> I've compiled explicitelly with -O2, because without optimisations it takes
> ridicilously large amount of RAM.
> I've changed {# OPTIONS to OPTIONS_GHC as Bulat sugested
> but still no effect. Options have to be specified on command line in
> order to work.

Ensure that the {-# OPTIONS ... #-} lines is the *first* line of the
file, and that no comments precede it.

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


Re: [Haskell-cafe] x86 code generation going wrong?

2006-01-08 Thread Branimir Maksimovic





From: Chris Kuklewicz <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED], Haskell Cafe 
Subject: Re: [Haskell-cafe] x86 code generation going wrong?
Date: Sun, 08 Jan 2006 20:33:57 +

Brian Sniffen wrote:
> The first couldn't even complete on my 2.26 GHz Celeron! It's only got
> 512 MB of RAM,  which may be part of the problem.

I should not leak memory but it may be an optimization problem.

Try explicitly using "ghc -O2 -funbox-strict-fields".


On p4. 2.4 ghz 512mb first example takes about 2.5 mb of ram.
I've compiled explicitelly with -O2, because without optimisations it takes
ridicilously large amount of RAM.
I've changed {# OPTIONS to OPTIONS_GHC as Bulat sugested
but still no effect. Options have to be specified on command line in
order to work.


Greetings, Bane.

_
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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


Re: [Haskell-cafe] x86 code generation going wrong?

2006-01-08 Thread Chris Kuklewicz
Brian Sniffen wrote:
> The first couldn't even complete on my 2.26 GHz Celeron! It's only got
> 512 MB of RAM,  which may be part of the problem.

I should not leak memory but it may be an optimization problem.

Try explicitly using "ghc -O2 -funbox-strict-fields".

> 
> Stack space overflow: current size 1048576 bytes.
> Use `+RTS -Ksize' to increase it.
> ./test1 < sum-file-test-input  25.33s user 2.89s system 18% cpu 2:32.02 total
> 
> ./test2 < sum-file-test-input  4.79s user 0.20s system 94% cpu 5.276 total
> 
> ./test3 < sum-file-test-input  4.46s user 0.14s system 99% cpu 4.623 total
> 
> --
> Brian T. Sniffen
> [EMAIL PROTECTED]or[EMAIL PROTECTED]
> http://www.evenmere.org/~bts
> 

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


RE: [Haskell-cafe] x86 code generation going wrong?

2006-01-08 Thread Branimir Maksimovic





From: Chris Kuklewicz <[EMAIL PROTECTED]>
To: haskell-cafe@haskell.org
Subject: [Haskell-cafe] x86 code generation going wrong?
Date: Sat, 07 Jan 2006 16:18:59 +

Hello,

  I need to ask for some help to test x86 code generation.

There is a factor of two runtime difference between the code I am
benchmarking on my OS X powerbook G4 (ghc 6.4.1) and shootout's speed on
a linux x86 machine (ghc 6.4.1).

Could someone else running on x86 test the three versions pasted below
before I think about submitting another one to the shootout?


Here are the tests on P4 2.4 ghz and athlon 64 3000 linux test1-3 in 
respective order

of appearance (note:OPTIONS didn't do anything I have to
compile -O2 -fglasgow-exts explicitely, because I've got compile error for 
test3.hs )


[EMAIL PROTECTED] ~/haskell/myhaskell] $ time ./test1 < sum-file-test-input
400

real0m3.550s
user0m3.440s
sys 0m0.080s
[EMAIL PROTECTED] ~/haskell/myhaskell] $ time ./test2 < sum-file-test-input
400

real0m3.708s
user0m3.660s
sys 0m0.060s
[EMAIL PROTECTED] ~/haskell/myhaskell] $ time ./test3 < sum-file-test-input
400

real0m3.678s
user0m3.620s
sys 0m0.050s

This is on athlon64 3000 , linux :

[EMAIL PROTECTED] ~]$ time ./test1 < sum-file-test-input
400

real0m5.782s
user0m5.724s
sys 0m0.056s

[EMAIL PROTECTED] ~]$ time ./test2 < sum-file-test-input
400

real0m5.953s
user0m5.900s
sys 0m0.052s
[EMAIL PROTECTED] ~]$ time ./test3 < sum-file-test-input
400

real0m5.403s
user0m5.332s
sys 0m0.072s

Greetings, Bane.



To compile "ghc --make filename.hs -o program"

To run "cat input-file | time ./program"

where to save space, the gzip'd input file is at

http://paradosso.mit.edu/~ckuklewicz/sum-file-test-input.gz

-
-- Original version
{-# OPTIONS -O2 #-}
import Char( ord )

main :: IO ()
main = getContents >>= print . accP 0 0

accP :: Int -> Int -> String -> Int
accP before this  []   =   before+this
accP before this ('\n':xs) = accP (before+this) 0xs
accP before this ('-' :xs) = accN  before   this xs
accP before this (x   :xs) = accP  before  (this*10+ord(x)-ord('0')) xs

accN :: Int -> Int -> String -> Int
accN before this  []   =   before-this
accN before this ('\n':xs) = accP (before-this) 0xs
accN before this (x   :xs) = accN  before  (this*10+ord(x)-ord('0')) xs

-
-- Faster on G4, 2x slower on x86
{-# OPTIONS -O2 -funbox-strict-fields #-}
import GHC.Base

data I = I !Int

main = print . new (I 0) =<< getContents

new (I i) []   = i
new (I i) ('-':xs) = neg (I 0) xs
where neg (I n) ('\n':xs) = new (I (i - n)) xs
  neg (I n) (x   :xs) = neg (I (parse x + (10 * n))) xs
new (I i) (x:xs) = pos (I (parse x)) xs
where pos (I n) ('\n':xs) = new (I (i + n)) xs
  pos (I n) (x   :xs) = pos (I (parse x + (10 * n))) xs

parse c = ord c - ord '0'

-
-- Explicitly unboxed proposal, faster on G4
{-# OPTIONS -fglasgow-exts -O2 #-}

import GHC.Base

main = print . sumFile =<< getContents
where sumFile = (\rest -> newLine rest 0#)

newLine [] rt = (I# rt)
newLine ('-':rest) rt = negLine rest 0#
where negLine ('\n':rest) soFar = newLine rest (rt -# soFar)
  negLine ( x  :rest) soFar = negLine rest (d2i x +# (10# *# 
soFar))

newLine (x:rest) rt = posLine rest (d2i x)
where posLine ('\n':rest) soFar = newLine rest (rt +# soFar)
  posLine ( x  :rest) soFar = posLine rest (d2i x +# (10# *# 
soFar))


d2i (C# c) = (ord# c) -# z
where z = ord# '0'#
-

Thanks,
  Chris

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


_
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


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