|
1 /* |
|
2 * LIBOIL - Library of Optimized Inner Loops |
|
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org> |
|
4 * All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions |
|
8 * are met: |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * |
|
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
25 * POSSIBILITY OF SUCH DAMAGE. |
|
26 */ |
|
27 |
|
28 #ifdef HAVE_CONFIG_H |
|
29 #include "config.h" |
|
30 #endif |
|
31 #include <liboil/liboilfunction.h> |
|
32 #include <liboil/liboildebug.h> |
|
33 #include <liboil/liboilcpu.h> |
|
34 #include <liboil/liboilfault.h> |
|
35 #include <liboil/liboilutils.h> |
|
36 |
|
37 #include <unistd.h> |
|
38 #include <fcntl.h> |
|
39 #include <stdlib.h> |
|
40 #include <string.h> |
|
41 #include <stdio.h> |
|
42 #include <setjmp.h> |
|
43 #include <signal.h> |
|
44 #include <sys/time.h> |
|
45 #include <time.h> |
|
46 |
|
47 /***** alpha *****/ |
|
48 |
|
49 #if defined(__alpha__) |
|
50 static unsigned long |
|
51 oil_profile_stamp_alpha(void) |
|
52 { |
|
53 unsigned int ts; |
|
54 __asm__ __volatile__ ("rpcc %0\n" : "=r"(ts)); |
|
55 return ts; |
|
56 } |
|
57 |
|
58 static void |
|
59 oil_cpu_detect_alpha(void) |
|
60 { |
|
61 _oil_profile_stamp = oil_profile_stamp_alpha; |
|
62 } |
|
63 #endif |
|
64 |
|
65 /***** ia64 *****/ |
|
66 |
|
67 #if defined(__ia64__) |
|
68 static unsigned long |
|
69 oil_profile_stamp_ia64(void) |
|
70 { |
|
71 unsigned int ts; |
|
72 __asm__ __volatile__("mov %0=ar.itc\n" : "=r"(ts) :: "memory"); |
|
73 return ts; |
|
74 } |
|
75 |
|
76 static void |
|
77 oil_cpu_detect_ia64(void) |
|
78 { |
|
79 _oil_profile_stamp = oil_profile_stamp_ia64; |
|
80 } |
|
81 #endif |
|
82 |
|
83 /***** s390 *****/ |
|
84 |
|
85 #if defined(__s390__) |
|
86 static unsigned long |
|
87 oil_profile_stamp_s390(void) |
|
88 { |
|
89 uint64_t ts; |
|
90 __asm__ __volatile__ ("STCK %0(%0)\n" : : "r" (&ts)); |
|
91 return ts; |
|
92 } |
|
93 |
|
94 static void |
|
95 oil_cpu_detect_s390(void) |
|
96 { |
|
97 _oil_profile_stamp = oil_profile_stamp_s390; |
|
98 } |
|
99 #endif |
|
100 |
|
101 /***** mips *****/ |
|
102 |
|
103 #if defined(__mips__) |
|
104 #if 0 |
|
105 /* broken */ |
|
106 static unsigned long |
|
107 oil_profile_stamp_mips(void) |
|
108 { |
|
109 unsigned int ts; |
|
110 __asm__ __volatile__ ( |
|
111 " .set push \n" |
|
112 " .set reorder \n" |
|
113 " mfc0 %0,$9 \n" |
|
114 " .set pop \n" |
|
115 : "=m" (ts)); |
|
116 return ts; |
|
117 } |
|
118 #endif |
|
119 |
|
120 static void |
|
121 oil_cpu_detect_mips(void) |
|
122 { |
|
123 //_oil_profile_stamp = oil_profile_stamp_mips; |
|
124 } |
|
125 #endif |
|
126 |
|
127 void |
|
128 oil_cpu_detect_arch(void) |
|
129 { |
|
130 #ifdef __alpha__ |
|
131 oil_cpu_detect_alpha(); |
|
132 #endif |
|
133 #ifdef __ia64__ |
|
134 oil_cpu_detect_ia64(); |
|
135 #endif |
|
136 #ifdef __s390__ |
|
137 oil_cpu_detect_s390(); |
|
138 #endif |
|
139 #ifdef __mips__ |
|
140 oil_cpu_detect_mips(); |
|
141 #endif |
|
142 } |
|
143 |