From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58]) by dpdk.org (Postfix) with ESMTP id 596AD4C6E for ; Thu, 20 Mar 2014 12:41:00 +0100 (CET) Received: from hmsreliant.think-freely.org ([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1WQbMi-0004hr-Cx; Thu, 20 Mar 2014 07:42:31 -0400 From: Neil Horman To: dev@dpdk.org Date: Thu, 20 Mar 2014 07:42:13 -0400 Message-Id: <1395315733-8108-1-git-send-email-nhorman@tuxdriver.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1395175414-25232-1-git-send-email-nhorman@tuxdriver.com> References: <1395175414-25232-1-git-send-email-nhorman@tuxdriver.com> X-Spam-Score: -2.9 (--) X-Spam-Status: No Cc: "H. Peter Anvin" Subject: [dpdk-dev] [PATCH v3] eal: Fix up assembly for x86_64 in rte_cpu_get_features X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Mar 2014 11:41:00 -0000 x86_64 doesn't need to save off and restore ebx when issuing cpuid, since x86_64 uses RIP relative addressing. Doing the save actually clobbers the lower half of rbx, which could be used and not saved off independently, leading to undefined behavior. Fix up the defines so that for x86_64 we just issue the cpuid instruction, which is safe. Also, while we're at it, lets clean up the input and output constraints on the inline asm, so that we don't load registers that the cpuid instruction isn't sensitive to. Note that this patch does alter the API, in that specifcations to ebx and edx are ignored. I chose to go ahead and do that because there is only a single caller of this function and neither register is ever written currently. Signed-off-by: Neil Horman CC: "H. Peter Anvin" --- lib/librte_eal/common/eal_common_cpuflags.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/eal_common_cpuflags.c b/lib/librte_eal/common/eal_common_cpuflags.c index 1ebf78c..0a18d53 100644 --- a/lib/librte_eal/common/eal_common_cpuflags.c +++ b/lib/librte_eal/common/eal_common_cpuflags.c @@ -192,7 +192,7 @@ rte_cpu_get_features(struct cpuid_parameters_t params) { int eax, ebx, ecx, edx; /* registers */ -#ifndef __PIC__ +#if !defined(__PIC__) || !defined(__i386__) asm volatile ("cpuid" /* output */ : "=a" (eax), @@ -201,23 +201,19 @@ rte_cpu_get_features(struct cpuid_parameters_t params) "=d" (edx) /* input */ : "a" (params.eax), - "b" (params.ebx), - "c" (params.ecx), - "d" (params.edx)); + "c" (params.ecx)); #else asm volatile ( - "mov %%ebx, %%edi\n" + "mov %%ebx, %0\n" "cpuid\n" - "xchgl %%ebx, %%edi;\n" - : "=a" (eax), - "=D" (ebx), + "xchgl %%ebx, %0\n" + : "=r" (ebx), + "=a" (eax), "=c" (ecx), "=d" (edx) /* input */ : "a" (params.eax), - "D" (params.ebx), - "c" (params.ecx), - "d" (params.edx)); + "c" (params.ecx)); #endif switch (params.return_register) { -- 1.8.3.1