Message ID | CAB5ADv-AWwaJzD+LWnQK9Lv2dnrNVEKGZ3WbXa8g6PfFYYo2qA@mail.gmail.com |
---|---|
State | New |
Headers | show |
diff --git a/target-i386/topology.h b/target-i386/topology.h index 07a6c5f..cda6bf5 100644 --- a/target-i386/topology.h +++ b/target-i386/topology.h @@ -117,6 +117,19 @@ static inline void x86_topo_ids_from_idx(unsigned nr_cores, *pkg_id = core_index / nr_cores; } +/* This function will return whether @num is power of 2. + * + * Returns: 1 indicate @num is power of 2, 0 indicate @num is not. + */ +static int is_2_power(int num) +{ + if (num < 0 || num > 256) { + return 1; + } + + return !(num & (num - 1)); +} + /* Make APIC ID for the CPU 'cpu_index' *