Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* GCC inline ASM is 'evil'
@ 2002-11-13  0:04 Peter Petrakis
  2002-11-13  0:32 ` Falk Hueffner
  2002-11-14  6:50 ` Richard Henderson
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Petrakis @ 2002-11-13  0:04 UTC (permalink / raw)
  To: 'Axp-List

Hi Guys,

There are some inline ASM bits I'm wrestling with in the EBSDK port which
I just cant seem to figure out. Now I've read the gcc docs and looked at
examples
in the kernel and I still can't seem to get it right. I'm hoping someone here
could
shed some light on my errors.

#define INLINE static
#define ASM asm
//#include <c_asm.h>

#endif

#ifndef _WIN32
#pragma inline (atomic_inc)
#endif
INLINE int atomic_inc(int source,volatile int *dest)
{
   unsigned int temp=0,ret;
    asm ("mb;");
    while (temp==0)
    {
//          ret= ASM("ldl_l   %v0,(%a0);", dest);
            asm  ( "ldl_l %0,(%16)": "=r" (ret): "p"(dest) );

            temp= ASM("addl   %a0,1,%v0;\
                  stl_c   %v0,(%a1) ;",ret,dest);
    }
    ASM ("mb;");
    return ret;
}

The ASM line that is commented out is DU inline ASM, which actually makes sense.
On the next line is my attempt :). I 'seem' to have my  operands correctly
constrained, as best as I can figure. The error I get is.

../h/interlock.h:67: invalid `asm': operand number out of range

What does that mean??? I've tried so many different combinations that even if I
made the compiler error go away I wouldn't trust the code. What am I doing wrong
here? Thanks in advance.


Peter
--
www.linuxalpha.org	www.alphadriven.org
Peter Petrakis         Warrior/Engineer        voodoo@alphadriven.org
"<BLAM!!> Who the hell are you!? Name's Ash <click clock> Housewares..."




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GCC inline ASM is 'evil'
  2002-11-13  0:04 GCC inline ASM is 'evil' Peter Petrakis
@ 2002-11-13  0:32 ` Falk Hueffner
  2002-11-14  6:51   ` Richard Henderson
  2002-11-14  6:50 ` Richard Henderson
  1 sibling, 1 reply; 4+ messages in thread
From: Falk Hueffner @ 2002-11-13  0:32 UTC (permalink / raw)
  To: axp-list

"Peter Petrakis" <voodoo@alphadriven.org> writes:

>     asm ("mb;");

You need asm volatile here, or the compiler can optimize it away.

>     while (temp==0)
>     {
> //          ret= ASM("ldl_l   %v0,(%a0);", dest);
>             asm  ( "ldl_l %0,(%16)": "=r" (ret): "p"(dest) );
> 
>             temp= ASM("addl   %a0,1,%v0;\
>                   stl_c   %v0,(%a1) ;",ret,dest);
>     }
>     ASM ("mb;");
>     return ret;
> }
> 
> The ASM line that is commented out is DU inline ASM, which actually
> makes sense.  On the next line is my attempt :). I 'seem' to have my
> operands correctly constrained, as best as I can figure. The error I
> get is.
> 
> ../h/interlock.h:67: invalid `asm': operand number out of range
> 
> What does that mean???

Argument Nr. 16 does not exist, you only mention 2.

You probably want something like (untested):

long tmp;
asm volatile(
        "ldl_l  %2,%1\n"
        "addl   %2,1,%0\n"
        "stl_c  %0,%1\n"
        : "=r"(ret), "=m"(dest)
        : "r"(tmp));

-- 
	Falk




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GCC inline ASM is 'evil'
  2002-11-13  0:04 GCC inline ASM is 'evil' Peter Petrakis
  2002-11-13  0:32 ` Falk Hueffner
@ 2002-11-14  6:50 ` Richard Henderson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2002-11-14  6:50 UTC (permalink / raw)
  To: axp-list

On Tue, Nov 12, 2002 at 07:04:00PM -0500, Peter Petrakis wrote:
> //          ret= ASM("ldl_l   %v0,(%a0);", dest);
>             asm  ( "ldl_l %0,(%16)": "=r" (ret): "p"(dest) );
> 
>             temp= ASM("addl   %a0,1,%v0;\
>                   stl_c   %v0,(%a1) ;",ret,dest);

Incidentally, the original asm is broken as well, unless you're 
going to get guarantees from somewhere that DU won't move a 
memory access in between the ldl_l and stl_c.  You have to do
this as a single block of asm text.


r~




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GCC inline ASM is 'evil'
  2002-11-13  0:32 ` Falk Hueffner
@ 2002-11-14  6:51   ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2002-11-14  6:51 UTC (permalink / raw)
  To: axp-list

On Wed, Nov 13, 2002 at 01:32:06AM +0100, Falk Hueffner wrote:
> You probably want something like (untested):
> 
> long tmp;
> asm volatile(
>         "ldl_l  %2,%1\n"
>         "addl   %2,1,%0\n"
>         "stl_c  %0,%1\n"
>         : "=r"(ret), "=m"(dest)
>         : "r"(tmp));

tmp needs to be an output as well, since it is modified.
dest needs to be an input, since its old value isn't dead.

	asm volatile (
         "ldl_l  %2,%1\n"
         "addl   %2,1,%0\n"
         "stl_c  %0,%1\n"
	 : "=r"(ret), "=m"(dest), "=r"(tmp)
	 : "m"(dest));

		

r~




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-11-14  6:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-13  0:04 GCC inline ASM is 'evil' Peter Petrakis
2002-11-13  0:32 ` Falk Hueffner
2002-11-14  6:51   ` Richard Henderson
2002-11-14  6:50 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox