ãã®å®è£ ã®äž»ãªéãã¯JITã³ã³ãã€ã©ã§ãããããã«ãããå€ãã®å Žåã é ãJavaã«é¢ããã¹ããŒãã¡ã³ãã¯å®å šã«åãå ¥ããããªããªããŸããã
ããã§ãCLRãPythonãRubyãPerlãããã«çŽ æŽãããããã°ã©ãã³ã°èšèª Rãªã©ãã»ãšãã©ãã¹ãŠã®ã€ã³ã¿ãŒããªã¿ãŒãã©ãããã©ãŒã ãç¬èªã®JITãã©ã³ã¹ã¬ãŒã¿ãŒå®è£ ãååŸããŸããã
ãã®èšäºã®äžéšãšããŠãç£æ¥çšJITã³ã³ãã€ã©ãŒã®å®è£ ã«é¢ããããŸãç¥ãããŠããªã詳现ã«å ãåœãŠãã€ããã¯ãããŸããããåºæ¬çãªããšã®éåžžã«è¡šé¢çãªçŽ¹ä»ã§ãããé¢é£ãããããã¯ã«é¢ãããã¬ãŒãã³ã°ãããžã§ã¯ãã«é¢ããã¹ããŒãªãŒã§ãã
ãããã£ãŠãããªãã¯ç«ã«èå³ããããããããŸããïŒ
- åºæ¬çã«ãJITã³ã³ãã€ã©ãäœã§ããããç解ããŠããªãããããããªèª€è§£ãããããããã®ã¢ãããŒãã¯è§£éãããã¯ããã«åªããŠããŸãã
- ã€ã³ã¿ããªã¿èšèªçšã®ç°¡åãªJITãæžããããšæããŸãã
- ããªãã¯ã³ãŒã¹ãããã°ã©ãã³ã°èšèªãšã³ã³ãã€ã©ããæããåŠçã®ããã®å®éçãªã¿ã¹ã¯ãããã«é¢çœãããããšãæ°ã«ããŸããã
- ããªãã¯ãã®çµµãã©ã®ããã«æãããã®ãçåã«æã£ãŠããŸãã
JITã³ã³ãã€ã«ã®å©ç¹
å©ç¹ã«ã€ããŠè©±ãã«ã¯ããŸããããäœã§ããããç解ããŸãã é ãããå§ããŸããããã€ãŸããã³ã³ãã€ã«ãããèšèªã®å®çŸ©ããå§ããŸãããã
ã³ã³ãã€ã«ãããããã°ã©ãã³ã°èšèªãšã¯ ãã³ã³ãã€ã©ã«ãã£ãŠãœãŒã¹ã³ãŒããç¹å®ã®ã¢ãŒããã¯ãã£ïŒããšãã°x86 / ARMïŒã®ãã·ã³ã³ãŒãã«å€æãããããã°ã©ãã³ã°èšèªã§ãã ãã®ãã·ã³ã³ãŒãã¯ãããã»ããµãå®å šã«ç解ã§ããäžé£ã®ã³ãã³ãã§ããã仲ä»è ãªãã§å®è¡ã§ããŸãã
解éãããããã°ã©ãã³ã°èšèªã¯ãCPUã§çŽæ¥å®è¡ããããã«ãœãŒã¹ããã·ã³ã³ãŒãã«å€æããããç¹å¥ãªã€ã³ã¿ãŒããªã¿ãŒããã°ã©ã ã䜿çšããŠå®è¡ããããšããç¹ã§ç°ãªããŸãã
äžéãªãã·ã§ã³ãšããŠãå€ãã®èšèªïŒJavaãCïŒãPythonïŒããã·ã³ã«äŸåããªããã€ãã³ãŒãã«å€æãããŸã ã
CPUã§çŽæ¥å®è¡ããããšã¯ã§ãããå®è¡ããã«ã¯ã€ã³ã¿ããªã¿ãå¿ èŠã§ãã
ãªã解éãé ãã®ã§ããïŒ ãã®è³ªåã«å¯Ÿããçãã¯ãå¥åŠãªããšã«ã誰ã«ãšã£ãŠãæããã§ã¯ãããŸããããããã¯éåžžã«åçŽã§ãããåã³ãã³ããåå¥ã«è§£éãããã®ã³ãã³ãã®ã»ãã³ãã£ã¯ã¹ãããã»ããµèšèªã«ç¿»èš³ããããã«è¿œå ã®ãªãœãŒã¹ãè²»ãããŸãã ããã«ãææ°ã®ããã»ããµã¯ã·ãŒã±ã³ã·ã£ã«ã³ãã³ãã®å®è¡çšã«æé©åãããŠããïŒ Conveyorãåç §ïŒãã»ãšãã©ã®å Žåãã€ã³ã¿ãŒããªã¿ãŒã¯äžé£ã®ãªãã·ã§ã³ãåãã巚倧ãªã¹ã€ããã§ããã é·ç§»äºæž¬ãè¡ãæ¢ãŸãã«é§åããŸãã
ãã€ãã³ãŒããããã»ããµèšèªã«å€æããå®è¡ã®ããã«CPUã«è»¢éããããšã¯ããããã®åé¡ãã¹ãŠã«å¯Ÿãã1åã®èªç¶ãªè§£æ±ºçã§ãã ããã¯åœŒããæãé »ç¹ã«è¡ãããšã§ããããã®ããã»ã¹ãJust-in-time-compilation ïŒJITïŒãšåŒã³ãŸãã ããã«ãçæãããã³ãŒãã®ããŸããŸãªæé©åãæãé »ç¹ã«å®è¡ãããã®ã¯ããã®ãã§ãŒãºäžã§ãã
ãããç·Žç¿ããŸãããã
åé¡ã®å£°æ
ç§ãã¡ã®å€§åŠã®ã³ãŒã¹ãä»®æ³åãšä»®æ³ãã·ã³ãã¯ããããã¹ããããVirtualBoxãNativeClientãªã©ã®VMã®ããŸããŸãªã¯ã©ã¹ã®éçºã«åå ããå®è£ ã®è©³çŽ°ãçŽæ¥ç¥ã£ãŠãããã³ã©ã€ã»ã€ãŽããã£ã«ãã£ãŠæããããŠããŸãã çŸä»£ã®ãã¯ãããžãŒã®çŽ æŽãããã®ãããã§ãã³ãŒã¹ã«ã€ããŠã¯è¬çŸ©å®€ã§å ¬éãããŠãããããã¢ã«ãããã¯å€§åŠã®åŠçã§ããå¿ èŠã¯ãããŸããã ãã¡ãããã³ãŒã¹ã®åæ¹åæ§ãšè¬çŸ©ã§èŽè¡ãšååãããããããã¯å°ãééã£ãŠããããšã«æ³šæããå¿ èŠããããŸãã
ã³ãŒã¹ã®äžç°ãšããŠãè©Šéšã®å ¥åŠè³æ ŒãååŸããããã«ãåŠçã¯åçŽãªã¹ã¿ãã¯åä»®æ³ã€ã³ã¿ãŒããªã¿ãŒãã·ã³ãšãã©ã³ã¹ã¬ãŒã¿ãŒã®å®è£ ãCã©ã€ã¯ãªèšèªã®ãã€ãã³ãŒãã«æžã蟌ãããã«æ±ããããŸããã å®éãã¿ã¹ã¯ã¯äžèŠæããããããããåçŽã§ããã¿ã¹ã¯ãšå ±ã«å€ãã®æ¢è£œã®C ++ã³ãŒããçºè¡ãããŸãã
- 翻蚳ãããŸãã«ããã°ã©ãã³ã°èšèªã®ASTã®ããŒãµãŒã æ¬åœã«ããããšãããããŸããïŒ éåžžã6幎ç®ãŸã§ã«ãAUã®åŠçã¯16ã®ç°ãªãããŒãµãŒãæžãæéããããå¥ã®ååž°äžéãæžãããšã¯ãŸã£ããé¢çœããªãã
- 詳现ãªã³ã¡ã³ãä»ãã®åæåã®ãã€ãã³ãŒãåœä»€ã¿ã€ãã®ãªã¹ãã
- ãã€ãã³ãŒããæäœããããã®ãŠãŒãã£ãªãã£ã¯ã©ã¹ïŒãã®æ§ç¯ãšãã€ããªè¡šçŸã䜿çšããŸãã
ãã®ã¿ã¹ã¯å šäœã®ã³ãŒãåã¯mathvmã§ããããã¯ãå€ãã®å Žåãããã°ã©ãã³ã°èšèªã®äž»ãªç®çãäœããæ°ããããšã§ããããã§ãã
å žåçãªmathvmããã°ã©ã ïŒ
function int fib(int x) { if (x <= 1) { return x; } int r = fib(x - 1); return r + fib(x - 2); } print(fib(35), '\n');
èšèªã®äž»ãªæ©èœïŒ
- ããŒã¿åã®æäœïŒintãdoubleãstringããããã«å¯Ÿããç®è¡æŒç®ã
- æšæºå¶åŸ¡æ§é ïŒifãwhileãforãprintã
- ã¯ããŒãžã£ãŒã®ååšã®çµæãšããŠãé¢æ°å ã§é¢æ°ã宣èšããæ©èœã ãã®æ©èœã¯ãã€ã³ã¿ãŒããªã¿ãŒãèšèšãããšãã«å€ãã®è³ªåãåŒãèµ·ãããŸããããã¯ããŒãžã£ãŒãæäœããããã®æ瀺ãå©çšã§ããããšãèãããšãã€ãŸããã®ãããã¯ã«ã¯ãªããŸããã§ããã
- ãã€ãã£ãé¢æ°ã宣èšããæ©èœ ã ã€ãŸãããã€ãã£ãã§ããŒã¯ãããæ¬äœãšã·ã³ãã«ã®ååã®ãªãé¢æ°ã宣èšã§ããŸããããã¯ããã©ã¡ãŒã¿ãŒRTLD_DEFAULTã䜿çšããŠdlsymãä»ããŠä»®æ³ãã·ã³ã«ãã£ãŠããŒãã§ããŸãã
ããšãã°ã次ã®ããã«ïŒ
function void printfIDS(string format, int x1, double x2, string x3) native 'printf'; printfIDS('%d %f %s\n', 1, 2, 'abc');
- 第äžã«ãå®è¡æã«é¢æ°ãžã®ãã€ã³ã¿ãŒãæã£ãŠããå Žåã以åã«æªç¥ã®åŒæ°ã»ãããé¢æ°ã«æž¡ãæ¹æ³ãããã«ã¯ããããŸããã眲åãšèšç®ãããåŒæ°ã¯ã¡ã¢ãªã®ç¹å®ã®å Žæã«ä¿åãããŸãã ããã¯å®å
šã«ã¯ãã¹ãã©ãããã©ãŒã ã®æ¹æ³ã§ã¯äžå¯èœã§ããããšã¯å€ããå°ãªããæããã§ãããå°ãªããšãåŒã³åºãèŠçŽãä¿®æ£ããå¿
èŠããããŸãã 人æ°ã®ããUNIXã·ã¹ãã ã§äœ¿çšãããŠããSystem V ABIããã®åŒã³åºãèŠçŽã«åæããŸããã
ãããããã®åŸã§ãã£ãŠããæãçã¿ã®ãªãç®æšãéæããæ¹æ³ã¯æããã§ã¯ãªãããã§ãã
é ã«æµ®ããã ã®ã¯ãåŒæ°ã察å¿ããã¬ãžã¹ã¿ãšã¹ã¿ãã¯ã®ã»ã«ã«å解ããã³ãŒããåãã巚倧ã§æãããã¢ã»ã³ãã©ã®æ¿å ¥ã ãã§ããã ãã®çµæãç§ã¯ãããã«ç°ãªããœãªã¥ãŒã·ã§ã³ãéžæããŸãããããã«ã€ããŠã¯ä»¥äžã§èª¬æããŸãã
- ãã€ãã£ãé¢æ°ã¯ãçµæã®èšèªã®æ©èœã倧å¹
ã«æ¡åŒµããŸãã æ°æ¥éã®ãã§ãŒãžã³ã°ã®åŸãã€ã³ã¿ãŒããªã¿ãŒãšç¿»èš³è
ãæºåãæŽããå°åœ¢ãšã®éãæ°å€çµ±åã®ä»£ããã«ã ãã®ãããªäœããããªãã®é è³ã§å§ãŸããç»é¢ã«ã¯ãŒã«ãªãµã€ã±ããªãã¯ãªã¢ãã¡ãŒã·ã§ã³ãæç»ããŸãïŒèšäºã®åé ã®ã¹ã¯ãªãŒã³ã·ã§ãããåç
§ïŒãããã¯çŽ æŽãããããŒãã¹ã§ãã
æ°é ãã®ããèªè ã¯ãäœããã®çç±ã§ãããã°ã©ã ãæåŸã®ã¢ã€ãã ããæç»ããã1ç§ãããã®ãã¬ãŒã æ°ïŒFPSïŒãèšç®ããããšã«æ°ä»ãã§ãããã ãã®ææšã«ãããéèš³è ã®ããã©ãŒãã³ã¹ãè©äŸ¡ããããšãã§ããããã誰ãã«éå±ããã«æããæè²ããã»ã¹ã«ç«¶äºå¿ãããããããšãã§ããŸãã
éèš³è ãããã§æéã§ãããåæ§ã®ãã³ãããŒã¯ãããã€ãèªåçã«è©Šéšã«åæ Œããããã«ååã®æãšå°æ¬ãåŸãåŠçã ãã®ã²ãŒã ããã¬ã€ããæåã®ã¹ã¬ããã§ã¯ãªãããšã«æ³šæããŠãã ãããéåžžãåã€ããã«ã¯JITã³ã³ãã€ã©ãå®è£ ããå¿ èŠããããŸããã
é£ãã
åçŽãªãã€ãã³ãŒãåœä»€ã®ã»ãã³ãã£ã¯ã¹ãx86åœä»€ã»ããã®å¯Ÿå¿ããèŠçŽ ã«åçŽã«å€æããããšã¯æ¬è³ªçã«é£ããããã«æãããŸããïŒ
- ã³ã³ãã€ã«ãããèšèªãããã°ãæåéãã¢ã»ã³ããªèšèªã§ããã¹ããçæããããã«å¿ããŠã¢ã»ã³ãã«ããŠå®è¡å¯èœãã¡ã€ã«ãäœæã§ããŸãã
ããããJITãããŒããã£ã¹ãã®ãã¬ãŒã ã¯ãŒã¯ã§ã¯ãããã»ã¹ããããã®2ã€ã®ãã§ãŒãºã«åå²ããããšã¯èš±ãããªãèŽ æ²¢ã§ãããVMããã»ã¹ã®ã¡ã¢ãªã§ãã·ã³ã³ãŒããããã«çæããæ¹æ³ãäœããã®æ¹æ³ã§åŠç¿ããå¿ èŠããããŸãã
- ãŸãããã¹ãŠã®ã¡ã¢ãªé åããã·ã³ã³ãŒãã®èšè¿°ã«é©ããŠããããã§ã¯ãããŸããã ããæ£ç¢ºã«ã¯ãã©ããã«æžã蟌ãããšãã§ããŸãããå®è¡å¯èœãšããŠããŒã¯ãããããŒãžãæã€ã¡ã¢ãªé åã«ã®ã¿å®è¡ã転éã§ããŸãã åçŽãªmalloc'omã§ã¯ã§ããªãããã§ãã
- çæ³çã«ã¯ããã¡ãããçµæã®ãã·ã³ã³ãŒãã¯ã§ããã ãæ©ãåäœããã¯ãã§ãã
ã¢ã¹ããã
Asmjitã¯ãæåã®2ã€ã®åé¡ã解決ããã®ã«éåžžã«é©ããŠããŸããéå»æ°å¹Žéã«1人ã倧éšåãéçºããèè ã®ä»ã®ãããžã§ã¯ãã§äœ¿çšããããªãŒãã³ãœãŒã¹ã©ã€ãã©ãªãããã³GTA San Andreas MPãµãŒããŒã®ã¹ã¯ãªããã®JITã§ã ã
ååã瀺ãããã«ããã®äž»ãªäœ¿åœã¯ããžã£ã¹ãã€ã³ã¿ã€ã ãã·ã³ã³ãŒããçæããããã®äŸ¿å©ãªAPIãäœæããããšã§ãã ãã®ãããªãã¯ã€ã³ã¿ãŒãã§ã€ã¹ã¯ã2ã€ã®éšåã«åããããšãã§ããŸãã
- X86Assemblerã¯ãåºæ¬çã«æ¬¡ã®3ã€ã®ããšãå®è¡ã§ããäœã¬ãã«ã€ã³ã¿ãŒãã§ã€ã¹ã§ãã
- å®è¡ç¹æš©ã§ã¡ã¢ãªã®å²ãåœãŠãéå§ããŸãã
- åœä»€/ããŒã¿ãé çªã«é
眮ããã³ãŒãã®ä»ã®ã»ã¯ã·ã§ã³ããã®é·ç§»ãããå Žæã«ã©ãã«ãé
眮ããŸãã
ã³ãŒããæäœããããã«ãã©ã€ãã©ãªã«ã¯äžé£ã®ãªãã©ã³ãã¯ã©ã¹ããããŸãïŒGpRegãXmmRegãImmãMemãããã³ã¯ã©ã¹å ã®ååœä»€ã«ã¯ããã®åœä»€ã«æå¹ãªãªãŒããŒããŒãã®åãã»ãããæã€åãååã®ã¡ãœããããããŸãã ããšãã°ãã·ã°ããã£movïŒX86MemïŒãX86MemïŒïŒãããã¡ãœããã¯ãããã¯ãã§ãã
- ãã£ã±ãã«ãªã£ãã¡ã¢ãªã®å é ãžã®ãã€ã³ã¿ãååŸããŸããããã¯ãé¢æ°ãžã®ãã€ã³ã¿ããšã³ããªãã€ã³ããšããŠäœ¿çšã§ããŸãã
- X86Compilerã¯ãã«ãã»ã«åããX86Assemblerã®é«ã¬ãã«ã©ãããŒã§ãã
- é¢æ°å®çŸ©ã®åŽãšåŒã³åºãã®å Žæã®äž¡æ¹ã§ãæå®ãããåŒã³åºãèŠçŽã«åŸã£ãŠé¢æ°ãäœæããåŒæ°ãæäœããŸãïŒãšããã§ããã€ãã£ãé¢æ°ãå®è£
ããæãç°¡åãªæ¹æ³ïŒ ã
- ã¬ãžã¹ã¿ãŒã®å²ãåœãŠïŒå€æ°ïŒGpVarãŸãã¯XmmVarïŒãå®çŸ©ããããšãã§ããã³ã³ãã€ã©ãŒã¯å€æ°ã®ä¿åå ŽæãéžæããŸãã æ€çŽ¢ããªãã£ãäºçŽã¯ããã«è¡ããŸãããã©ã®å²ãåœãŠã¢ã«ãŽãªãºã ã䜿çšãããŠãããã¯ç¥ããŸããã ç§ãèšããå¯äžã®ããšã¯ãç°¡åãªå®éšã§å©çšå¯èœãªã¬ãžã¹ã¿ãããªãåççã«äœ¿çšãããããšã§ãã
- é¢æ°å®çŸ©ã®åŽãšåŒã³åºãã®å Žæã®äž¡æ¹ã§ãæå®ãããåŒã³åºãèŠçŽã«åŸã£ãŠé¢æ°ãäœæããåŒæ°ãæäœããŸãïŒãšããã§ããã€ãã£ãé¢æ°ãå®è£
ããæãç°¡åãªæ¹æ³ïŒ ã
ç§ã®å®è£ ã§ã¯ãã¢ã»ã³ãã©ãŒã䜿çšããŸããããã®ã¢ã»ã³ãã©ãŒã¯ããã®éææ§ãšããåªããå¶åŸ¡æ§ãå®çŸããŸããã
Asmjitã䜿çšããæãç°¡åãªå®äŸïŒ
#include "asmjit/asmjit.h" #include <iostream> int main(int argc, char** argv) { using namespace std; using namespace asmjit; using namespace asmjit::x86; JitRuntime runtime; // RAII object X86Assembler assembler(&runtime); assembler.add(rdi, rsi); // add second argument to first assembler.mov(rax, rdi); // mov result to return register assembler.ret(); void * address = assembler.make(); cout << reinterpret_cast<int64_t (*) (int64_t, int64_t)>(address)(2, 2) << endl; // 4 return 0; }
ã¢ã»ã³ãã©ãŒã«ç²ŸéããŠãã人ã¯ããŸã質åãã¹ãã§ã¯ãªããšæããŸãã èšåããå¯äžã®ãã®ã¯ãå²ãåœãŠãããã¡ã¢ãªã®å¯¿åœã«è²¬ä»»ãããã©ã³ã¿ã€ã ãªããžã§ã¯ãã§ãã 圌女ã¯åœŒã®ãã¹ãã©ã¯ã¿ïŒ RAII ïŒãåŒã³åºããåŸã«è§£æŸãããŸãã
ããå€ãã®äœ¿çšäŸã¯ãã©ã€ãã©ãªãã¹ãã®ãããã£ã¬ã¯ããªãŸãã¯ãªããžããªã«ãããŸãã
ãããã°
å¥åŠãªããšã«ãçæãããã³ãŒãã®ãããã°ã¯ç¹ã«éªæªã§ã¯ãããŸããã
ãŸããäœãåé¡ãçºçããå ŽåãAmsjitãã°ã泚ææ·±ãèŠãããšãã§ããŸãã ãã°ã§ã¯ãåãåã£ãã¢ã»ã³ãã©ã³ãŒããšãããã«è¡šç€ºãããå Žæããã®ã³ã¡ã³ãã確èªã§ããŸãã
ããã§ã圹ã«ç«ããªãå Žåã¯ãææ°ã®ãããã¬ãŒïŒgdb / VSïŒã®ã»ãšãã©ã§ãéã¢ã»ã³ããªã䜿çšããŠãããã°ã¢ãŒãã§åäœããå¯èœæ§ããããŸãã ã€ãŸããçæãããé¢æ°ãžã®åŒã³åºãã®ä»£ããã«ãã¬ãŒã¯ãã€ã³ãã眮ãããšãã§ãã Step Intoã¯ã¢ã»ã³ãã©ãŒã³ãŒãã䜿çšããŠç»é¢ã«è»¢éããŸããããã§ãã»ãŒéåžžã©ããã¹ãããããšã«ãããã°ã§ããŸãã
éèŠã§ã
- 10ã®ãã¡3ã€ã®å Žåã30åã§ã³ã³ãã€ã©ã§ã¯ãªãã解éãããããã°ã©ã èªäœã«ãšã©ãŒãèŠã€ãããŸãã
- æ®å¿µãªãããAsmjitã¯ãŸã ããŸãéäžçã«äœ¿çšãããŠããªããããããŸããŸãªçšåºŠã®åä»ãªãã°ãå«ãŸããŠããå¯èœæ§ããããŸãã ãããã£ãŠããã°ããŸãã«ããªããæãã§ãããã®ã§ããããšã«æ³šæããŠãã ããã ç§ã¯äœã«ãåºããããŸããã§ããããã¯ã©ã¹ã¡ãŒãã¯å¹žéã§ã¯ãããŸããã§ãããç¡å¹ãªã³ãŒããçæããããšããäºå®ã¯ãã°ã«ã衚瀺ãããããããã¬ãŒã«ã®ã¿è¡šç€ºãããŸããã
æé©å
3æ¥éã®ã¢ã¯ãã£ããªããã°ã©ãã³ã°ãšãããã°ã®åŸãæåã®å®å šã«æŽç·ŽãããŠããªãããŒãžã§ã³ã®JITãã©ã³ã¹ã¬ãŒã¿ãŒãç»å ŽããŸããããã®ããŒãžã§ã³ã§ã¯ãã¹ã¿ãã¯ãšå€æ°ã®ãã¹ãŠã®å€ãã¡ã¢ãªãŒã«æ¯åä¿åãããŠããŸããã
ãã®ãããªãœãªã¥ãŒã·ã§ã³ã§ãããæ倧6 FPSã®ã€ã³ã¿ãŒããªã¿ãŒã§åŸããã6 FPSã§çŽ6åã®ããã©ãŒãã³ã¹ã®åäžããããããŸããã
äžè¬ã«ãåŠæã®åããã²ãŒã ã®ã«ãŒã«ãæ確ã«ãªã£ããšããç§ã¯ããã¬ãªã³ã®èšç»ãç«ãŠãŸãããSSAã§ã®ãã€ãã³ãŒãå€æãšã¹ããŒãã¬ãžã¹ã¿å²ãåœãŠã¢ã«ãŽãªãºã ã䜿çšããŠããã¹ãŠã倧人ã®æ¹æ³ã§è¡ãããšã§ãã
ããããæéãšå¹³å¡ãªcoç ã®æ·±å»ãªäžè¶³ã®ããã«ããã¹ãŠãããå¹³å¡ã«ãªããŸããã
ã¬ãžã¹ã¿å²ãåœãŠ
念ã®ãããããã°ã©ã ã®ããã©ãŒãã³ã¹ã«é¢ããŠæãéèŠãªãã€ã³ãã®1ã€ã¯ã䜿çšå¯èœãªCPUã¬ãžã¹ã¿ã䜿çšããå¹çã§ããããšãæãåºãããŠãã ãããããã¯ãäž»ãªèšç®ã¢ã¯ãã£ããã£ããããã§ã®ã¿å®è¡å¯èœã§ããããšã«å ããŠãããã«ãL1ãã£ãã·ã¥ã«ããã¡ã¢ãªãžã®èªã¿åã/æžã蟌ã¿ããã¬ãžã¹ã¿ã§ã®åæ§ã®æäœãããæ倧2åé·ãæ©èœããããã§ãã
æãé£ããã®ã§ã¯ãªãããããå¹æçãªãã¥ãŒãªã¹ãã£ãã¯ãªãœãªã¥ãŒã·ã§ã³ã䜿çšããŸããïŒä»®æ³ãã·ã³ã¹ã¿ãã¯ã®æåã®èŠçŽ ãæ±çšã¹ãããïŒæåå/æŽæ°ïŒã®7èŠçŽ ãæµ®åå°æ°ç¹æ°ã®ã¹ãããã®14èŠçŽ ãã¬ãžã¹ã¿ã«æ ŒçŽããŸãã
é¢æ°ã®ãã¬ãŒã ã¯ãŒã¯ã§æãããããªå€æ°ã¯å®éã«ã¹ã¿ãã¯ã®äžçªäžã«ããããã¹ãŠã®èšç®ã«é¢äžããããããã®ãœãªã¥ãŒã·ã§ã³ã¯æãæ£åœåãããŠããããã§ãã
ããã«ãé¢æ°ãåŒã³åºããšãã«åŒæ°ã®ã¬ã€ã¢ãŠããšåãã¬ãžã¹ã¿ã䜿çšãããšãå Žåã«ãã£ãŠã¯åŒã³åºãã®å Žæã§æéãç¯çŽã§ããŸãã
ãããã®ã¢ã€ãã¢ãå®è£ ããçµæã 9 FPSã®ã¢ã¯ã»ã©ã¬ãŒã·ã§ã³ãåŸããã45 FPSã«éããŸããã
ã®ããç©Žã®æé©å
çæã«å¯ŸããåçŽãªå€å žçã¢ãããŒãã®1ã€ã¯ãããããPeepholeæé©åã§ããããã¯ãç¹å®ã®åœä»€ã·ãŒã±ã³ã¹ãèŠã€ããŠä»ã®ããçç£çãªåœä»€ã«çœ®ãæãããšããèãæ¹ã§ããããšãã°ãmathvmãã€ãã³ãŒãã®è¡šçŸåãäžè¶³ããŠãããããïŒx0 <= x1ïŒã®ãããªæ¯èŒæŒç®åã¯æ¬¡ã®ããã«èª¬æããå¿ èŠããããŸãã
LOADIVAR_0 LOADIVAR_1 IF_CMPLE L1 ILOAD_0 // 0 JA L2 // L1: ILOAD_1 L2: ...
åœä»€ã®éå®å®¶x'86ã¯ããã®ãããªã³ãŒãã¯ã¯ããã«çããåäžã®æ¡ä»¶ä»ããžã£ã³ããªãã§èšè¿°ã§ãããšèšããŸãã
mov rdi, %(var0) mov rsi, %(var1) cmp rdi, rsi setle al movzx rax, al
ä»ã®å Žåã«ãåæ§ã®æ§é ããããŸãïŒåŠå®æŒç®åãforã«ãŒãã ãããã®ãã¿ãŒã³ã®æ€åºãšä¿®æ£ã«ããã 4 FPSãã49ãã€ã³ãã«å éããŸããã
ã¯ããŒãžã£ãŒã®æé©å
åé¢æ°ã®ããããŒã°ãšãšãããŒã°ã§ã¯ããŒãžã£ãŒã確å®ã«æ©èœãããããã«ãæåŸã®åŒã³åºãã®å€æ°ãã¹ã¿ãã¯å€ã®ç¹å¥ã«å²ãåœãŠãããã¡ã¢ãªé åã«ããã¢ãã¬ã¹ãä¿åããŸããã
ããã«ã以åã®ããŒã¹ãã€ã³ã¿ãŒãä¿åããã³åŸ©å ããå¿ èŠããããŸãã ãã®åã³ã¯ãã¹ãŠãã¡ã¢ãªãç©æ¥µçã«äœ¿çšããŠãã人ãå«ããåé話ã«æ倧7ã€ã®è¿œå ã®æ瀺ãæ®ããŸããã
å®éãã»ãšãã©ã®é¢æ°ã¯ããèªäœã«ã¯ããŒãžã£ãŒãå«ãã§ããªãããããããã®æ倱ã¯åé¿ã§ããŸãã
ãããã£ãŠãç絡ã®ååšã«ã€ããŠåä¿¡ãããã€ãã³ãŒãå šäœã®è¿œå åæãå®è¡ãã察å¿ããåé·ãªåœä»€ãåé€ãããçµæã挫ç»ã¯ããã«3 FPSãé«éã«æç»ãå§ããŸããã
ã€ã³ã©ã€ã³å
ãã€ã¯ãæé©åã«é¢ããã¹ããŒãªãŒã®æåŸã®ãã€ã³ãã¯ã ã€ã³ã©ã€ã³åãŸãã¯ãã·ã¢èªã®ãåã蟌ã¿ãã§ãã ç£æ¥çšã³ã³ãã€ã©ãå°ããªé¢æ°ãåŒã³åºãã³ã¹ããšæ Œéããæ¹æ³ïŒåŒã³åºãããé¢æ°ã®ã³ãŒãã¯ãããããŒã°/ãšãããŒã°ããã³ä»ã®ãäžèŠãªãåœä»€ãªãã§ãåŒã³åºãã®å Žæã§åçŽã«è€è£œãããŸãã 確ãã«ãå®éã«ã¯ãã³ã³ãã€ã©ã¯éåžžã«æ éã«åã蟌ããšãã決å®ã«è¿ã¥ããŠããããšã«æ³šæããå¿ èŠããããŸã-çµæã®ãã·ã³ã³ãŒãã®ãµã€ãºã¯ãäœæ¥ã®å質ã®å°ºåºŠã§ããããŸãã
ãã ããç§ã®å Žåã¯ãæšå®ãããæéã§ãããããåã蟌ãŸãããã¹ãŠïŒéååž°åŒã³åºãïŒãåã蟌ãããšãè©Šã¿ãŸããã
ãããŠãããã§ãå¥åŠãªããšã«ãASTãããã€ãã³ãŒããžã®å€æã¬ãã«ã§äœæ¥ããæ¹ãç°¡åã§ããããšãããããŸããã
åŸããã2 FPSã®å¢å ã¯ã以åã®å Žåã»ã©éèŠã§ã¯ãããŸããã§ããããåèš53ã54 FPSïŒã»ãŒ9åã®å éïŒã¯åã°ããããåŸãŸããã§ããã åã泚æã®å éã¯ãä»ã®å©çšå¯èœãªãã³ãããŒã¯ã§èŠ³å¯ãããŸããã
èå³æ·±ãããšã«ãç§ã®åçŽãªJITãã©ã³ã¹ã¬ãŒã¿ã§ãããã€ã³ã¿ãŒããªã¿ãŒããŸã£ããèµ·åããããã¹ãŠã®ã³ãŒããããã«ã³ã³ãã€ã«ããŸããããæé«ã®ããã©ãŒãã³ã¹ãåŸãã«ã¯ãŠã©ãŒã ã¢ãããæ°åç¹°ãè¿ããŸããã
ããã¯ãå¿ èŠãªãã¹ãŠãã³ã³ãã€ã«ãããã ãã§ãªããããã°ã©ã ã®ãããã¡ã€ã«ãä¿®æ£ããããã«ããã³ãããŒã¯ã§ã®ãŠã©ãŒã ã¢ãããå¿ èŠã§ãããšããäºå®ã«é¢ããæš©åšãã人ã ã®å£°æã瀺ããŠããŸãã
ãŸãšã
ãã®çµæãç§ã®å®è£ ã¯æéã«ãªããŸããããããã¯ç§ãæãcãªååšã§ãããšããäºå®ãšã¯ããŸãé¢ä¿ããããŸããããJITã®æãåçŽãªå®è£ ãããäœæãããšããäºå®ã¯ãããŸããã
ãããã£ãŠãå°ãªããšãããã€ãã®ã¹ããŒãã®é°è¬ã®æ¬ åŠã¯åå©ãèŠãé ããã
ç§ã®å®è£ ã®ãœãŒã¹ã¯ã ãªããžããªã®implãã£ã¬ã¯ããªã«ãããŸãã
ã³ãŒãã®å質ã«ã€ããŠäºåã«è¬çœªããŸãããããã¯ãŸã ããã¡ãã®ãããžã§ã¯ãã§ããããã以äžãµããŒãããäºå®ã¯ãããŸããã
ãæž èŽããããšãããããŸããïŒ