1214152Sed//===-- switch.S - Implement switch* --------------------------------------===// 2214152Sed// 3214152Sed// The LLVM Compiler Infrastructure 4214152Sed// 5222656Sed// This file is dual licensed under the MIT and the University of Illinois Open 6222656Sed// Source Licenses. See LICENSE.TXT for details. 7214152Sed// 8214152Sed//===----------------------------------------------------------------------===// 9214152Sed 10214152Sed#include "../assembly.h" 11214152Sed 12214152Sed// 13214152Sed// When compiling switch statements in thumb mode, the compiler 14214152Sed// can use these __switch* helper functions The compiler emits a blx to 15214152Sed// the __switch* function followed by a table of displacements for each 16214152Sed// case statement. On entry, R0 is the index into the table. The __switch* 17214152Sed// function uses the return address in lr to find the start of the table. 18214152Sed// The first entry in the table is the count of the entries in the table. 19214152Sed// It then uses R0 to index into the table and get the displacement of the 20214152Sed// address to jump to. If R0 is greater than the size of the table, it jumps 21214152Sed// to the last entry in the table. Each displacement in the table is actually 22214152Sed// the distance from lr to the label, thus making the tables PIC. 23214152Sed 24214152Sed 25214152Sed .text 26214152Sed .syntax unified 27214152Sed 28214152Sed// 29214152Sed// The table contains signed byte sized elements which are 1/2 the distance 30214152Sed// from lr to the target label. 31214152Sed// 32214152Sed .align 2 33214152SedDEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch8) 34214152Sed ldrb ip, [lr, #-1] // get first byte in table 35214152Sed cmp r0, ip // signed compare with index 36214152Sed ldrsbcc r0, [lr, r0] // get indexed byte out of table 37214152Sed ldrsbhs r0, [lr, ip] // if out of range, use last entry in table 38214152Sed add ip, lr, r0, lsl #1 // compute label = lr + element*2 39214152Sed bx ip // jump to computed label 40214152Sed 41214152Sed // tell linker it can break up file at label boundaries 42214152Sed .subsections_via_symbols 43214152Sed 44