#include #include #include #include #include #include "libcpuid.h" #include "libcpuid_util.h" void match_features(const struct feature_map_t* matchtable, int count, uint32_t reg, struct cpu_id_t* data) { int i; for (i = 0; i < count; i++) if (reg & (1u << matchtable[i].bit)) data->flags[matchtable[i].feature] = 1; } static int xmatch_entry(char c, const char* p) { int i, j; if (c == 0) return -1; if (c == p[0]) return 1; if (p[0] == '.') return 1; if (p[0] == '#' && isdigit(c)) return 1; if (p[0] == '[') { j = 1; while (p[j] && p[j] != ']') j++; if (!p[j]) return -1; for (i = 1; i < j; i++) if (p[i] == c) return j + 1; } return -1; } int match_pattern(const char* s, const char* p) { int i, j, dj, k, n, m; n = (int) strlen(s); m = (int) strlen(p); for (i = 0; i < n; i++) { if (xmatch_entry(s[i], p) != -1) { j = 0; k = 0; while (j < m && ((dj = xmatch_entry(s[i + k], p + j)) != -1)) { k++; j += dj; } if (j == m) return i + 1; } } return 0; } struct cpu_id_t* get_cached_cpuid(void) { static int initialized = 0; static struct cpu_id_t id; if (initialized) return &id; if (cpu_identify(NULL, &id)) memset(&id, 0, sizeof(id)); initialized = 1; return &id; } int match_all(uint64_t bits, uint64_t mask) { return (bits & mask) == mask; }