Debian Codegraph @

mozglue/build/mips.cpp

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 /* compile-time and runtime tests for whether to use MIPS-specific extensions */
6
7 #include "mips.h"
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 enum {
14 MIPS_FLAG_LOONGSON3 = 1,
15 };
16
17 static unsigned get_mips_cpu_flags(void) {
18 unsigned flags = 0;
19 FILE* fin;
20
21 fin = fopen("/proc/cpuinfo", "r");
22 if (fin != nullptr) {
23 char buf[1024];
24 memset(buf, 0, sizeof(buf));
25 fread(buf, sizeof(char), sizeof(buf) - 1, fin);
26 fclose(fin);
27 if (strstr(buf, "Loongson-3")) flags |= MIPS_FLAG_LOONGSON3;
28 }
29 return flags;
30 }
31
32 static bool check_loongson3(void) {
33 // Cache a local copy so we only have to read /proc/cpuinfo once.
34 static unsigned mips_cpu_flags = get_mips_cpu_flags();
35 return (mips_cpu_flags & MIPS_FLAG_LOONGSON3) != 0;
36 }
37
38 namespace mozilla {
39 namespace mips_private {
40 bool isLoongson3 = check_loongson3();
41 } // namespace mips_private
42 } // namespace mozilla