[PATCH] read_time() for SPARC
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in? -- M?ns Rullg?rd mans at mansr.com
On Tue Sep 7 22:21:56 2010 M?ns Rullg?rd wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Tue Sep 7 22:21:56 2010 M?ns Rullg?rd wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why? -- M?ns Rullg?rd mans at mansr.com
On Wed Sep 8 07:51:21 2010 M?ns Rullg?rd wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why?
The rd instruction uses only register operands and the r constraint is considered 32-bit (the rest bits are filled by the compiler). I see no register constraint which would be 64-bit with v9 and v8+. Michael
On Wed, Sep 08, 2010 at 12:41:16PM +0400, Michael Kostylev wrote:
On Wed Sep 8 07:51:21 2010 M?ns Rullg?rd wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why?
The rd instruction uses only register operands and the r constraint is considered 32-bit (the rest bits are filled by the compiler). I see no register constraint which would be 64-bit with v9 and v8+.
its under ifdef v9 and if there is such shortcomming that makes existing registers unaccessable it should be reported to the gcc devels [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Good people do not need laws to tell them to act responsibly, while bad people will find a way around the laws. -- Plato
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Wed Sep 8 07:51:21 2010 M?ns Rullg?rd wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why?
The rd instruction uses only register operands and the r constraint is considered 32-bit (the rest bits are filled by the compiler). I see no register constraint which would be 64-bit with v9 and v8+.
$ cat sparc.c long long foo() { long long tc; __asm__ ("rd %%tick, %0" : "=r"(tc)); return tc; } $ sparc64-unknown-linux-gnu-gcc -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc Disassembly of section .text: 0000000000000000 <foo>: 0: 91 41 00 00 rd %tick, %o0 4: 81 c3 e0 08 retl 8: 01 00 00 00 nop $ sparc64-unknown-linux-gnu-gcc -mv8plus -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc Disassembly of section .text: 0000000000000000 <foo>: 0: 91 41 00 00 rd %tick, %o0 4: 81 c3 e0 08 retl 8: 01 00 00 00 nop I see no problem here. The correct test for 64-bit Sparc is __arch64__, not __sparc_v9__. The latter may be defined even in a 32-bit build. -- M?ns Rullg?rd mans at mansr.com
On Wed Sep 8 21:54:43 2010 M?ns Rullg?rd wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#ifdef __sparc_v9__ + +#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0\n\t" + : "=m" (tc) :: "g1"); + return tc; +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why?
The rd instruction uses only register operands and the r constraint is considered 32-bit (the rest bits are filled by the compiler). I see no register constraint which would be 64-bit with v9 and v8+.
$ cat sparc.c long long foo() { long long tc; __asm__ ("rd %%tick, %0" : "=r"(tc)); return tc; } $ sparc64-unknown-linux-gnu-gcc -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc
Disassembly of section .text:
0000000000000000 <foo>: 0: 91 41 00 00 rd %tick, %o0 4: 81 c3 e0 08 retl 8: 01 00 00 00 nop $ sparc64-unknown-linux-gnu-gcc -mv8plus -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc
That's wrong. You must use -m32. How it looks on a real machine: % gcc -O3 -c sparc.c /tmp/ccdAPwzx.s: Assembler messages: /tmp/ccdAPwzx.s:9: Error: Architecture mismatch on "rd". /tmp/ccdAPwzx.s:9: (Requires v9|v9a|v9b; requested architecture is sparclite.) % gcc -mcpu=v9 -O3 -c sparc.c && objdump -d sparc.o
sparc.o: file format elf32-sparc
Disassembly of section .text: 00000000 <foo>: 0: 85 41 00 00 rd %tick, %g2 4: 92 10 00 03 mov %g3, %o1 8: 81 c3 e0 08 retl c: 90 10 00 02 mov %g2, %o0 Not better when inlined. % file sparc.o sparc.o: ELF 32-bit MSB relocatable, SPARC32PLUS, V8+ Required, version 1 (SYSV), not stripped Speaking of macros: % gcc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v8__ 1 % gcc -mcpu=v9 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1 % gcc -m64 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __arch64__ 1 % gcc -m64 -mcpu=ultrasparc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1 #define __arch64__ 1 -> #if defined (__sparc_v9__) || defined (__arch64__) Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Wed Sep 8 21:54:43 2010 M?ns Rullg?rd wrote:
> The attached patch provides access to a 63-bit tick counter which is > available on the v9 cpus in the manner compatible with the v8+ abi. > > +#ifndef AVUTIL_SPARC_TIMER_H > +#define AVUTIL_SPARC_TIMER_H > + > +#ifdef __sparc_v9__ > + > +#include <stdint.h> > + > +#define AV_READ_TIME read_time > + > +static inline uint64_t read_time(void) > +{ > + uint64_t tc; > + __asm__ volatile("rd %%tick,%%g1\n\t" > + "stx %%g1,%0\n\t" > + : "=m" (tc) :: "g1"); > + return tc; > +}
Why can't you read the counter directly to whatever register 'tc' lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why?
The rd instruction uses only register operands and the r constraint is considered 32-bit (the rest bits are filled by the compiler). I see no register constraint which would be 64-bit with v9 and v8+.
$ cat sparc.c long long foo() { long long tc; __asm__ ("rd %%tick, %0" : "=r"(tc)); return tc; } $ sparc64-unknown-linux-gnu-gcc -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc
Disassembly of section .text:
0000000000000000 <foo>: 0: 91 41 00 00 rd %tick, %o0 4: 81 c3 e0 08 retl 8: 01 00 00 00 nop $ sparc64-unknown-linux-gnu-gcc -mv8plus -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc
That's wrong. You must use -m32. How it looks on a real machine:
-m32 usually implies a pure 32-bit build. 64-bit registers will of course not be used with such settings. The whole v8+ thing is thoroughly confusing too.
% gcc -O3 -c sparc.c /tmp/ccdAPwzx.s: Assembler messages: /tmp/ccdAPwzx.s:9: Error: Architecture mismatch on "rd". /tmp/ccdAPwzx.s:9: (Requires v9|v9a|v9b; requested architecture is sparclite.)
% gcc -mcpu=v9 -O3 -c sparc.c && objdump -d sparc.o
sparc.o: file format elf32-sparc
Disassembly of section .text:
00000000 <foo>: 0: 85 41 00 00 rd %tick, %g2 4: 92 10 00 03 mov %g3, %o1 8: 81 c3 e0 08 retl c: 90 10 00 02 mov %g2, %o0
That is exactly what I'd expect from a 32-bit build that happens to be running on a 64-bit machine.
Not better when inlined.
% file sparc.o sparc.o: ELF 32-bit MSB relocatable, SPARC32PLUS, V8+ Required, version 1 (SYSV), not stripped
Speaking of macros:
% gcc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v8__ 1
% gcc -mcpu=v9 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is a 32-bit build optimised for v9 CPU. Makes sense.
% gcc -m64 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __arch64__ 1
Unspecified 64-bit CPU.
% gcc -m64 -mcpu=ultrasparc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1 #define __arch64__ 1
-> #if defined (__sparc_v9__) || defined (__arch64__)
You are contradicting yourself. The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does. If the rd instruction requires a v9 CPU, the test should be for __sparc_v9__ && __arch64__. -- M?ns Rullg?rd mans at mansr.com
On Thu Sep 9 11:31:15 2010 M?ns Rullg?rd wrote:
>> The attached patch provides access to a 63-bit tick counter which is >> available on the v9 cpus in the manner compatible with the v8+ abi. >> >> +#ifndef AVUTIL_SPARC_TIMER_H >> +#define AVUTIL_SPARC_TIMER_H >> + >> +#ifdef __sparc_v9__ >> + >> +#include <stdint.h> >> + >> +#define AV_READ_TIME read_time >> + >> +static inline uint64_t read_time(void) >> +{ >> + uint64_t tc; >> + __asm__ volatile("rd %%tick,%%g1\n\t" >> + "stx %%g1,%0\n\t" >> + : "=m" (tc) :: "g1"); >> + return tc; >> +} > >Why can't you read the counter directly to whatever register 'tc' >lives in?
That will not work with v8+, tc will be filled with the least significant 32 bits.
Why?
The rd instruction uses only register operands and the r constraint is considered 32-bit (the rest bits are filled by the compiler). I see no register constraint which would be 64-bit with v9 and v8+.
$ cat sparc.c long long foo() { long long tc; __asm__ ("rd %%tick, %0" : "=r"(tc)); return tc; } $ sparc64-unknown-linux-gnu-gcc -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc
Disassembly of section .text:
0000000000000000 <foo>: 0: 91 41 00 00 rd %tick, %o0 4: 81 c3 e0 08 retl 8: 01 00 00 00 nop $ sparc64-unknown-linux-gnu-gcc -mv8plus -O3 -c sparc.c && sparc64-unknown-linux-gnu-objdump -d sparc.o sparc.o: file format elf64-sparc
That's wrong. You must use -m32. How it looks on a real machine:
-m32 usually implies a pure 32-bit build. 64-bit registers will of course not be used with such settings. The whole v8+ thing is thoroughly confusing too.
% gcc -O3 -c sparc.c /tmp/ccdAPwzx.s: Assembler messages: /tmp/ccdAPwzx.s:9: Error: Architecture mismatch on "rd". /tmp/ccdAPwzx.s:9: (Requires v9|v9a|v9b; requested architecture is sparclite.)
% gcc -mcpu=v9 -O3 -c sparc.c && objdump -d sparc.o
sparc.o: file format elf32-sparc
Disassembly of section .text:
00000000 <foo>: 0: 85 41 00 00 rd %tick, %g2 4: 92 10 00 03 mov %g3, %o1 8: 81 c3 e0 08 retl c: 90 10 00 02 mov %g2, %o0
That is exactly what I'd expect from a 32-bit build that happens to be running on a 64-bit machine.
Not better when inlined.
% file sparc.o sparc.o: ELF 32-bit MSB relocatable, SPARC32PLUS, V8+ Required, version 1 (SYSV), not stripped
Speaking of macros:
% gcc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v8__ 1
% gcc -mcpu=v9 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is a 32-bit build optimised for v9 CPU. Makes sense.
% gcc -m64 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __arch64__ 1
Unspecified 64-bit CPU.
% gcc -m64 -mcpu=ultrasparc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1 #define __arch64__ 1
-> #if defined (__sparc_v9__) || defined (__arch64__)
You are contradicting yourself.
Nope.
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
If the rd instruction requires a v9 CPU, the test should be for __sparc_v9__ && __arch64__.
The v9 abi is usable only on the appropriate hardware. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
Exactly, and without the v9 ABI we can't use 64-bit registers.
If the rd instruction requires a v9 CPU, the test should be for __sparc_v9__ && __arch64__.
The v9 abi is usable only on the appropriate hardware.
Yes, the v9 ABI requires support from both hardware and system software. If either is missing, it cannot be used. -- M?ns Rullg?rd mans at mansr.com
On Thu Sep 9 11:59:55 2010 M?ns Rullg?rd wrote:
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
Exactly, and without the v9 ABI we can't use 64-bit registers.
We can with v8+ and we do. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Thu Sep 9 11:59:55 2010 M?ns Rullg?rd wrote:
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
Exactly, and without the v9 ABI we can't use 64-bit registers.
We can with v8+ and we do.
Absurd, and gcc appears to disagree. -- M?ns Rullg?rd mans at mansr.com
On Thu Sep 9 12:15:05 2010 M?ns Rullg?rd wrote:
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
Exactly, and without the v9 ABI we can't use 64-bit registers.
We can with v8+ and we do.
"SPARC V8PLUS ABI Restrictions [...] The rest of the register restrictions remain unchanged from SPARC V8 ABI. However, the global registers are 64-bit registers and may be used as such by user programs."
Absurd, and gcc appears to disagree.
If it does not use the 64-bit general regs when it is meaningful then gcc sucks. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Thu Sep 9 12:15:05 2010 M?ns Rullg?rd wrote:
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
Exactly, and without the v9 ABI we can't use 64-bit registers.
We can with v8+ and we do.
"SPARC V8PLUS ABI Restrictions [...] The rest of the register restrictions remain unchanged from SPARC V8 ABI. However, the global registers are 64-bit registers and may be used as such by user programs."
Please explain the meaning of "global register".
Absurd, and gcc appears to disagree.
If it does not use the 64-bit general regs when it is meaningful then gcc sucks.
That would hardly be a surprise. Anyhow, the memory store in your patch is clearly not needed in some configurations. We should detect these and use the efficient way there. -- M?ns Rullg?rd mans at mansr.com
On Thu, 9 Sep 2010, M?ns Rullg?rd wrote:
Michael Kostylev <michael.kostylev at gmail.com> writes:
The presence of __sparc_v9__ clearly does not imply we are allowed to use 64-bit registers; __arch64__ does.
__sparc_v9__ means the v9 hardware, __arch64__ means the v9 abi.
Exactly, and without the v9 ABI we can't use 64-bit registers.
This is inaccurate. See: http://developers.sun.com/solaris/articles/sparcv9abi.html Specifically, global registers (g0-g7) are 64-bit in (the poorly documented) v8plus ABI. -Jeff
On Thu, 9 Sep 2010, M?ns Rullg?rd wrote:
Michael Kostylev <michael.kostylev at gmail.com> writes:
Disassembly of section .text:
% gcc -O3 -c sparc.c /tmp/ccdAPwzx.s: Assembler messages: /tmp/ccdAPwzx.s:9: Error: Architecture mismatch on "rd". /tmp/ccdAPwzx.s:9: (Requires v9|v9a|v9b; requested architecture is sparclite.)
% gcc -mcpu=v9 -O3 -c sparc.c && objdump -d sparc.o
sparc.o: file format elf32-sparc
Disassembly of section .text:
00000000 <foo>: 0: 85 41 00 00 rd %tick, %g2 4: 92 10 00 03 mov %g3, %o1 8: 81 c3 e0 08 retl c: 90 10 00 02 mov %g2, %o0
That is exactly what I'd expect from a 32-bit build that happens to be running on a 64-bit machine.
This will yield incorrect results on 32-bit builds. Michael's original implementation will work properly on any v9 cpu compiled as either 32 or 64-bit binaries when using v8plus isa or higher. The implementation offered by Mans will only function properly on 64-bit compilations. This is obviously the optimal implementation for 64-bit builds. I see no way to coerce gcc into proper interpretation of the %gX registers as being able to contain a 64-bit C variable in 32-bit, v8plus, builds; the "h" constraint doesn't appear to influence this as one might hope. gcc simply treats the C variable as a register pair on exit of the inline asm as shown above. -Jeff
Jeff Downs <heydowns at somuchpressure.net> writes:
This will yield incorrect results on 32-bit builds. Michael's original implementation will work properly on any v9 cpu compiled as either 32 or 64-bit binaries when using v8plus isa or higher. The implementation offered by Mans will only function properly on 64-bit compilations. This is obviously the optimal implementation for 64-bit builds.
Since the optimal implementation apparently differs depending on something, we must somehow detect whatever it is and supply the corresponding code. I'm getting tired of repeating this. Now I've given up trying to guess how to do this. Every mail you guys send only makes me more confused. I have also made a note to never, ever go near a Sparc system. -- M?ns Rullg?rd mans at mansr.com
On Thu, 9 Sep 2010, Michael Kostylev wrote:
Speaking of macros:
% gcc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v8__ 1
While not particularly relevant to the ongoing discussion, for completeness please note this is only true for gcc >= 4.2. On earlier versions, __sparc_v8__ will not be defined. Also, for Sparc/Solaris, it is __sparcv8.
% gcc -mcpu=v9 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
More relevant here, the above is not the case with any (32-bit defaulting) gcc I tried on Sparc/Solaris. The __sparc_v9__ define is not present, only __sparcv8
% gcc -m64 -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __arch64__ 1
Here, sparc/solaris adds __sparcv9
% gcc -m64 -mcpu=ultrasparc -E -xc -dM /dev/null | grep 'arch\|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1 #define __arch64__ 1
And here results are the same except that it is __sparcv9 for Sparc/Solaris. -Jeff
On Wed, Sep 08, 2010 at 01:08:57AM +0400, Michael Kostylev wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
Michael
sparc/timer.h | 41 +++++++++++++++++++++++++++++++++++++++++ timer.h | 2 ++ 2 files changed, 43 insertions(+) 555a36c6bda504671f232b6e9433e4f429a2e3fd sparc-timer.diff
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first but 1 unneeded instruction in code that is used primarely for debuging and otherwise is in no way speed critical and on a rare arch is not worth the work&discussion here [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The real ebay dictionary, page 3 "Rare item" - "Common item with rare defect or maybe just a lie" "Professional" - "'Toy' made in china, not functional except as doorstop" "Experts will know" - "The seller hopes you are not an expert"
Michael Niedermayer <michaelni at gmx.at> writes:
On Wed, Sep 08, 2010 at 01:08:57AM +0400, Michael Kostylev wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
Michael
sparc/timer.h | 41 +++++++++++++++++++++++++++++++++++++++++ timer.h | 2 ++ 2 files changed, 43 insertions(+) 555a36c6bda504671f232b6e9433e4f429a2e3fd sparc-timer.diff
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
but 1 unneeded instruction in code that is used primarely for debuging and otherwise is in no way speed critical and on a rare arch is not worth the work&discussion here
If two or three extra lines can make it optimal, I think that should be done. -- M?ns Rullg?rd mans at mansr.com
On Thu, Sep 09, 2010 at 10:01:44PM +0100, M?ns Rullg?rd wrote:
Michael Niedermayer <michaelni at gmx.at> writes:
On Wed, Sep 08, 2010 at 01:08:57AM +0400, Michael Kostylev wrote:
The attached patch provides access to a 63-bit tick counter which is available on the v9 cpus in the manner compatible with the v8+ abi.
Michael
sparc/timer.h | 41 +++++++++++++++++++++++++++++++++++++++++ timer.h | 2 ++ 2 files changed, 43 insertions(+) 555a36c6bda504671f232b6e9433e4f429a2e3fd sparc-timer.diff
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
but 1 unneeded instruction in code that is used primarely for debuging and otherwise is in no way speed critical and on a rare arch is not worth the work&discussion here
If two or three extra lines can make it optimal, I think that should be done.
iam not against it if someone wants to do it but i dont think its reasonable to require it [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Avoid a single point of failure, be that a person or equipment.
On Thu Sep 9 22:01:44 2010 M?ns Rullg?rd wrote:
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
Redone. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Thu Sep 9 22:01:44 2010 M?ns Rullg?rd wrote:
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
Redone.
Michael
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right: $ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
+#include <stdint.h> + +#define AV_READ_TIME read_time + +static inline uint64_t read_time(void) +{ + uint64_t tc; + +#ifdef __arch64__ + __asm__ volatile("rd %%tick,%0" : "=r" (tc)); +#else + __asm__ volatile("rd %%tick,%%g1\n\t" + "stx %%g1,%0" + : "=m" (tc) :: "g1"); +#endif /* __arch64__ */ + + return tc; +}
Now that wasn't so hard, was it? -- M?ns Rullg?rd mans at mansr.com
On Fri Sep 10 08:59:27 2010 M?ns Rullg?rd wrote:
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
Redone.
Michael
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right:
There is an issue with -m32 on Solaris.
$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2. Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Fri Sep 10 08:59:27 2010 M?ns Rullg?rd wrote:
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
Redone.
Michael
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right:
There is an issue with -m32 on Solaris.
I don't understand.
$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2.
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch. -- M?ns Rullg?rd mans at mansr.com
On Fri Sep 10 09:47:34 2010 M?ns Rullg?rd wrote:
if the only issue left is the sometimes unneeded stx instruction then i approve the patch with this. If there are other issues they of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
Redone.
Michael
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right:
There is an issue with -m32 on Solaris.
I don't understand.
As mentioned, __sparc_v9__ is never defined there.
$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2.
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well. Anyway, there is no such problem on Sparc. Anything else? Michael
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Fri Sep 10 09:47:34 2010 M?ns Rullg?rd wrote:
> if the only issue left is the sometimes unneeded stx instruction > then i approve the patch with this. If there are other issues they > of course have to be fixed first
Apparently the ifdef test in the patch is not reliable.
Redone.
Michael
+#ifndef AVUTIL_SPARC_TIMER_H +#define AVUTIL_SPARC_TIMER_H + +#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right:
There is an issue with -m32 on Solaris.
I don't understand.
As mentioned, __sparc_v9__ is never defined there.
That does not make __sparc_v9__ alone a sufficient condition for using 64-bit registers.
$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2.
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well. Anyway, there is no such problem on Sparc. Anything else?
A 32-bit kernel on Sparc will only preserve the low 32 bits of the registers. How could it possibly do otherwise? Or is such a system impossible for some reason? -- M?ns Rullg?rd mans at mansr.com
On Fri, Sep 10, 2010 at 10:46:45AM +0100, M?ns Rullg?rd wrote: [...]
$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2.
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well. Anyway, there is no such problem on Sparc. Anything else?
A 32-bit kernel on Sparc will only preserve the low 32 bits of the registers. How could it possibly do otherwise? Or is such a system impossible for some reason?
i dont know about sparc but a cpu surely could provide means to save and restore future registers. that could be by instructions that just do the save and restore or by a function in rom of teh cpu somewhere that one can call id even say a well designed cpu should do that unless the additional complexity is an issue [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB There will always be a question for which you do not know the correct awnser.
Michael Niedermayer <michaelni at gmx.at> writes:
On Fri, Sep 10, 2010 at 10:46:45AM +0100, M?ns Rullg?rd wrote: [...]
$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' #define sparc 1 #define __sparc__ 1 #define __sparc 1 #define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2.
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well. Anyway, there is no such problem on Sparc. Anything else?
A 32-bit kernel on Sparc will only preserve the low 32 bits of the registers. How could it possibly do otherwise? Or is such a system impossible for some reason?
i dont know about sparc but a cpu surely could provide means to save and restore future registers. that could be by instructions that just do the save and restore or by a function in rom of teh cpu somewhere that one can call id even say a well designed cpu should do that unless the additional complexity is an issue
How would you manage the unknown amount of memory required for this? -- M?ns Rullg?rd mans at mansr.com
On Fri, Sep 10, 2010 at 01:05:08PM +0100, M?ns Rullg?rd wrote:
Michael Niedermayer <michaelni at gmx.at> writes:
On Fri, Sep 10, 2010 at 10:46:45AM +0100, M?ns Rullg?rd wrote: [...]
>$ sparc-unknown-linux-gnu-gcc -m32 -mcpu=v9 -mno-v8plus -dM -E -xc /dev/null | grep -E 'arch|sparc' >#define sparc 1 >#define __sparc__ 1 >#define __sparc 1 >#define __sparc_v9__ 1
This is as right as xor rax,rax in an i386 binary built with -march=core2.
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well. Anyway, there is no such problem on Sparc. Anything else?
A 32-bit kernel on Sparc will only preserve the low 32 bits of the registers. How could it possibly do otherwise? Or is such a system impossible for some reason?
i dont know about sparc but a cpu surely could provide means to save and restore future registers. that could be by instructions that just do the save and restore or by a function in rom of teh cpu somewhere that one can call id even say a well designed cpu should do that unless the additional complexity is an issue
How would you manage the unknown amount of memory required for this?
that could be just stored in rom or returned by an instruction or there could be enough reserved space in previous cpu generations [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides
On Fri, 10 Sep 2010, M?ns Rullg?rd wrote:
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Fri Sep 10 09:47:34 2010 M?ns Rullg?rd wrote:
[...]
+#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right:
There is an issue with -m32 on Solaris.
I don't understand.
As mentioned, __sparc_v9__ is never defined there.
That does not make __sparc_v9__ alone a sufficient condition for using 64-bit registers.
As far as I can tell, there is no reliably set macro to indicate that v8plus is in use on Solaris. SunCC sets a macro (__v8plus or similar, IIRC) but gcc does not emulate this behavior.
Jeff Downs <heydowns at somuchpressure.net> writes:
On Fri, 10 Sep 2010, M?ns Rullg?rd wrote:
Michael Kostylev <michael.kostylev at gmail.com> writes:
On Fri Sep 10 09:47:34 2010 M?ns Rullg?rd wrote:
[...]
> +#if defined(__arch64__) || defined(__sparc_v9__)
I'm still not convinced this is right:
There is an issue with -m32 on Solaris.
I don't understand.
As mentioned, __sparc_v9__ is never defined there.
That does not make __sparc_v9__ alone a sufficient condition for using 64-bit registers.
As far as I can tell, there is no reliably set macro to indicate that v8plus is in use on Solaris. SunCC sets a macro (__v8plus or similar, IIRC) but gcc does not emulate this behavior.
Bummer. Is a configure test possible? This could be useful to know for other purposes than reading the timer. -- M?ns Rullg?rd mans at mansr.com
On Fri, 10 Sep 2010, M?ns Rullg?rd wrote:
Jeff Downs <heydowns at somuchpressure.net> writes:
As far as I can tell, there is no reliably set macro to indicate that v8plus is in use on Solaris. SunCC sets a macro (__v8plus or similar, IIRC) but gcc does not emulate this behavior.
Bummer. Is a configure test possible?
This could be useful to know for other purposes than reading the timer.
Should be, yes. I think it can be as simple as an asm() with your favorite v8plus/v9 instruction, as the assembler will reject it when gcc is told to target a pre-v9 CPU. Of course, this is with the Solaris assembler (the gcc-preferred assembler on Sparc/Solaris); someone might want to check with a GNU binutils-based toolchain (on Sparc/Linux). $ echo 'int main() { __asm__("sllx %%g1, 1, %%g1\n\t" ::: "g1"); }' | /usr/local/gcc440/bin/gcc -mcpu=v8 -m32 -x c - /usr/ccs/bin/as: "/var/tmp//ccKwiHyS.s", line 10: error: cannot use v8plus instructions in a non-v8plus target binary However, using -mcpu=v9 instead will compile fine (as it also would with -m64): $ echo 'int main() { __asm__("sllx %%g1, 1, %%g1\n\t" ::: "g1"); }' | /usr/local/gcc440/bin/gcc -mcpu=v9 -m32 -x c - BTW - in reality, pretty much any Sparc system running today will support these instructions. Pre-v9 CPUs haven't been sold (by Sun anyway) in roughly 15 years afaik. Of course, compilers much more recent than this (gcc < 4.2) will still generate code restricted to v8 or prior by default, so the configure check is still probably a good idea if we do proceed to use v8plus instructions. -Jeff
On Fri, Sep 10, 2010 at 01:32:07PM +0400, Michael Kostylev wrote:
On Fri Sep 10 09:47:34 2010 M?ns Rullg?rd wrote:
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well.
And it won't enable SSE either. Which has the additional advantage that a kernel can avoid restoring and saving again the SSE state if the program doesn't use it during its slice. Handling CPU extensions with forward-, backward- and other compatibility is one of the very few things where others could take a lesson from x86.
Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:
On Fri, Sep 10, 2010 at 01:32:07PM +0400, Michael Kostylev wrote:
On Fri Sep 10 09:47:34 2010 M?ns Rullg?rd wrote:
Yes, that instruction would be invalid there. In a pure 32-bit environment, you can't use the high half of 64-bit registers, even if they are physically present. Consider what happens on a context switch.
An ancient kernel will not preserve the sse registers as well.
And it won't enable SSE either.
Which means you can't use SSE at all on such a kernel, regardless of the CPU it's running on.
Which has the additional advantage that a kernel can avoid restoring and saving again the SSE state if the program doesn't use it during its slice. Handling CPU extensions with forward-, backward- and other compatibility is one of the very few things where others could take a lesson from x86.
Lazy FPU context switching is a pretty standard trick used on most architectures with an FPU. Also, the compatible at all cost line is one I'm quite happy others haven't followed. -- M?ns Rullg?rd mans at mansr.com
participants (5)
-
heydowns@somuchpressure.net -
mans@mansr.com -
michael.kostylev@gmail.com -
michaelni@gmx.at -
Reimar.Doeffinger@gmx.de