On 30 April 2010 01:54, Henrik Sperre Johansen <[email protected]> wrote: > On 29.04.2010 17:13, Igor Stasenko wrote: >> >> Core packages were broken, and were unable to load w/o errors. >> But now seems everything loads well. >> Use NBInstaller install. >> >> Thanks to Henrik for help! > > Here's a small example, as well as profile: > > SmallInteger >> nbFib > <primitive: 'primitiveNativeCall' module: 'NativeBoostPlugin'> > ^ NBNativeCodeGen methodAssembly: [:gen | > | loopStart proxy asm EAX EBX ECX | > asm := gen asm. > proxy := NBInterpreterProxy new asm: asm. > loopStart := asm uniqueLabelName: 'loopStart'. > > EAX := asm assembler reg0. > EBX := asm assembler reg3. > ECX := asm assembler reg1. > proxy receiver. > proxy integerValueOf: EAX. > > asm mov: EAX to: ECX; > mov: 0 to: EAX; > mov: 1 to: EBX; > label: loopStart; > add: EAX with: EBX; > xchg: EAX with: EBX; > "next three could be replaced by loopnz and a dec ECX before > loop, but loopnz isn't there yet" > dec: ECX; > cmp: ECX with: 1; > jg: loopStart. > > proxy positive32BitIntegerFor: EBX. > gen epilogue] > > SmallInteger >>fib > |tmp res| > tmp := 1. > res := 0. > 0 to: self -1 do: [:ix | |oldRes| > oldRes := res. > res := tmp + res. > tmp := oldRes.]. > ^res > > Neither work for negative integers, and nbFib overflows for 48, haven't > added largeInt creation logic :) > ohh.. you will be need more than just create large int. Since at 48 you will get past the size of register, you'll have to switch to different loop. And it will end up with quite complex assembler :)
But if we leave the complexity aside, the thing is, that you can greatly optimize it comparing to smalltalk implementation. You can use stack, for keeping a variable-length big int during calculation. So, you will need to create a single final BigInt oop only when loop ends. > [1 to: 100000 do: [:ix | 47 fib]] timeToRun 361 > [1 to: 100000 do: [:ix | 47 nbFib]] timeToRun 21 > [1 to: 100000 do: [:ix | ]] timeToRun 2 > > Cheers, > Henry > > > > > _______________________________________________ > Pharo-project mailing list > [email protected] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > -- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
