mips.cpp (1089B)
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 <string.h> 11 12 enum { 13 MIPS_FLAG_LOONGSON3 = 1, 14 }; 15 16 static unsigned get_mips_cpu_flags(void) { 17 unsigned flags = 0; 18 FILE* fin; 19 20 fin = fopen("/proc/cpuinfo", "r"); 21 if (fin != nullptr) { 22 char buf[1024]; 23 memset(buf, 0, sizeof(buf)); 24 fread(buf, sizeof(char), sizeof(buf) - 1, fin); 25 fclose(fin); 26 if (strstr(buf, "Loongson-3")) flags |= MIPS_FLAG_LOONGSON3; 27 } 28 return flags; 29 } 30 31 static bool check_loongson3(void) { 32 // Cache a local copy so we only have to read /proc/cpuinfo once. 33 static unsigned mips_cpu_flags = get_mips_cpu_flags(); 34 return (mips_cpu_flags & MIPS_FLAG_LOONGSON3) != 0; 35 } 36 37 namespace mozilla { 38 namespace mips_private { 39 bool isLoongson3 = check_loongson3(); 40 } // namespace mips_private 41 } // namespace mozilla