[03/12] x86: cpu -- Use bitwise operator for option check

Submitted by Cyrill Gorcunov on Aug. 30, 2018, 11 a.m.

Details

Message ID 20180830110027.12706-4-gorcunov@gmail.com
State Accepted
Series "x86: cpu -- Rework feature testing"
Headers show

Commit Message

Cyrill Gorcunov Aug. 30, 2018, 11 a.m.
Usually people simply leave cpu checkin in default
mode (which is fpu level) but idea was to be able
to compose a mixture of settings, for this sake
CPU_CAP_ constants are bit shifts. Thus use bitwise
operator for this.

Same time define CPU_CAP_ as bit shifts explicitly
and use explicit CPU_CAP_NONE compare where needed.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Dmitry Safonov <0x7f454c46@gmaill.com>
---
 criu/arch/x86/cpu.c       |  6 +++---
 criu/include/cr_options.h | 10 +++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/arch/x86/cpu.c b/criu/arch/x86/cpu.c
index 9751261ab277..c59f9d63fe84 100644
--- a/criu/arch/x86/cpu.c
+++ b/criu/arch/x86/cpu.c
@@ -236,7 +236,7 @@  static int cpu_validate_features(compel_cpuinfo_t *cpu_info)
 	if (cpu_has_unsupported_features())
 		return -1;
 
-	if (opts.cpu_cap == CPU_CAP_FPU) {
+	if (opts.cpu_cap & CPU_CAP_FPU) {
 		/*
 		 * If we're requested to check FPU only ignore
 		 * any other bit. It's up to a user if the
@@ -288,7 +288,7 @@  static int cpu_validate_features(compel_cpuinfo_t *cpu_info)
 	/*
 	 * Capability on instructions level only.
 	 */
-	if (opts.cpu_cap == CPU_CAP_INS)
+	if (opts.cpu_cap & CPU_CAP_INS)
 		return cpu_validate_ins_features(cpu_info);
 
 	/*
@@ -458,7 +458,7 @@  int cpuinfo_check(void)
 	 * still allow to check instructions only
 	 * and etc.
 	 */
-	if (!opts.cpu_cap)
+	if (opts.cpu_cap == CPU_CAP_NONE)
 		opts.cpu_cap = CPU_CAP_ALL;
 
 	if (cpu_validate_cpuinfo())
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index 44588fce7a71..4de777be655e 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -24,11 +24,11 @@ 
 /*
  * CPU capability options.
  */
-#define CPU_CAP_NONE		(0u)
-#define CPU_CAP_ALL		(-1u)
-#define CPU_CAP_FPU		(1u)		/* Only FPU capability required */
-#define CPU_CAP_CPU		(2u)		/* Strict CPU capability required */
-#define CPU_CAP_INS (4u)			/* Instructions CPU capability */
+#define CPU_CAP_NONE		(0u << 0)	/* Don't check capability at all */
+#define CPU_CAP_FPU		(1u << 0)	/* Only FPU capability required */
+#define CPU_CAP_CPU		(1u << 1)	/* Strict CPU capability required */
+#define CPU_CAP_INS		(1u << 2)	/* Instructions CPU capability */
+#define CPU_CAP_ALL		(CPU_CAP_FPU | CPU_CAP_CPU | CPU_CAP_INS)
 #define CPU_CAP_DEFAULT		(CPU_CAP_FPU)
 
 struct cg_root_opt {