|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "jit/mips/Architecture-mips.h" |
|
8 |
|
9 #include <elf.h> |
|
10 |
|
11 #include <fcntl.h> |
|
12 #include <unistd.h> |
|
13 |
|
14 #define HWCAP_MIPS (1 << 31) |
|
15 #define HWCAP_FPU (1 << 0) |
|
16 |
|
17 namespace js { |
|
18 namespace jit { |
|
19 |
|
20 uint32_t GetMIPSFlags() |
|
21 { |
|
22 static bool isSet = false; |
|
23 static uint32_t flags = 0; |
|
24 if (isSet) |
|
25 return flags; |
|
26 #if WTF_OS_LINUX |
|
27 FILE *fp = fopen("/proc/cpuinfo", "r"); |
|
28 if (!fp) |
|
29 return false; |
|
30 |
|
31 char buf[1024]; |
|
32 memset(buf, 0, sizeof(buf)); |
|
33 fread(buf, sizeof(char), sizeof(buf)-1, fp); |
|
34 fclose(fp); |
|
35 if (strstr(buf, "FPU")) |
|
36 flags |= HWCAP_FPU; |
|
37 |
|
38 isSet = true; |
|
39 return flags; |
|
40 #endif |
|
41 |
|
42 return false; |
|
43 } |
|
44 |
|
45 bool hasFPU() |
|
46 { |
|
47 return js::jit::GetMIPSFlags() & HWCAP_FPU; |
|
48 } |
|
49 |
|
50 Registers::Code |
|
51 Registers::FromName(const char *name) |
|
52 { |
|
53 for (size_t i = 0; i < Total; i++) { |
|
54 if (strcmp(GetName(i), name) == 0) |
|
55 return Code(i); |
|
56 } |
|
57 |
|
58 return Invalid; |
|
59 } |
|
60 |
|
61 FloatRegisters::Code |
|
62 FloatRegisters::FromName(const char *name) |
|
63 { |
|
64 for (size_t i = 0; i < Total; i++) { |
|
65 if (strcmp(GetName(i), name) == 0) |
|
66 return Code(i); |
|
67 } |
|
68 |
|
69 return Invalid; |
|
70 } |
|
71 |
|
72 |
|
73 |
|
74 } // namespace ion |
|
75 } // namespace js |
|
76 |