blob: 3f690aafd88daf50490ff0d44961bc07b45636f4 [file] [log] [blame]
Zonr Chang932648d2010-10-13 22:23:56 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Shih-wei Liao77ed6142010-04-07 12:21:42 -070017#include "runtime/lib/absvdi2.c"
18#include "runtime/lib/absvsi2.c"
19#include "runtime/lib/addvdi3.c"
20#include "runtime/lib/addvsi3.c"
21#include "runtime/lib/ashldi3.c"
22#ifndef ANDROID
23# include "runtime/lib/ashrdi3.c"
24#endif
25#include "runtime/lib/clzdi2.c"
26#include "runtime/lib/clzsi2.c"
27#include "runtime/lib/cmpdi2.c"
28#include "runtime/lib/ctzdi2.c"
29#include "runtime/lib/ctzsi2.c"
30#ifndef ANDROID // no complex.h
31# include "runtime/lib/divdc3.c"
32#endif
33#include "runtime/lib/divdi3.c"
34#ifndef ANDROID // no complex.h
35# include "runtime/lib/divsc3.c"
36#endif
37#include "runtime/lib/ffsdi2.c"
38#include "runtime/lib/fixdfdi.c"
39#include "runtime/lib/fixsfdi.c"
40#include "runtime/lib/fixunsdfdi.c"
41#include "runtime/lib/fixunsdfsi.c"
42#include "runtime/lib/fixunssfdi.c"
43#include "runtime/lib/fixunssfsi.c"
44#include "runtime/lib/floatdidf.c"
45#include "runtime/lib/floatdisf.c"
46#include "runtime/lib/floatundidf.c"
47#include "runtime/lib/floatundisf.c"
48#include "runtime/lib/lshrdi3.c"
49#include "runtime/lib/moddi3.c"
50#ifndef ANDROID // no complex.h
51# include "runtime/lib/muldc3.c"
52#endif
53#include "runtime/lib/muldi3.c"
54#ifndef ANDROID // no complex.h
55# include "runtime/lib/mulsc3.c"
56#endif
57#include "runtime/lib/mulvdi3.c"
58#include "runtime/lib/mulvsi3.c"
59#include "runtime/lib/negdi2.c"
60#include "runtime/lib/negvdi2.c"
61#include "runtime/lib/negvsi2.c"
62#include "runtime/lib/paritydi2.c"
63#include "runtime/lib/paritysi2.c"
64#include "runtime/lib/popcountdi2.c"
65#include "runtime/lib/popcountsi2.c"
66#include "runtime/lib/powidf2.c"
67#include "runtime/lib/powisf2.c"
68#include "runtime/lib/subvdi3.c"
69#include "runtime/lib/subvsi3.c"
70#include "runtime/lib/ucmpdi2.c"
71#include "runtime/lib/udivdi3.c"
Shih-wei Liao210eb402010-08-26 08:55:40 -070072#include "runtime/lib/udivsi3.c"
Shih-wei Liao77ed6142010-04-07 12:21:42 -070073#include "runtime/lib/udivmoddi4.c"
74#include "runtime/lib/umoddi3.c"
75#include "runtime/lib/eprintf.c"
76
77#include <string.h>
78#include <stdlib.h>
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -070079#include <assert.h>
Shih-wei Liao77ed6142010-04-07 12:21:42 -070080
81typedef struct {
Zonr Chang932648d2010-10-13 22:23:56 +080082 const char *mName;
83 void *mPtr;
Shih-wei Liao77ed6142010-04-07 12:21:42 -070084} RuntimeFunction;
85
86#define USE_VFP_RUNTIME 1
87
88#if defined(__arm__)
89 #define DEF_GENERIC_RUNTIME(func) \
Zonr Chang932648d2010-10-13 22:23:56 +080090 extern void *func;
Shih-wei Liao77ed6142010-04-07 12:21:42 -070091 #define DEF_VFP_RUNTIME(func) \
Zonr Chang932648d2010-10-13 22:23:56 +080092 extern void *func ## vfp;
Shih-wei Liao77ed6142010-04-07 12:21:42 -070093 #define DEF_LLVM_RUNTIME(func)
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -070094 #define DEF_BCC_RUNTIME(func)
Loganc4395232010-11-27 18:54:17 +080095#include "Runtime.def"
Shih-wei Liao77ed6142010-04-07 12:21:42 -070096#endif
97
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -070098static const RuntimeFunction gRuntimes[] = {
Shih-wei Liao77ed6142010-04-07 12:21:42 -070099#if defined(__arm__)
100 #define DEF_GENERIC_RUNTIME(func) \
101 { #func, (void*) &func },
102 // TODO: enable only when target support VFP
103 #define DEF_VFP_RUNTIME(func) \
104 { #func, (void*) &func ## vfp },
105#else
106 // host compiler library must contain generic runtime
107 #define DEF_GENERIC_RUNTIME(func)
108 #define DEF_VFP_RUNTIME(func)
109#endif
110#define DEF_LLVM_RUNTIME(func) \
111 { #func, (void*) &func },
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -0700112#define DEF_BCC_RUNTIME(func) \
113 { #func, &func ## _bcc },
Loganc4395232010-11-27 18:54:17 +0800114#include "Runtime.def"
Shih-wei Liao77ed6142010-04-07 12:21:42 -0700115};
116
Zonr Chang932648d2010-10-13 22:23:56 +0800117static int CompareRuntimeFunction(const void *a, const void *b) {
118 return strcmp(((const RuntimeFunction*) a)->mName,
Shih-wei Liao77ed6142010-04-07 12:21:42 -0700119 ((const RuntimeFunction*) b)->mName);
120}
121
Zonr Chang932648d2010-10-13 22:23:56 +0800122void *FindRuntimeFunction(const char *Name) {
123 // binary search
Shih-wei Liao77ed6142010-04-07 12:21:42 -0700124 const RuntimeFunction Key = { Name, NULL };
Zonr Chang932648d2010-10-13 22:23:56 +0800125 const RuntimeFunction *R =
126 bsearch(&Key,
127 gRuntimes,
128 sizeof(gRuntimes) / sizeof(RuntimeFunction),
Shih-wei Liao77ed6142010-04-07 12:21:42 -0700129 sizeof(RuntimeFunction),
130 CompareRuntimeFunction);
Zonr Chang932648d2010-10-13 22:23:56 +0800131
132 return ((R) ? R->mPtr : NULL);
Shih-wei Liao77ed6142010-04-07 12:21:42 -0700133}
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -0700134
135void VerifyRuntimesTable() {
Zonr Chang932648d2010-10-13 22:23:56 +0800136 unsigned N = sizeof(gRuntimes) / sizeof(RuntimeFunction), i;
137 for(i = 0; i < N; i++) {
138 const char *Name = gRuntimes[i].mName;
139 int *Ptr = FindRuntimeFunction(Name);
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -0700140
Zonr Chang932648d2010-10-13 22:23:56 +0800141 if (Ptr != (int*) gRuntimes[i].mPtr)
142 assert(false && "Table is corrupted (runtime name should be sorted in "
Loganc4395232010-11-27 18:54:17 +0800143 "Runtime.def).");
Shih-wei Liaoabd1e3d2010-04-28 01:47:00 -0700144 }
145}