Changeset 11353 in vbox for trunk/src/VBox/Devices/Storage/testcase
- Timestamp:
- Aug 12, 2008 12:55:15 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 34523
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp
r10715 r11353 83 83 84 84 rc = VDCreateBase(pVD, pszBackend, pszFilename, enmType, cbSize, 85 uFlags, "Test image", &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,86 NULL, NULL);85 uFlags, "Test image", &PCHS, &LCHS, NULL, 86 VD_OPEN_FLAGS_NORMAL, NULL, NULL); 87 87 CHECK("VDCreateBase()"); 88 88 … … 101 101 102 102 /** 103 * The following code is based on the work of George Marsaglia 104 * taken from 103 * The following code is based on the work of George Marsaglia 104 * taken from 105 105 * http://groups.google.ws/group/comp.sys.sun.admin/msg/7c667186f6cbf354 106 * and 107 * http://groups.google.ws/group/comp.lang.c/msg/0e170777c6e79e8d 106 * and 107 * http://groups.google.ws/group/comp.lang.c/msg/0e170777c6e79e8d 108 108 */ 109 109 110 /* 111 A C version of a very very good 64-bit RNG is given below. 112 You should be able to adapt it to your particular needs. 113 114 It is based on the complimentary-multiple-with-carry 115 sequence 116 x(n)=a*x(n-4)+carry mod 2^64-1, 117 which works as follows: 118 Assume a certain multiplier 'a' and a base 'b'. 119 Given a current x value and a current carry 'c', 120 form: t=a*x+c 121 Then the new carry is c=floor(t/b) 122 and the new x value is x = b-1-(t mod b). 123 124 125 Ordinarily, for 32-bit mwc or cmwc sequences, the 126 value t=a*x+c can be formed in 64 bits, then the new c 127 is the top and the new x the bottom 32 bits (with a little 128 fiddling when b=2^32-1 and cmwc rather than mwc.) 129 130 131 To generate 64-bit x's, it is difficult to form 132 t=a*x+c in 128 bits then get the new c and new x 133 from the the top and bottom halves. 134 But if 'a' has a special form, for example, 135 a=2^62+2^47+2 and b=2^64-1, then the new c and 136 the new x can be formed with shifts, tests and +/-'s, 137 again with a little fiddling because b=2^64-1 rather 138 than 2^64. (The latter is not an optimal choice because, 139 being a square, it cannot be a primitive root of the 140 prime a*b^k+1, where 'k' is the 'lag': 141 x(n)=a*x(n-k)+carry mod b.) 142 But the multiplier a=2^62+2^47+2 makes a*b^4+1 a prime for 143 which b=2^64-1 is a primitive root, and getting the new x and 144 new c can be done with arithmetic on integers the size of x. 145 */ 110 /* 111 A C version of a very very good 64-bit RNG is given below. 112 You should be able to adapt it to your particular needs. 113 114 It is based on the complimentary-multiple-with-carry 115 sequence 116 x(n)=a*x(n-4)+carry mod 2^64-1, 117 which works as follows: 118 Assume a certain multiplier 'a' and a base 'b'. 119 Given a current x value and a current carry 'c', 120 form: t=a*x+c 121 Then the new carry is c=floor(t/b) 122 and the new x value is x = b-1-(t mod b). 123 124 125 Ordinarily, for 32-bit mwc or cmwc sequences, the 126 value t=a*x+c can be formed in 64 bits, then the new c 127 is the top and the new x the bottom 32 bits (with a little 128 fiddling when b=2^32-1 and cmwc rather than mwc.) 129 130 131 To generate 64-bit x's, it is difficult to form 132 t=a*x+c in 128 bits then get the new c and new x 133 from the the top and bottom halves. 134 But if 'a' has a special form, for example, 135 a=2^62+2^47+2 and b=2^64-1, then the new c and 136 the new x can be formed with shifts, tests and +/-'s, 137 again with a little fiddling because b=2^64-1 rather 138 than 2^64. (The latter is not an optimal choice because, 139 being a square, it cannot be a primitive root of the 140 prime a*b^k+1, where 'k' is the 'lag': 141 x(n)=a*x(n-k)+carry mod b.) 142 But the multiplier a=2^62+2^47+2 makes a*b^4+1 a prime for 143 which b=2^64-1 is a primitive root, and getting the new x and 144 new c can be done with arithmetic on integers the size of x. 145 */ 146 146 147 147 struct RndCtx … … 159 159 160 160 /** 161 * Initialize seeds. 162 * 161 * Initialize seeds. 162 * 163 163 * @remarks You should choose ANY 4 random 64-bit 164 164 * seeds x,y,z,w < 2^64-1 and a random seed c in … … 196 196 RTDECL(uint64_t) RTPRandU64(PRNDCTX pCtx) 197 197 { 198 uint64_t t; 199 t = (pCtx->x<<47) + (pCtx->x<<62) + (pCtx->x<<1); 200 t += pCtx->c; t+= (t < pCtx->c); 201 pCtx->c = (t<pCtx->c) + (pCtx->x>>17) + (pCtx->x>>2) + (pCtx->x>>63); 202 pCtx->x = pCtx->y; pCtx->y = pCtx->z ; pCtx->z = pCtx->w; 203 return (pCtx->w = ~(t + pCtx->c)-1); 204 } 198 uint64_t t; 199 t = (pCtx->x<<47) + (pCtx->x<<62) + (pCtx->x<<1); 200 t += pCtx->c; t+= (t < pCtx->c); 201 pCtx->c = (t<pCtx->c) + (pCtx->x>>17) + (pCtx->x>>2) + (pCtx->x>>63); 202 pCtx->x = pCtx->y; pCtx->y = pCtx->z ; pCtx->z = pCtx->w; 203 return (pCtx->w = ~(t + pCtx->c)-1); 204 } 205 205 206 206 /** 207 * Generate a 64-bit unsigned pseudo random number in the set 208 * [u64First..u64Last]. 207 * Generate a 64-bit unsigned pseudo random number in the set 208 * [u64First..u64Last]. 209 209 * 210 210 * @returns The pseudo random number. … … 240 240 pCtx->u32y ^= pCtx->u32y<<5, 241 241 pCtx->u32x + pCtx->u32y ); 242 } 242 } 243 243 244 244 /** 245 * Generate a 32-bit unsigned pseudo random number in the set 246 * [u32First..u32Last]. 245 * Generate a 32-bit unsigned pseudo random number in the set 246 * [u32First..u32Last]. 247 247 * 248 248 * @returns The pseudo random number. … … 283 283 else 284 284 { 285 RTPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx)); 286 RTLogPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx)); 285 RTPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx)); 286 RTLogPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx)); 287 287 } 288 288 } … … 481 481 VD_IMAGE_TYPE_NORMAL, u64DiskSize, 482 482 VD_IMAGE_FLAGS_NONE, "Test image", 483 &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,483 &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL, 484 484 NULL, NULL); 485 485 CHECK("VDCreateBase()"); … … 506 506 507 507 rc = VDCreateDiff(pVD, pszBackend, pszDiffFilename, 508 VD_IMAGE_FLAGS_NONE, "Test diff image", 508 VD_IMAGE_FLAGS_NONE, "Test diff image", NULL, 509 509 VD_OPEN_FLAGS_NORMAL, NULL, NULL); 510 510 CHECK("VDCreateDiff()"); … … 587 587 VD_IMAGE_TYPE_NORMAL, u64DiskSize, 588 588 VD_IMAGE_FLAGS_NONE, "Test image", 589 &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,589 &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL, 590 590 NULL, NULL); 591 591 CHECK("VDCreateBase()");
Note:
See TracChangeset
for help on using the changeset viewer.