Bug 1833854 - Part 6: Round requested nursery before checking range when changing...
[gecko.git] / mozglue / build / mips.cpp
blob7166080f5ea01bf779c601fad1787f4ecb53d284
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/. */
5 /* compile-time and runtime tests for whether to use MIPS-specific extensions */
7 #include "mips.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 enum {
14 MIPS_FLAG_LOONGSON3 = 1,
17 static unsigned get_mips_cpu_flags(void) {
18 unsigned flags = 0;
19 FILE* fin;
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;
29 return flags;
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;
38 namespace mozilla {
39 namespace mips_private {
40 bool isLoongson3 = check_loongson3();
41 } // namespace mips_private
42 } // namespace mozilla