public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Matt Mackall <mpm@selenic.com>
To: Andrew Morton <akpm@osdl.org>, "Theodore Ts'o" <tytso@mit.edu>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 9/10] random pt2: kill redundant rotate_left definitions
Date: Fri, 14 Jan 2005 18:49:08 -0600	[thread overview]
Message-ID: <10.563253706@selenic.com> (raw)
In-Reply-To: <9.563253706@selenic.com>

We've got three definitions of rotate_left. Remove x86 and duplicate
rotate definitions. Remaining definition is fixed up such that recent
gcc will generate rol instructions on x86 at least.

A later patch will move this to bitops and clean up the other tree users.

Signed-off-by: Matt Mackall <mpm@selenic.com>

Index: rnd/drivers/char/random.c
===================================================================
--- rnd.orig/drivers/char/random.c	2005-01-12 21:28:06.993624332 -0800
+++ rnd/drivers/char/random.c	2005-01-12 21:28:07.768525540 -0800
@@ -401,26 +401,10 @@
  * purposes
  *
  *****************************************************************/
-
-/*
- * Unfortunately, while the GCC optimizer for the i386 understands how
- * to optimize a static rotate left of x bits, it doesn't know how to
- * deal with a variable rotate of x bits.  So we use a bit of asm magic.
- */
-#if (!defined (__i386__))
-static inline __u32 rotate_left(int i, __u32 word)
-{
-	return (word << i) | (word >> (32 - i));
-}
-#else
-static inline __u32 rotate_left(int i, __u32 word)
+static inline __u32 rol32(__u32 word, int shift)
 {
-	__asm__("roll %%cl,%0"
-		:"=r" (word)
-		:"0" (word),"c" (i));
-	return word;
+	return (word << shift) | (word >> (32 - shift));
 }
-#endif
 
 /*
  * More asm magic....
@@ -572,7 +556,7 @@
 	add_ptr = r->add_ptr;
 
 	while (nwords--) {
-		w = rotate_left(input_rotate, next_w);
+		w = rol32(input_rotate, next_w);
 		if (nwords > 0)
 			next_w = *in++;
 		i = add_ptr = (add_ptr - 1) & wordmask;
@@ -941,10 +925,8 @@
 #define K3  0x8F1BBCDCL			/* Rounds 40-59: sqrt(5) * 2^30 */
 #define K4  0xCA62C1D6L			/* Rounds 60-79: sqrt(10) * 2^30 */
 
-#define ROTL(n,X)  (((X) << n ) | ((X) >> (32 - n)))
-
 #define subRound(a, b, c, d, e, f, k, data) \
-    (e += ROTL(5, a) + f(b, c, d) + k + data, b = ROTL(30, b))
+    (e += rol32(a, 5) + f(b, c, d) + k + data, b = rol32(b, 30))
 
 static void SHATransform(__u32 digest[85], __u32 const data[16])
 {
@@ -962,7 +944,7 @@
 	memcpy(W, data, 16*sizeof(__u32));
 	for (i = 0; i < 64; i++) {
 		TEMP = W[i] ^ W[i+2] ^ W[i+8] ^ W[i+13];
-		W[i+16] = ROTL(1, TEMP);
+		W[i+16] = rol32(TEMP, 1);
 	}
 
 	/* Set up first buffer and local data buffer */
@@ -990,25 +972,25 @@
 			else
 				TEMP = f4(B, C, D) + K4;
 		}
-		TEMP += ROTL(5, A) + E + W[i];
-		E = D; D = C; C = ROTL(30, B); B = A; A = TEMP;
+		TEMP += rol32(A, 5) + E + W[i];
+		E = D; D = C; C = rol32(B, 30); B = A; A = TEMP;
 	}
 #elif SHA_CODE_SIZE == 1
 	for (i = 0; i < 20; i++) {
-		TEMP = f1(B, C, D) + K1 + ROTL(5, A) + E + W[i];
-		E = D; D = C; C = ROTL(30, B); B = A; A = TEMP;
+		TEMP = f1(B, C, D) + K1 + rol32(A, 5) + E + W[i];
+		E = D; D = C; C = rol32(B, 30); B = A; A = TEMP;
 	}
 	for (; i < 40; i++) {
-		TEMP = f2(B, C, D) + K2 + ROTL(5, A) + E + W[i];
-		E = D; D = C; C = ROTL(30, B); B = A; A = TEMP;
+		TEMP = f2(B, C, D) + K2 + rol32(A, 5) + E + W[i];
+		E = D; D = C; C = rol32(B, 30); B = A; A = TEMP;
 	}
 	for (; i < 60; i++) {
-		TEMP = f3(B, C, D) + K3 + ROTL(5, A) + E + W[i];
-		E = D; D = C; C = ROTL(30, B); B = A; A = TEMP;
+		TEMP = f3(B, C, D) + K3 + rol32(A, 5) + E + W[i];
+		E = D; D = C; C = rol22(B, 30); B = A; A = TEMP;
 	}
 	for (; i < 80; i++) {
-		TEMP = f4(B, C, D) + K4 + ROTL(5, A) + E + W[i];
-		E = D; D = C; C = ROTL(30, B); B = A; A = TEMP;
+		TEMP = f4(B, C, D) + K4 + rol32(A, 5) + E + W[i];
+		E = D; D = C; C = rol32(B, 30); B = A; A = TEMP;
 	}
 #elif SHA_CODE_SIZE == 2
 	for (i = 0; i < 20; i += 5) {
@@ -1138,7 +1120,6 @@
 #undef W
 }
 
-#undef ROTL
 #undef f1
 #undef f2
 #undef f3

  reply	other threads:[~2005-01-15  0:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-15  0:49 [PATCH 1/10] random pt2: cleanup waitqueue logic, fix missed wakeup Matt Mackall
2005-01-15  0:49 ` [PATCH 2/10] random pt2: kill pool clearing Matt Mackall
2005-01-15  0:49   ` [PATCH 3/10] random pt2: combine legacy ioctls Matt Mackall
2005-01-15  0:49     ` [PATCH 4/10] random pt2: re-init all pools on zero Matt Mackall
2005-01-15  0:49       ` [PATCH 5/10] random pt2: simplify initialization Matt Mackall
2005-01-15  0:49         ` [PATCH 6/10] random pt2: kill memsets of static data Matt Mackall
2005-01-15  0:49           ` [PATCH 7/10] random pt2: kill dead extract_state struct Matt Mackall
2005-01-15  0:49             ` [PATCH 8/10] random pt2: kill 2.2 compat waitqueue defs Matt Mackall
2005-01-15  0:49               ` Matt Mackall [this message]
2005-01-15  0:49                 ` [PATCH 10/10] random pt2: kill misnamed log2 Matt Mackall

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=10.563253706@selenic.com \
    --to=mpm@selenic.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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