開發紀錄 2015q3 Homework 4
 
  • 作業要求 (A)
  • 難度:低 (適合之前 Homework #2 自認作不好者)
  • 研究其他同學在 Homework #2+程式成果,選出對自己有啟發 (正面) 的兩份作業成果,以及認為應該改善 (負面) 的三份作業,需要評註與解說 
  • 作業要求 (B)
  • 改善 JIT compiler,加入若干 optimization techniques
 
  • 作業要求 (C)
  • Rubi 實做切換到 DynASM,並且設計效能評估機制,從而改善 
  • 原本 x86 code generator 換成 DynASM 語法
 

作業(B)

Brainfuck language
Created in 1993 by Urban Müller
  • ' > '  ++p                                point to the next cell
  • ' < '   --p                                 point to the previous cell
  • ' + '   ++*p                              increment the byte value
  • ' - '    --*p                               decrement the byte value
  • ' . '   putchar(*p)                    output the byte value
  • ' , '   *p=getchar()                  store the value at data pointer
  • ' [ '   while(*p){                       if byte value = 0 jump to instruction after ]
                      or continue execution
  • ' ] '   }                                     jump back to matching ]
 
=> enough to be Turing Complete(can solve any problem that a Turing machine can)
 
compiler
  1.  extra preparation time   (taking the time to do translation of the input file to native machine code ahead of time)
  1.  but then program run very quickly  (jump to where they need to go in a few instructions O(1))
  1.  compiler only need to pay that tax once whenever run the code
 
Compile a simple object file
  • => compile the Brainfuck program to assembly code
  • => link it into an executable
 
interpreter
  1. order of magnitude
  1. run slowly  (translate one by one,it scans back and forth for matching brackets O(N))
  1. start right away (get to work right away without spending any time translating)
  1. let u see result ( you can de your bug immediately)
  1. there’s potential for stack buffer overrun since we’re not performing bounds checks
  1. would probably translate the higher level language to a byte code, and thus be able to calculate the offsets used for jumps directly
 
JIT
  1. between interpretation and compilation , combines the best of both worlds
  1. JIT have to read the input file or build up the instructions to execute at runtime
  1. jump to where they need to go in a few instructions O(1)