summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xdelta3/xdelta3-main.h2
-rw-r--r--xdelta3/xdelta3-test.h97
2 files changed, 54 insertions, 45 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 0e16e53..fdbbc8e 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -1762,7 +1762,7 @@ main_merge_func (xd3_stream* stream, main_file *no_write)
1762 1762
1763 if (! xd3_decoder_needs_source (stream)) 1763 if (! xd3_decoder_needs_source (stream))
1764 { 1764 {
1765 DP(RINT "cannot merge inputs which do not have a source file\n"); 1765 XPR(NT "cannot merge inputs which do not have a source file\n");
1766 return XD3_INVALID; 1766 return XD3_INVALID;
1767 } 1767 }
1768 1768
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h
index c34aa3f..979683f 100644
--- a/xdelta3/xdelta3-test.h
+++ b/xdelta3/xdelta3-test.h
@@ -20,56 +20,65 @@
20 * attributed to Michael Brundage. Thanks! 20 * attributed to Michael Brundage. Thanks!
21 * http://www.qbrundage.com/michaelb/pubs/essays/random_number_generation.html 21 * http://www.qbrundage.com/michaelb/pubs/essays/random_number_generation.html
22 */ 22 */
23#define MT_LEN 624 23static const uint32_t TEST_SEED1 = 5489UL;
24#define MT_IA 397 24#define MT_LEN 624
25#define MT_IB (MT_LEN - MT_IA) 25#define MT_IA 397
26#define UPPER_MASK 0x80000000 26static const uint32_t UPPER_MASK = 0x80000000;
27#define LOWER_MASK 0x7FFFFFFF 27static const uint32_t LOWER_MASK = 0x7FFFFFFF;
28#define MATRIX_A 0x9908B0DF 28static const uint32_t MATRIX_A = 0x9908B0DF;
29#define TWIST(b,i,j) ((b)[i] & UPPER_MASK) | ((b)[j] & LOWER_MASK) 29
30#define MAGIC(s) (((s)&1)*MATRIX_A) 30typedef struct mtrand mtrand;
31 31
32struct mtrand_ { 32struct mtrand {
33 int mt_index; 33 int mt_index_;
34 uint32_t mt_buffer[MT_LEN]; 34 uint32_t mt_buffer_[MT_LEN];
35}; 35};
36 36
37typedef struct mtrand_ mtrand; 37void mt_init(mtrand *mt, uint32_t seed) {
38
39static void mt_init (mtrand *mt, int seed) {
40 int i; 38 int i;
41 srand (seed); 39 mt->mt_buffer_[0] = seed;
42 for (i = 0; i < MT_LEN; i++) 40 mt->mt_index_ = MT_LEN;
43 { 41 for (i = 1; i < MT_LEN; i++) {
44 mt->mt_buffer[i] = rand (); 42 /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
45 } 43 /* In the previous versions, MSBs of the seed affect */
46 mt->mt_index = 0; 44 /* only MSBs of the array mt[]. */
45 /* 2002/01/09 modified by Makoto Matsumoto */
46 mt->mt_buffer_[i] =
47 (1812433253UL * (mt->mt_buffer_[i-1] ^ (mt->mt_buffer_[i-1] >> 30)) + i);
48 }
47} 49}
48 50
49static uint32_t mt_random (mtrand *mt) { 51
50 uint32_t * b = mt->mt_buffer; 52uint32_t mt_random (mtrand *mt) {
51 int idx = mt->mt_index; 53 uint32_t y;
52 uint32_t s; 54 unsigned long mag01[2];
53 int i; 55 mag01[0] = 0;
54 56 mag01[1] = MATRIX_A;
55 if (idx == MT_LEN*sizeof(uint32_t)) 57
56 { 58 if (mt->mt_index_ >= MT_LEN) {
57 idx = 0; 59 int kk;
58 i = 0; 60
59 for (; i < MT_IB; i++) { 61 for (kk = 0; kk < MT_LEN - MT_IA; kk++) {
60 s = TWIST(b, i, i+1); 62 y = (mt->mt_buffer_[kk] & UPPER_MASK) | (mt->mt_buffer_[kk + 1] & LOWER_MASK);
61 b[i] = b[i + MT_IA] ^ (s >> 1) ^ MAGIC(s); 63 mt->mt_buffer_[kk] = mt->mt_buffer_[kk + MT_IA] ^ (y >> 1) ^ mag01[y & 0x1UL];
62 }
63 for (; i < MT_LEN-1; i++) {
64 s = TWIST(b, i, i+1);
65 b[i] = b[i - MT_IB] ^ (s >> 1) ^ MAGIC(s);
66 }
67
68 s = TWIST(b, MT_LEN-1, 0);
69 b[MT_LEN-1] = b[MT_IA-1] ^ (s >> 1) ^ MAGIC(s);
70 } 64 }
71 mt->mt_index = idx + sizeof(uint32_t); 65 for (;kk < MT_LEN - 1; kk++) {
72 return *(uint32_t *)((unsigned char *)b + idx); 66 y = (mt->mt_buffer_[kk] & UPPER_MASK) | (mt->mt_buffer_[kk + 1] & LOWER_MASK);
67 mt->mt_buffer_[kk] = mt->mt_buffer_[kk + (MT_IA - MT_LEN)] ^ (y >> 1) ^ mag01[y & 0x1UL];
68 }
69 y = (mt->mt_buffer_[MT_LEN - 1] & UPPER_MASK) | (mt->mt_buffer_[0] & LOWER_MASK);
70 mt->mt_buffer_[MT_LEN - 1] = mt->mt_buffer_[MT_IA - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];
71 mt->mt_index_ = 0;
72 }
73
74 y = mt->mt_buffer_[mt->mt_index_++];
75
76 y ^= (y >> 11);
77 y ^= (y << 7) & 0x9d2c5680UL;
78 y ^= (y << 15) & 0xefc60000UL;
79 y ^= (y >> 18);
80
81 return y;
73} 82}
74 83
75static mtrand static_mtrand; 84static mtrand static_mtrand;