summaryrefslogtreecommitdiff
path: root/lib/arm
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2009-09-18 00:07:52 +0000
committerNick Kledzik <kledzik@apple.com>2009-09-18 00:07:52 +0000
commit0c610555977c674691139d8bc348a32e428e94ff (patch)
tree22df31ce0140a3bedb1d3fe87c7e5061f09b1980 /lib/arm
parent0963c9e8ea7f97732b0fce419fa6f2e96d951969 (diff)
add support for __switch* needed for switch statements in thumb codegen
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@82184 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/arm')
-rw-r--r--lib/arm/switch.S93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/arm/switch.S b/lib/arm/switch.S
new file mode 100644
index 000000000..bfde0dad2
--- /dev/null
+++ b/lib/arm/switch.S
@@ -0,0 +1,93 @@
+//===-- switch.S - Implement switch* --------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+//
+// 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 unsigned byte sized elements which are 1/2 the distance
+// from lr to the target label.
+//
+ .globl ___switchu8
+ .private_extern ___switchu8
+___switchu8:
+ ldrb ip, [lr, #-1] // get first byte in table
+ cmp r0, ip // compare with index
+ ldrbcc r0, [lr, r0] // get indexed byte out of table
+ ldrbhs 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
+
+
+
+//
+// The table contains signed byte sized elements which are 1/2 the distance
+// from lr to the target label.
+//
+ .globl ___switch8
+ .private_extern ___switch8
+___switch8:
+ ldrb ip, [lr, #-1] // get first byte in table
+ cmp r0, ip // signed compare with index
+ ldrsbcc 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
+
+
+//
+// The table contains signed 2-byte sized elements which are 1/2 the distance
+// from lr to the target label.
+//
+ .globl ___switch16
+ .private_extern ___switch16
+___switch16:
+ ldrh ip, [lr, #-1] // get first 16-bit word in table
+ cmp r0, ip // compare with index
+ add r0, lr, r0, lsl #1 // compute address of element in table
+ ldrshcc r0, [r0, #1] // load 16-bit element if r0 is in range
+ add ip, lr, ip, lsl #1 // compute address of last element in table
+ ldrshhs r0, [ip, #1] // load 16-bit element if r0 out of range
+ add ip, lr, r0, lsl #1 // compute label = lr + element*2
+ bx ip // jump to computed label
+
+
+//
+// The table contains signed 4-byte sized elements which are the distance
+// from lr to the target label.
+//
+ .globl ___switch32
+ .private_extern ___switch32
+___switch32:
+ ldr ip, [lr, #-1] // get first 32-bit word in table
+ cmp r0, ip // compare with index
+ add r0, lr, r0, lsl #2 // compute address of element in table
+ ldrcc r0, [r0, #3] // load 32-bit element if r0 is in range
+ add ip, lr, ip, lsl #2 // compute address of last element in table
+ ldrcs r0, [ip, #3] // load 32-bit element if r0 out of range
+ add ip, lr, r0 // compute label = lr + element
+ bx ip // jump to computed label
+
+
+ // tell linker it can break up file at label boundaries
+ .subsections_via_symbols
+