<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Vanessa,<br><br>   Clément pointed you to good sources.  The most concise guide to implementing them is however in the standard trunk image itself in the "decoding - private - sista v1" category of InstructionStream.<div>To support multiple bytecode sets CompiledCode maintains a flag bit in its header word that selects one of two bytecode sets, represented as BytecodeEncoder subclasses in the CompiledCode class vars PrimaryBytecodeSetEncoderClass & SecondaryBytecodeSetEncoderClass. A CompiledCode answers the relevant class via CompiledCode>>encoderClass which tests the bit and answers the relevant class.  Then double dispatching is used to invoke the relevant bytecode set decode:</div><div><br></div><div><i>InstructionStream methods for instruction decode</i></div><div><div><b>interpretNextInstructionFor:</b> client</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>"<i>Send to the argument, client, a message that specifies the type of the next instruction.</i>"</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>^self method encoderClass interpretNextInstructionFor: client in: self</div></div><div><br></div><div><i>EncoderForV3PlusClosures class methods for instruction stream support</i></div><div><div><b>interpretNextInstructionFor:</b> aClient <b>in:</b> anInstructionStream</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">        </span>"<i>Double-dispatch through the encoder to select the correct instruction set decoder.</i>"</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>^anInstructionStream interpretNextV3ClosuresInstructionFor: aClient<br><br><i>EncoderForSistaV1 class methods for instruction stream support</i></div></div><div><div><b>interpretNextInstructionFor:</b> aClient <b>in:</b> anInstructionStream</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>"<i>Double-dispatch through the encoder to select the correct instruction set decoder.</i>"</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>^anInstructionStream interpretNextSistaV1InstructionFor: aClient</div></div><div><br></div><div>which gets us back to the decoders in InstructionStream.  In particular,</div><div><i>InstructionStream methods for decoding - private - sista v1</i></div><div><div><b>interpretNextSistaV1InstructionFor:</b> client</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>"<i>Send to the argument, client, a message that specifies the next instruction.</i>"</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>| byte div16 offset method extA extB savedPC |</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>method := self method.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>"<i>For a table of the bytecode set, see EncoderForSistaV1's class comment.</i>"</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>"<i>consume and compute any extensions first.</i>"</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>extA := extB := 0.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>savedPC := pc.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>[byte := self method at: pc.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span> pc := pc + 1.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span> byte >= 16rE0 and: [byte <= 16rE1]] whileTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>[| extByte |</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">           </span> extByte := self method at: pc.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span> pc := pc + 1.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">         </span> byte = 16rE0</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>[extA := (extA bitShift: 8) + extByte]</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                 </span>ifFalse:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                               </span>[extB := (extB = 0 and: [extByte > 127])</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                                    </span>ifTrue: [extByte - 256]</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                                                        </span>ifFalse: [(extB bitShift: 8) + extByte]]].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>div16 := byte // 16.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>offset := byte \\ 16.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  </span>"<i>We do an inline quasi-binary search on each of the possible 16 values of div16</i>"</div><div><span style="white-space:pre">... all the one byte codes elided...</span></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>"<i>2 byte and 3 byte codes</i>"</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>byte < 248 ifTrue:</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>[^self interpretNext2ByteSistaV1Instruction: byte for: client extA: extA extB: extB startPC: savedPC].</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>^self interpretNext3ByteSistaV1Instruction: byte for: client extA: extA extB: extB startPC: savedPC</div></div><div><br></div><div><br></div><div>and then all remaining implementation is in Context.</div></div></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 29, 2020 at 9:34 PM Vanessa Freudenberg <<a href="mailto:vanessa@codefrau.net">vanessa@codefrau.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <div dir="auto">Eliot / Clément / Everyone -</div><div dir="auto"><br></div><div dir="auto">What’s the best documentation for the new byte codes?</div><div dir="auto"><br></div><div dir="auto">I found the 2014 paper, and Clèment’s thesis, and I don’t think either is detailed enough to implement them correctly. Just wondering if there’s anything else I could peruse other than the VM source code.</div><div dir="auto"><br></div><div dir="auto">Cheers!</div><div dir="auto">Vanessa</div><div dir="auto"><br></div><div dir="auto"><br></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>