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.

8 2 <strong>ARM</strong>• Register r11 was used as a frame pointer (FP), but this has been deprecated in theAAPCS and can now be used as a general purpose register.• Register r12 is also called the intra-procedure-call scratch register, it is used to storetemporary values during the execution of a subroutine. The value of this register isnot guaranteed to be preserved through subroutine calls.• Register r13 is used as a stack pointer (SP) pointing to the top of the currently usedstack (the lowest address).• Register r14 also called the link register (LR) is used to store the return address ofthe calling subroutine <strong>for</strong> procedure calls.• Register r15 is the program counter (PC), containing the address of the currentinstruction. Writing to this register results in an unconditional branch.According to the AAPCS arguments to procedures are passed in registers r0 to r3 andon the stack. By passing the first arguments in registers, calls with up to four integerarguments can profit from avoiding the overhead of passing the arguments on the stack.The return values of sub-procedure calls are returned in the same registers used to passarguments. For this reasons the caller has to take care of preserving values stored in theseregisters. On the other hand the callee has to take care to preserve the values stored inthe registers r4 to r10 which are to be used <strong>for</strong> local variables.Figure 1 shows an example of a procedure written in <strong>ARM</strong> assembler that follows thecalling convention defined in the AAPCS, Figure 2 shows the equivalent algorithm writtenin Python. The procedure in this example calculates the Fibonacci number of an inputpassed in register r0 using a recursive algorithm. When entering the procedure the callersaved registers, that are going to be used, and the link register that contains the returnaddress are saved on the stack. Next, by checking if the input passed in register r0 isless than two we can check <strong>for</strong> the base cases (r0=0 or r0=1). In case we hit such a basecase, using a conditionally executed POP instruction (see Section 2.2.5 <strong>for</strong> details), we restorethe caller saved registers and load the return address into the program counter thusper<strong>for</strong>ming a jump to it. the recursive calculation of the two previous Fibonacci numbersby calling the same procedure using the branch and link instruction (BL) and passing theargument in register r0. The BL instruction stores the return address in the link registerand per<strong>for</strong>ms a jump to the address or label passed. Finally we calculate the sum of bothnumbers and store it in r0 as the return value. To return, using a POP instruction, werestore the caller saved registers and put the saved value of the link register into programcounter per<strong>for</strong>ming an unconditional branch to the return address.The AAPCS defines, based on a 32 bit word size, as core data types signed and unsignedbytes, halfwords, words and double words as well as half, single and double precisionfloating point numbers and finally vector data types. According to the size of the datatypes the values are stored in one, two or four consecutive registers.Section 5.5 of the AAPCS describes in detail the algorithm used to pass arguments toprocedures, describing the encoding of the arguments in registers, the stack and the coprocessorregisters taking into account the different sizes of data types described above.Larger data structures or data structures with variable size are passed and returned to

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

Saved successfully!

Ooh no, something went wrong!