trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tyson.w.smith@gmail.com
To: davej@codemonkey.org.uk
Cc: trinity@vger.kernel.org, Tyson Smith <tyson.w.smith@gmail.com>
Subject: [PATCH 3/7] Unnest the get_interesting_<Nbit>_value() calls
Date: Wed,  4 Mar 2015 13:10:54 -0800	[thread overview]
Message-ID: <1425503454-38059-1-git-send-email-tyson.w.smith@gmail.com> (raw)

From: Tyson Smith <tyson.w.smith@gmail.com>

This will help evenly distribute the calls to each
get_interesting_<Nbit>_value() functions. It will also make the modification
to the distribution easier in the future if tweaks are needed. Move call to
plus_minus_two() from get_interesting_32bit_value() to get_interesting_value().
---
 interesting-numbers.c | 61 +++++++++++++++++++++++----------------------------
 1 file changed, 28 insertions(+), 33 deletions(-)

diff --git a/interesting-numbers.c b/interesting-numbers.c
index 4b23b4c..e08e27d 100644
--- a/interesting-numbers.c
+++ b/interesting-numbers.c
@@ -35,22 +35,20 @@ static int get_interesting_16bit_value(void)
 {
 	int num = 0;
 
-	switch (rand() % 8) {
+	switch (rand() % 7) {
 	case 0:	num = 0;
 		break;
-	case 1:	num = get_interesting_8bit_value();
+	case 1:	num = -32768;
 		break;
-	case 2:	num = -32768;
+	case 2:	num = -129;
 		break;
-	case 3:	num = -129;
+	case 3:	num = 255;
 		break;
-	case 4:	num = 255;
+	case 4:	num = 32767;
 		break;
-	case 5:	num = 32767;
+	case 5:	num = 1UL << (rand() % 15);
 		break;
-	case 6:	num = 1UL << (rand() % 15);
-		break;
-	case 7:	num = rand() % 0xffff;
+	case 6:	num = rand() % 0xffff;
 		break;
 	}
 
@@ -61,37 +59,28 @@ unsigned int get_interesting_32bit_value(void)
 {
 	unsigned int num = 0;
 
-	switch (rand() % 11) {
+	switch (rand() % 9) {
 	case 0:	num = 0;
 		break;
-
-	case 1:	num = get_interesting_8bit_value();
+	case 1:	num = 1UL << (rand() % 32);	// set a single bit.
 		break;
-
-	case 2:	num = get_interesting_16bit_value();
+	case 2:	num = 0x8fffffff;
 		break;
-
-	case 3:	num = 1UL << (rand() % 32);	// set a single bit.
-		break;
-	case 4:	num = 0x8fffffff;
-		break;
-	case 5:	num = 0xff;
+	case 3:	num = 0xff;
 		num = num << (rand() % 31);
 		break;
-	case 6: num = 0xffff0000;
+	case 4: num = 0xffff0000;
 		break;
-	case 7: num = 0xffffe000;
+	case 5: num = 0xffffe000;
 		break;
-	case 8: num = 0xffffff00 | (rand() % 256);
+	case 6: num = 0xffffff00 | (rand() % 256);
 		break;
-	case 9: num = 0xffffffff - page_size;
+	case 7: num = 0xffffffff - page_size;
 		break;
-	case 10: num = 0xffffffff;
+	case 8: num = 0xffffffff;
 		break;
 	}
 
-	num = rand() & 0xf ? num : plus_minus_two(num);	// 1 in 16 call plus_minus_two
-
 	return num;
 }
 
@@ -119,13 +108,19 @@ static unsigned long per_arch_interesting_addr(unsigned long low)
 
 unsigned long get_interesting_value(void)
 {
-#if __WORDSIZE == 32
-	return get_interesting_32bit_value();
-#else
 	unsigned long low = 0;
 
-	if (rand_bool())
-		low = get_interesting_32bit_value();
+	switch (rand() % 3) {
+	case 0:	low = get_interesting_8bit_value();
+		break;
+	case 1:	low = get_interesting_16bit_value();
+		break;
+	case 2: low = get_interesting_32bit_value();
+		break;
+	}
+
+	low = (rand() & 0xf) ? low : plus_minus_two(low);	// 1 in 16 call plus_minus_two
+#if __WORDSIZE != 32
 
 	switch (rand() % 13) {
 	case 0: return 0;
@@ -143,6 +138,6 @@ unsigned long get_interesting_value(void)
 	case 12: return (low << 32);
 	}
 
-	return low;	// unreachable, but gcc is dumb.
 #endif	/* __WORDSIZE */
+	return low;
 }
-- 
1.9.1

                 reply	other threads:[~2015-03-04 21:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1425503454-38059-1-git-send-email-tyson.w.smith@gmail.com \
    --to=tyson.w.smith@gmail.com \
    --cc=davej@codemonkey.org.uk \
    --cc=trinity@vger.kernel.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 read-only IMAP folder(s) and NNTP newsgroup(s).