diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2010-11-11 14:39:48 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2010-11-11 14:39:48 +0000 |
commit | 74490a4f82c4130881d0e61e2b9a4be8f247b7c4 (patch) | |
tree | 249ea1775c0fd84b41ae695ee852626a61053068 /risugen | |
parent | 62f689e360bc348e535c9f308e1f294b31a44fde (diff) |
Bias the initial values generated for FP regs towards special cases
When generating initial values for FP registers, arrange that
"interesting" values such as NaNs, infinities and zeroes come
up more often than they would if we just generated random bit
patterns. This should improve the coverage of edge cases.
Diffstat (limited to 'risugen')
-rwxr-xr-x | risugen | 80 |
1 files changed, 78 insertions, 2 deletions
@@ -97,6 +97,82 @@ sub write_switch_to_arm() insn16(0xbf00); # nop } +sub write_random_double_fpreg() +{ + my ($low, $high); + my $r = rand(100); + if ($r < 5) { + # +-0 (5%) + $low = $high = 0; + $high |= 0x80000000 if (rand() < 0.5); + } elsif ($r < 10) { + # NaN (5%) + # (plus a tiny chance of generating +-Inf) + $low = rand(0xffffffff); + $high = rand(0xffffffff) | 0x7ff00000; + } elsif ($r < 15) { + # Infinity (5%) + $low = 0; + $high = 0x7ff00000; + $high |= 0x80000000 if (rand() < 0.5); + } elsif ($r < 30) { + # Denormalized number (15%) + # (plus tiny chance of +-0) + $low = rand(0xffffffff); + $high = rand(0xffffffff) & ~0x7ff00000; + } else { + # Normalized number (70%) + # (plus a small chance of the other cases) + $low = rand(0xffffffff); + $high = rand(0xffffffff); + } + insn32($low); + insn32($high); +} + +sub write_random_single_fpreg() +{ + my ($value); + my $r = rand(100); + if ($r < 5) { + # +-0 (5%) + $value = 0; + $value |= 0x80000000 if (rand() < 0.5); + } elsif ($r < 10) { + # NaN (5%) + # (plus a tiny chance of generating +-Inf) + $value = rand(0xffffffff) | 0x7f800000; + } elsif ($r < 15) { + # Infinity (5%) + $value = 0x7f800000; + $value |= 0x80000000 if (rand() < 0.5); + } elsif ($r < 30) { + # Denormalized number (15%) + # (plus tiny chance of +-0) + $value = rand(0xffffffff) & ~0x7f800000; + } else { + # Normalized number (70%) + # (plus a small chance of the other cases) + $value = rand(0xffffffff); + } + insn32($value); +} + +sub write_random_fpreg() +{ + # Write out 64 bits of random data intended to + # initialise an FP register. + # We tweak the "randomness" here to increase the + # chances of picking interesting values like + # NaN, -0.0, and so on, which would be unlikely + # to occur if we simply picked 64 random bits. + if (rand() < 0.5) { + write_random_double_fpreg(); + } else { + write_random_single_fpreg(); + write_random_single_fpreg(); + } +} sub write_random_register_data() { @@ -122,8 +198,8 @@ sub write_random_register_data() my $datalen = 14; $datalen += (32 * $vfp); insn32(0xea000000 + ($datalen-1)); # b next - for (0..(($vfp * 32) - 1)) { - insn32(rand(0xffffffff)); + for (0..(($vfp * 16) - 1)) { + write_random_fpreg(); } # .word [14 words of data for r0..r12,r14] for (0..13) { |