1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
{$mode macpas}
{$r-}
procedure error(l: longint);
begin
writeln('error near ',l);
halt(1);
end;
procedure test8bit;
type
ta = 0..1;
tb = packed array[0..999] of ta;
tc = array[0..124] of byte;
const
{$ifdef ENDIAN_BIG}
results: array[0..9] of ta = (1,0,1,0,1,0,1,0,1,0);
{$else}
results: array[0..9] of ta = (0,1,0,1,0,1,0,1,0,1);
{$endif}
var
a: ta;
b: tb;
i: longint;
begin
b[0] := results[0];
b[1] := results[1];
b[2] := results[2];
b[3] := results[3];
b[4] := results[4];
b[5] := results[5];
b[6] := results[6];
b[7] := results[7];
b[8] := results[8];
b[9] := results[9];
if (b[0] <> results[0]) then
error(1);
if (b[1] <> results[1]) then
error(2);
if (b[2] <> results[2]) then
error(3);
if (b[3] <> results[3]) then
error(4);
if (b[4] <> results[4]) then
error(5);
// if (b[600] <> 1) then
// error(6);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(7);
// i := 500;
// if (b[i] <> 1) then
// error(8);
end;
procedure test8to16bit;
type
ta = 0..7;
tb = packed array[0..1000] of ta;
const
{$ifdef ENDIAN_BIG}
{ 010 110 100 101 101 001 011 010 010 11010010110100101101001011010 }
results: array[0..5] of ta = (2,6,4,5,5,1);
{$else}
{ (memory layout is different but equivalent with starting at end }
{ 01011010010110100101101001011 010 010 110 100 101 101 001 011 010 }
results: array[0..5] of ta = (2,3,1,5,5,4);
{$endif}
var
a: ta;
b: tb;
i: longint;
begin
b[0] := results[0];
b[1] := results[1];
b[2] := results[2];
b[3] := results[3];
b[4] := results[4];
b[5] := results[5];
if (b[0] <> results[0]) then
error(11);
if (b[1] <> results[1]) then
error(12);
if (b[2] <> results[2]) then
error(13);
if (b[3] <> results[3]) then
error(14);
if (b[4] <> results[4]) then
error(15);
if (b[5] <> results[5]) then
error(155);
// if (b[600] <> 2) then
// error(16);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(17);
// i := 500;
// if (b[i] <> 5) then
// error(18);
end;
procedure test16bit;
type
ta = 0..511;
tb = packed array[0..799] of ta;
tc = array[0..899] of byte;
const
{$ifdef ENDIAN_BIG}
{ 010110100 111011001 011010011 101100101 101001110 110010110 100111011 001011010 0111011001011010011101100101101001110110 }
results: array[0..4] of ta = ($5A*2,$76 * 4 + 1,$69 * 2 + 1,$B2 * 2 + 1,$A7 * 2);
{$else}
{ algorithm: cut bit string in 16 bit chunks, byteswap, take 9 bits from right to left per chunck, continuing at the right of the next chunck if the previous one is used up }
{ 001011010 100111011 110010110 101001110 101100101 011 0101101001110110010110100111011001011010011101100101101001110110 }
results: array[0..4] of ta = ($2D*2,$9D*2+1,$CB*2,$A7*2,$B2*2+1);
{$endif}
var
a: ta;
b: tb;
i: longint;
begin
b[0] := results[0];
b[1] := results[1];
b[2] := results[2];
b[3] := results[3];
b[4] := results[4];
if (b[0] <> results[0]) then
error(21);
if (b[1] <> results[1]) then
error(22);
if (b[2] <> results[2]) then
error(23);
if (b[3] <> results[3]) then
error(24);
if (b[4] <> results[4]) then
error(25);
// if (b[600] <> $76 * 2) then
// error(26);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(27);
// i := 500;
// if (b[i] <> $A7 * 2) then
// error(28);
end;
procedure test16to24bit;
type
ta = 0..2047;
tb = packed array[0..799] of ta;
tc = array[0..1099] of byte;
const
{$ifdef ENDIAN_BIG}
results: array[0..4] of ta = ($5A * 8 + 3,$B2 * 8 + 6,$9D * 8 + 4,$B4 * 8 + 7,$65 * 8 + 5);
{$else}
{ %11001011010 01101001110 00111011001 01100101101 10110100111 011101100 0111011001011010 0111011001011010 0111011001011010 }
results: array[0..4] of ta = ($0000065A,$0000034E,$000001D9,$0000032D,$000005A7);
{$endif}
var
a: ta;
b: tb;
i: longint;
begin
b[0] := results[0];
b[1] := results[1];
b[2] := results[2];
b[3] := results[3];
b[4] := results[4];
if (b[0] <> results[0]) then
error(31);
if (b[1] <> results[1]) then
error(32);
if (b[2] <> results[2]) then
error(33);
if (b[3] <> results[3]) then
error(34);
if (b[4] <> results[4]) then
error(35);
// if (b[600] <> $76 * 8 + 2) then
// error(36);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(37);
// i := 500;
// if (b[i] <> $65 * 8 + 5) then
// error(38);
end;
procedure test32bit;
type
ta = 0..(1 shl 19) - 1;
tb = packed array[0..799] of ta;
tc = array[0..1899] of byte;
const
{$ifdef ENDIAN_BIG}
results: array[0..4] of ta = ($5A76*8+2, $D3B2*8+6,$9D96*8+4,$ECB4*8+7,$65A7*8+3);
{$else}
{ 0100111011001011010 0110100111011001011 0010110100111011001 0110010110100111011 1110110010110100111 0 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010 01110110010110100111011001011010}
results: array[0..4] of ta = ($0002765A,$00034ECB,$000169D9,$00032D3B,$000765A7);
{$endif}
var
a: ta;
b: tb;
i: longint;
begin
b[0] := results[0];
b[1] := results[1];
b[2] := results[2];
b[3] := results[3];
b[4] := results[4];
if (b[0] <> results[0]) then
error(41);
if (b[1] <> results[1]) then
error(42);
if (b[2] <> results[2]) then
error(43);
if (b[3] <> results[3]) then
error(44);
if (b[4] <> results[4]) then
error(45);
// if (b[600] <> $765A*8+3) then
// error(46);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(47);
// i := 500;
// if (b[i] <> $65a7*8+3) then
// error(48);
end;
{
write(hexstr(%1110110010110100111011001011010 ,8),',$');
write(hexstr(%1101100101101001110110010110100 ,8),',$');
write(hexstr(%1011001011010011101100101101001 ,8),',$');
write(hexstr(%0110010110100111011001011010011 ,8),',$');
writeln(hexstr(%1100101101001110110010110100111 ,8));
}
procedure test32to40bit;
type
ta = 0..$7fffffff;
tb = packed array[0..799] of ta;
tc = array[0..3099] of byte;
const
{$ifdef ENDIAN_BIG}
results: array[0..4] of ta = ($5A765A7*8+3,$2D3B2D3*8+5,$969D969*8+6,$CB4ECB4*8+7,$65A765A*8+3);
{$else}
{
1110110010110100111011001011010 1101100101101001110110010110100 1011001011010011101100101101001 0110010110100111011001011010011 1100101101001110110010110100111 1001011010011101100101101001110 011101
}
results: array[0..4] of ta = ($765A765A,$6CB4ECB4,$5969D969,$32D3B2D3,$65A765A7);
{$endif}
var
a: ta;
b: tb;
i: longint;
begin
b[0] := results[0];
b[1] := results[1];
b[2] := results[2];
b[3] := results[3];
b[4] := results[4];
if (b[0] <> results[0]) then
error(51);
if (b[1] <> results[1]) then
error(52);
if (b[2] <> results[2]) then
error(53);
if (b[3] <> results[3]) then
error(54);
if (b[4] <> results[4]) then
error(55);
for i := low(results) to high(results) do
if b[i] <> results[i] then
error(57);
// i := 500;
// if (b[i] <> $65A765A*8+3) then
// error(58);
end;
begin
test8bit;
test8to16bit;
test16bit;
test16to24bit;
test32bit;
test32to40bit;
end.
|