brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 0db875c Raw
44 lines · plain
1//===-- switch.S - Implement switch* --------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "../assembly.h"10 11//12// When compiling switch statements in thumb mode, the compiler13// can use these __switch* helper functions  The compiler emits a blx to14// the __switch* function followed by a table of displacements for each15// case statement.  On entry, R0 is the index into the table. The __switch*16// function uses the return address in lr to find the start of the table.17// The first entry in the table is the count of the entries in the table.18// It then uses R0 to index into the table and get the displacement of the19// address to jump to.  If R0 is greater than the size of the table, it jumps20// to the last entry in the table. Each displacement in the table is actually21// the distance from lr to the label, thus making the tables PIC.22 23 24	.text25	.syntax unified26 27//28// The table contains signed byte sized elements which are 1/2 the distance29// from lr to the target label.30//31	.p2align 232DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch8)33	ldrb    ip, [lr, #-1]           // get first byte in table34	cmp     r0, ip                  // signed compare with index35	ite lo36	ldrsblo r0, [lr, r0]            // get indexed byte out of table37	ldrsbhs r0, [lr, ip]            // if out of range, use last entry in table38	add     ip, lr, r0, lsl #1      // compute label = lr + element*239	bx      ip                      // jump to computed label40END_COMPILERRT_FUNCTION(__switch8)41 42NO_EXEC_STACK_DIRECTIVE43 44