Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-benchmarks/i7z/files: i7z-0.27-cpuid.patch
Date: Wed, 31 Aug 2011 14:16:36
Message-Id: 20110831141626.5245A20051@flycatcher.gentoo.org
1 vapier 11/08/31 14:16:26
2
3 Added: i7z-0.27-cpuid.patch
4 Log:
5 Fix multiple issues with cpuid().
6
7 (Portage version: 2.2.0_alpha51/cvs/Linux x86_64)
8
9 Revision Changes Path
10 1.1 app-benchmarks/i7z/files/i7z-0.27-cpuid.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-benchmarks/i7z/files/i7z-0.27-cpuid.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-benchmarks/i7z/files/i7z-0.27-cpuid.patch?rev=1.1&content-type=text/plain
14
15 Index: i7z-0.27-cpuid.patch
16 ===================================================================
17 http://code.google.com/p/i7z/issues/detail?id=31
18
19 this makes cpuid work on 32bit and 64bit systems, both PIC and non-PIC
20
21 the things it fixes:
22 - no more silent clobbering of ebx/ecx/edx
23 - works under 32bit pic builds (gcc doesnt like to clobber ebx)
24 - ebx gets saved/restored via edi register
25 - get_vendor incorrectly used ebx,ecx,edx when it should be ebx,edx,ecx
26 - unify all the cpuid implementations to make usage much simpler
27
28 I WROTE THIS
29
30 --- a/helper_functions.c
31 +++ b/helper_functions.c
32 @@ -87,41 +87,40 @@ print_family_info (struct family_info *proc_info)
33 // printf(" Extended Family %d\n", proc_info->extended_family);
34 }
35
36 +static inline void cpuid (unsigned int info, unsigned int *eax, unsigned int *ebx,
37 + unsigned int *ecx, unsigned int *edx)
38 +{
39 + unsigned int _eax = info, _ebx, _ecx, _edx;
40 + asm volatile ("mov %%ebx, %%edi;" // save ebx (for PIC)
41 + "cpuid;"
42 + "mov %%ebx, %%esi;" // pass to caller
43 + "mov %%edi, %%ebx;" // restore ebx
44 + :"+a" (_eax), "=S" (_ebx), "=c" (_ecx), "=d" (_edx)
45 + : /* inputs: eax is handled above */
46 + :"edi" /* clobbers: we hit edi directly */);
47 + if (eax) *eax = _eax;
48 + if (ebx) *ebx = _ebx;
49 + if (ecx) *ecx = _ecx;
50 + if (edx) *edx = _edx;
51 +}
52
53 -#ifdef x64_BIT
54 void get_vendor (char *vendor_string)
55 {
56 //get vendor name
57 - unsigned int b, c, d, e;
58 - // int i;
59 - asm volatile ("mov %4, %%eax; " // 0 into eax
60 - "cpuid;" "mov %%eax, %0;" // eeax into b
61 - "mov %%ebx, %1;" // eebx into c
62 - "mov %%edx, %2;" // eeax into d
63 - "mov %%ecx, %3;" // eeax into e
64 - :"=r" (b), "=r" (c), "=r" (d), "=r" (e) /* output */
65 - :"r" (0) /* input */
66 - :"%eax", "%ebx", "%ecx", "%edx" /* clobbered register, will be modifying inside the asm routine so dont use them */
67 - );
68 - memcpy (vendor_string, &c, 4);
69 + unsigned int a, b, c, d;
70 + cpuid (0, &a, &b, &c, &d);
71 + memcpy (vendor_string, &b, 4);
72 memcpy (vendor_string + 4, &d, 4);
73 - memcpy (vendor_string + 8, &e, 4);
74 + memcpy (vendor_string + 8, &c, 4);
75 vendor_string[12] = '\0';
76 // printf("Vendor %s\n",vendor_string);
77 }
78 -#endif
79
80 int turbo_status ()
81 {
82 //turbo state flag
83 unsigned int eax;
84 - // int i;
85 - asm volatile ("mov %1, %%eax; " // 0 into eax
86 - "cpuid;" "mov %%eax, %0;" // eeax into b
87 - :"=r" (eax) /* output */
88 - :"r" (6) /* input */
89 - :"%eax" /* clobbered register, will be modifying inside the asm routine so dont use them */
90 - );
91 + cpuid (6, &eax, NULL, NULL, NULL);
92
93 //printf("eax %d\n",(eax&0x2)>>1);
94
95 @@ -132,12 +131,7 @@ void get_familyinformation (struct family_info *proc_info)
96 {
97 //get info about CPU
98 unsigned int b;
99 - asm volatile ("mov %1, %%eax; " // 0 into eax
100 - "cpuid;" "mov %%eax, %0;" // eeax into b
101 - :"=r" (b) /* output */
102 - :"r" (1) /* input */
103 - :"%eax" /* clobbered register, will be modifying inside the asm routine so dont use them */
104 - );
105 + cpuid (1, &b, NULL, NULL, NULL);
106 // printf ("eax %x\n", b);
107 proc_info->stepping = b & 0x0000000F; //bits 3:0
108 proc_info->model = (b & 0x000000F0) >> 4; //bits 7:4
109 @@ -348,7 +342,6 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge)
110 {
111 struct family_info proc_info;
112
113 -#ifdef x64_BIT
114 char vendor_string[13];
115 get_vendor (vendor_string);
116 if (strcmp (vendor_string, "GenuineIntel") == 0)
117 @@ -359,14 +352,6 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge)
118 ("this was designed to be a intel proc utility. You can perhaps mod it for your machine?\n");
119 exit (1);
120 }
121 -#endif
122 -
123 -#ifndef x64_BIT
124 - //anecdotal evidence: get_vendor doesnt seem to work on 32-bit
125 - printf
126 - ("I dont know the CPUID code to check on 32-bit OS, so i will assume that you have an Intel processor\n");
127 - printf ("Don't worry if i don't find a nehalem next, i'll quit anyways\n");
128 -#endif
129
130 get_familyinformation (&proc_info);
131 print_family_info (&proc_info);
132 --- a/i7z.h
133 +++ b/i7z.h
134 @@ -106,9 +106,7 @@ __asm__ __volatile__ ("rdtsc":"=a" (lo), "=d" (hi));
135
136 void print_family_info (struct family_info *proc_info);
137
138 -#ifdef x64_BIT
139 void get_vendor (char *vendor_string);
140 -#endif
141
142 int turbo_status ();
143 double cpufreq_info();