mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
Attempting to replace 64-bit mask with bool array
This commit is contained in:
@@ -138,7 +138,7 @@ struct features {
|
|||||||
|
|
||||||
struct extensions {
|
struct extensions {
|
||||||
char* str;
|
char* str;
|
||||||
uint64_t mask;
|
bool* mask; // allocated at runtime with size RISCV_ISA_EXT_ID_MAX-1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cpuInfo {
|
struct cpuInfo {
|
||||||
|
|||||||
@@ -949,14 +949,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ARCH_RISCV
|
#ifdef ARCH_RISCV
|
||||||
// https://stackoverflow.com/a/2709523
|
void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, bool use_short, bool* extensions_mask) {
|
||||||
uint64_t number_of_bits(uint64_t i) {
|
|
||||||
i = i - ((i >> 1) & 0x5555555555555555);
|
|
||||||
i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
|
|
||||||
return (((i + (i >> 4)) & 0xF0F0F0F0F0F0F0F) * 0x101010101010101) >> 56;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, bool use_short, uint64_t extensions_mask) {
|
|
||||||
struct ascii_logo* logo = art->art;
|
struct ascii_logo* logo = art->art;
|
||||||
int attr_to_print = 0;
|
int attr_to_print = 0;
|
||||||
int attr_type;
|
int attr_type;
|
||||||
@@ -966,7 +959,7 @@ void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, bool use_s
|
|||||||
int32_t ext_list_size = sizeof(extension_list)/sizeof(extension_list[0]);
|
int32_t ext_list_size = sizeof(extension_list)/sizeof(extension_list[0]);
|
||||||
int32_t ext_num = 0;
|
int32_t ext_num = 0;
|
||||||
int32_t ext_to_print = 0;
|
int32_t ext_to_print = 0;
|
||||||
int32_t num_extensions = number_of_bits(extensions_mask);
|
int32_t num_extensions = get_num_extensions(extensions_mask);
|
||||||
int32_t space_up = ((int)logo->height - (int)(art->n_attributes_set + num_extensions))/2;
|
int32_t space_up = ((int)logo->height - (int)(art->n_attributes_set + num_extensions))/2;
|
||||||
int32_t space_down = (int)logo->height - (int)(art->n_attributes_set + num_extensions) - (int)space_up;
|
int32_t space_down = (int)logo->height - (int)(art->n_attributes_set + num_extensions) - (int)space_up;
|
||||||
uint32_t logo_pos = 0;
|
uint32_t logo_pos = 0;
|
||||||
@@ -1012,7 +1005,11 @@ void print_ascii_riscv(struct ascii* art, uint32_t la, int32_t termw, bool use_s
|
|||||||
// Print extension
|
// Print extension
|
||||||
if(attr_to_print > 0 && art->attributes[attr_to_print-1]->type == ATTRIBUTE_EXTENSIONS && ext_num != num_extensions) {
|
if(attr_to_print > 0 && art->attributes[attr_to_print-1]->type == ATTRIBUTE_EXTENSIONS && ext_num != num_extensions) {
|
||||||
// Search for the extension to print
|
// Search for the extension to print
|
||||||
while(ext_to_print < ext_list_size && !((extensions_mask >> extension_list[ext_to_print].id) & 1U)) ext_to_print++;
|
printf("ext_to_print: %d\n", ext_to_print);
|
||||||
|
|
||||||
|
while (ext_to_print < ext_list_size && !((extensions_mask[extension_list[ext_to_print].id])))
|
||||||
|
ext_to_print++;
|
||||||
|
|
||||||
if(ext_to_print == ext_list_size) {
|
if(ext_to_print == ext_list_size) {
|
||||||
printBug("print_ascii_riscv: Unable to find the extension to print");
|
printBug("print_ascii_riscv: Unable to find the extension to print");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#define SET_ISA_EXT_MAP(name, bit) \
|
#define SET_ISA_EXT_MAP(name, bit) \
|
||||||
if(strncmp(multi_letter_extension, name, \
|
if(strncmp(multi_letter_extension, name, \
|
||||||
multi_letter_extension_len) == 0) { \
|
multi_letter_extension_len) == 0) { \
|
||||||
ext->mask |= 1UL << bit; \
|
ext->mask[bit] = true; \
|
||||||
maskset = true; \
|
maskset = true; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ bool valid_extension(char ext) {
|
|||||||
|
|
||||||
struct extensions* get_extensions_from_str(char* str) {
|
struct extensions* get_extensions_from_str(char* str) {
|
||||||
struct extensions* ext = emalloc(sizeof(struct extensions));
|
struct extensions* ext = emalloc(sizeof(struct extensions));
|
||||||
ext->mask = 0;
|
ext->mask = ecalloc((RISCV_ISA_EXT_ID_MAX-1) * sizeof(bool));
|
||||||
ext->str = NULL;
|
ext->str = NULL;
|
||||||
|
|
||||||
if(str == NULL) {
|
if(str == NULL) {
|
||||||
@@ -165,6 +165,8 @@ struct extensions* get_extensions_from_str(char* str) {
|
|||||||
|
|
||||||
// Code inspired in Linux kernel (riscv_fill_hwcap):
|
// Code inspired in Linux kernel (riscv_fill_hwcap):
|
||||||
// https://elixir.bootlin.com/linux/v6.2.10/source/arch/riscv/kernel/cpufeature.c
|
// https://elixir.bootlin.com/linux/v6.2.10/source/arch/riscv/kernel/cpufeature.c
|
||||||
|
// Now it seems to be here in riscv_parse_isa_string:
|
||||||
|
// https://elixir.bootlin.com/linux/v6.16/source/arch/riscv/kernel/cpufeature.c
|
||||||
char* isa = str;
|
char* isa = str;
|
||||||
if (!strncmp(isa, "rv32", 4))
|
if (!strncmp(isa, "rv32", 4))
|
||||||
isa += 4;
|
isa += 4;
|
||||||
@@ -196,7 +198,7 @@ struct extensions* get_extensions_from_str(char* str) {
|
|||||||
// adding it to the mask
|
// adding it to the mask
|
||||||
if(valid_extension(*e)) {
|
if(valid_extension(*e)) {
|
||||||
int n = *e - 'a';
|
int n = *e - 'a';
|
||||||
ext->mask |= 1UL << n;
|
ext->mask[n] = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printBug("get_extensions_from_str: Invalid extension: '%c'", *e);
|
printBug("get_extensions_from_str: Invalid extension: '%c'", *e);
|
||||||
@@ -207,6 +209,18 @@ struct extensions* get_extensions_from_str(char* str) {
|
|||||||
return ext;
|
return ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 get_num_extensions(bool* mask) {
|
||||||
|
uint32 num = 0;
|
||||||
|
for (int i=0; i < RISCV_ISA_EXT_ID_MAX-1; i++) {
|
||||||
|
if (mask[i]) num++;
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_mask_empty(bool* mask) {
|
||||||
|
return get_num_extensions(mask) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct cpuInfo* get_cpu_info(void) {
|
struct cpuInfo* get_cpu_info(void) {
|
||||||
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
|
struct cpuInfo* cpu = malloc(sizeof(struct cpuInfo));
|
||||||
//init_cpu_info(cpu);
|
//init_cpu_info(cpu);
|
||||||
@@ -219,7 +233,7 @@ struct cpuInfo* get_cpu_info(void) {
|
|||||||
cpu->hv = emalloc(sizeof(struct hypervisor));
|
cpu->hv = emalloc(sizeof(struct hypervisor));
|
||||||
cpu->hv->present = false;
|
cpu->hv->present = false;
|
||||||
cpu->ext = get_extensions_from_str(ext_str);
|
cpu->ext = get_extensions_from_str(ext_str);
|
||||||
if(cpu->ext->str != NULL && cpu->ext->mask == 0) return NULL;
|
if(cpu->ext->str != NULL && is_mask_empty(cpu->ext->mask)) return NULL;
|
||||||
cpu->arch = get_uarch(cpu);
|
cpu->arch = get_uarch(cpu);
|
||||||
cpu->soc = get_soc(cpu);
|
cpu->soc = get_soc(cpu);
|
||||||
cpu->freq = get_frequency_info(0);
|
cpu->freq = get_frequency_info(0);
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ static const struct extension extension_list[] = {
|
|||||||
struct cpuInfo* get_cpu_info(void);
|
struct cpuInfo* get_cpu_info(void);
|
||||||
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo);
|
char* get_str_topology(struct cpuInfo* cpu, struct topology* topo);
|
||||||
char* get_str_extensions(struct cpuInfo* cpu);
|
char* get_str_extensions(struct cpuInfo* cpu);
|
||||||
|
uint32 get_num_extensions(bool* mask);
|
||||||
void print_debug(struct cpuInfo* cpu);
|
void print_debug(struct cpuInfo* cpu);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user