diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | deps/sysobj_early/include/cpubits.h | 34 | ||||
-rw-r--r-- | deps/sysobj_early/src/cpubits.c (renamed from hardinfo/cpubits.c) | 43 | ||||
-rw-r--r-- | hardinfo/cpu_util.c | 3 |
4 files changed, 67 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 078ae9ce..39cd191b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,6 +237,7 @@ add_library(sysobj_early STATIC deps/sysobj_early/gui/uri_handler.c deps/sysobj_early/src/util_edid.c deps/sysobj_early/src/format_early.c + deps/sysobj_early/src/cpubits.c ) set_target_properties(sysobj_early PROPERTIES COMPILE_FLAGS "-std=c99 -Wall -Wextra -Wno-parentheses -Wno-unused-function") target_link_libraries(sysobj_early m) diff --git a/deps/sysobj_early/include/cpubits.h b/deps/sysobj_early/include/cpubits.h new file mode 100644 index 00000000..a7effbf1 --- /dev/null +++ b/deps/sysobj_early/include/cpubits.h @@ -0,0 +1,34 @@ +/* + * rpiz - https://github.com/bp0/rpiz + * Copyright (C) 2017 Burt P. <pburt0@gmail.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <stdint.h> + +typedef uint32_t cpubits; +uint32_t cpubits_count(cpubits *b); +int cpubits_min(cpubits *b); +int cpubits_max(cpubits *b); +int cpubits_next(cpubits *b, int start, int end); +cpubits *cpubits_from_str(char *str); +char *cpubits_to_str(cpubits *bits, char *str, int max_len); + +#define CPUBITS_SIZE 4096 /* bytes, multiple of sizeof(uint32_t) */ +#define CPUBIT_SET(BITS, BIT) (BITS[BIT/32] |= (1 << BIT%32)) +#define CPUBIT_GET(BITS, BIT) ((BITS[BIT/32] & (1 << BIT%32)) >> BIT%32) +#define CPUBITS_CLEAR(BITS) memset(BITS, 0, CPUBITS_SIZE) diff --git a/hardinfo/cpubits.c b/deps/sysobj_early/src/cpubits.c index 281a26e1..fe8ba207 100644 --- a/hardinfo/cpubits.c +++ b/deps/sysobj_early/src/cpubits.c @@ -18,17 +18,11 @@ * */ -#include <stdint.h> - -typedef uint32_t cpubits; -uint32_t cpubits_count(cpubits *b); -cpubits *cpubits_from_str(char *str); -char *cpubits_to_str(cpubits *bits, char *str, int max_len); - -#define CPUBITS_SIZE 4096 /* bytes, multiple of sizeof(uint32_t) */ -#define CPUBIT_SET(BITS, BIT) (BITS[(BIT)/32] |= (1 << (BIT)%32)) -#define CPUBIT_GET(BITS, BIT) ((BITS[(BIT)/32] & (1 << (BIT)%32)) >> (BIT)%32) -#define CPUBITS_CLEAR(BITS) memset(BITS, 0, CPUBITS_SIZE) +#define _GNU_SOURCE +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "cpubits.h" uint32_t cpubits_count(cpubits *b) { static const uint32_t max = CPUBITS_SIZE * 8; @@ -40,16 +34,41 @@ uint32_t cpubits_count(cpubits *b) { return count; } +int cpubits_min(cpubits *b) { + int i = 0; + while (i < CPUBITS_SIZE * 8) { + if (CPUBIT_GET(b, i)) + return i; + i++; + } + return -1; +} + int cpubits_max(cpubits *b) { int i = CPUBITS_SIZE * 8 - 1; while (i >= 0) { if (CPUBIT_GET(b, i)) - break; + return i; i--; } return i; } +int cpubits_next(cpubits *b, int start, int end) { + start++; /* not including the start bit */ + if (start >= 0) { + int i = start; + if (end == -1) + end = CPUBITS_SIZE * 8; + while (i < end) { + if (CPUBIT_GET(b, i)) + return i; + i++; + } + } + return -1; +} + cpubits *cpubits_from_str(char *str) { char *v, *nv, *hy; int r0, r1; diff --git a/hardinfo/cpu_util.c b/hardinfo/cpu_util.c index a598d2ed..5064c173 100644 --- a/hardinfo/cpu_util.c +++ b/hardinfo/cpu_util.c @@ -20,8 +20,7 @@ #include <string.h> #include "hardinfo.h" #include "cpu_util.h" - -#include "cpubits.c" +#include "cpubits.h" #define CPU_TOPO_NULL -9877 |