packages feed

uvector-0.1: tests/notes

    import Data.Array.Vector

    main = print .  sumU $ zipWithU (*)
                            (enumFromToU 1 (100000000 :: Int))
                            (enumFromToU 2 (100000001 :: Int))

A subset of the NDP arrays library. After stream fusion kicks in,
this compiles to the following (very nice!) core:

    {-# LANGUAGE MagicHash #-}

    import GHC.Prim
    import GHC.Base

    go :: Int# -> Int# -> Int# -> Int#
    go a b c =
        case b ># 100000000# of
          False ->
            case a ># 100000001# of
              False ->
                go ((+#) a 1#)
                   ((+#) b 1#)
                   ((+#) c ((*#) b a))
              True -> c
          True -> c

    main = print (I# (go 2# 1# 0#))

Which is exactly what we want, and much the same as this C:

Which shows up some differences between the native code generator and the 
C backend:

    -fvia-C -O2 -optc-O:

        $ time ./T_c
        677921401802298880
        ./T_c  0.21s user 0.00s system 98% cpu 0.213 total

    -fasm -O2

        $ time ./T_asm
        677921401802298880
        ./T_c  0.26s user 0.00s system 94% cpu 0.276 total

And now