From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nicolas Pitre <nico@cam.org>
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] block-sha1: more good unaligned memory access candidates
Date: Thu, 13 Aug 2009 09:45:54 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.01.0908130934400.28882@localhost.localdomain> (raw)
In-Reply-To: <alpine.LFD.2.00.0908130017080.10633@xanadu.home>
On Thu, 13 Aug 2009, Nicolas Pitre wrote:
>
> In addition to X86, PowerPC and S390 are capable of unaligned memory
> accesses.
>
> Signed-off-by: Nicolas Pitre <nico@cam.org>
Ack on all your patches (1-3 + this). Looks fine to me.
I do wonder if we should try to do basically "per-architecture hack
header-files", and then have for each architecture a small trivial
'hack-x86.h' kind of thing that just does
/* x86 hacks */
#define get_be32(p) ntohl(*(unsigned int *)(p))
#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
#define setW(x, val) (*(volatile unsigned int *)&W(x) = (val))
#define SHA_ASM(op, x, n) ({ unsigned int __res; __asm__(op " %1,%0":"=r" (__res):"i" (n), "0" (x)); __res; })
#define SHA_ROL(x,n) SHA_ASM("rol", x, n)
#define SHA_ROR(x,n) SHA_ASM("ror", x, n)
and then we'd have each architecture separated out. Add a few
"generic helpers":
- be32-generic.h:
#define get_be32(p) ( \
(*((unsigned char *)(p) + 0) << 24) | \
(*((unsigned char *)(p) + 1) << 16) | \
(*((unsigned char *)(p) + 2) << 8) | \
(*((unsigned char *)(p) + 3) << 0) )
#define put_be32(p, v) do { \
unsigned int __v = (v); \
*((unsigned char *)(p) + 0) = __v >> 24; \
*((unsigned char *)(p) + 1) = __v >> 16; \
*((unsigned char *)(p) + 2) = __v >> 8; \
*((unsigned char *)(p) + 3) = __v >> 0; } while (0)
- rotate-generic.h:
#define SHA_ROT(X,l,r) (((X) << (l)) | ((X) >> (r)))
#define SHA_ROL(X,n) SHA_ROT(X,n,32-(n))
#define SHA_ROR(X,n) SHA_ROT(X,32-(n),n)
that architectures could use when they want to use some particular
portable version. Then, add a final "hack-generic.h" with the fallback
cases that just does
#include "be32-generic.h"
#include "rotate-generic.h"
#define setW(x,val) (W(x) = (val))
and you'd have all the hacks separated out and fairly easily used by
different architectures.. (ie the ARM version would just look like
- hack-arm.h:
#include "be32-generic.h"
#include "rotate-generic.h"
#define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0)
and you'd be all done.
Hmm? I don't know if this kind of generalization is strictly needed, so
I'm just throwing it out as an idea.
Linus
next prev parent reply other threads:[~2009-08-13 16:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-13 4:29 [PATCH] block-sha1: more good unaligned memory access candidates Nicolas Pitre
2009-08-13 16:45 ` Linus Torvalds [this message]
2009-08-13 17:23 ` Nicolas Pitre
2009-08-13 19:33 ` Junio C Hamano
2009-08-13 19:54 ` Linus Torvalds
2009-08-13 20:13 ` Nicolas Pitre
2009-08-14 22:52 ` [PATCH] block-sha1/sha1.c: silence compiler complaints by casting void* to uintptr_t Brandon Casey
2009-08-15 0:08 ` Johannes Schindelin
2009-08-15 0:19 ` Linus Torvalds
2009-08-15 0:44 ` Brandon Casey
2009-08-15 1:46 ` Junio C Hamano
2009-08-15 2:34 ` Brandon Casey
2009-08-15 3:16 ` Junio C Hamano
2009-08-15 18:43 ` Linus Torvalds
2009-08-15 0:52 ` Brandon Casey
-- strict thread matches above, loose matches on Subject: below --
2009-08-13 20:15 [PATCH] block-sha1: more good unaligned memory access candidates George Spelvin
2009-08-13 21:28 ` Nicolas Pitre
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=alpine.LFD.2.01.0908130934400.28882@localhost.localdomain \
--to=torvalds@linux-foundation.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=nico@cam.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