All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney@avtrex.com>
To: Winson Yung <winson.yung@gmail.com>
Cc: linux-mips@linux-mips.org
Subject: Re: MIPS assembly question
Date: Thu, 20 Sep 2007 16:44:28 -0700	[thread overview]
Message-ID: <46F305DC.7080106@avtrex.com> (raw)
In-Reply-To: <48413e3e0709201614pd8fc58dga6354d5d2330f288@mail.gmail.com>

Winson Yung wrote:
> Hi there, I have some general mips inline assembly question regards to
> 32 bit atomic operation, here a section of its assembly
> implementation:
> 
>                 "       .set    mips3                                   \n"
>                 "1:     ll      %0, %2                  # __cmpxchg_u32 \n"
>                 "       bne     %0, %z3, 2f                             \n"
>                 "       .set    mips0                                   \n"
>                 "       move    $1, %z4                                 \n"
>                 "       .set    mips3                                   \n"
>                 "       sc      $1, %1                                  \n"
>                 "       beqzl   $1, 1b                                  \n"
> 
> Questions:
> 
> 1) what does 'z' mean in the line of 'bne %0, %z3, 2f'?

I think this 'z' comes from print_operand() in gcc/config/mips/mips.c in 
  GCC:

    'z'	if the operand is 0, use $0 instead of normal operand.

This is an optimization so that if you are comparing against the value 
of zero, you can use $0 instead of loading up another register with the 
value of zero first.

> 2) Is $1 suppose to be use as an constant 1, I don't understand the
> line 'sc  $1, %1'

$1 is register 1.  AKA $at.

So that line is Store Conditional Word from register 1 into the memory 
location indicated by operand 1.

> 
> Will appreciate if someone can point out to me a good tutorial on
> explaining these little things.
> 

If it is not in the GCC documentation, then you have to look at the GCC 
source code.  I don't know of any better way.

David Daney

  reply	other threads:[~2007-09-20 23:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-20 23:14 MIPS assembly question Winson Yung
2007-09-20 23:44 ` David Daney [this message]
2007-09-21  9:34 ` Freddy Spierenburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46F305DC.7080106@avtrex.com \
    --to=ddaney@avtrex.com \
    --cc=linux-mips@linux-mips.org \
    --cc=winson.yung@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.