[FFmpeg-devel] [PATCH] read_time() for SPARC

Måns Rullgård mans
Wed Sep 8 22:54:43 CEST 2010


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



More information about the ffmpeg-devel mailing list