<br><br><div class="gmail_quote">On Fri, Sep 21, 2012 at 9:25 AM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com" target="_blank">siguctua@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 21 September 2012 17:53, Denis Kudriashov <<a href="mailto:dionisiydk@gmail.com">dionisiydk@gmail.com</a>> wrote:<br>
><br>
> Hello<br>
<div class="im">><br>
> 2012/9/21 Igor Stasenko <<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>><br>
>><br>
>> nbFoo2<br>
>> <primitive: #primitiveNativeCall module: #NativeBoostPlugin error: errorCode><br>
>><br>
>> ^ NBNativeCodeGen methodAssembly: [:gen :proxy :asm |<br>
>> asm noStackFrame.<br>
>> asm<br>
>> mov: (42 << 1) + 1 to: asm EAX;<br>
>> ret.<br>
>> ]<br>
>><br>
>> And this one uses JIT:<br>
>><br>
>> nbFoo<br>
>> <primitive: 220 error: errorCode><br>
>><br>
>> [ errorCode = ErrRunningViaInterpreter ] whileTrue: [ ^ self nbFoo ].<br>
>><br>
>> ^ NBNativeCodeGen jitMethodAssembly: [:gen :proxy :asm |<br>
>> asm noStackFrame.<br>
>> asm<br>
>> mov: (42 << 1) + 1 to: asm EDX;<br>
>> ret: 4 asUImm.<br>
>> ]<br>
><br>
><br>
</div>> Why assembly code is different for jitted and non jitted versions?<br>
<br>
<br>
In short: because Cog JIT code uses different convention(s).<br>
One of them is return value should be in EDX, unlike from cdecl<br>
convention, which is EAX.<br>
<br>
<br>
> What I should change in my nativeboost assembly to be able to jit it?<br>
><br>
<br>
i think, most of the time it is entry and leave code..<br>
and accessing method's argument(s). The rest, like calling<br>
interpreterProxy's functions<br>
can be left unchanged.<br>
Also, it must be noted, that JIT code uses own stack and making calls<br>
to C functions<br>
might be very dangerous (overflow stack) unless you know that C<br>
function won't consume much stack space.<br>
(otherwise you need to temporary switch stack when doing such calls).<br></blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I don't know too much details right now, but Eliot knows better<br>
because he wrote it :)<br>
<br>
<br>
> Any way thank's for such impressive work.<br>
><br>
> Best regards,<br>
> Denis<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
--<br>
Best regards,<br>
Igor Stasenko.<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>