Linux MIPS Architecture development
 help / color / mirror / Atom feed
* How to emulate lw/sw instruction by lb/sb instruction
@ 2006-09-25  0:41 william_lei
  2006-09-25  6:03 ` Florian Fainelli
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: william_lei @ 2006-09-25  0:41 UTC (permalink / raw)
  To: linux-mips

Dear all
      Could someone tell me how to modify GCC as titled?because we have met
problem while porting some middleware,which will generate some lw/sw
instruction to unaligned address,so I would modify GCC to not generate
lw/sw instructions for this pieces code.
Regards
William Lei

************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any
attachments) may be confidential, proprietary, privileged, or otherwise
exempt from disclosure under applicable laws. It is intended to be conveyed
only to the designated recipient(s). Any use, dissemination, distribution,
printing, retaining or copying of this e-mail (including its attachments)
by unintended recipient(s) is strictly prohibited and may be unlawful. If
you are not an intended recipient of this e-mail, or believe that you have
received this e-mail in error, please notify the sender immediately (by
replying to this e-mail), delete any and all copies of this e-mail
(including any attachments) from your system, and do not disclose the
content of this e-mail to any other person. Thank you!

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

* Re: How to emulate lw/sw instruction by lb/sb instruction
  2006-09-25  0:41 How to emulate lw/sw instruction by lb/sb instruction william_lei
@ 2006-09-25  6:03 ` Florian Fainelli
  2006-09-25 10:49 ` Ulrich Eckhardt
  2006-09-25 11:05 ` Ralf Baechle
  2 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2006-09-25  6:03 UTC (permalink / raw)
  To: william_lei; +Cc: linux-mips

[-- Attachment #1: Type: text/plain, Size: 2159 bytes --]

Hi William,

As far as I know, there is the nonmips project [1] which is providing a 
toolchain for mips clones such as the Lexra 5280 we can find in Realtek 865x 
SoC for instance. This SoC does not have lw/sw instruction set.

The Realtek 8181 project also provide a patch to emulate those instructions by 
the kernel, see [2].

Hope this helps !

[1] http://nonmips.sourceforge.net/
[2] http://rtl8181.sourceforge.net/


Le lundi 25 septembre 2006 02:41, william_lei@ali.com.tw a écrit :
> Dear all
>       Could someone tell me how to modify GCC as titled?because we have met
> problem while porting some middleware,which will generate some lw/sw
> instruction to unaligned address,so I would modify GCC to not generate
> lw/sw instructions for this pieces code.
> Regards
> William Lei
>
> ************* Email Confidentiality Notice ********************
>
> The information contained in this e-mail message (including any
> attachments) may be confidential, proprietary, privileged, or otherwise
> exempt from disclosure under applicable laws. It is intended to be conveyed
> only to the designated recipient(s). Any use, dissemination, distribution,
> printing, retaining or copying of this e-mail (including its attachments)
> by unintended recipient(s) is strictly prohibited and may be unlawful. If
> you are not an intended recipient of this e-mail, or believe that you have
> received this e-mail in error, please notify the sender immediately (by
> replying to this e-mail), delete any and all copies of this e-mail
> (including any attachments) from your system, and do not disclose the
> content of this e-mail to any other person. Thank you!

-- 
Cordialement, Florian Fainelli
---------------------------------------------
5, rue Charles Fourier
Chambre 1202
91011 Evry
http://www.alphacore.net
(+33) 01 60 76 64 21
(+33) 06 09 02 64 95
---------------------------------------------
Association MiNET
http://www.minet.net
---------------------------------------------
Institut National des Télécommunications
http://www.int-evry.fr/telecomint
---------------------------------------------

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: How to emulate lw/sw instruction by lb/sb instruction
       [not found] <001401c6e07e$8b07c080$10eca8c0@grendel>
@ 2006-09-25 10:35 ` william_lei
  2006-09-25 16:11   ` Maciej W. Rozycki
  2006-09-27 20:14   ` Jim Wilson
  0 siblings, 2 replies; 7+ messages in thread
From: william_lei @ 2006-09-25 10:35 UTC (permalink / raw)
  To: Kevin D. Kissell; +Cc: linux-mips


Dear Kevin
      Because there are some aligned instruction will load/store from/to
unaligned base address in some module,such as "lw t0,56(sp)  ##sp is odd
address"
that's why I want some special version GCC can avoid generating load/store
4 bytes opcode,then I can use this "GCC" to compile specified module and
linked with others,it will avoid unnecessary exception processing when
these instruction to be invoked and come up with best performance for me.
Regards
William Lei


|---------+---------------------------->
|         |           "Kevin D.        |
|         |           Kissell"         |
|         |           <kevink@mips.com>|
|         |                            |
|         |                            |
|         |           2006-09-25 16:42 |
|---------+---------------------------->
  >------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                              |
  |       To:       <linux-mips@linux-mips.org>, <william_lei@ali.com.tw>                                                        |
  |       cc:                                                                                                                    |
  |       Subject:  Re: How to emulate lw/sw instruction by lb/sb instruction                                                    |
  >------------------------------------------------------------------------------------------------------------------------------|





The MIPS Linux kernel is capable of handling unalgined loads and
stores in emulation.  This is less efficient than synthesizing the word
access out of byte or left/right load/store operations in-line, but it's
only done when there really is an unaligned access, whereas forcing
the compiler to synthesize *all* loads/stores adds that overhead
even when the addresses are actually aligned.

            Regards,

            Kevin K.

----- Original Message -----
From: <william_lei@ali.com.tw>
To: <linux-mips@linux-mips.org>
Sent: Monday, September 25, 2006 2:41 AM
Subject: How to emulate lw/sw instruction by lb/sb instruction


> Dear all
>       Could someone tell me how to modify GCC as titled?because we have
met
> problem while porting some middleware,which will generate some lw/sw
> instruction to unaligned address,so I would modify GCC to not generate
> lw/sw instructions for this pieces code.
> Regards
> William Lei
>
> ************* Email Confidentiality Notice ********************
>
> The information contained in this e-mail message (including any
> attachments) may be confidential, proprietary, privileged, or otherwise
> exempt from disclosure under applicable laws. It is intended to be
conveyed
> only to the designated recipient(s). Any use, dissemination,
distribution,
> printing, retaining or copying of this e-mail (including its attachments)
> by unintended recipient(s) is strictly prohibited and may be unlawful. If
> you are not an intended recipient of this e-mail, or believe that you
have
> received this e-mail in error, please notify the sender immediately (by
> replying to this e-mail), delete any and all copies of this e-mail
> (including any attachments) from your system, and do not disclose the
> content of this e-mail to any other person. Thank you!
>
>
>
>

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

* Re: How to emulate lw/sw instruction by lb/sb instruction
  2006-09-25  0:41 How to emulate lw/sw instruction by lb/sb instruction william_lei
  2006-09-25  6:03 ` Florian Fainelli
@ 2006-09-25 10:49 ` Ulrich Eckhardt
  2006-09-25 11:05 ` Ralf Baechle
  2 siblings, 0 replies; 7+ messages in thread
From: Ulrich Eckhardt @ 2006-09-25 10:49 UTC (permalink / raw)
  To: linux-mips

On Monday 25 September 2006 02:41, william_lei@ali.com.tw wrote:
> Could someone tell me how to modify GCC as titled?because we have met
> problem while porting some middleware,which will generate some lw/sw
> instruction to unaligned address,so I would modify GCC to not generate
> lw/sw instructions for this pieces code.

I'm not exactly sure what problem you are facing but if I understand you 
correctly and you have code that simply does misaligned accesses, you would 
be better off fixing the code. The reason is that such unaligned accesses 
would have to be emulated with bytewise access and combining/dissecting the 
values accordingly, which hurts performance (processing and cache). Even when 
run on x86 (where such accesses don't cause bus errors) this would be the 
better choice, because even there these are emulated in hardware and only 
cause hidden performance losses.

Other than that, I would rather filter the output of GCC, i.e. use -S (or what 
it was) to generate assembler code and then replace the lw/sw instructions 
via your $FAVOURITE_TEXTPROCESSING_TOOL in the affected files. Most other 
software isn't that broken and would only suffer from such changes.

Thinking about it, I believe there is also a way (some __attribute__) to tell 
GCC that some pointer is not aligned and it will then output suitable code 
for unaligned accesses. This requires changes to the generated sourcecode 
though, but would be a rather clean solution because it would work on other 
platforms, too.

Just wondering, what middleware are you talking about?

Uli


**************************************************************************************
           Visit our website at <http://www.satorlaser.de/>
**************************************************************************************

Diese E-Mail und jede mit dieser E-Mail versandte Datei ist vertraulich und ausschließlich für die Nutzung durch den vorgesehenen Empfänger bestimmt. Sollten Sie nicht der vorgesehene Empfänger dieser E-Mail sein, informieren Sie bitte den Absender.  Jeder unbefugte Zugriff oder unbefugte Weiterleitung, die Fertigung einer Kopie oder sonstige in diesem Zusammenhang stehende Handlung ist untersagt.


This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please be so kind to inform the sender. Any other unauthorised access, unauthorised forwarding, copying or other action in this connection at all, is prohibited.
**************************************************************************************

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

* Re: How to emulate lw/sw instruction by lb/sb instruction
  2006-09-25  0:41 How to emulate lw/sw instruction by lb/sb instruction william_lei
  2006-09-25  6:03 ` Florian Fainelli
  2006-09-25 10:49 ` Ulrich Eckhardt
@ 2006-09-25 11:05 ` Ralf Baechle
  2 siblings, 0 replies; 7+ messages in thread
From: Ralf Baechle @ 2006-09-25 11:05 UTC (permalink / raw)
  To: william_lei; +Cc: linux-mips

On Mon, Sep 25, 2006 at 08:41:53AM +0800, william_lei@ali.com.tw wrote:

> Dear all
>       Could someone tell me how to modify GCC as titled?because we have met
> problem while porting some middleware,which will generate some lw/sw
> instruction to unaligned address,so I would modify GCC to not generate
> lw/sw instructions for this pieces code.

You can use gcc's __attribute__((packed)) to define a data structure
that does not have any alignment gaps in it.  Gcc will then use unaligned
loads and stores to access this structure.  This however is a kludge, for
best performance you should redefine the data structures your code is
working to avoid such missalignment.

Otoh if the miss-alignment case is rare only then you may actually be
better off by relying on the kernel's handling of this case.

  Ralf

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

* Re: How to emulate lw/sw instruction by lb/sb instruction
  2006-09-25 10:35 ` william_lei
@ 2006-09-25 16:11   ` Maciej W. Rozycki
  2006-09-27 20:14   ` Jim Wilson
  1 sibling, 0 replies; 7+ messages in thread
From: Maciej W. Rozycki @ 2006-09-25 16:11 UTC (permalink / raw)
  To: william_lei; +Cc: Kevin D. Kissell, linux-mips

On Mon, 25 Sep 2006, william_lei@ali.com.tw wrote:

>       Because there are some aligned instruction will load/store from/to
> unaligned base address in some module,such as "lw t0,56(sp)  ##sp is odd
> address"

 Hmm, the stack at an odd address -- somebody must be in the hard joking 
mood...

  Maciej

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

* Re: How to emulate lw/sw instruction by lb/sb instruction
  2006-09-25 10:35 ` william_lei
  2006-09-25 16:11   ` Maciej W. Rozycki
@ 2006-09-27 20:14   ` Jim Wilson
  1 sibling, 0 replies; 7+ messages in thread
From: Jim Wilson @ 2006-09-27 20:14 UTC (permalink / raw)
  To: william_lei; +Cc: linux-mips

On Mon, 2006-09-25 at 18:35 +0800, william_lei@ali.com.tw wrote:
>       Because there are some aligned instruction will load/store from/to
> unaligned base address in some module,such as "lw t0,56(sp)  ##sp is odd
> address"

You are better off fixing your code.  SP must always be aligned to an 8
byte boundary minimum, 16 bytes for the New ABIs.

Changing gcc would be difficult, and it isn't even clear if such a
change can be made to work.  If it is possible, the resulting code will
likely be so bad as to be nearly useless.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com

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

end of thread, other threads:[~2006-09-27 20:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-25  0:41 How to emulate lw/sw instruction by lb/sb instruction william_lei
2006-09-25  6:03 ` Florian Fainelli
2006-09-25 10:49 ` Ulrich Eckhardt
2006-09-25 11:05 ` Ralf Baechle
     [not found] <001401c6e07e$8b07c080$10eca8c0@grendel>
2006-09-25 10:35 ` william_lei
2006-09-25 16:11   ` Maciej W. Rozycki
2006-09-27 20:14   ` Jim Wilson

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