10.07.2015 Views

An ARM Backend for PyPyls Tracing JIT - STUPS Group

An ARM Backend for PyPyls Tracing JIT - STUPS Group

An ARM Backend for PyPyls Tracing JIT - STUPS Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

26 6 A BACKEND FOR PYPY’S <strong>JIT</strong>address it by its offset to the program counter. The first solution has the advantage thatit works with conditional execution. Figure 16 shows the function used to load constantsof up to 32 bits into a register, passing in the variable r that marks the target register,where the value will be stored after executing the generated instructions. If the valuefits in 2 bytes or if the instructions are to be executed conditionally we load the constantbyte by byte into the target register (see the function _load_by_shifting in Figure 16).Initially the lowest byte is moved into the target register, all further bytes are written tothe register by an ORR operation which applies a logical OR to the argument register andthe shifted 8 bit immediate value, Figure 14 shows how the constant 0xBDBC would beloaded into register r4 using this approach. For the second approach to loading a constant,used when the constant requires three or four bytes and we do not need conditionalexecution, we encode the constant in the program stream, read it using an address basedon an offset to the value of the PC and per<strong>for</strong>m a small unconditional jump to continueexecution after the location of the value. With this method loading a 32 bit constantstakes at most 3 words (2 instructions plus 1 data word) see Figure 15 <strong>for</strong> an example ofthe code generated to load the constant 0x6A5EF3C5 into register r4....MOV r4, #179ORR r4, r4, #189 LSL #8...Figure 14: Loading a constant by shifting the bytes into the target register...LDR R4, [PC + #8]ADD PC, PC, #40x6A5EF3C5...Figure 15: Loading a constant encoded in the program streamWe also experimented with using exclusively one or the other approach but this mixedapproach gives the best results in terms of speed, although the differences are small.A further method worth investigating, which we have not tried so far, is using a constantpool stored in memory in a location that can be accessed by offset addressing relativeto the PC where all the used constants are stored. Constants can then be loaded intoa register by being referenced by their corresponding offset to the PC. This techniquewould save the jump and work with conditional execution.6.2 Register Allocation<strong>An</strong> important aspect <strong>for</strong> the results produced by a compiler, which is also valid <strong>for</strong> justin-timecompilers, is register allocation. Register allocation is the process of assigningCPU registers to the variables used in the intermediate representation of a program. Thisprocess should be fast, especially <strong>for</strong> <strong>JIT</strong>s, and at the same time produce good results to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!