Skip to contentSkip to conversation

x86: Simplify calls to cpuid by using + for in/out constraints

PATCH In review Josh Triplett 2 participants 3 messages Aug 8, 2009 – Aug 9, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Simplify calls to cpuid by using + for in/out constraints

---

Build-tested only.

 arch/x86/include/asm/processor.h |    7 +++----
 arch/x86/xen/enlighten.c         |    7 +++----
 2 files changed, 6 insertions(+), 8 deletions(-)
arch/x86/include/asm/processor.h +3 -4
index c776826..dfa947e 100644
@@ -180,11 +180,10 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
 {
 	/* ecx is often an input as well as an output. */
 	asm("cpuid"
-	    : "=a" (*eax),
+	    : "+a" (*eax),
 	      "=b" (*ebx),
-	      "=c" (*ecx),
-	      "=d" (*edx)
-	    : "0" (*eax), "2" (*ecx));
+	      "+c" (*ecx),
+	      "=d" (*edx));
 }
 
 static inline void load_cr3(pgd_t *pgdir)
arch/x86/xen/enlighten.c +3 -4
index 6ee2ef8..6eab164 100644
@@ -190,11 +190,10 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx,
 	}
 
 	asm(XEN_EMULATE_PREFIX "cpuid"
-		: "=a" (*ax),
+		: "+a" (*ax),
 		  "=b" (*bx),
-		  "=c" (*cx),
-		  "=d" (*dx)
-		: "0" (*ax), "2" (*cx));
+		  "+c" (*cx),
+		  "=d" (*dx));
 
 	*cx &= maskecx;
 	*dx &= maskedx;
Signature · 1 line
1.5.6.5
#1 lore raw

I would prefer to not apply this patch unless there is a good reason. The existing code isn't broken, and any time we change an asm() statement we risk triggering bugs in some obscure gcc version.

It isn't, of course, that the proposed change is wrong, but simply that it is an unnecessary change, and since it involves asm() statements I would like to reject it for churn reduction reasons. Especially so since it is "build-tested only".

-hpa

Quoted 47 lines · Josh Triplett

---

Build-tested only.

 arch/x86/include/asm/processor.h |    7 +++----
 arch/x86/xen/enlighten.c         |    7 +++----
 2 files changed, 6 insertions(+), 8 deletions(-)
arch/x86/include/asm/processor.h +3 -4
index c776826..dfa947e 100644
@@ -180,11 +180,10 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
 {
 	/* ecx is often an input as well as an output. */
 	asm("cpuid"
-	    : "=a" (*eax),
+	    : "+a" (*eax),
 	      "=b" (*ebx),
-	      "=c" (*ecx),
-	      "=d" (*edx)
-	    : "0" (*eax), "2" (*ecx));
+	      "+c" (*ecx),
+	      "=d" (*edx));
 }
 
 static inline void load_cr3(pgd_t *pgdir)
arch/x86/xen/enlighten.c +3 -4
index 6ee2ef8..6eab164 100644
@@ -190,11 +190,10 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx,
 	}
 
 	asm(XEN_EMULATE_PREFIX "cpuid"
-		: "=a" (*ax),
+		: "+a" (*ax),
 		  "=b" (*bx),
-		  "=c" (*cx),
-		  "=d" (*dx)
-		: "0" (*ax), "2" (*cx));
+		  "+c" (*cx),
+		  "=d" (*dx));
 
 	*cx &= maskecx;
 	*dx &= maskedx;
#2 lore raw
Quoted 3 lines · H. Peter Anvin

I would prefer to not apply this patch unless there is a good reason. The existing code isn't broken, and any time we change an asm() statement we risk triggering bugs in some obscure gcc version.

Fair enough.

Quoted 4 lines

It isn't, of course, that the proposed change is wrong, but simply that it is an unnecessary change, and since it involves asm() statements I would like to reject it for churn reduction reasons. Especially so since it is "build-tested only".

Given the risk of "bugs in some obscure gcc version", it doesn't seem like running it or even comparing for identical code would validate anything more than the correctness of the gcc version currently in use.

- Josh triplett