Joshua Isom wrote:
I just wrote up the binarytrees test in pir, based on the c version. Although I haven't waited more than twenty minutes yet, I can't get it working with the argument being 16(what they test with) beyond printing the first line. The results I'm getting, it's slow, and I don't have enough ram. Right now, on FreeBSD, it's taking up over 280 megs of memory, varying between 50 and 80 megs resident. And apparently something in the jit core with FreeBSD 5.4 is broken... Something with the integers...

Actually it took 1.3 GB of RAM to finish. Woot. And Chip is to blame this time not me :)

  PMC_cont_ASSIGN(SELF, new_foo(something));

did evaluate the new_foo twice i.e. each return continuation helper struct was allocate twice (and freed once).

Now it finishes in 2m44 [1] taking 53 M RAM for N=16. Still too slow with too much memory used.

I've delete the whole del_tree stuff too, it might just slows things down.

I notice that a lot of the code pertains to lines 42-47, creating an array and storing values in it. But by far, the biggest part of the execution is tied in calling subroutines and returning.

Yep. 3 tips:
  a) use Parrot -C
  b) use {Fixed,Resizable}PMCArray instead of Array
  c) always use the same call/return signature
      e.g. don't mix ack(x,y) and ack(x, 1)
that is get rid of the constant by using a temp $I1 = 1 for the 2nd case

[1] It takes now 2m11 with c) done too

Attached is my version of biarytree.pir.

leo
.sub itemcheck
        .param pmc node
        $I0 = exists node[0]
        unless $I0 goto final
        .local pmc tmp
        tmp = node[0]
        unless_null tmp, else
        $I0 = node[2]
        .return($I0)
else:
        # tmp = node[0]
        $I0 = itemcheck(tmp)
        tmp = node[1]
        $I1 = itemcheck(tmp)
        $I0 -= $I1
        $I1 = node[2]
        $I0 += $I1
final:
        .return($I0)
.end

.sub bottomuptree
        .param int item
        .param int dep
        .local pmc left, right, tree
        .local int item2
        unless dep > 0 goto else
        item2 = item * 2
        $I0 = item2 - 1
        dec dep
        left = bottomuptree($I0, dep)
        right = bottomuptree(item2, dep)
        goto endif
else:
        null left
        null right
endif:
        tree = new .FixedPMCArray
        tree = 3
        tree[0] = left
        tree[1] = right
        tree[2] = item
        .return(tree)
.end

.sub main :main
        .param pmc argv
        .local int N, dep, mindepth, maxdepth, stretchdepth
        .local pmc stretchtree, longlivedtree, tmptree
        $S0 = argv[1]
        N = $S0
        mindepth = 4
        unless N < 6 goto else
        maxdepth = mindepth + 2
        goto endif
else:
        maxdepth = N
endif:
        stretchdepth = maxdepth + 1
        $I0 = 0
        stretchtree = bottomuptree($I0, stretchdepth)
        $I0 = itemcheck(stretchtree)

        print "stretch tree of depth "
        print stretchdepth
        print "\t check: "
        print $I0 
        print "\n"

        null stretchtree
        $I0 = 0
        longlivedtree = bottomuptree($I0, maxdepth)

        dep = mindepth
beginfor_1:

        .local int i, iterations, check

        $N0 = maxdepth - dep
        $N0 += mindepth
        $N1 = 2
        $N2 = pow $N1, $N0
        iterations = $N2
        
        check = 0

        i = 1
        beginfor_2:
       noop

                        tmptree = bottomuptree(i, dep)
                        $I0 = itemcheck(tmptree)
                        check += $I0
                        $I0 = 0 - i
                        tmptree = bottomuptree($I0, dep)
                        $I0 = itemcheck(tmptree)
                        check += $I0
                
        inc i
        if i <= iterations goto beginfor_2
        $I0 = iterations * 2
        print $I0 
        print "\t trees of depth "
        print dep
        print "\t check: " 
        print check
        print "\n"


        dep += 2
        if dep <= maxdepth goto beginfor_1

        $I0 = itemcheck(longlivedtree)
        print "long lived tree of depth "
        print maxdepth
        print "\t check: "
        print $I0 
        print "\n"

.end

Reply via email to