From: Gabriel Paubert <paubert@iram.es>
To: Becky Bruce <bgill@freescale.com>
Cc: linuxppc64-dev@ozlabs.org, linuxppc-dev@ozlabs.org
Subject: [PATCH] powerpc: improved byte swapping functions
Date: Wed, 5 Oct 2005 20:20:31 +0200 [thread overview]
Message-ID: <20051005182031.GA15359@iram.es> (raw)
In-Reply-To: <20050927211534.GA32173@iram.es>
From: Gabriel Paubert <paubert@iram.es>
The previous versions of ___arch__swab16 and ___arch__swab32 were
not optimal. In most cases the code can be made shorter and faster
with this patch.
Signed-off-by: Gabriel Paubert <paubert@iram.es>
---
Additional notes:
1) for ___arch__swab16, the trick is to let the compiler
generate a single rlwinm instruction for the final right
shift and cast.
2) For ___arch_swab32, the rotated value passed as a parameter
already has 2 bytes at the right place, so only 2 rlwimi
instructions are necessary to complete the byte swap.
3) edit if you don't like the formatting of the result.
4) I've been reading the thread about how to format patches
and I hope that I got it right. But I believe that the
diffstat output is overkill for such a small patch.
Regards,
Gabriel
diff --git a/include/asm-powerpc/byteorder.h b/include/asm-powerpc/byteorder.h
--- a/include/asm-powerpc/byteorder.h
+++ b/include/asm-powerpc/byteorder.h
@@ -42,23 +42,22 @@ static __inline__ void st_le32(volatile
static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 value)
{
- __u16 result;
+ __u32 tmp;
- __asm__("rlwimi %0,%1,8,16,23"
- : "=r" (result)
- : "r" (value), "0" (value >> 8));
- return result;
+ __asm__("rlwimi %0,%0,16,8,15"
+ : "=r" (tmp) : "0" (value));
+ return (__u16)(tmp>>8);
}
static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 value)
{
__u32 result;
- __asm__("rlwimi %0,%1,24,16,23\n\t"
- "rlwimi %0,%1,8,8,15\n\t"
- "rlwimi %0,%1,24,0,7"
+ __asm__(
+" rlwimi %0,%1,24,16,23\n"
+" rlwimi %0,%1,24,0,7\n"
: "=r" (result)
- : "r" (value), "0" (value >> 24));
+ : "r" (value), "0" ((value >> 24)|(value<<8)));
return result;
}
prev parent reply other threads:[~2005-10-05 18:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-27 19:28 [PATCH] powerpc: merge byteorder.h Becky Bruce
2005-09-27 21:15 ` Gabriel Paubert
2005-10-05 18:20 ` Gabriel Paubert [this message]
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=20051005182031.GA15359@iram.es \
--to=paubert@iram.es \
--cc=bgill@freescale.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=linuxppc64-dev@ozlabs.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).