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 10/10] random pt2: kill misnamed log2
Date: Fri, 14 Jan 2005 18:49:08 -0600	[thread overview]
Message-ID: <11.563253706@selenic.com> (raw)
In-Reply-To: <10.563253706@selenic.com>

Remove incorrectly named ln (it's log2!) and x86 asm function and
replace with fls bitop.

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:07.768525540 -0800
+++ rnd/drivers/char/random.c	2005-01-12 21:28:08.700406735 -0800
@@ -395,54 +395,11 @@
 static void sysctl_init_random(struct entropy_store *random_state);
 #endif
 
-/*****************************************************************
- *
- * Utility functions, with some ASM defined functions for speed
- * purposes
- *
- *****************************************************************/
 static inline __u32 rol32(__u32 word, int shift)
 {
 	return (word << shift) | (word >> (32 - shift));
 }
 
-/*
- * More asm magic....
- *
- * For entropy estimation, we need to do an integral base 2
- * logarithm.
- *
- * Note the "12bits" suffix - this is used for numbers between
- * 0 and 4095 only.  This allows a few shortcuts.
- */
-#if 0	/* Slow but clear version */
-static inline __u32 int_ln_12bits(__u32 word)
-{
-	__u32 nbits = 0;
-
-	while (word >>= 1)
-		nbits++;
-	return nbits;
-}
-#else	/* Faster (more clever) version, courtesy Colin Plumb */
-static inline __u32 int_ln_12bits(__u32 word)
-{
-	/* Smear msbit right to make an n-bit mask */
-	word |= word >> 8;
-	word |= word >> 4;
-	word |= word >> 2;
-	word |= word >> 1;
-	/* Remove one bit to make this a logarithm */
-	word >>= 1;
-	/* Count the bits set in the word */
-	word -= (word >> 1) & 0x555;
-	word = (word & 0x333) + ((word >> 2) & 0x333);
-	word += (word >> 4);
-	word += (word >> 8);
-	return word & 15;
-}
-#endif
-
 #if 0
 static int debug = 0;
 module_param(debug, bool, 0644);
@@ -808,10 +765,7 @@
 		 * Round down by 1 bit on general principles,
 		 * and limit entropy entimate to 12 bits.
 		 */
-		delta >>= 1;
-		delta &= (1 << 12) - 1;
-
-		entropy = int_ln_12bits(delta);
+		entropy = min_t(int, fls(delta>>1), 11);
 	}
 
 	/*

      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               ` [PATCH 9/10] random pt2: kill redundant rotate_left definitions Matt Mackall
2005-01-15  0:49                 ` Matt Mackall [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=11.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