[Vm-dev] [NB] NativeBoost meets JIT

Eliot Miranda eliot.miranda at gmail.com
Fri Sep 21 17:54:53 UTC 2012


On Fri, Sep 21, 2012 at 9:25 AM, Igor Stasenko <siguctua at gmail.com> wrote:

>
> On 21 September 2012 17:53, Denis Kudriashov <dionisiydk at gmail.com> wrote:
> >
> > Hello
> >
> > 2012/9/21 Igor Stasenko <siguctua at gmail.com>
> >>
> >> nbFoo2
> >>         <primitive: #primitiveNativeCall module: #NativeBoostPlugin
> error: errorCode>
> >>
> >>         ^ NBNativeCodeGen methodAssembly: [:gen :proxy :asm |
> >>                 asm noStackFrame.
> >>                 asm
> >>                         mov: (42 << 1) + 1 to: asm EAX;
> >>                         ret.
> >>         ]
> >>
> >> And this one uses JIT:
> >>
> >> nbFoo
> >>         <primitive: 220 error: errorCode>
> >>
> >>         [ errorCode = ErrRunningViaInterpreter  ] whileTrue: [ ^ self
> nbFoo ].
> >>
> >>         ^ NBNativeCodeGen jitMethodAssembly: [:gen :proxy :asm |
> >>                 asm noStackFrame.
> >>                 asm
> >>                         mov: (42 << 1) + 1 to: asm EDX;
> >>                         ret: 4 asUImm.
> >>         ]
> >
> >
> > Why assembly code is different for jitted and non jitted versions?
>
>
> In short: because Cog JIT code uses different convention(s).
> One of them is return value should be in EDX, unlike from cdecl
> convention, which is EAX.
>
>
> > What I should change in my nativeboost assembly to be able to jit it?
> >
>
> i think, most of the time it is entry and leave code..
> and accessing method's argument(s). The rest, like calling
> interpreterProxy's functions
> can be left unchanged.
> Also, it must be noted, that JIT code uses own stack and making calls
> to C functions
> might be very dangerous (overflow stack) unless you know that C
> function won't consume much stack space.
>  (otherwise you need to temporary switch stack when doing such calls).
>

Exactly.  The Smalltalk stack is paged, about 1k bytes per page, all part
of the context-to-stack mapping scheme.  One can't run general C code on
that stack.  Only code which is known not to consume stack space could be
used safely.  Instead, as NB does, the JIT generates machine code for
certain performance-critical primitives and runs them directly on the
Smalltalk stack.


>
> I don't know too much details right now, but Eliot knows better
> because he wrote it :)
>
>
> > Any way thank's for such impressive work.
> >
> > Best regards,
> > Denis
>
>
> --
> Best regards,
> Igor Stasenko.
>



-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20120921/17a1a6f3/attachment.htm


More information about the Vm-dev mailing list