On Mon, 12 Jan 2009 10:36:37 EST erik quanstrom <quans...@quanstro.net> wrote: > how do you get around the fact that the parallelism > is limited by the instruction set and the fact that one > slow sub-instruction could stall the whole instruction? > > > The hardware also has built-in support for closures. Every function > > executed is implicitly paired with a given local memory region. > > what's the difference between this and stack?
Consider this: (define (counter n) (lambda () (set! n (+1 n)) n)) In C like syntax: (int(*)()) counter(int n) { int foo() { return ++n;} return foo; } ... int(*c1)() = counter(5); int(*c2)() = counter(2); int x = c1(); // x is 6 x += c2(); // x is 6+3 x += c2(); // x is 9+4 n lives past the lifetime of counter so a stack is not enough. So for the returned function from counter(), you have to allocate n on the heap. And you need to store ptr to this space along with the returned function (e.g. c1 has its own local store, so does c2). However, in general what Itanium does is not a win since in practice most functions do not need local storage (even if written in a language richer than C!). Such a ptr to the local store associated with a function ptr can be used to implement objects -- ptrs of all "methods" to the same object point to the same storage. Not sure if anyone has implemented objects this way.