to reflect the new license. These used slightly different spellings that defeated my regular expressions. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351648
44 lines
1.7 KiB
ArmAsm
44 lines
1.7 KiB
ArmAsm
//===-- switch.S - Implement switch* --------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "../assembly.h"
|
|
|
|
//
|
|
// When compiling switch statements in thumb mode, the compiler
|
|
// can use these __switch* helper functions The compiler emits a blx to
|
|
// the __switch* function followed by a table of displacements for each
|
|
// case statement. On entry, R0 is the index into the table. The __switch*
|
|
// function uses the return address in lr to find the start of the table.
|
|
// The first entry in the table is the count of the entries in the table.
|
|
// It then uses R0 to index into the table and get the displacement of the
|
|
// address to jump to. If R0 is greater than the size of the table, it jumps
|
|
// to the last entry in the table. Each displacement in the table is actually
|
|
// the distance from lr to the label, thus making the tables PIC.
|
|
|
|
|
|
.text
|
|
.syntax unified
|
|
|
|
//
|
|
// The table contains signed byte sized elements which are 1/2 the distance
|
|
// from lr to the target label.
|
|
//
|
|
.p2align 2
|
|
DEFINE_COMPILERRT_PRIVATE_FUNCTION(__switch8)
|
|
ldrb ip, [lr, #-1] // get first byte in table
|
|
cmp r0, ip // signed compare with index
|
|
ite lo
|
|
ldrsblo r0, [lr, r0] // get indexed byte out of table
|
|
ldrsbhs r0, [lr, ip] // if out of range, use last entry in table
|
|
add ip, lr, r0, lsl #1 // compute label = lr + element*2
|
|
bx ip // jump to computed label
|
|
END_COMPILERRT_FUNCTION(__switch8)
|
|
|
|
NO_EXEC_STACK_DIRECTIVE
|
|
|