Skip to contentSkip to conversation

Mutex fast-path implementation sh4a

DISCUSSION michael 2 participants 3 messages Nov 19, 2008 – Nov 20, 2008 SuperH

lore
Share & tools
lore

michael

author
#0 lore raw

Hi,

I'm not an expert of sh4 assembler instruction on gcc, but I figure out how to implement
the fastpath_lock and trylock, and I obtain this code:

static inline void
__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))

{
        int __res;

        __asm__ __volatile__ (

                "movli.l        @%1, %0 \n\t"
                "dt             %0      \n\t"
                "movco.l        %0, @%1 \n\t"
                : "=&z" (__res)
                : "r" (&(count)->counter)
                : "t" );

        if (unlikely(__res != count->counter))
                fail_fn(count);
}

The retval function is very quite similar to this one. I don't find documentation about sh assembler,
can someone point me out to documentation?
The start point was the arm implementation and the arch/sh/include/asm/atomic-llsc.h file.

Can be a correct implementation?

Regards Michael

#1 lore raw
Quoted 8 lines · michael

Hi,

I'm not an expert of sh4 assembler instruction on gcc, but I figure out how to implement
the fastpath_lock and trylock, and I obtain this code:

static inline void
__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))

Quoted 16 lines
{
       int __res;

       __asm__ __volatile__ (

               "movli.l        @%1, %0 \n\t"
               "dt             %0      \n\t"
               "movco.l        %0, @%1 \n\t"
               : "=&z" (__res)
               : "r" (&(count)->counter)
               : "t" );

       if (unlikely(__res != count->counter))
               fail_fn(count);
}

The assembly looks fine, but you probably want to change the __res test to something like:

	if (unlikely(__res != 0))
		fail_fn(count);

Given that you already have the counter value implemented there. This will save you an additional memory access due to the fact the atomic counter is volatile.

When you are implementing this, you should also include the comment from ARM, as the single-pass atomic sequence without looping semantics aren't entirely obvious without it.

Quoted 3 lines

The retval function is very quite similar to this one. I don't find documentation about sh assembler,
can someone point me out to documentation?

What sort of documentation are you looking for? A good start is the SH-4A software manual, which you can find the pdf for from any SH-4A part specification download. If you are particularly concerned about inline assembly, then you need to look at the GCC manual for SH-specific information. Anything else you can feel free to ask on the list.

#2 lore raw
In reply to michael

Hi,
...

Quoted 4 lines

When you are implementing this, you should also include the comment from ARM, as the single-pass atomic sequence without looping semantics aren't entirely obvious without it.

I change the comment in the pathes that I already send.

Quoted 5 lines
Quoted 3 lines

The retval function is very quite similar to this one. I don't find documentation about sh assembler,
can someone point me out to documentation?

What sort of documentation are you looking for? A good start is the SH-4A

I have downloaded that one, thanks.

Quoted 4 lines

software manual, which you can find the pdf for from any SH-4A part specification download. If you are particularly concerned about inline assembly, then you need to look at the GCC manual for SH-specific information. Anything else you can feel free to ask on the list.

I don't find it, but I will take a look at google.

Regards Michael

Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo