From 339ca8ac28d585a3407f1b07be4b0d9fdbc465f7 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 12:28:41 +0100 Subject: Writing to an array --- test/array-write.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/array-write.c diff --git a/test/array-write.c b/test/array-write.c new file mode 100644 index 0000000..7cb37f2 --- /dev/null +++ b/test/array-write.c @@ -0,0 +1,12 @@ +int main() { + int x[2] = {5, 10}; + int y[2]; + for(int i=0; i<2;i++){ + y[i] += x[i] * (i+1); + } + + int sum = 0; + for(int j=0; j <2; j++) + sum += y[j]; + return sum; +} -- cgit From 4b49703d9fd74ed3e8143683ade5f5849d97787b Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 12:28:52 +0100 Subject: Better mm check --- test/matrix2.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/matrix2.c diff --git a/test/matrix2.c b/test/matrix2.c new file mode 100644 index 0000000..96571be --- /dev/null +++ b/test/matrix2.c @@ -0,0 +1,23 @@ +void matrix_multiply(int first[][2], int second[][2], int multiply[][2], int m, int q, int p, int *totalSum) { + int sum = 0; + for (int c = 0; c < m; c++) { + for (int d = 0; d < q; d++) { + for (int k = 0; k < p; k++) { + sum = sum + first[c][k]*second[k][d]; + } + multiply[c][d] = sum; + *totalSum += sum; + sum = 0; + } + } +} + +int main() { + int f[2][2] = {{1, 2}, {3, 4}}; + int s[2][2] = {{1, 2}, {3, 4}}; + int m[2][2] = {{0, 0}, {0, 0}}; + int sum = 0; + + matrix_multiply(f, s, m, 2, 2, 2, &sum); + return sum; +} -- cgit From 679425c10f48c89433fb4de06c1363b737baa9ae Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 12:36:31 +0100 Subject: simpler --- test/array-write.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/array-write.c b/test/array-write.c index 7cb37f2..697d6ed 100644 --- a/test/array-write.c +++ b/test/array-write.c @@ -1,8 +1,8 @@ int main() { int x[2] = {5, 10}; - int y[2]; + int y[2]; //= {0 , 0}; for(int i=0; i<2;i++){ - y[i] += x[i] * (i+1); + y[i] += x[i] ; } int sum = 0; -- cgit From 9ee43ea5cd1b637a27743a451f697001f07bf47a Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 12:36:53 +0100 Subject: test on indirect addressing --- test/array-indirect.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/array-indirect.c diff --git a/test/array-indirect.c b/test/array-indirect.c new file mode 100644 index 0000000..0315da1 --- /dev/null +++ b/test/array-indirect.c @@ -0,0 +1,13 @@ +int main() { + int index[2] = {1, 0}; + int x[2] = {5, 10}; + int y[2] = {0, 0}; + for(int i=0; i<2;i++){ + y[i] = x[index[i]] * (i+1); + } + + int sum = 0; + for(int j=0; j <2; j++) + sum += y[j]; + return sum; +} -- cgit From 71b6f483093599088c48d166dbe496b64462bd4b Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 12:51:40 +0100 Subject: summing on volatile variable --- test/array-volatile.c | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/array-volatile.c diff --git a/test/array-volatile.c b/test/array-volatile.c new file mode 100644 index 0000000..f12b79a --- /dev/null +++ b/test/array-volatile.c @@ -0,0 +1,7 @@ +int main() { + int x[2] = {5, 10}; + volatile int sum; + for(int j=0; j <2; j++) + sum += x[j]; + return sum; +} -- cgit From d51ad9622d0913564870db50f8ab95d7cba30452 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 13:04:13 +0100 Subject: out of bounds - x[2] is y[0] --- test/array-out-of-bounds.c | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/array-out-of-bounds.c diff --git a/test/array-out-of-bounds.c b/test/array-out-of-bounds.c new file mode 100644 index 0000000..425bf39 --- /dev/null +++ b/test/array-out-of-bounds.c @@ -0,0 +1,9 @@ +int main() { + int x[2] = {1, 2}; + int y[2] = {3, 4}; + x[2] = 0; + int sum = 0; + for(int i=0; i<2; i++) + sum += (x[i] * y[i]); + +} -- cgit From 66e0117b6519f97eeef931a51ad029ee630f81f4 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 13:06:25 +0100 Subject: added return --- test/array-out-of-bounds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/array-out-of-bounds.c b/test/array-out-of-bounds.c index 425bf39..1f20c0c 100644 --- a/test/array-out-of-bounds.c +++ b/test/array-out-of-bounds.c @@ -5,5 +5,5 @@ int main() { int sum = 0; for(int i=0; i<2; i++) sum += (x[i] * y[i]); - + return sum; } -- cgit From b936f4425fdeee3a50fcd3861cb6f53ed88f70de Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 13 Jun 2020 15:09:27 +0100 Subject: address masking --- test/array-addr-mask.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test/array-addr-mask.c diff --git a/test/array-addr-mask.c b/test/array-addr-mask.c new file mode 100644 index 0000000..5ba5601 --- /dev/null +++ b/test/array-addr-mask.c @@ -0,0 +1,6 @@ +int main() { + unsigned int x[8] = {1,2,3,4,5,6,7,8}; + unsigned int index = 6; + unsigned int addr = index & 3; + return (x[addr]); +} -- cgit From 948513fea60b0b226e0fa0d6d31f34fd4c490697 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 20 Jun 2020 10:58:40 +0100 Subject: Some fixes, but still buggy probably --- src/translation/HTLgen.v | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 4fcb557..935f9a1 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -291,8 +291,8 @@ Definition translate_instr (op : Op.operation) (args : list reg) : mon expr := (Vlit (intToValue n)))) | Op.Oshru, r1::r2::nil => ret (bop Vshru r1 r2) | Op.Oshruimm n, r::nil => ret (boplit Vshru r n) - | Op.Ororimm n, r::nil => ret (Vbinop Vand (boplit Vshr r n) (boplit Vshl r (Integers.Int.sub (Integers.Int.repr 32) n))) - | Op.Oshldimm n, r::nil => error (Errors.msg "Htlgen: Instruction not implemented: Oshldimm") + | Op.Ororimm n, r::nil => ret (Vbinop Vor (boplit Vshr r n) (boplit Vshl r (Integers.Int.sub (Integers.Int.repr 32) n))) + | Op.Oshldimm n, r::nil => ret (Vbinop Vor (boplit Vshl r n) (boplit Vshr r (Integers.Int.sub (Integers.Int.repr 32) n))) | Op.Ocmp c, _ => translate_condition c args | Op.Osel c AST.Tint, r1::r2::rl => do tc <- translate_condition c rl; -- cgit From fe6c5d6335bf911bab201aeb00f78c8e2455b2c5 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 20 Jun 2020 15:48:52 +0100 Subject: sha running in coqup - must delete functions manually --- benchmarks/CHStone/sha/sha_coqup.c | 1357 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1357 insertions(+) create mode 100755 benchmarks/CHStone/sha/sha_coqup.c diff --git a/benchmarks/CHStone/sha/sha_coqup.c b/benchmarks/CHStone/sha/sha_coqup.c new file mode 100755 index 0000000..eea3a8a --- /dev/null +++ b/benchmarks/CHStone/sha/sha_coqup.c @@ -0,0 +1,1357 @@ +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +/* NIST Secure Hash Algorithm */ +/* heavily modified by Uwe Hollerbach uh@alumni.caltech edu */ +/* from Peter C. Gutmann's implementation as found in */ +/* Applied Cryptography by Bruce Schneier */ + +/* NIST's proposed modification to SHA of 7/11/94 may be */ +/* activated by defining USE_MODIFIED_SHA */ + +#include + +/* NIST Secure Hash Algorithm */ +/* heavily modified from Peter C. Gutmann's implementation */ + +/* Useful defines & typedefs */ + +typedef unsigned int BYTE; +typedef unsigned int INT32; + +#define SHA_BLOCKSIZE 64 + +void sha_init (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi); +void sha_update (const BYTE *, int, INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]); +void sha_final (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]); + +void sha_stream (INT32 sha_info_digest[5]); +void sha_print (); + +#define BLOCK_SIZE 8192 +#define VSIZE 2 + +/* ++--------------------------------------------------------------------------+ +| * Test Vectors (added for CHStone) | +| indata, in_i : input data | ++--------------------------------------------------------------------------+ +*/ +#define f1(x,y,z) ((x & y) | (~x & z)) +#define f2(x,y,z) (x ^ y ^ z) +#define f3(x,y,z) ((x & y) | (x & z) | (y & z)) +#define f4(x,y,z) (x ^ y ^ z) + +/* SHA constants */ + +#define CONST1 0x5a827999L +#define CONST2 0x6ed9eba1L +#define CONST3 0x8f1bbcdcL +#define CONST4 0xca62c1d6L + +/* 32-bit rotate */ + +#define ROT32(x,n) ((x << n) | (x >> (32 - n))) + +#define FUNC(n,i) \ + temp = ROT32(A,5) + f##n(B,C,D) + E + W[i] + CONST##n; \ + E = D; D = C; C = ROT32(B,30); B = A; A = temp + +void +local_memset (INT32 * s, int c, int n, int e) +{ + INT32 uc; + INT32 *p; + int m; + + m = n >> 2; + uc = c; + p = (INT32 *) s; + while (e-- > 0) + { + p++; + } + while (m-- > 0) + { + *p++ = uc; + } +} + +void +local_memcpy (INT32 * s1, const BYTE * s2, int n) +{ + INT32 *p1; + BYTE *p2; + INT32 tmp; + int m; + m = n >> 2; + p1 = (INT32 *) s1; + p2 = (BYTE *) s2; + + while (m-- > 0) + { + tmp = 0; + tmp |= 0xFF & *p2++; + tmp |= (0xFF & *p2++) << 8; + tmp |= (0xFF & *p2++) << 16; + tmp |= (0xFF & *p2++) << 24; + *p1 = tmp; + p1++; + } +} + +/* do SHA transformation */ + +static void +sha_transform (INT32 sha_info_digest[5], INT32 sha_info_data[16]) +{ + int i; + INT32 temp, A, B, C, D, E, W[80]; + + for (i = 0; i < 16; ++i) + { + W[i] = sha_info_data[i]; + } + for (i = 16; i < 80; ++i) + { + W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + } + A = sha_info_digest[0]; + B = sha_info_digest[1]; + C = sha_info_digest[2]; + D = sha_info_digest[3]; + E = sha_info_digest[4]; + + for (i = 0; i < 20; ++i) + { + FUNC (1, i); + } + for (i = 20; i < 40; ++i) + { + FUNC (2, i); + } + for (i = 40; i < 60; ++i) + { + FUNC (3, i); + } + for (i = 60; i < 80; ++i) + { + FUNC (4, i); + } + + sha_info_digest[0] += A; + sha_info_digest[1] += B; + sha_info_digest[2] += C; + sha_info_digest[3] += D; + sha_info_digest[4] += E; +} + +/* initialize the SHA digest */ + +void +sha_init (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi) +{ + sha_info_digest[0] = 0x67452301L; + sha_info_digest[1] = 0xefcdab89L; + sha_info_digest[2] = 0x98badcfeL; + sha_info_digest[3] = 0x10325476L; + sha_info_digest[4] = 0xc3d2e1f0L; + *sha_info_count_lo = 0L; + *sha_info_count_hi = 0L; +} + +/* update the SHA digest */ + +void +sha_update (const BYTE * buffer, int count, INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]) +{ + if ((*sha_info_count_lo + ((INT32) count << 3)) < *sha_info_count_lo) + { + *sha_info_count_hi = *sha_info_count_hi + 1 ; + } + *sha_info_count_lo += (INT32) count << 3; + *sha_info_count_hi += (INT32) count >> 29; + while (count >= SHA_BLOCKSIZE) + { + local_memcpy (sha_info_data, buffer, SHA_BLOCKSIZE); + sha_transform (sha_info_digest, sha_info_data); + buffer += SHA_BLOCKSIZE; + count -= SHA_BLOCKSIZE; + } + local_memcpy (sha_info_data, buffer, count); +} + +/* finish computing the SHA digest */ + +void +sha_final (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]) +{ + int count; + INT32 lo_bit_count; + INT32 hi_bit_count; + + + lo_bit_count = *sha_info_count_lo; + hi_bit_count = *sha_info_count_hi; + count = (int) ((lo_bit_count >> 3) & 0x3f); + sha_info_data[count++] = 0x80; + if (count > 56) + { + local_memset (sha_info_data, 0, 64 - count, count); + sha_transform (sha_info_digest, sha_info_data); + local_memset (sha_info_data, 0, 56, 0); + } + else + { + local_memset (sha_info_data, 0, 56 - count, count); + } + sha_info_data[14] = hi_bit_count; + sha_info_data[15] = lo_bit_count; + sha_transform (sha_info_digest, sha_info_data); +} + +/* compute the SHA digest of a FILE stream */ +void +sha_stream (INT32 sha_info_digest[5]) +{ + int i, j; + const BYTE *p; + INT32 sha_info_count_lo, sha_info_count_hi; /* 64-bit bit count */ + INT32 sha_info_data[16]; + const BYTE indata[VSIZE][BLOCK_SIZE] = { + {75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, + 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, + 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, + 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, + 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, + 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, + 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, + 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, + 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, + 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, + 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, + 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, + 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, + 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, + 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, + 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, + 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, + 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, + 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, + 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, + 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, + 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, + 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, + 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, + 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, + 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, + 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, + 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, + 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, + 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, + 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, + 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, + 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, + 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, + 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, + 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, + 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, + 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, + 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, + 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, + 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, + 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, + 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, + 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, + 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, + 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, + 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, + 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, + 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, + 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, + 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, + 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, + 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, + 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, + 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, + 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, + 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, + 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, + 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, + 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, + 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, + 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, + 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, + 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, + 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 79, 114, 119, 111, 114, 114, 121, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, + 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, + 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, + 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, + 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, + 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, + 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, + 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, + 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, + 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, + 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, + 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, + 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, + 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, + 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, + 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, + 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, + 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, + 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, + 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, + 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, + 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, + 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, + 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, + 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, + 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, + 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, + 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, + 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, + 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, + 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, + 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, + 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, + 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, + 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, + 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, + 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, + 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, + 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, + 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, + 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, + 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, + 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, + 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, + 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, + 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, + 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, + 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, + 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, + 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, + 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, + 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, + 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, + 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, + 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, + 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, + 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, + 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, + 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, + 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, + 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, + 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, + 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, + 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, + 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, + 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, + 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, + 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, + 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, + 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, + 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, + 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, + 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, + 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, + 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, + 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, + 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, + 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 75, 117, 114, 116, + 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, + 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, + 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, + 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, + 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, + 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, + 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, + 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, + 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, + 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, + 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, + 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, + 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, + 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, + 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, + 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, + 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, + 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, + 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, + 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, + 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, + 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, + 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, + 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, + 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, + 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, + 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, + 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, + 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, + 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, + 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, + 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, + 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, + 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, + 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, + 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, + 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, + 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, + 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, + 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117}, + {116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, + 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, + 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, + 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, + 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, + 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, + 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, + 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, + 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, + 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, + 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, + 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, + 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, + 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, + 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, + 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, + 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, + 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, + 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, + 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, + 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, + 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, + 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, + 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, + 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, + 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, + 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, + 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, + 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, + 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, + 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, + 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, + 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, + 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, + 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, + 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, + 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, + 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, + 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, + 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, + 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, + 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, + 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, + 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, + 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, + 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, + 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, + 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, + 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, + 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, + 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, + 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, + 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, + 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, + 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, + 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, + 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, + 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, + 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, + 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, + 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, + 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, + 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, + 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, + 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, + 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, + 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, + 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, + 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, + 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, + 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, + 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, + 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, + 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, + 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, + 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, + 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, + 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, + 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, + 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, + 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, + 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, + 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, + 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, + 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, + 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, + 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, + 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, + 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, + 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, + 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, + 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, + 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, + 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, + 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, + 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, + 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, + 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, + 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, + 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, + 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, + 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, + 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, + 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, + 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, + 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, + 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, + 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, + 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, + 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, + 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, + 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, + 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, + 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, + 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, + 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, + 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, + 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, + 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, + 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, + 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, + 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, + 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, + 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, + 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, + 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, + 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, + 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, + 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, + 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, + 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, + 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, + 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, + 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, + 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, + 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, + 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, + 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, + 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, + 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, + 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, + 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, + 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, + 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, + 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, + 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, + 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, + 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, + 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, + 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, + 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, + 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, + 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, + 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, + 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, + 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, + 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, + 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, + 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, + 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, + 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, + 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, + 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, + 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, + 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, + 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, + 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, + 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, + 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, + 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, + 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, + 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, + 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, + 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, + 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, + 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, + 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, + 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, + 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, + 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, + 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, + 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, + 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, + 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, + 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, + 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, + 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, + 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, + 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, + 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, + 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, + 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, + 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, + 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, + 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, + 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, + 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, + 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, + 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, + 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, + 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, + 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, + 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, + 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, + 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, + 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, + 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, + 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, + 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, + 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, + 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, + 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, + 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, + 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, + 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, + 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, + 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, + 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, + 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, + 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, + 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, + 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111} +}; +const int in_i[VSIZE] = { 8192, 8192 }; + + sha_init(sha_info_digest, &sha_info_count_lo, &sha_info_count_hi); + for (j = 0; j < VSIZE; j++) + { + i = in_i[j]; + p = &indata[j][0]; + sha_update (p, i, sha_info_digest, &sha_info_count_lo, &sha_info_count_hi, sha_info_data); + } + sha_final (sha_info_digest, &sha_info_count_lo, &sha_info_count_hi, sha_info_data); +} +/* ++--------------------------------------------------------------------------+ +| * Test Vector (added for CHStone) | +| outData : expected output data | ++--------------------------------------------------------------------------+ +*/ +int +main () +{ + const INT32 outData[5] = + { 0x006a5a37UL, 0x93dc9485UL, 0x2c412112UL, 0x63f7ba43UL, 0xad73f922UL }; + INT32 sha_info_digest[5]; /* message digest */ + + int i; + int main_result; + main_result = 0; + sha_stream (sha_info_digest); + + for (i = 0; i < 5; i++) + { + printf("%d: %x == %x\n", i, sha_info_digest[i], outData[i]); + main_result += (sha_info_digest[i] != outData[i]); + } + printf ("%d\n", main_result); + + return main_result; + } -- cgit From 2fb0545e09c92cec8d4e80e93316dee309a27fc5 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 21 Jun 2020 13:25:06 +0100 Subject: Add fixed benchmarks --- benchmarks/CHStone/adpcm/adpcm.c | 82 +++++++++++++++++------------------ benchmarks/CHStone/mips/mips.c | 89 ++++++++++++++++++++++++++++++++++++-- benchmarks/CHStone/sha/sha_coqup.c | 4 -- 3 files changed, 125 insertions(+), 50 deletions(-) diff --git a/benchmarks/CHStone/adpcm/adpcm.c b/benchmarks/CHStone/adpcm/adpcm.c index 613b1bd..7cf81d1 100755 --- a/benchmarks/CHStone/adpcm/adpcm.c +++ b/benchmarks/CHStone/adpcm/adpcm.c @@ -62,7 +62,6 @@ /* */ /* */ /*************************************************************************/ -#include int encode (int, int); void decode (int); @@ -250,23 +249,23 @@ encode (int xin1, int xin2) int i; const int *h_ptr; int *tqmf_ptr, *tqmf_ptr1; - long int xa, xb; + int xa, xb; int decis; /* transmit quadrature mirror filters implemented here */ h_ptr = h; tqmf_ptr = tqmf; - xa = (long) (*tqmf_ptr++) * (*h_ptr++); - xb = (long) (*tqmf_ptr++) * (*h_ptr++); + xa = (int) (*tqmf_ptr++) * (*h_ptr++); + xb = (int) (*tqmf_ptr++) * (*h_ptr++); /* main multiply accumulate loop for samples and coefficients */ for (i = 0; i < 10; i++) { - xa += (long) (*tqmf_ptr++) * (*h_ptr++); - xb += (long) (*tqmf_ptr++) * (*h_ptr++); + xa += (int) (*tqmf_ptr++) * (*h_ptr++); + xb += (int) (*tqmf_ptr++) * (*h_ptr++); } /* final mult/accumulate */ - xa += (long) (*tqmf_ptr++) * (*h_ptr++); - xb += (long) (*tqmf_ptr) * (*h_ptr++); + xa += (int) (*tqmf_ptr++) * (*h_ptr++); + xb += (int) (*tqmf_ptr) * (*h_ptr++); /* update delay line tqmf */ tqmf_ptr1 = tqmf_ptr - 2; @@ -298,7 +297,7 @@ encode (int xin1, int xin2) /* computes quantized difference signal */ /* for invqbl, truncate by 2 lsbs, so mode = 3 */ - dlt = ((long) detl * qq4_code4_table[il >> 2]) >> 15; + dlt = ((int) detl * qq4_code4_table[il >> 2]) >> 15; /* logscl: updates logarithmic quant. scale factor in low sub band */ nbl = logscl (il, nbl); @@ -354,12 +353,12 @@ encode (int xin1, int xin2) { ih = 1; /* 0,1 are neg codes */ } - decis = (564L * (long) deth) >> 12L; + decis = (564L * (int) deth) >> 12L; if (abs (eh) > decis) ih--; /* mih = 2 case */ /* compute the quantized difference signal, higher sub-band*/ - dh = ((long) deth * qq2_code2_table[ih]) >> 15L; + dh = ((int) deth * qq2_code2_table[ih]) >> 15L; /* logsch: update logarithmic quantizer scale factor in hi sub-band*/ nbh = logsch (ih, nbh); @@ -401,7 +400,7 @@ void decode (int input) { int i; - long int xa1, xa2; /* qmf accumulators */ + int xa1, xa2; /* qmf accumulators */ const int *h_ptr; int *ac_ptr, *ac_ptr1, *ad_ptr, *ad_ptr1; @@ -420,10 +419,10 @@ decode (int input) dec_sl = dec_spl + dec_szl; /* compute quantized difference signal for adaptive predic */ - dec_dlt = ((long) dec_detl * qq4_code4_table[ilr >> 2]) >> 15; + dec_dlt = ((int) dec_detl * qq4_code4_table[ilr >> 2]) >> 15; /* compute quantized difference signal for decoder output */ - dl = ((long) dec_detl * qq6_code6_table[il]) >> 15; + dl = ((int) dec_detl * qq6_code6_table[il]) >> 15; rl = dl + dec_sl; @@ -467,7 +466,7 @@ decode (int input) dec_sh = dec_sph + dec_szh; /* in-place compute the quantized difference signal */ - dec_dh = ((long) dec_deth * qq2_code2_table[ih]) >> 15L; + dec_dh = ((int) dec_deth * qq2_code2_table[ih]) >> 15L; /* logsch: update logarithmic quantizer scale factor in hi sub band */ dec_nbh = logsch (ih, dec_nbh); @@ -506,17 +505,17 @@ decode (int input) h_ptr = h; ac_ptr = accumc; ad_ptr = accumd; - xa1 = (long) xd *(*h_ptr++); - xa2 = (long) xs *(*h_ptr++); + xa1 = (int) xd *(*h_ptr++); + xa2 = (int) xs *(*h_ptr++); /* main multiply accumulate loop for samples and coefficients */ for (i = 0; i < 10; i++) { - xa1 += (long) (*ac_ptr++) * (*h_ptr++); - xa2 += (long) (*ad_ptr++) * (*h_ptr++); + xa1 += (int) (*ac_ptr++) * (*h_ptr++); + xa2 += (int) (*ad_ptr++) * (*h_ptr++); } /* final mult/accumulate */ - xa1 += (long) (*ac_ptr) * (*h_ptr++); - xa2 += (long) (*ad_ptr) * (*h_ptr++); + xa1 += (int) (*ac_ptr) * (*h_ptr++); + xa2 += (int) (*ad_ptr) * (*h_ptr++); /* scale by 2^14 */ xout1 = xa1 >> 14; @@ -581,10 +580,10 @@ int filtez (int *bpl, int *dlt) { int i; - long int zl; - zl = (long) (*bpl++) * (*dlt++); + int zl; + zl = (int) (*bpl++) * (*dlt++); for (i = 1; i < 6; i++) - zl += (long) (*bpl++) * (*dlt++); + zl += (int) (*bpl++) * (*dlt++); return ((int) (zl >> 14)); /* x2 here */ } @@ -595,11 +594,11 @@ filtez (int *bpl, int *dlt) int filtep (int rlt1, int al1, int rlt2, int al2) { - long int pl, pl2; + int pl, pl2; pl = 2 * rlt1; - pl = (long) al1 *pl; + pl = (int) al1 *pl; pl2 = 2 * rlt2; - pl += (long) al2 *pl2; + pl += (int) al2 *pl2; return ((int) (pl >> 15)); } @@ -608,14 +607,14 @@ int quantl (int el, int detl) { int ril, mil; - long int wd, decis; + int wd, decis; /* abs of difference signal */ wd = abs (el); /* determine mil based on decision levels and detl gain */ for (mil = 0; mil < 30; mil++) { - decis = (decis_levl[mil] * (long) detl) >> 15L; + decis = (decis_levl[mil] * (int) detl) >> 15L; if (wd <= decis) break; } @@ -633,8 +632,8 @@ quantl (int el, int detl) int logscl (int il, int nbl) { - long int wd; - wd = ((long) nbl * 127L) >> 7L; /* leak factor 127/128 */ + int wd; + wd = ((int) nbl * 127L) >> 7L; /* leak factor 127/128 */ nbl = (int) wd + wl_code_table[il >> 2]; if (nbl < 0) nbl = 0; @@ -674,7 +673,7 @@ upzero (int dlt, int *dlti, int *bli) { for (i = 0; i < 6; i++) { - if ((long) dlt * dlti[i] >= 0) + if ((int) dlt * dlti[i] >= 0) wd2 = 128; else wd2 = -128; @@ -697,13 +696,13 @@ upzero (int dlt, int *dlti, int *bli) int uppol2 (int al1, int al2, int plt, int plt1, int plt2) { - long int wd2, wd4; + int wd2, wd4; int apl2; - wd2 = 4L * (long) al1; - if ((long) plt * plt1 >= 0L) + wd2 = 4L * (int) al1; + if ((int) plt * plt1 >= 0L) wd2 = -wd2; /* check same sign */ wd2 = wd2 >> 7; /* gain of 1/128 */ - if ((long) plt * plt2 >= 0L) + if ((int) plt * plt2 >= 0L) { wd4 = wd2 + 128; /* same sign case */ } @@ -711,7 +710,7 @@ uppol2 (int al1, int al2, int plt, int plt1, int plt2) { wd4 = wd2 - 128; } - apl2 = wd4 + (127L * (long) al2 >> 7L); /* leak factor of 127/128 */ + apl2 = wd4 + (127L * (int) al2 >> 7L); /* leak factor of 127/128 */ /* apl2 is limited to +-.75 */ if (apl2 > 12288) @@ -727,10 +726,10 @@ uppol2 (int al1, int al2, int plt, int plt1, int plt2) int uppol1 (int al1, int apl2, int plt, int plt1) { - long int wd2; + int wd2; int wd3, apl1; - wd2 = ((long) al1 * 255L) >> 8L; /* leak factor of 255/256 */ - if ((long) plt * plt1 >= 0L) + wd2 = ((int) al1 * 255L) >> 8L; /* leak factor of 255/256 */ + if ((int) plt * plt1 >= 0L) { apl1 = (int) wd2 + 192; /* same sign case */ } @@ -754,7 +753,7 @@ int logsch (int ih, int nbh) { int wd; - wd = ((long) nbh * 127L) >> 7L; /* leak factor 127/128 */ + wd = ((int) nbh * 127L) >> 7L; /* leak factor 127/128 */ nbh = wd + wh_code_table[ih]; if (nbh < 0) nbh = 0; @@ -877,6 +876,5 @@ main () main_result += 1; } } - printf ("%d\n", main_result); return main_result; } diff --git a/benchmarks/CHStone/mips/mips.c b/benchmarks/CHStone/mips/mips.c index 09591fe..7352e81 100755 --- a/benchmarks/CHStone/mips/mips.c +++ b/benchmarks/CHStone/mips/mips.c @@ -34,7 +34,90 @@ * agents, transferees, successors, and assigns. * */ -#include + +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +/* + * Copyright (C) 2008 + * Y. Hara, H. Tomiyama, S. Honda, H. Takada and K. Ishii + * Nagoya University, Japan + * All rights reserved. + * + * Disclaimer of Warranty + * + * These software programs are available to the user without any license fee or + * royalty on an "as is" basis. The authors disclaims any and all warranties, + * whether express, implied, or statuary, including any implied warranties or + * merchantability or of fitness for a particular purpose. In no event shall the + * copyright-holder be liable for any incidental, punitive, or consequential damages + * of any kind whatsoever arising from the use of these programs. This disclaimer + * of warranty extends to the user of these programs and user's customers, employees, + * agents, transferees, successors, and assigns. + * + */ +const unsigned int imem[44] = { + 0x8fa40000, // [0x00400000] lw $4, 0($29) ; 175: lw $a0 0($sp) # argc + 0x27a50004, // [0x00400004] addiu $5, $29, 4 ; 176: addiu $a1 $sp 4 # argv + 0x24a60004, // [0x00400008] addiu $6, $5, 4 ; 177: addiu $a2 $a1 4 # envp + 0x00041080, // [0x0040000c] sll $2, $4, 2 ; 178: sll $v0 $a0 2 + 0x00c23021, // [0x00400010] addu $6, $6, $2 ; 179: addu $a2 $a2 $v0 + 0x0c100016, // [0x00400014] jal 0x00400058 [main] ; 180: jal main + 0x00000000, // [0x00400018] nop ; 181: nop + 0x3402000a, // [0x0040001c] ori $2, $0, 10 ; 183: li $v0 10 + 0x0000000c, // [0x00400020] syscall ; 184: syscall # syscall 10 (exit) + 0x3c011001, // [0x00400024] lui $1, 4097 [A] ; 4: la $t0,A ; C&S + 0x34280000, // [0x00400028] ori $8, $1, 0 [A] + 0x00044880, // [0x0040002c] sll $9, $4, 2 ; 5: sll $t1,$a0,2 + 0x01094821, // [0x00400030] addu $9, $8, $9 ; 6: addu $t1,$t0,$t1 + 0x8d2a0000, // [0x00400034] lw $10, 0($9) ; 7: lw $t2,($t1) + 0x00055880, // [0x00400038] sll $11, $5, 2 ; 8: sll $t3,$a1,2 + 0x010b5821, // [0x0040003c] addu $11, $8, $11 ; 9: addu $t3,$t0,$t3 + 0x8d6c0000, // [0x00400040] lw $12, 0($11) ; 10: lw $t4,($t3) + 0x018a682a, // [0x00400044] slt $13, $12, $10 ; 11: slt $t5,$t4,$t2 + 0x11a00003, // [0x00400048] beq $13, $0, 12 [L1-0x00400048] ; 12: beq $t5,$zero,L1 + 0xad2c0000, // [0x0040004c] sw $12, 0($9) ; 13: sw $t4,($t1) + 0xad6a0000, // [0x00400050] sw $10, 0($11) ; 14: sw $t2,($t3) + 0x03e00008, // [0x00400054] jr $31 ; 15: jr $ra ; L1 + 0x27bdfff4, // [0x00400058] addiu $29, $29, -12 ; 17: addiu $sp,$sp,-12 ; main + 0xafbf0008, // [0x0040005c] sw $31, 8($29) ; 18: sw $ra,8($sp) + 0xafb10004, // [0x00400060] sw $17, 4($29) ; 19: sw $s1,4($sp) + 0xafb00000, // [0x00400064] sw $16, 0($29) ; 20: sw $s0,0($sp) + 0x24100000, // [0x00400068] addiu $16, $0, 0 ; 21: addiu $s0,$zero,0 + 0x2a080008, // [0x0040006c] slti $8, $16, 8 ; 22: slti $t0,$s0,8 ; L5 + 0x1100000b, // [0x00400070] beq $8, $0, 44 [L2-0x00400070] ; 23: beq $t0,$zero,L2 + 0x26110001, // [0x00400074] addiu $17, $16, 1 ; 24: addiu $s1,$s0,1 + 0x2a280008, // [0x00400078] slti $8, $17, 8 ; 25: slti $t0,$s1,8 ; L4 + 0x11000006, // [0x0040007c] beq $8, $0, 24 [L3-0x0040007c] ; 26: beq $t0,$zero,L3 + 0x26040000, // [0x00400080] addiu $4, $16, 0 ; 27: addiu $a0,$s0,0 + 0x26250000, // [0x00400084] addiu $5, $17, 0 ; 28: addiu $a1,$s1,0 + 0x0c100009, // [0x00400088] jal 0x00400024 [compare_swap] ; 29: jal compare_swap + 0x26310001, // [0x0040008c] addiu $17, $17, 1 ; 30: addiu $s1,$s1,1 + 0x0810001e, // [0x00400090] j 0x00400078 [L4] ; 31: j L4 + 0x26100001, // [0x00400094] addiu $16, $16, 1 ; 32: addiu $s0,$s0,1 ; L3 + 0x0810001b, // [0x00400098] j 0x0040006c [L5] ; 33: j L5 + 0x8fbf0008, // [0x0040009c] lw $31, 8($29) ; 34: lw $ra,8($sp) ; L2 + 0x8fb10004, // [0x004000a0] lw $17, 4($29) ; 35: lw $s1,4($sp) + 0x8fb00000, // [0x004000a4] lw $16, 0($29) ; 36: lw $s0,0($sp) + 0x27bd000c, // [0x004000a8] addiu $29, $29, 12 ; 37: addiu $sp,$sp,12 + 0x03e00008, // [0x004000ac] jr $31 ; 38: jr $ra +}; + int main_result; #define R 0 @@ -80,7 +163,6 @@ int main_result; #define SLTI 10 #define SLTIU 11 -#include "imem.h" /* +--------------------------------------------------------------------------+ | * Test Vectors (added for CHStone) | @@ -97,7 +179,7 @@ const int outData[8] = { -17, -9, 0, 3, 5, 11, 22, 38 }; int main () { - long long hilo; + int hilo; int reg[32]; int Hi = 0; int Lo = 0; @@ -300,7 +382,6 @@ main () main_result += (dmem[j] != outData[j]); } - printf ("%d\n", main_result); return main_result; } } diff --git a/benchmarks/CHStone/sha/sha_coqup.c b/benchmarks/CHStone/sha/sha_coqup.c index eea3a8a..3c4d7c8 100755 --- a/benchmarks/CHStone/sha/sha_coqup.c +++ b/benchmarks/CHStone/sha/sha_coqup.c @@ -24,8 +24,6 @@ /* NIST's proposed modification to SHA of 7/11/94 may be */ /* activated by defining USE_MODIFIED_SHA */ -#include - /* NIST Secure Hash Algorithm */ /* heavily modified from Peter C. Gutmann's implementation */ @@ -1348,10 +1346,8 @@ main () for (i = 0; i < 5; i++) { - printf("%d: %x == %x\n", i, sha_info_digest[i], outData[i]); main_result += (sha_info_digest[i] != outData[i]); } - printf ("%d\n", main_result); return main_result; } -- cgit From 15f559fee65f70e984891717904bba6a3255ee13 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Mon, 22 Jun 2020 14:27:16 +0100 Subject: mips working well! --- benchmarks/CHStone/mips/mips.c | 476 ++++++++++++++++++++--------------------- 1 file changed, 238 insertions(+), 238 deletions(-) diff --git a/benchmarks/CHStone/mips/mips.c b/benchmarks/CHStone/mips/mips.c index 7352e81..9482a5e 100755 --- a/benchmarks/CHStone/mips/mips.c +++ b/benchmarks/CHStone/mips/mips.c @@ -71,55 +71,6 @@ * agents, transferees, successors, and assigns. * */ -const unsigned int imem[44] = { - 0x8fa40000, // [0x00400000] lw $4, 0($29) ; 175: lw $a0 0($sp) # argc - 0x27a50004, // [0x00400004] addiu $5, $29, 4 ; 176: addiu $a1 $sp 4 # argv - 0x24a60004, // [0x00400008] addiu $6, $5, 4 ; 177: addiu $a2 $a1 4 # envp - 0x00041080, // [0x0040000c] sll $2, $4, 2 ; 178: sll $v0 $a0 2 - 0x00c23021, // [0x00400010] addu $6, $6, $2 ; 179: addu $a2 $a2 $v0 - 0x0c100016, // [0x00400014] jal 0x00400058 [main] ; 180: jal main - 0x00000000, // [0x00400018] nop ; 181: nop - 0x3402000a, // [0x0040001c] ori $2, $0, 10 ; 183: li $v0 10 - 0x0000000c, // [0x00400020] syscall ; 184: syscall # syscall 10 (exit) - 0x3c011001, // [0x00400024] lui $1, 4097 [A] ; 4: la $t0,A ; C&S - 0x34280000, // [0x00400028] ori $8, $1, 0 [A] - 0x00044880, // [0x0040002c] sll $9, $4, 2 ; 5: sll $t1,$a0,2 - 0x01094821, // [0x00400030] addu $9, $8, $9 ; 6: addu $t1,$t0,$t1 - 0x8d2a0000, // [0x00400034] lw $10, 0($9) ; 7: lw $t2,($t1) - 0x00055880, // [0x00400038] sll $11, $5, 2 ; 8: sll $t3,$a1,2 - 0x010b5821, // [0x0040003c] addu $11, $8, $11 ; 9: addu $t3,$t0,$t3 - 0x8d6c0000, // [0x00400040] lw $12, 0($11) ; 10: lw $t4,($t3) - 0x018a682a, // [0x00400044] slt $13, $12, $10 ; 11: slt $t5,$t4,$t2 - 0x11a00003, // [0x00400048] beq $13, $0, 12 [L1-0x00400048] ; 12: beq $t5,$zero,L1 - 0xad2c0000, // [0x0040004c] sw $12, 0($9) ; 13: sw $t4,($t1) - 0xad6a0000, // [0x00400050] sw $10, 0($11) ; 14: sw $t2,($t3) - 0x03e00008, // [0x00400054] jr $31 ; 15: jr $ra ; L1 - 0x27bdfff4, // [0x00400058] addiu $29, $29, -12 ; 17: addiu $sp,$sp,-12 ; main - 0xafbf0008, // [0x0040005c] sw $31, 8($29) ; 18: sw $ra,8($sp) - 0xafb10004, // [0x00400060] sw $17, 4($29) ; 19: sw $s1,4($sp) - 0xafb00000, // [0x00400064] sw $16, 0($29) ; 20: sw $s0,0($sp) - 0x24100000, // [0x00400068] addiu $16, $0, 0 ; 21: addiu $s0,$zero,0 - 0x2a080008, // [0x0040006c] slti $8, $16, 8 ; 22: slti $t0,$s0,8 ; L5 - 0x1100000b, // [0x00400070] beq $8, $0, 44 [L2-0x00400070] ; 23: beq $t0,$zero,L2 - 0x26110001, // [0x00400074] addiu $17, $16, 1 ; 24: addiu $s1,$s0,1 - 0x2a280008, // [0x00400078] slti $8, $17, 8 ; 25: slti $t0,$s1,8 ; L4 - 0x11000006, // [0x0040007c] beq $8, $0, 24 [L3-0x0040007c] ; 26: beq $t0,$zero,L3 - 0x26040000, // [0x00400080] addiu $4, $16, 0 ; 27: addiu $a0,$s0,0 - 0x26250000, // [0x00400084] addiu $5, $17, 0 ; 28: addiu $a1,$s1,0 - 0x0c100009, // [0x00400088] jal 0x00400024 [compare_swap] ; 29: jal compare_swap - 0x26310001, // [0x0040008c] addiu $17, $17, 1 ; 30: addiu $s1,$s1,1 - 0x0810001e, // [0x00400090] j 0x00400078 [L4] ; 31: j L4 - 0x26100001, // [0x00400094] addiu $16, $16, 1 ; 32: addiu $s0,$s0,1 ; L3 - 0x0810001b, // [0x00400098] j 0x0040006c [L5] ; 33: j L5 - 0x8fbf0008, // [0x0040009c] lw $31, 8($29) ; 34: lw $ra,8($sp) ; L2 - 0x8fb10004, // [0x004000a0] lw $17, 4($29) ; 35: lw $s1,4($sp) - 0x8fb00000, // [0x004000a4] lw $16, 0($29) ; 36: lw $s0,0($sp) - 0x27bd000c, // [0x004000a8] addiu $29, $29, 12 ; 37: addiu $sp,$sp,12 - 0x03e00008, // [0x004000ac] jr $31 ; 38: jr $ra -}; - -int main_result; - #define R 0 #define ADDU 33 @@ -170,15 +121,64 @@ int main_result; | outData : expected output data | +--------------------------------------------------------------------------+ */ -const int A[8] = { 22, 5, -9, 3, -17, 38, 0, 11 }; -const int outData[8] = { -17, -9, 0, 3, 5, 11, 22, 38 }; - #define IADDR(x) (((x)&0x000000ff)>>2) #define DADDR(x) (((x)&0x000000ff)>>2) int main () { + const unsigned int imem[44] = { + 0x8fa40000, // [0x00400000] lw $4, 0($29) ; 175: lw $a0 0($sp) # argc + 0x27a50004, // [0x00400004] addiu $5, $29, 4 ; 176: addiu $a1 $sp 4 # argv + 0x24a60004, // [0x00400008] addiu $6, $5, 4 ; 177: addiu $a2 $a1 4 # envp + 0x00041080, // [0x0040000c] sll $2, $4, 2 ; 178: sll $v0 $a0 2 + 0x00c23021, // [0x00400010] addu $6, $6, $2 ; 179: addu $a2 $a2 $v0 + 0x0c100016, // [0x00400014] jal 0x00400058 [main] ; 180: jal main + 0x00000000, // [0x00400018] nop ; 181: nop + 0x3402000a, // [0x0040001c] ori $2, $0, 10 ; 183: li $v0 10 + 0x0000000c, // [0x00400020] syscall ; 184: syscall # syscall 10 (exit) + 0x3c011001, // [0x00400024] lui $1, 4097 [A] ; 4: la $t0,A ; C&S + 0x34280000, // [0x00400028] ori $8, $1, 0 [A] + 0x00044880, // [0x0040002c] sll $9, $4, 2 ; 5: sll $t1,$a0,2 + 0x01094821, // [0x00400030] addu $9, $8, $9 ; 6: addu $t1,$t0,$t1 + 0x8d2a0000, // [0x00400034] lw $10, 0($9) ; 7: lw $t2,($t1) + 0x00055880, // [0x00400038] sll $11, $5, 2 ; 8: sll $t3,$a1,2 + 0x010b5821, // [0x0040003c] addu $11, $8, $11 ; 9: addu $t3,$t0,$t3 + 0x8d6c0000, // [0x00400040] lw $12, 0($11) ; 10: lw $t4,($t3) + 0x018a682a, // [0x00400044] slt $13, $12, $10 ; 11: slt $t5,$t4,$t2 + 0x11a00003, // [0x00400048] beq $13, $0, 12 [L1-0x00400048] ; 12: beq $t5,$zero,L1 + 0xad2c0000, // [0x0040004c] sw $12, 0($9) ; 13: sw $t4,($t1) + 0xad6a0000, // [0x00400050] sw $10, 0($11) ; 14: sw $t2,($t3) + 0x03e00008, // [0x00400054] jr $31 ; 15: jr $ra ; L1 + 0x27bdfff4, // [0x00400058] addiu $29, $29, -12 ; 17: addiu $sp,$sp,-12 ; main + 0xafbf0008, // [0x0040005c] sw $31, 8($29) ; 18: sw $ra,8($sp) + 0xafb10004, // [0x00400060] sw $17, 4($29) ; 19: sw $s1,4($sp) + 0xafb00000, // [0x00400064] sw $16, 0($29) ; 20: sw $s0,0($sp) + 0x24100000, // [0x00400068] addiu $16, $0, 0 ; 21: addiu $s0,$zero,0 + 0x2a080008, // [0x0040006c] slti $8, $16, 8 ; 22: slti $t0,$s0,8 ; L5 + 0x1100000b, // [0x00400070] beq $8, $0, 44 [L2-0x00400070] ; 23: beq $t0,$zero,L2 + 0x26110001, // [0x00400074] addiu $17, $16, 1 ; 24: addiu $s1,$s0,1 + 0x2a280008, // [0x00400078] slti $8, $17, 8 ; 25: slti $t0,$s1,8 ; L4 + 0x11000006, // [0x0040007c] beq $8, $0, 24 [L3-0x0040007c] ; 26: beq $t0,$zero,L3 + 0x26040000, // [0x00400080] addiu $4, $16, 0 ; 27: addiu $a0,$s0,0 + 0x26250000, // [0x00400084] addiu $5, $17, 0 ; 28: addiu $a1,$s1,0 + 0x0c100009, // [0x00400088] jal 0x00400024 [compare_swap] ; 29: jal compare_swap + 0x26310001, // [0x0040008c] addiu $17, $17, 1 ; 30: addiu $s1,$s1,1 + 0x0810001e, // [0x00400090] j 0x00400078 [L4] ; 31: j L4 + 0x26100001, // [0x00400094] addiu $16, $16, 1 ; 32: addiu $s0,$s0,1 ; L3 + 0x0810001b, // [0x00400098] j 0x0040006c [L5] ; 33: j L5 + 0x8fbf0008, // [0x0040009c] lw $31, 8($29) ; 34: lw $ra,8($sp) ; L2 + 0x8fb10004, // [0x004000a0] lw $17, 4($29) ; 35: lw $s1,4($sp) + 0x8fb00000, // [0x004000a4] lw $16, 0($29) ; 36: lw $s0,0($sp) + 0x27bd000c, // [0x004000a8] addiu $29, $29, 12 ; 37: addiu $sp,$sp,12 + 0x03e00008, // [0x004000ac] jr $31 ; 38: jr $ra + }; + + const int A[8] = { 22, 5, -9, 3, -17, 38, 0, 11 }; + const int outData[8] = { -17, -9, 0, 3, 5, 11, 22, 38 }; + + int main_result; + int hilo; int reg[32]; int Hi = 0; @@ -194,194 +194,194 @@ main () int rd; int shamt; int funct; - short address; + int address; int tgtadr; - while (1) + while (1) + { + int i; + int n_inst; + + n_inst = 0; + main_result = 0; + + for (i = 0; i < 32; i++) + { + reg[i] = 0; + } + reg[29] = 0x7fffeffc; + + for (i = 0; i < 8; i++) { - int i; - int n_inst; - - n_inst = 0; - main_result = 0; - - for (i = 0; i < 32; i++) - { - reg[i] = 0; - } - reg[29] = 0x7fffeffc; - - for (i = 0; i < 64; i++) - { - dmem[i] = A[i]; - } - - pc = 0x00400000; - - do - { - ins = imem[IADDR (pc)]; - pc = pc + 4; - - op = ins >> 26; - - switch (op) - { - case R: - funct = ins & 0x3f; - shamt = (ins >> 6) & 0x1f; - rd = (ins >> 11) & 0x1f; - rt = (ins >> 16) & 0x1f; - rs = (ins >> 21) & 0x1f; - - switch (funct) - { - - case ADDU: - reg[rd] = reg[rs] + reg[rt]; - break; - case SUBU: - reg[rd] = reg[rs] - reg[rt]; - break; - - case MULT: - hilo = (long long) reg[rs] * (long long) reg[rt]; - Lo = hilo & 0x00000000ffffffffULL; - Hi = ((int) (hilo >> 32)) & 0xffffffffUL; - break; - case MULTU: - hilo = - (unsigned long long) ((unsigned int) (reg[rs])) * - (unsigned long long) ((unsigned int) (reg[rt])); - Lo = hilo & 0x00000000ffffffffULL; - Hi = ((int) (hilo >> 32)) & 0xffffffffUL; - break; - - case MFHI: - reg[rd] = Hi; - break; - case MFLO: - reg[rd] = Lo; - break; - - case AND: - reg[rd] = reg[rs] & reg[rt]; - break; - case OR: - reg[rd] = reg[rs] | reg[rt]; - break; - case XOR: - reg[rd] = reg[rs] ^ reg[rt]; - break; - case SLL: - reg[rd] = reg[rt] << shamt; - break; - case SRL: - reg[rd] = reg[rt] >> shamt; - break; - case SLLV: - reg[rd] = reg[rt] << reg[rs]; - break; - case SRLV: - reg[rd] = reg[rt] >> reg[rs]; - break; - - case SLT: - reg[rd] = reg[rs] < reg[rt]; - break; - case SLTU: - reg[rd] = (unsigned int) reg[rs] < (unsigned int) reg[rt]; - break; - - case JR: - pc = reg[rs]; - break; - default: - pc = 0; // error - break; - } - break; - - case J: - tgtadr = ins & 0x3ffffff; - pc = tgtadr << 2; - break; - case JAL: - tgtadr = ins & 0x3ffffff; - reg[31] = pc; - pc = tgtadr << 2; - break; - - default: - - address = ins & 0xffff; - rt = (ins >> 16) & 0x1f; - rs = (ins >> 21) & 0x1f; - switch (op) - { - case ADDIU: - reg[rt] = reg[rs] + address; - break; - - case ANDI: - reg[rt] = reg[rs] & (unsigned short) address; - break; - case ORI: - reg[rt] = reg[rs] | (unsigned short) address; - break; - case XORI: - reg[rt] = reg[rs] ^ (unsigned short) address; - break; - - case LW: - reg[rt] = dmem[DADDR (reg[rs] + address)]; - break; - case SW: - dmem[DADDR (reg[rs] + address)] = reg[rt]; - break; - - case LUI: - reg[rt] = address << 16; - break; - - case BEQ: - if (reg[rs] == reg[rt]) - pc = pc - 4 + (address << 2); - break; - case BNE: - if (reg[rs] != reg[rt]) - pc = pc - 4 + (address << 2); - break; - case BGEZ: - if (reg[rs] >= 0) - pc = pc - 4 + (address << 2); - break; - - case SLTI: - reg[rt] = reg[rs] < address; - break; - - case SLTIU: - reg[rt] = (unsigned int) reg[rs] < (unsigned short) address; - break; - - default: - pc = 0; /* error */ - break; - } - break; - } - reg[0] = 0; - n_inst = n_inst + 1; - } - while (pc != 0); - - main_result += (n_inst != 611); - for (j = 0; j < 8; j++) - { - main_result += (dmem[j] != outData[j]); - } - - return main_result; + dmem[i] = A[i]; } + + pc = 0x00400000; + + do + { + ins = imem[IADDR (pc)]; + pc = pc + 4; + + op = ins >> 26; + + switch (op) + { + case R: + funct = ins & 0x3f; + shamt = (ins >> 6) & 0x1f; + rd = (ins >> 11) & 0x1f; + rt = (ins >> 16) & 0x1f; + rs = (ins >> 21) & 0x1f; + + switch (funct) + { + + case ADDU: + reg[rd] = reg[rs] + reg[rt]; + break; + case SUBU: + reg[rd] = reg[rs] - reg[rt]; + break; + /* + case MULT: + hilo = (long long) reg[rs] * (long long) reg[rt]; + Lo = hilo & 0x00000000ffffffffULL; + Hi = ((int) (hilo >> 32)) & 0xffffffffUL; + break; + case MULTU: + hilo = + (unsigned long long) ((unsigned int) (reg[rs])) * + (unsigned long long) ((unsigned int) (reg[rt])); + Lo = hilo & 0x00000000ffffffffULL; + Hi = ((int) (hilo >> 32)) & 0xffffffffUL; + break; + */ + case MFHI: + reg[rd] = Hi; + break; + case MFLO: + reg[rd] = Lo; + break; + + case AND: + reg[rd] = reg[rs] & reg[rt]; + break; + case OR: + reg[rd] = reg[rs] | reg[rt]; + break; + case XOR: + reg[rd] = reg[rs] ^ reg[rt]; + break; + case SLL: + reg[rd] = reg[rt] << shamt; + break; + case SRL: + reg[rd] = reg[rt] >> shamt; + break; + case SLLV: + reg[rd] = reg[rt] << reg[rs]; + break; + case SRLV: + reg[rd] = reg[rt] >> reg[rs]; + break; + + case SLT: + reg[rd] = reg[rs] < reg[rt]; + break; + case SLTU: + reg[rd] = (unsigned int) reg[rs] < (unsigned int) reg[rt]; + break; + + case JR: + pc = reg[rs]; + break; + default: + pc = 0; // error + break; + } + break; + + case J: + tgtadr = ins & 0x3ffffff; + pc = tgtadr << 2; + break; + case JAL: + tgtadr = ins & 0x3ffffff; + reg[31] = pc; + pc = tgtadr << 2; + break; + + default: + + address = ins & 0xffff; + rt = (ins >> 16) & 0x1f; + rs = (ins >> 21) & 0x1f; + switch (op) + { + case ADDIU: + reg[rt] = reg[rs] + address; + break; + + case ANDI: + reg[rt] = reg[rs] & (unsigned ) address; + break; + case ORI: + reg[rt] = reg[rs] | (unsigned ) address; + break; + case XORI: + reg[rt] = reg[rs] ^ (unsigned ) address; + break; + + case LW: + reg[rt] = dmem[DADDR (reg[rs] + address)]; + break; + case SW: + dmem[DADDR (reg[rs] + address)] = reg[rt]; + break; + + case LUI: + reg[rt] = address << 16; + break; + + case BEQ: + if (reg[rs] == reg[rt]) + pc = pc - 4 + (address << 2); + break; + case BNE: + if (reg[rs] != reg[rt]) + pc = pc - 4 + (address << 2); + break; + case BGEZ: + if (reg[rs] >= 0) + pc = pc - 4 + (address << 2); + break; + + case SLTI: + reg[rt] = reg[rs] < address; + break; + + case SLTIU: + reg[rt] = (unsigned int) reg[rs] < (unsigned int) address; + break; + + default: + pc = 0; /* error */ + break; + } + break; + } + reg[0] = 0; + n_inst = n_inst + 1; + } + while (pc != 0); + + main_result += (n_inst != 611); + for (j = 0; j < 8; j++) + { + main_result += (dmem[j] == outData[j]); + } + + return main_result; + } } -- cgit From 50e39ac2f0499941a80684550627f166bbf5d3ee Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Mon, 22 Jun 2020 16:23:03 +0100 Subject: adpcm tweaks - passed gcc --- benchmarks/CHStone/adpcm/adpcm.c | 1251 +++++++++++++++++++------------------- 1 file changed, 613 insertions(+), 638 deletions(-) diff --git a/benchmarks/CHStone/adpcm/adpcm.c b/benchmarks/CHStone/adpcm/adpcm.c index 7cf81d1..b11eed9 100755 --- a/benchmarks/CHStone/adpcm/adpcm.c +++ b/benchmarks/CHStone/adpcm/adpcm.c @@ -1,21 +1,21 @@ /* -+--------------------------------------------------------------------------+ -| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | -| ======================================================================== | -| | -| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | -| H. Takada and K. Ishii | -| Nagoya University, Japan | -| | -| * Remark : | -| 1. This source code is modified to unify the formats of the benchmark | -| programs in CHStone. | -| 2. Test vectors are added for CHStone. | -| 3. If "main_result" is 0 at the end of the program, the program is | -| correctly executed. | -| 4. Please follow the copyright of each benchmark program. | -+--------------------------------------------------------------------------+ -*/ + +--------------------------------------------------------------------------+ + | CHStone : a suite of benchmark programs for C-based High-Level Synthesis | + | ======================================================================== | + | | + | * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | + | H. Takada and K. Ishii | + | Nagoya University, Japan | + | | + | * Remark : | + | 1. This source code is modified to unify the formats of the benchmark | + | programs in CHStone. | + | 2. Test vectors are added for CHStone. | + | 3. If "main_result" is 0 at the end of the program, the program is | + | correctly executed. | + | 4. Please follow the copyright of each benchmark program. | + +--------------------------------------------------------------------------+ + */ /*************************************************************************/ /* */ /* SNU-RT Benchmark Suite for Worst Case Timing Analysis */ @@ -63,6 +63,9 @@ /* */ /*************************************************************************/ +#define SIZE 100 +#define IN_END 100 + int encode (int, int); void decode (int); int filtez (int *bpl, int *dlt); @@ -76,162 +79,12 @@ int uppol1 (int al1, int apl2, int plt, int plt1); int logsch (int ih, int nbh); void reset (); -/* G722 C code */ - -/* variables for transimit quadrature mirror filter here */ -int tqmf[24]; - -/* QMF filter coefficients: -scaled by a factor of 4 compared to G722 CCITT recomendation */ -const int h[24] = { - 12, -44, -44, 212, 48, -624, 128, 1448, - -840, -3220, 3804, 15504, 15504, 3804, -3220, -840, - 1448, 128, -624, 48, 212, -44, -44, 12 -}; - -int xl, xh; - -/* variables for receive quadrature mirror filter here */ -int accumc[11], accumd[11]; - -/* outputs of decode() */ -int xout1, xout2; - -int xs, xd; - -/* variables for encoder (hi and lo) here */ - -int il, szl, spl, sl, el; - -const int qq4_code4_table[16] = { - 0, -20456, -12896, -8968, -6288, -4240, -2584, -1200, - 20456, 12896, 8968, 6288, 4240, 2584, 1200, 0 -}; - - -const int qq6_code6_table[64] = { - -136, -136, -136, -136, -24808, -21904, -19008, -16704, - -14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856, - -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576, - -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728, - 24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192, - 10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456, - 4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032, - 1688, 1360, 1040, 728, 432, 136, -432, -136 -}; - -int delay_bpl[6]; - -int delay_dltx[6]; - -const int wl_code_table[16] = { - -60, 3042, 1198, 538, 334, 172, 58, -30, - 3042, 1198, 538, 334, 172, 58, -30, -60 -}; - -const int ilb_table[32] = { - 2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383, - 2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834, - 2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371, - 3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008 -}; - -int nbl; /* delay line */ -int al1, al2; -int plt, plt1, plt2; -int dlt; -int rlt, rlt1, rlt2; - -/* decision levels - pre-multiplied by 8, 0 to indicate end */ -const int decis_levl[30] = { - 280, 576, 880, 1200, 1520, 1864, 2208, 2584, - 2960, 3376, 3784, 4240, 4696, 5200, 5712, 6288, - 6864, 7520, 8184, 8968, 9752, 10712, 11664, 12896, - 14120, 15840, 17560, 20456, 23352, 32767 -}; - -int detl; - -/* quantization table 31 long to make quantl look-up easier, -last entry is for mil=30 case when wd is max */ -const int quant26bt_pos[31] = { - 61, 60, 59, 58, 57, 56, 55, 54, - 53, 52, 51, 50, 49, 48, 47, 46, - 45, 44, 43, 42, 41, 40, 39, 38, - 37, 36, 35, 34, 33, 32, 32 -}; - -/* quantization table 31 long to make quantl look-up easier, -last entry is for mil=30 case when wd is max */ -const int quant26bt_neg[31] = { - 63, 62, 31, 30, 29, 28, 27, 26, - 25, 24, 23, 22, 21, 20, 19, 18, - 17, 16, 15, 14, 13, 12, 11, 10, - 9, 8, 7, 6, 5, 4, 4 -}; - - -int deth; -int sh; /* this comes from adaptive predictor */ -int eh; - -const int qq2_code2_table[4] = { - -7408, -1616, 7408, 1616 -}; - -const int wh_code_table[4] = { - 798, -214, 798, -214 -}; - - -int dh, ih; -int nbh, szh; -int sph, ph, yh, rh; - -int delay_dhx[6]; - -int delay_bph[6]; - -int ah1, ah2; -int ph1, ph2; -int rh1, rh2; - -/* variables for decoder here */ -int ilr, rl; -int dec_deth, dec_detl, dec_dlt; - -int dec_del_bpl[6]; - -int dec_del_dltx[6]; - -int dec_plt, dec_plt1, dec_plt2; -int dec_szl, dec_spl, dec_sl; -int dec_rlt1, dec_rlt2, dec_rlt; -int dec_al1, dec_al2; -int dl; -int dec_nbl, dec_dh, dec_nbh; - -/* variables used in filtez */ -int dec_del_bph[6]; - -int dec_del_dhx[6]; - -int dec_szh; -/* variables used in filtep */ -int dec_rh1, dec_rh2; -int dec_ah1, dec_ah2; -int dec_ph, dec_sph; - -int dec_sh; - -int dec_ph1, dec_ph2; - /* G722 encode function two ints in, one 8 bit output */ /* put input samples in xin1 = first value, xin2 = second value */ /* returns il and ih stored together */ -int + int abs (int n) { int m; @@ -243,340 +96,10 @@ abs (int n) return m; } -int -encode (int xin1, int xin2) -{ - int i; - const int *h_ptr; - int *tqmf_ptr, *tqmf_ptr1; - int xa, xb; - int decis; - -/* transmit quadrature mirror filters implemented here */ - h_ptr = h; - tqmf_ptr = tqmf; - xa = (int) (*tqmf_ptr++) * (*h_ptr++); - xb = (int) (*tqmf_ptr++) * (*h_ptr++); -/* main multiply accumulate loop for samples and coefficients */ - for (i = 0; i < 10; i++) - { - xa += (int) (*tqmf_ptr++) * (*h_ptr++); - xb += (int) (*tqmf_ptr++) * (*h_ptr++); - } -/* final mult/accumulate */ - xa += (int) (*tqmf_ptr++) * (*h_ptr++); - xb += (int) (*tqmf_ptr) * (*h_ptr++); - -/* update delay line tqmf */ - tqmf_ptr1 = tqmf_ptr - 2; - for (i = 0; i < 22; i++) - *tqmf_ptr-- = *tqmf_ptr1--; - *tqmf_ptr-- = xin1; - *tqmf_ptr = xin2; - -/* scale outputs */ - xl = (xa + xb) >> 15; - xh = (xa - xb) >> 15; - -/* end of quadrature mirror filter code */ - -/* starting with lower sub band encoder */ - -/* filtez - compute predictor output section - zero section */ - szl = filtez (delay_bpl, delay_dltx); - -/* filtep - compute predictor output signal (pole section) */ - spl = filtep (rlt1, al1, rlt2, al2); - -/* compute the predictor output value in the lower sub_band encoder */ - sl = szl + spl; - el = xl - sl; - -/* quantl: quantize the difference signal */ - il = quantl (el, detl); - -/* computes quantized difference signal */ -/* for invqbl, truncate by 2 lsbs, so mode = 3 */ - dlt = ((int) detl * qq4_code4_table[il >> 2]) >> 15; - -/* logscl: updates logarithmic quant. scale factor in low sub band */ - nbl = logscl (il, nbl); - -/* scalel: compute the quantizer scale factor in the lower sub band */ -/* calling parameters nbl and 8 (constant such that scalel can be scaleh) */ - detl = scalel (nbl, 8); - -/* parrec - simple addition to compute recontructed signal for adaptive pred */ - plt = dlt + szl; - -/* upzero: update zero section predictor coefficients (sixth order)*/ -/* calling parameters: dlt, dlt1, dlt2, ..., dlt6 from dlt */ -/* bpli (linear_buffer in which all six values are delayed */ -/* return params: updated bpli, delayed dltx */ - upzero (dlt, delay_dltx, delay_bpl); - -/* uppol2- update second predictor coefficient apl2 and delay it as al2 */ -/* calling parameters: al1, al2, plt, plt1, plt2 */ - al2 = uppol2 (al1, al2, plt, plt1, plt2); - -/* uppol1 :update first predictor coefficient apl1 and delay it as al1 */ -/* calling parameters: al1, apl2, plt, plt1 */ - al1 = uppol1 (al1, al2, plt, plt1); - -/* recons : compute recontructed signal for adaptive predictor */ - rlt = sl + dlt; - -/* done with lower sub_band encoder; now implement delays for next time*/ - rlt2 = rlt1; - rlt1 = rlt; - plt2 = plt1; - plt1 = plt; - -/* high band encode */ - - szh = filtez (delay_bph, delay_dhx); - - sph = filtep (rh1, ah1, rh2, ah2); - -/* predic: sh = sph + szh */ - sh = sph + szh; -/* subtra: eh = xh - sh */ - eh = xh - sh; - -/* quanth - quantization of difference signal for higher sub-band */ -/* quanth: in-place for speed params: eh, deth (has init. value) */ - if (eh >= 0) - { - ih = 3; /* 2,3 are pos codes */ - } - else - { - ih = 1; /* 0,1 are neg codes */ - } - decis = (564L * (int) deth) >> 12L; - if (abs (eh) > decis) - ih--; /* mih = 2 case */ - -/* compute the quantized difference signal, higher sub-band*/ - dh = ((int) deth * qq2_code2_table[ih]) >> 15L; - -/* logsch: update logarithmic quantizer scale factor in hi sub-band*/ - nbh = logsch (ih, nbh); - -/* note : scalel and scaleh use same code, different parameters */ - deth = scalel (nbh, 10); - -/* parrec - add pole predictor output to quantized diff. signal */ - ph = dh + szh; - -/* upzero: update zero section predictor coefficients (sixth order) */ -/* calling parameters: dh, dhi, bphi */ -/* return params: updated bphi, delayed dhx */ - upzero (dh, delay_dhx, delay_bph); - -/* uppol2: update second predictor coef aph2 and delay as ah2 */ -/* calling params: ah1, ah2, ph, ph1, ph2 */ - ah2 = uppol2 (ah1, ah2, ph, ph1, ph2); - -/* uppol1: update first predictor coef. aph2 and delay it as ah1 */ - ah1 = uppol1 (ah1, ah2, ph, ph1); - -/* recons for higher sub-band */ - yh = sh + dh; - -/* done with higher sub-band encoder, now Delay for next time */ - rh2 = rh1; - rh1 = yh; - ph2 = ph1; - ph1 = ph; - -/* multiplex ih and il to get signals together */ - return (il | (ih << 6)); -} - -/* decode function, result in xout1 and xout2 */ - -void -decode (int input) -{ - int i; - int xa1, xa2; /* qmf accumulators */ - const int *h_ptr; - int *ac_ptr, *ac_ptr1, *ad_ptr, *ad_ptr1; - -/* split transmitted word from input into ilr and ih */ - ilr = input & 0x3f; - ih = input >> 6; - -/* LOWER SUB_BAND DECODER */ - -/* filtez: compute predictor output for zero section */ - dec_szl = filtez (dec_del_bpl, dec_del_dltx); - -/* filtep: compute predictor output signal for pole section */ - dec_spl = filtep (dec_rlt1, dec_al1, dec_rlt2, dec_al2); - - dec_sl = dec_spl + dec_szl; - -/* compute quantized difference signal for adaptive predic */ - dec_dlt = ((int) dec_detl * qq4_code4_table[ilr >> 2]) >> 15; - -/* compute quantized difference signal for decoder output */ - dl = ((int) dec_detl * qq6_code6_table[il]) >> 15; - - rl = dl + dec_sl; - -/* logscl: quantizer scale factor adaptation in the lower sub-band */ - dec_nbl = logscl (ilr, dec_nbl); - -/* scalel: computes quantizer scale factor in the lower sub band */ - dec_detl = scalel (dec_nbl, 8); - -/* parrec - add pole predictor output to quantized diff. signal */ -/* for partially reconstructed signal */ - dec_plt = dec_dlt + dec_szl; - -/* upzero: update zero section predictor coefficients */ - upzero (dec_dlt, dec_del_dltx, dec_del_bpl); - -/* uppol2: update second predictor coefficient apl2 and delay it as al2 */ - dec_al2 = uppol2 (dec_al1, dec_al2, dec_plt, dec_plt1, dec_plt2); - -/* uppol1: update first predictor coef. (pole setion) */ - dec_al1 = uppol1 (dec_al1, dec_al2, dec_plt, dec_plt1); - -/* recons : compute recontructed signal for adaptive predictor */ - dec_rlt = dec_sl + dec_dlt; - -/* done with lower sub band decoder, implement delays for next time */ - dec_rlt2 = dec_rlt1; - dec_rlt1 = dec_rlt; - dec_plt2 = dec_plt1; - dec_plt1 = dec_plt; - -/* HIGH SUB-BAND DECODER */ - -/* filtez: compute predictor output for zero section */ - dec_szh = filtez (dec_del_bph, dec_del_dhx); - -/* filtep: compute predictor output signal for pole section */ - dec_sph = filtep (dec_rh1, dec_ah1, dec_rh2, dec_ah2); - -/* predic:compute the predictor output value in the higher sub_band decoder */ - dec_sh = dec_sph + dec_szh; - -/* in-place compute the quantized difference signal */ - dec_dh = ((int) dec_deth * qq2_code2_table[ih]) >> 15L; - -/* logsch: update logarithmic quantizer scale factor in hi sub band */ - dec_nbh = logsch (ih, dec_nbh); - -/* scalel: compute the quantizer scale factor in the higher sub band */ - dec_deth = scalel (dec_nbh, 10); - -/* parrec: compute partially recontructed signal */ - dec_ph = dec_dh + dec_szh; - -/* upzero: update zero section predictor coefficients */ - upzero (dec_dh, dec_del_dhx, dec_del_bph); - -/* uppol2: update second predictor coefficient aph2 and delay it as ah2 */ - dec_ah2 = uppol2 (dec_ah1, dec_ah2, dec_ph, dec_ph1, dec_ph2); - -/* uppol1: update first predictor coef. (pole setion) */ - dec_ah1 = uppol1 (dec_ah1, dec_ah2, dec_ph, dec_ph1); - -/* recons : compute recontructed signal for adaptive predictor */ - rh = dec_sh + dec_dh; - -/* done with high band decode, implementing delays for next time here */ - dec_rh2 = dec_rh1; - dec_rh1 = rh; - dec_ph2 = dec_ph1; - dec_ph1 = dec_ph; - -/* end of higher sub_band decoder */ - -/* end with receive quadrature mirror filters */ - xd = rl - rh; - xs = rl + rh; - -/* receive quadrature mirror filters implemented here */ - h_ptr = h; - ac_ptr = accumc; - ad_ptr = accumd; - xa1 = (int) xd *(*h_ptr++); - xa2 = (int) xs *(*h_ptr++); -/* main multiply accumulate loop for samples and coefficients */ - for (i = 0; i < 10; i++) - { - xa1 += (int) (*ac_ptr++) * (*h_ptr++); - xa2 += (int) (*ad_ptr++) * (*h_ptr++); - } -/* final mult/accumulate */ - xa1 += (int) (*ac_ptr) * (*h_ptr++); - xa2 += (int) (*ad_ptr) * (*h_ptr++); - -/* scale by 2^14 */ - xout1 = xa1 >> 14; - xout2 = xa2 >> 14; - -/* update delay lines */ - ac_ptr1 = ac_ptr - 1; - ad_ptr1 = ad_ptr - 1; - for (i = 0; i < 10; i++) - { - *ac_ptr-- = *ac_ptr1--; - *ad_ptr-- = *ad_ptr1--; - } - *ac_ptr = xd; - *ad_ptr = xs; -} - -/* clear all storage locations */ - -void -reset () -{ - int i; - - detl = dec_detl = 32; /* reset to min scale factor */ - deth = dec_deth = 8; - nbl = al1 = al2 = plt1 = plt2 = rlt1 = rlt2 = 0; - nbh = ah1 = ah2 = ph1 = ph2 = rh1 = rh2 = 0; - dec_nbl = dec_al1 = dec_al2 = dec_plt1 = dec_plt2 = dec_rlt1 = dec_rlt2 = 0; - dec_nbh = dec_ah1 = dec_ah2 = dec_ph1 = dec_ph2 = dec_rh1 = dec_rh2 = 0; - - for (i = 0; i < 6; i++) - { - delay_dltx[i] = 0; - delay_dhx[i] = 0; - dec_del_dltx[i] = 0; - dec_del_dhx[i] = 0; - } - - for (i = 0; i < 6; i++) - { - delay_bpl[i] = 0; - delay_bph[i] = 0; - dec_del_bpl[i] = 0; - dec_del_bph[i] = 0; - } - - for (i = 0; i < 24; i++) - tqmf[i] = 0; // i<23 - - for (i = 0; i < 11; i++) - { - accumc[i] = 0; - accumd[i] = 0; - } -} - /* filtez - compute predictor output signal (zero section) */ /* input: bpl1-6 and dlt1-6, output: szl */ -int + int filtez (int *bpl, int *dlt) { int i; @@ -591,7 +114,7 @@ filtez (int *bpl, int *dlt) /* filtep - compute predictor output signal (pole section) */ /* input rlt1-2 and al1-2, output spl */ -int + int filtep (int rlt1, int al1, int rlt2, int al2) { int pl, pl2; @@ -603,22 +126,49 @@ filtep (int rlt1, int al1, int rlt2, int al2) } /* quantl - quantize the difference signal in the lower sub-band */ -int + int quantl (int el, int detl) { + + const int decis_levl[30] = { + 280, 576, 880, 1200, 1520, 1864, 2208, 2584, + 2960, 3376, 3784, 4240, 4696, 5200, 5712, 6288, + 6864, 7520, 8184, 8968, 9752, 10712, 11664, 12896, + 14120, 15840, 17560, 20456, 23352, 32767 + }; + /* decision levels - pre-multiplied by 8, 0 to indicate end */ + /* quantization table 31 long to make quantl look-up easier, + last entry is for mil=30 case when wd is max */ + const int quant26bt_pos[31] = { + 61, 60, 59, 58, 57, 56, 55, 54, + 53, 52, 51, 50, 49, 48, 47, 46, + 45, 44, 43, 42, 41, 40, 39, 38, + 37, 36, 35, 34, 33, 32, 32 + }; + + /* quantization table 31 long to make quantl look-up easier, + last entry is for mil=30 case when wd is max */ + const int quant26bt_neg[31] = { + 63, 62, 31, 30, 29, 28, 27, 26, + 25, 24, 23, 22, 21, 20, 19, 18, + 17, 16, 15, 14, 13, 12, 11, 10, + 9, 8, 7, 6, 5, 4, 4 + }; + + int ril, mil; int wd, decis; -/* abs of difference signal */ + /* abs of difference signal */ wd = abs (el); -/* determine mil based on decision levels and detl gain */ + /* determine mil based on decision levels and detl gain */ for (mil = 0; mil < 30; mil++) - { - decis = (decis_levl[mil] * (int) detl) >> 15L; - if (wd <= decis) - break; - } -/* if mil=30 then wd is less than all decision levels */ + { + decis = (decis_levl[mil] * (int) detl) >> 15L; + if (wd <= decis) + break; + } + /* if mil=30 then wd is less than all decision levels */ if (el >= 0) ril = quant26bt_pos[mil]; else @@ -629,9 +179,14 @@ quantl (int el, int detl) /* logscl - update log quantizer scale factor in lower sub-band */ /* note that nbl is passed and returned */ -int + int logscl (int il, int nbl) { + const int wl_code_table[16] = { + -60, 3042, 1198, 538, 334, 172, 58, -30, + 3042, 1198, 538, 334, 172, 58, -30, -60 + }; + int wd; wd = ((int) nbl * 127L) >> 7L; /* leak factor 127/128 */ nbl = (int) wd + wl_code_table[il >> 2]; @@ -644,10 +199,17 @@ logscl (int il, int nbl) /* scalel: compute quantizer scale factor in lower or upper sub-band*/ -int + int scalel (int nbl, int shift_constant) { + const int ilb_table[32] = { + 2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383, + 2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834, + 2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371, + 3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008 + }; int wd1, wd2, wd3; + wd1 = (nbl >> 6) & 31; wd2 = nbl >> 11; wd3 = ilb_table[wd1] >> (shift_constant + 1 - wd2); @@ -657,31 +219,31 @@ scalel (int nbl, int shift_constant) /* upzero - inputs: dlt, dlti[0-5], bli[0-5], outputs: updated bli[0-5] */ /* also implements delay of bli and update of dlti from dlt */ -void + void upzero (int dlt, int *dlti, int *bli) { int i, wd2, wd3; -/*if dlt is zero, then no sum into bli */ + /*if dlt is zero, then no sum into bli */ if (dlt == 0) + { + for (i = 0; i < 6; i++) { - for (i = 0; i < 6; i++) - { - bli[i] = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ - } + bli[i] = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ } + } else + { + for (i = 0; i < 6; i++) { - for (i = 0; i < 6; i++) - { - if ((int) dlt * dlti[i] >= 0) - wd2 = 128; - else - wd2 = -128; - wd3 = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ - bli[i] = wd2 + wd3; - } + if ((int) dlt * dlti[i] >= 0) + wd2 = 128; + else + wd2 = -128; + wd3 = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ + bli[i] = wd2 + wd3; } -/* implement delay line for dlt */ + } + /* implement delay line for dlt */ dlti[5] = dlti[4]; dlti[4] = dlti[3]; dlti[3] = dlti[2]; @@ -693,7 +255,7 @@ upzero (int dlt, int *dlti, int *bli) /* uppol2 - update second predictor coefficient (pole section) */ /* inputs: al1, al2, plt, plt1, plt2. outputs: apl2 */ -int + int uppol2 (int al1, int al2, int plt, int plt1, int plt2) { int wd2, wd4; @@ -703,16 +265,16 @@ uppol2 (int al1, int al2, int plt, int plt1, int plt2) wd2 = -wd2; /* check same sign */ wd2 = wd2 >> 7; /* gain of 1/128 */ if ((int) plt * plt2 >= 0L) - { - wd4 = wd2 + 128; /* same sign case */ - } + { + wd4 = wd2 + 128; /* same sign case */ + } else - { - wd4 = wd2 - 128; - } + { + wd4 = wd2 - 128; + } apl2 = wd4 + (127L * (int) al2 >> 7L); /* leak factor of 127/128 */ -/* apl2 is limited to +-.75 */ + /* apl2 is limited to +-.75 */ if (apl2 > 12288) apl2 = 12288; if (apl2 < -12288) @@ -723,21 +285,21 @@ uppol2 (int al1, int al2, int plt, int plt1, int plt2) /* uppol1 - update first predictor coefficient (pole section) */ /* inputs: al1, apl2, plt, plt1. outputs: apl1 */ -int + int uppol1 (int al1, int apl2, int plt, int plt1) { int wd2; int wd3, apl1; wd2 = ((int) al1 * 255L) >> 8L; /* leak factor of 255/256 */ if ((int) plt * plt1 >= 0L) - { - apl1 = (int) wd2 + 192; /* same sign case */ - } + { + apl1 = (int) wd2 + 192; /* same sign case */ + } else - { - apl1 = (int) wd2 - 192; - } -/* note: wd3= .9375-.75 is always positive */ + { + apl1 = (int) wd2 - 192; + } + /* note: wd3= .9375-.75 is always positive */ wd3 = 15360 - apl2; /* limit value */ if (apl1 > wd3) apl1 = wd3; @@ -749,10 +311,14 @@ uppol1 (int al1, int apl2, int plt, int plt1) /* logsch - update log quantizer scale factor in higher sub-band */ /* note that nbh is passed and returned */ -int + int logsch (int ih, int nbh) { int wd; + const int wh_code_table[4] = { + 798, -214, 798, -214 + }; + wd = ((int) nbh * 127L) >> 7L; /* leak factor 127/128 */ nbh = wd + wh_code_table[ih]; if (nbh < 0) @@ -763,118 +329,527 @@ logsch (int ih, int nbh) } /* -+--------------------------------------------------------------------------+ -| * Test Vectors (added for CHStone) | -| test_data : input data | -| test_compressed : expected output data for "encode" | -| test_result : expected output data for "decode" | -+--------------------------------------------------------------------------+ -*/ + +--------------------------------------------------------------------------+ + | * Test Vectors (added for CHStone) | + | test_data : input data | + | test_compressed : expected output data for "encode" | + | test_result : expected output data for "decode" | + +--------------------------------------------------------------------------+ + */ + +/* G722 C code */ -#define SIZE 100 -#define IN_END 100 -const int test_data[SIZE] = { - 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x43, 0x43, 0x43, - 0x43, 0x43, 0x43, 0x43, 0x42, - 0x42, 0x42, 0x42, 0x42, 0x42, - 0x41, 0x41, 0x41, 0x41, 0x41, - 0x40, 0x40, 0x40, 0x40, 0x40, - 0x40, 0x40, 0x40, 0x3f, 0x3f, - 0x3f, 0x3f, 0x3f, 0x3e, 0x3e, - 0x3e, 0x3e, 0x3e, 0x3e, 0x3d, - 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3c, 0x3c, 0x3c, - 0x3c, 0x3c, 0x3c, 0x3c, 0x3c -}; -int compressed[SIZE], result[SIZE]; -const int test_compressed[SIZE] = { - 0xfd, 0xde, 0x77, 0xba, 0xf2, - 0x90, 0x20, 0xa0, 0xec, 0xed, - 0xef, 0xf1, 0xf3, 0xf4, 0xf5, - 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, - 0xf6, 0xf7, 0xf8, 0xf7, 0xf8, - 0xf7, 0xf9, 0xf8, 0xf7, 0xf9, - 0xf8, 0xf8, 0xf6, 0xf8, 0xf8, - 0xf7, 0xf9, 0xf9, 0xf9, 0xf8, - 0xf7, 0xfa, 0xf8, 0xf8, 0xf7, - 0xfb, 0xfa, 0xf9, 0xf8, 0xf8 -}; -const int test_result[SIZE] = { - 0, 0xffffffff, 0xffffffff, 0, 0, - 0xffffffff, 0, 0, 0xffffffff, 0xffffffff, - 0, 0, 0x1, 0x1, 0, - 0xfffffffe, 0xffffffff, 0xfffffffe, 0, 0xfffffffc, - 0x1, 0x1, 0x1, 0xfffffffb, 0x2, - 0x2, 0x3, 0xb, 0x14, 0x14, - 0x16, 0x18, 0x20, 0x21, 0x26, - 0x27, 0x2e, 0x2f, 0x33, 0x32, - 0x35, 0x33, 0x36, 0x34, 0x37, - 0x34, 0x37, 0x35, 0x38, 0x36, - 0x39, 0x38, 0x3b, 0x3a, 0x3f, - 0x3f, 0x40, 0x3a, 0x3d, 0x3e, - 0x41, 0x3c, 0x3e, 0x3f, 0x42, - 0x3e, 0x3b, 0x37, 0x3b, 0x3e, - 0x41, 0x3b, 0x3b, 0x3a, 0x3b, - 0x36, 0x39, 0x3b, 0x3f, 0x3c, - 0x3b, 0x37, 0x3b, 0x3d, 0x41, - 0x3d, 0x3e, 0x3c, 0x3e, 0x3b, - 0x3a, 0x37, 0x3b, 0x3e, 0x41, - 0x3c, 0x3b, 0x39, 0x3a, 0x36 -}; - -void -adpcm_main () + void +adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) { + /* variables for transimit quadrature mirror filter here */ + int tqmf[24]; + + /* QMF filter coefficients: + scaled by a factor of 4 compared to G722 CCITT recomendation */ + const int h[24] = { + 12, -44, -44, 212, 48, -624, 128, 1448, + -840, -3220, 3804, 15504, 15504, 3804, -3220, -840, + 1448, 128, -624, 48, 212, -44, -44, 12 + }; + + int xl, xh; + + /* variables for receive quadrature mirror filter here */ + int accumc[11], accumd[11]; + + /* outputs of decode() */ + int xout1, xout2; + + int xs, xd; + + /* variables for encoder (hi and lo) here */ + + int il, szl, spl, sl, el; + + int delay_bpl[6]; + + int delay_dltx[6]; + + int nbl; /* delay line */ + int al1, al2; + int plt, plt1, plt2; + int dlt; + int rlt, rlt1, rlt2; + + int detl; + + int deth; + int sh; /* this comes from adaptive predictor */ + int eh; + + const int qq2_code2_table[4] = { + -7408, -1616, 7408, 1616 + }; + + + int dh, ih; + int nbh, szh; + int sph, ph, yh, rh; + + int delay_dhx[6]; + + int delay_bph[6]; + + int ah1, ah2; + int ph1, ph2; + int rh1, rh2; + + /* variables for decoder here */ + int ilr, rl; + int dec_deth, dec_detl, dec_dlt; + + int dec_del_bpl[6]; + + int dec_del_dltx[6]; + + int dec_plt, dec_plt1, dec_plt2; + int dec_szl, dec_spl, dec_sl; + int dec_rlt1, dec_rlt2, dec_rlt; + int dec_al1, dec_al2; + int dl; + int dec_nbl, dec_dh, dec_nbh; + + /* variables used in filtez */ + int dec_del_bph[6]; + + int dec_del_dhx[6]; + + int dec_szh; + /* variables used in filtep */ + int dec_rh1, dec_rh2; + int dec_ah1, dec_ah2; + int dec_ph, dec_sph; + + int dec_sh; + + int dec_ph1, dec_ph2; int i, j; -/* reset, initialize required memory */ - reset (); + const int qq4_code4_table[16] = { + 0, -20456, -12896, -8968, -6288, -4240, -2584, -1200, + 20456, 12896, 8968, 6288, 4240, 2584, 1200, 0 + }; + const int qq6_code6_table[64] = { + -136, -136, -136, -136, -24808, -21904, -19008, -16704, + -14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856, + -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576, + -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728, + 24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192, + 10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456, + 4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032, + 1688, 1360, 1040, 728, 432, 136, -432, -136 + }; + + /* reset, initialize required memory */ + + detl = dec_detl = 32; /* reset to min scale factor */ + deth = dec_deth = 8; + nbl = al1 = al2 = plt1 = plt2 = rlt1 = rlt2 = 0; + nbh = ah1 = ah2 = ph1 = ph2 = rh1 = rh2 = 0; + dec_nbl = dec_al1 = dec_al2 = dec_plt1 = dec_plt2 = dec_rlt1 = dec_rlt2 = 0; + dec_nbh = dec_ah1 = dec_ah2 = dec_ph1 = dec_ph2 = dec_rh1 = dec_rh2 = 0; + + for (i = 0; i < 6; i++) + { + delay_dltx[i] = 0; + delay_dhx[i] = 0; + dec_del_dltx[i] = 0; + dec_del_dhx[i] = 0; + } + + for (i = 0; i < 6; i++) + { + delay_bpl[i] = 0; + delay_bph[i] = 0; + dec_del_bpl[i] = 0; + dec_del_bph[i] = 0; + } - j = 10; + for (i = 0; i < 24; i++) + tqmf[i] = 0; // i<23 + + for (i = 0; i < 11; i++) + { + accumc[i] = 0; + accumd[i] = 0; + } for (i = 0; i < IN_END; i += 2) + { + int xin1 = test_data[i + 0]; + int xin2 = test_data[i + 1]; + const int *h_ptr; + int *tqmf_ptr, *tqmf_ptr1; + int xa, xb; + int decis; + + /* transmit quadrature mirror filters implemented here */ + h_ptr = h; + tqmf_ptr = tqmf; + xa = (int) (*tqmf_ptr++) * (*h_ptr++); + xb = (int) (*tqmf_ptr++) * (*h_ptr++); + /* main multiply accumulate loop for samples and coefficients */ + for (int j = 0; j < 10; j++) + { + xa += (int) (*tqmf_ptr++) * (*h_ptr++); + xb += (int) (*tqmf_ptr++) * (*h_ptr++); + } + /* final mult/accumulate */ + xa += (int) (*tqmf_ptr++) * (*h_ptr++); + xb += (int) (*tqmf_ptr) * (*h_ptr++); + + /* update delay line tqmf */ + tqmf_ptr1 = tqmf_ptr - 2; + for (int j = 0; j < 22; j++) + *tqmf_ptr-- = *tqmf_ptr1--; + *tqmf_ptr-- = xin1; + *tqmf_ptr = xin2; + + /* scale outputs */ + xl = (xa + xb) >> 15; + xh = (xa - xb) >> 15; + + /* end of quadrature mirror filter code */ + + /* starting with lower sub band encoder */ + + /* filtez - compute predictor output section - zero section */ + szl = filtez (delay_bpl, delay_dltx); + + /* filtep - compute predictor output signal (pole section) */ + spl = filtep (rlt1, al1, rlt2, al2); + + /* compute the predictor output value in the lower sub_band encoder */ + sl = szl + spl; + el = xl - sl; + + /* quantl: quantize the difference signal */ + il = quantl (el, detl); + + /* computes quantized difference signal */ + /* for invqbl, truncate by 2 lsbs, so mode = 3 */ + dlt = ((int) detl * qq4_code4_table[il >> 2]) >> 15; + + /* logscl: updates logarithmic quant. scale factor in low sub band */ + nbl = logscl (il, nbl); + + /* scalel: compute the quantizer scale factor in the lower sub band */ + /* calling parameters nbl and 8 (constant such that scalel can be scaleh) */ + detl = scalel (nbl, 8); + + /* parrec - simple addition to compute recontructed signal for adaptive pred */ + plt = dlt + szl; + + /* upzero: update zero section predictor coefficients (sixth order)*/ + /* calling parameters: dlt, dlt1, dlt2, ..., dlt6 from dlt */ + /* bpli (linear_buffer in which all six values are delayed */ + /* return params: updated bpli, delayed dltx */ + upzero (dlt, delay_dltx, delay_bpl); + + /* uppol2- update second predictor coefficient apl2 and delay it as al2 */ + /* calling parameters: al1, al2, plt, plt1, plt2 */ + al2 = uppol2 (al1, al2, plt, plt1, plt2); + + /* uppol1 :update first predictor coefficient apl1 and delay it as al1 */ + /* calling parameters: al1, apl2, plt, plt1 */ + al1 = uppol1 (al1, al2, plt, plt1); + + /* recons : compute recontructed signal for adaptive predictor */ + rlt = sl + dlt; + + /* done with lower sub_band encoder; now implement delays for next time*/ + rlt2 = rlt1; + rlt1 = rlt; + plt2 = plt1; + plt1 = plt; + + /* high band encode */ + + szh = filtez (delay_bph, delay_dhx); + + sph = filtep (rh1, ah1, rh2, ah2); + + /* predic: sh = sph + szh */ + sh = sph + szh; + /* subtra: eh = xh - sh */ + eh = xh - sh; + + /* quanth - quantization of difference signal for higher sub-band */ + /* quanth: in-place for speed params: eh, deth (has init. value) */ + if (eh >= 0) { - compressed[i / 2] = encode (test_data[i], test_data[i + 1]); + ih = 3; /* 2,3 are pos codes */ } + else + { + ih = 1; /* 0,1 are neg codes */ + } + decis = (564L * (int) deth) >> 12L; + if (abs (eh) > decis) + ih--; /* mih = 2 case */ + + /* compute the quantized difference signal, higher sub-band*/ + dh = ((int) deth * qq2_code2_table[ih]) >> 15L; + + /* logsch: update logarithmic quantizer scale factor in hi sub-band*/ + nbh = logsch (ih, nbh); + + /* note : scalel and scaleh use same code, different parameters */ + deth = scalel (nbh, 10); + + /* parrec - add pole predictor output to quantized diff. signal */ + ph = dh + szh; + + /* upzero: update zero section predictor coefficients (sixth order) */ + /* calling parameters: dh, dhi, bphi */ + /* return params: updated bphi, delayed dhx */ + upzero (dh, delay_dhx, delay_bph); + + /* uppol2: update second predictor coef aph2 and delay as ah2 */ + /* calling params: ah1, ah2, ph, ph1, ph2 */ + ah2 = uppol2 (ah1, ah2, ph, ph1, ph2); + + /* uppol1: update first predictor coef. aph2 and delay it as ah1 */ + ah1 = uppol1 (ah1, ah2, ph, ph1); + + /* recons for higher sub-band */ + yh = sh + dh; + + /* done with higher sub-band encoder, now Delay for next time */ + rh2 = rh1; + rh1 = yh; + ph2 = ph1; + ph1 = ph; + + /* multiplex ih and il to get signals together */ + compressed[i/2] = (il | (ih << 6)); + } for (i = 0; i < IN_END; i += 2) + { + int input = compressed[i / 2]; + + int xa1, xa2; /* qmf accumulators */ + const int *h_ptr; + int *ac_ptr, *ac_ptr1, *ad_ptr, *ad_ptr1; + + /* split transmitted word from input into ilr and ih */ + ilr = input & 0x3f; + ih = input >> 6; + + /* LOWER SUB_BAND DECODER */ + + /* filtez: compute predictor output for zero section */ + dec_szl = filtez (dec_del_bpl, dec_del_dltx); + + /* filtep: compute predictor output signal for pole section */ + dec_spl = filtep (dec_rlt1, dec_al1, dec_rlt2, dec_al2); + + dec_sl = dec_spl + dec_szl; + + /* compute quantized difference signal for adaptive predic */ + dec_dlt = ((int) dec_detl * qq4_code4_table[ilr >> 2]) >> 15; + + /* compute quantized difference signal for decoder output */ + dl = ((int) dec_detl * qq6_code6_table[il]) >> 15; + + rl = dl + dec_sl; + + /* logscl: quantizer scale factor adaptation in the lower sub-band */ + dec_nbl = logscl (ilr, dec_nbl); + + /* scalel: computes quantizer scale factor in the lower sub band */ + dec_detl = scalel (dec_nbl, 8); + + /* parrec - add pole predictor output to quantized diff. signal */ + /* for partially reconstructed signal */ + dec_plt = dec_dlt + dec_szl; + + /* upzero: update zero section predictor coefficients */ + upzero (dec_dlt, dec_del_dltx, dec_del_bpl); + + /* uppol2: update second predictor coefficient apl2 and delay it as al2 */ + dec_al2 = uppol2 (dec_al1, dec_al2, dec_plt, dec_plt1, dec_plt2); + + /* uppol1: update first predictor coef. (pole setion) */ + dec_al1 = uppol1 (dec_al1, dec_al2, dec_plt, dec_plt1); + + /* recons : compute recontructed signal for adaptive predictor */ + dec_rlt = dec_sl + dec_dlt; + + /* done with lower sub band decoder, implement delays for next time */ + dec_rlt2 = dec_rlt1; + dec_rlt1 = dec_rlt; + dec_plt2 = dec_plt1; + dec_plt1 = dec_plt; + + /* HIGH SUB-BAND DECODER */ + + /* filtez: compute predictor output for zero section */ + dec_szh = filtez (dec_del_bph, dec_del_dhx); + + /* filtep: compute predictor output signal for pole section */ + dec_sph = filtep (dec_rh1, dec_ah1, dec_rh2, dec_ah2); + + /* predic:compute the predictor output value in the higher sub_band decoder */ + dec_sh = dec_sph + dec_szh; + + /* in-place compute the quantized difference signal */ + dec_dh = ((int) dec_deth * qq2_code2_table[ih]) >> 15L; + + /* logsch: update logarithmic quantizer scale factor in hi sub band */ + dec_nbh = logsch (ih, dec_nbh); + + /* scalel: compute the quantizer scale factor in the higher sub band */ + dec_deth = scalel (dec_nbh, 10); + + /* parrec: compute partially recontructed signal */ + dec_ph = dec_dh + dec_szh; + + /* upzero: update zero section predictor coefficients */ + upzero (dec_dh, dec_del_dhx, dec_del_bph); + + /* uppol2: update second predictor coefficient aph2 and delay it as ah2 */ + dec_ah2 = uppol2 (dec_ah1, dec_ah2, dec_ph, dec_ph1, dec_ph2); + + /* uppol1: update first predictor coef. (pole setion) */ + dec_ah1 = uppol1 (dec_ah1, dec_ah2, dec_ph, dec_ph1); + + /* recons : compute recontructed signal for adaptive predictor */ + rh = dec_sh + dec_dh; + + /* done with high band decode, implementing delays for next time here */ + dec_rh2 = dec_rh1; + dec_rh1 = rh; + dec_ph2 = dec_ph1; + dec_ph1 = dec_ph; + + /* end of higher sub_band decoder */ + + /* end with receive quadrature mirror filters */ + xd = rl - rh; + xs = rl + rh; + + /* receive quadrature mirror filters implemented here */ + h_ptr = h; + ac_ptr = accumc; + ad_ptr = accumd; + xa1 = (int) xd *(*h_ptr++); + xa2 = (int) xs *(*h_ptr++); + /* main multiply accumulate loop for samples and coefficients */ + for (int j = 0; j < 10; j++) { - decode (compressed[i / 2]); - result[i] = xout1; - result[i + 1] = xout2; + xa1 += (int) (*ac_ptr++) * (*h_ptr++); + xa2 += (int) (*ad_ptr++) * (*h_ptr++); + } + /* final mult/accumulate */ + xa1 += (int) (*ac_ptr) * (*h_ptr++); + xa2 += (int) (*ad_ptr) * (*h_ptr++); + + /* scale by 2^14 */ + xout1 = xa1 >> 14; + xout2 = xa2 >> 14; + + /* update delay lines */ + ac_ptr1 = ac_ptr - 1; + ad_ptr1 = ad_ptr - 1; + for (j = 0; j < 10; j++) + { + *ac_ptr-- = *ac_ptr1--; + *ad_ptr-- = *ad_ptr1--; } + *ac_ptr = xd; + *ad_ptr = xs; + result[i] = xout1; + result[i + 1] = xout2; + } } -int + int main () { int i; int main_result; - main_result = 0; - adpcm_main (); - for (i = 0; i < IN_END / 2; i++) - { - if (compressed[i] != test_compressed[i]) - { - main_result += 1; - } - } - for (i = 0; i < IN_END; i++) - { - if (result[i] != test_result[i]) - { - main_result += 1; - } - } - return main_result; + const int test_data[SIZE] = { + 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x43, 0x43, 0x43, + 0x43, 0x43, 0x43, 0x43, 0x42, + 0x42, 0x42, 0x42, 0x42, 0x42, + 0x41, 0x41, 0x41, 0x41, 0x41, + 0x40, 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x3f, 0x3f, + 0x3f, 0x3f, 0x3f, 0x3e, 0x3e, + 0x3e, 0x3e, 0x3e, 0x3e, 0x3d, + 0x3d, 0x3d, 0x3d, 0x3d, 0x3d, + 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, + 0x3c, 0x3c, 0x3c, 0x3c, 0x3b, + 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, + 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, + 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, + 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, + 0x3b, 0x3b, 0x3c, 0x3c, 0x3c, + 0x3c, 0x3c, 0x3c, 0x3c, 0x3c + }; + int compressed[SIZE], result[SIZE]; + const int test_compressed[SIZE] = { + 0xfd, 0xde, 0x77, 0xba, 0xf2, + 0x90, 0x20, 0xa0, 0xec, 0xed, + 0xef, 0xf1, 0xf3, 0xf4, 0xf5, + 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, + 0xf6, 0xf7, 0xf8, 0xf7, 0xf8, + 0xf7, 0xf9, 0xf8, 0xf7, 0xf9, + 0xf8, 0xf8, 0xf6, 0xf8, 0xf8, + 0xf7, 0xf9, 0xf9, 0xf9, 0xf8, + 0xf7, 0xfa, 0xf8, 0xf8, 0xf7, + 0xfb, 0xfa, 0xf9, 0xf8, 0xf8 + }; + const int test_result[SIZE] = { + 0, 0xffffffff, 0xffffffff, 0, 0, + 0xffffffff, 0, 0, 0xffffffff, 0xffffffff, + 0, 0, 0x1, 0x1, 0, + 0xfffffffe, 0xffffffff, 0xfffffffe, 0, 0xfffffffc, + 0x1, 0x1, 0x1, 0xfffffffb, 0x2, + 0x2, 0x3, 0xb, 0x14, 0x14, + 0x16, 0x18, 0x20, 0x21, 0x26, + 0x27, 0x2e, 0x2f, 0x33, 0x32, + 0x35, 0x33, 0x36, 0x34, 0x37, + 0x34, 0x37, 0x35, 0x38, 0x36, + 0x39, 0x38, 0x3b, 0x3a, 0x3f, + 0x3f, 0x40, 0x3a, 0x3d, 0x3e, + 0x41, 0x3c, 0x3e, 0x3f, 0x42, + 0x3e, 0x3b, 0x37, 0x3b, 0x3e, + 0x41, 0x3b, 0x3b, 0x3a, 0x3b, + 0x36, 0x39, 0x3b, 0x3f, 0x3c, + 0x3b, 0x37, 0x3b, 0x3d, 0x41, + 0x3d, 0x3e, 0x3c, 0x3e, 0x3b, + 0x3a, 0x37, 0x3b, 0x3e, 0x41, + 0x3c, 0x3b, 0x39, 0x3a, 0x36 + }; + + main_result = 0; + adpcm_main (test_data,compressed,result); + for (i = 0; i < IN_END / 2; i++) + { + if (compressed[i] != test_compressed[i]) + { + main_result += 1; + } + } + for (i = 0; i < IN_END; i++) + { + if (result[i] != test_result[i]) + { + main_result += 1; } + } + return main_result; +} -- cgit From 2d39b4d61a7394772956d76286237ddf9a9a2ded Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Wed, 24 Jun 2020 11:13:06 +0100 Subject: shift right --- benchmarks/unit-tests/shr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 benchmarks/unit-tests/shr.c diff --git a/benchmarks/unit-tests/shr.c b/benchmarks/unit-tests/shr.c new file mode 100644 index 0000000..e63e2fd --- /dev/null +++ b/benchmarks/unit-tests/shr.c @@ -0,0 +1,11 @@ + +int main (){ + + int input = -1024; + unsigned int shift = 5; + //printf("Before %d\n", input); + input >>= shift; + //printf("After %ud\n", input); + return input; + +} -- cgit From f87842f41e42bcb34be7b45110b0b2dccbc4c0f5 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Wed, 24 Jun 2020 12:27:44 +0100 Subject: pushing gsm changes --- benchmarks/CHStone/gsm/gsm.c | 541 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 489 insertions(+), 52 deletions(-) diff --git a/benchmarks/CHStone/gsm/gsm.c b/benchmarks/CHStone/gsm/gsm.c index 282437a..61172a4 100755 --- a/benchmarks/CHStone/gsm/gsm.c +++ b/benchmarks/CHStone/gsm/gsm.c @@ -16,95 +16,532 @@ | 4. Please follow the copyright of each benchmark program. | +--------------------------------------------------------------------------+ */ -#include -#include "lpc.c" +//#include +typedef int word; /* 16 bit signed int */ +typedef long longword; /* 32 bit signed int */ +#define MIN_WORD ((-32767)-1) +#define MAX_WORD ( 32767) + +#define SASR(x, by) ((x) >> (by)) + +#define GSM_MULT_R(a, b) gsm_mult_r(a, b) +#define GSM_MULT(a, b) gsm_mult(a, b) +#define GSM_ADD(a, b) gsm_add(a, b) +#define GSM_ABS(a) gsm_abs(a) + +#define saturate(x) \ + ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x)) + +word +gsm_add (word a, word b) +{ + longword sum; + sum = (longword) a + (longword) b; + return saturate (sum); +} + +word +gsm_mult (word a, word b) +{ + if (a == MIN_WORD && b == MIN_WORD) + return MAX_WORD; + else + return SASR ((longword) a * (longword) b, 15); +} + +word +gsm_mult_r (word a, word b) +{ + longword prod; + if (b == MIN_WORD && a == MIN_WORD) + return MAX_WORD; + else + { + prod = (longword) a *(longword) b + 16384; + prod >>= 15; + return prod & 0xFFFF; + } +} + +word +gsm_abs (word a) +{ + return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a; +} + +word +gsm_norm (longword a) /* -+--------------------------------------------------------------------------+ -| * Test Vectors (added for CHStone) | -| inData : input data | -| outData, outLARc : expected output data | -+--------------------------------------------------------------------------+ -*/ + * the number of left shifts needed to normalize the 32 bit + * variable L_var1 for positive values on the interval + * + * with minimum of + * minimum of 1073741824 (01000000000000000000000000000000) and + * maximum of 2147483647 (01111111111111111111111111111111) + * + * + * and for negative values on the interval with + * minimum of -2147483648 (-10000000000000000000000000000000) and + * maximum of -1073741824 ( -1000000000000000000000000000000). + * + * in order to normalize the result, the following + * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 ); + * + * (That's 'ffs', only from the left, not the right..) + */ +{ + const unsigned int bitoff[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + int ret; + if (a <= -1073741824) ret = 0; + else{ + if (a < 0) + { + if (a > -1073741824) + a = ~a; + } + + ret = a & 0xffff0000 ? + (a & 0xff000000 ? -1 + bitoff[0xFF & (a >> 24)] : + 7 + bitoff[0xFF & (a >> 16)]) + : (a & 0xff00 ? 15 + bitoff[0xFF & (a >> 8)] : 23 + bitoff[0xFF & a]); + } + /* + if (a < 0) + { + if (a <= -1073741824) + return 0; + a = ~a; + } + + return a & 0xffff0000 ? + (a & 0xff000000 ? -1 + bitoff[0xFF & (a >> 24)] : + 7 + bitoff[0xFF & (a >> 16)]) + : (a & 0xff00 ? 15 + bitoff[0xFF & (a >> 8)] : 23 + bitoff[0xFF & a]); + */ + + return ret; +} + +word +gsm_div (word num, word denum) +{ + longword L_num; + longword L_denum; + word div; + int k; + + L_num = num; + L_denum = denum; + div = 0; + k = 15; + /* The parameter num sometimes becomes zero. + * Although this is explicitly guarded against in 4.2.5, + * we assume that the result should then be zero as well. + */ + + if (num == 0) + return 0; + + while (k--) + { + div <<= 1; + L_num <<= 1; + + if (L_num >= L_denum) + { + L_num -= L_denum; + div++; + } + } + + return div; +} + +void +Autocorrelation (word * s /* [0..159] IN/OUT */ , + longword * L_ACF /* [0..8] OUT */ ) +/* + * The goal is to compute the array L_ACF[k]. The signal s[i] must + * be scaled in order to avoid an overflow situation. + */ +{ + register int k, i; + + word temp; + word smax; + word scalauto, n; + word *sp; + word sl; + + /* Search for the maximum. + */ + smax = 0; + for (k = 0; k <= 159; k++) + { + temp = GSM_ABS (s[k]); + if (temp > smax) + smax = temp; + } + + /* Computation of the scaling factor. + */ + if (smax == 0) + scalauto = 0; + else + scalauto = 4 - gsm_norm ((longword) smax << 16); /* sub(4,..) */ + + if (scalauto > 0 && scalauto <= 4) + { + n = scalauto; + for (k = 0; k <= 159; k++) + s[k] = GSM_MULT_R (s[k], 16384 >> (n - 1)); + } + + /* Compute the L_ACF[..]. + */ + { + sp = s; + sl = *sp; + +#define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]); + +#define NEXTI sl = *++sp + for (k = 8; k >= 0; k--) + L_ACF[k] = 0; + + STEP (0); + NEXTI; + STEP (0); + STEP (1); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + STEP (6); + NEXTI; + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + STEP (6); + STEP (7); + + for (i = 8; i <= 159; i++) + { + + NEXTI; + + STEP (0); + STEP (1); + STEP (2); + STEP (3); + STEP (4); + STEP (5); + STEP (6); + STEP (7); + STEP (8); + } + + for (k = 8; k >= 0; k--) + L_ACF[k] <<= 1; + + } + /* Rescaling of the array s[0..159] + */ + if (scalauto > 0) + for (k = 159; k >= 0; k--) + *s++ <<= scalauto; +} + +/* 4.2.5 */ + +void +Reflection_coefficients (longword * L_ACF /* 0...8 IN */ , + register word * r /* 0...7 OUT */ ) +{ + register int i, m, n; + register word temp; + word ACF[9]; /* 0..8 */ + word P[9]; /* 0..8 */ + word K[9]; /* 2..8 */ + + /* Schur recursion with 16 bits arithmetic. + */ + + if (L_ACF[0] == 0) + { + for (i = 8; i > 0; i--) + *r++ = 0; + return; + } + + temp = gsm_norm (L_ACF[0]); + for (i = 0; i <= 8; i++) + ACF[i] = SASR (L_ACF[i] << temp, 16); + + /* Initialize array P[..] and K[..] for the recursion. + */ + + for (i = 1; i <= 7; i++) + K[i] = ACF[i]; + for (i = 0; i <= 8; i++) + P[i] = ACF[i]; + + /* Compute reflection coefficients + */ + for (n = 1; n <= 8; n++, r++) + { + + temp = P[1]; + temp = GSM_ABS (temp); + if (P[0] < temp) + { + for (i = n; i <= 8; i++) + *r++ = 0; + return; + } + + *r = gsm_div (temp, P[0]); + + if (P[1] > 0) + *r = -*r; /* r[n] = sub(0, r[n]) */ + if (n == 8) + return; + + /* Schur recursion + */ + temp = GSM_MULT_R (P[1], *r); + P[0] = GSM_ADD (P[0], temp); + + for (m = 1; m <= 8 - n; m++) + { + temp = GSM_MULT_R (K[m], *r); + P[m] = GSM_ADD (P[m + 1], temp); + + temp = GSM_MULT_R (P[m + 1], *r); + K[m] = GSM_ADD (K[m], temp); + } + } +} + +/* 4.2.6 */ + +void +Transformation_to_Log_Area_Ratios (register word * r /* 0..7 IN/OUT */ ) +/* + * The following scaling for r[..] and LAR[..] has been used: + * + * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1. + * LAR[..] = integer( real_LAR[..] * 16384 ); + * with -1.625 <= real_LAR <= 1.625 + */ +{ + register word temp; + register int i; + + + /* Computation of the LAR[0..7] from the r[0..7] + */ + for (i = 1; i <= 8; i++, r++) + { + + temp = *r; + temp = GSM_ABS (temp); + + if (temp < 22118) + { + temp >>= 1; + } + else if (temp < 31130) + { + temp -= 11059; + } + else + { + temp -= 26112; + temp <<= 2; + } + + *r = *r < 0 ? -temp : temp; + } +} + +/* 4.2.7 */ + +void +Quantization_and_coding (register word * LAR /* [0..7] IN/OUT */ ) +{ + register word temp; + + + /* This procedure needs four tables; the following equations + * give the optimum scaling for the constants: + * + * A[0..7] = integer( real_A[0..7] * 1024 ) + * B[0..7] = integer( real_B[0..7] * 512 ) + * MAC[0..7] = maximum of the LARc[0..7] + * MIC[0..7] = minimum of the LARc[0..7] + */ + +# undef STEP +# define STEP( A, B, MAC, MIC ) \ + temp = GSM_MULT( A, *LAR ); \ + temp = GSM_ADD( temp, B ); \ + temp = GSM_ADD( temp, 256 ); \ + temp = SASR( temp, 9 ); \ + *LAR = temp>MAC ? MAC - MIC : (temp Date: Wed, 24 Jun 2020 13:25:48 +0100 Subject: Add instructions for Cmaskzero and Cmasknotzero --- src/translation/HTLgen.v | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index f109a8e..c96d4c7 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -275,8 +275,8 @@ Definition translate_condition (c : Op.condition) (args : list reg) : mon expr : | Op.Ccompu c, _ => translate_comparison c args | Op.Ccompimm c i, _ => translate_comparison_imm c args i | Op.Ccompuimm c i, _ => translate_comparison_imm c args i - | Op.Cmaskzero n, _ => error (Errors.msg "Htlgen: condition instruction not implemented: Cmaskzero") - | Op.Cmasknotzero n, _ => error (Errors.msg "Htlgen: condition instruction not implemented: Cmasknotzero") + | Op.Cmaskzero n, r::nil => ret (Vbinop Veq (boplit Vand r n) (Vlit (ZToValue 32 0))) + | Op.Cmasknotzero n, r::nil => ret (Vbinop Vne (boplit Vand r n) (Vlit (ZToValue 32 0))) | _, _ => error (Errors.msg "Htlgen: condition instruction not implemented: other") end. -- cgit From 41b8439e0a5199bfaf50d71ff3728c0b4ddee0bd Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Wed, 24 Jun 2020 14:12:49 +0100 Subject: Revert back to original gsm_norm --- benchmarks/CHStone/gsm/gsm.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/benchmarks/CHStone/gsm/gsm.c b/benchmarks/CHStone/gsm/gsm.c index 61172a4..ff472c3 100755 --- a/benchmarks/CHStone/gsm/gsm.c +++ b/benchmarks/CHStone/gsm/gsm.c @@ -110,21 +110,6 @@ gsm_norm (longword a) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - int ret; - if (a <= -1073741824) ret = 0; - else{ - if (a < 0) - { - if (a > -1073741824) - a = ~a; - } - - ret = a & 0xffff0000 ? - (a & 0xff000000 ? -1 + bitoff[0xFF & (a >> 24)] : - 7 + bitoff[0xFF & (a >> 16)]) - : (a & 0xff00 ? 15 + bitoff[0xFF & (a >> 8)] : 23 + bitoff[0xFF & a]); - } - /* if (a < 0) { if (a <= -1073741824) @@ -136,9 +121,6 @@ gsm_norm (longword a) (a & 0xff000000 ? -1 + bitoff[0xFF & (a >> 24)] : 7 + bitoff[0xFF & (a >> 16)]) : (a & 0xff00 ? 15 + bitoff[0xFF & (a >> 8)] : 23 + bitoff[0xFF & a]); - */ - - return ret; } word -- cgit From 29bc72076ece98fa7a341b2cac5f7ec0dc8b150b Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Wed, 24 Jun 2020 16:17:10 +0100 Subject: aes working! --- benchmarks/CHStone/aes/aes.c | 749 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 738 insertions(+), 11 deletions(-) diff --git a/benchmarks/CHStone/aes/aes.c b/benchmarks/CHStone/aes/aes.c index a0cdf2d..efbb5d8 100755 --- a/benchmarks/CHStone/aes/aes.c +++ b/benchmarks/CHStone/aes/aes.c @@ -62,17 +62,707 @@ #include -int main_result; +int +SubByte (int in, const int Sbox[16][16]) +{ + return Sbox[(in / 16)][(in % 16)]; +} + + +/* **************** key expand ************************ */ +int +KeySchedule (int type, int key[32], int word[4][120], const int Sbox[16][16]) +{ + int nk, nb, round_val; + int i, j, temp[4]; + const int Rcon0[30] = { + 0x01, 0x02, 0x04, 0x08, + 0x10, 0x20, 0x40, 0x80, + 0x1b, 0x36, 0x6c, 0xd8, + 0xab, 0x4d, 0x9a, 0x2f, + 0x5e, 0xbc, 0x63, 0xc6, + 0x97, 0x35, 0x6a, 0xd4, + 0xb3, 0x7d, 0xfa, 0xef, + 0xc5, 0x91, + }; + + + switch (type) + { + case 128128: + nk = 4; + nb = 4; + round_val = 10; + break; + case 128192: + nk = 4; + nb = 6; + round_val = 12; + break; + case 128256: + nk = 4; + nb = 8; + round_val = 14; + break; + case 192128: + nk = 6; + nb = 4; + round_val = 12; + break; + case 192192: + nk = 6; + nb = 6; + round_val = 12; + break; + case 192256: + nk = 6; + nb = 8; + round_val = 14; + break; + case 256128: + nk = 8; + nb = 4; + round_val = 14; + break; + case 256192: + nk = 8; + nb = 6; + round_val = 14; + break; + case 256256: + nk = 8; + nb = 8; + round_val = 14; + break; + default: + return -1; + } + for (j = 0; j < nk; ++j) + for (i = 0; i < 4; ++i) +/* 0 word */ + word[i][j] = key[i + j * 4]; + +/* expanded key is generated */ + for (j = nk; j < nb * (round_val + 1); ++j) + { + +/* RotByte */ + if ((j % nk) == 0) + { + temp[0] = SubByte (word[1][j - 1], Sbox) ^ Rcon0[(j / nk) - 1]; + temp[1] = SubByte (word[2][j - 1], Sbox); + temp[2] = SubByte (word[3][j - 1], Sbox); + temp[3] = SubByte (word[0][j - 1], Sbox); + } + if ((j % nk) != 0) + { + temp[0] = word[0][j - 1]; + temp[1] = word[1][j - 1]; + temp[2] = word[2][j - 1]; + temp[3] = word[3][j - 1]; + } + if (nk > 6 && j % nk == 4) + for (i = 0; i < 4; ++i) + temp[i] = SubByte (temp[i], Sbox); + for (i = 0; i < 4; ++i) + word[i][j] = word[i][j - nk] ^ temp[i]; + } + return 0; +} + +/* ********* ByteSub & ShiftRow ********* */ +void +ByteSub_ShiftRow (int statemt[32], int nb, const int Sbox[16][16]) +{ + int temp; + + switch (nb) + { + case 4: + temp = Sbox[statemt[1] >> 4][statemt[1] & 0xf]; + statemt[1] = Sbox[statemt[5] >> 4][statemt[5] & 0xf]; + statemt[5] = Sbox[statemt[9] >> 4][statemt[9] & 0xf]; + statemt[9] = Sbox[statemt[13] >> 4][statemt[13] & 0xf]; + statemt[13] = temp; + + temp = Sbox[statemt[2] >> 4][statemt[2] & 0xf]; + statemt[2] = Sbox[statemt[10] >> 4][statemt[10] & 0xf]; + statemt[10] = temp; + temp = Sbox[statemt[6] >> 4][statemt[6] & 0xf]; + statemt[6] = Sbox[statemt[14] >> 4][statemt[14] & 0xf]; + statemt[14] = temp; + + temp = Sbox[statemt[3] >> 4][statemt[3] & 0xf]; + statemt[3] = Sbox[statemt[15] >> 4][statemt[15] & 0xf]; + statemt[15] = Sbox[statemt[11] >> 4][statemt[11] & 0xf]; + statemt[11] = Sbox[statemt[7] >> 4][statemt[7] & 0xf]; + statemt[7] = temp; + + statemt[0] = Sbox[statemt[0] >> 4][statemt[0] & 0xf]; + statemt[4] = Sbox[statemt[4] >> 4][statemt[4] & 0xf]; + statemt[8] = Sbox[statemt[8] >> 4][statemt[8] & 0xf]; + statemt[12] = Sbox[statemt[12] >> 4][statemt[12] & 0xf]; + break; + case 6: + temp = Sbox[statemt[1] >> 4][statemt[1] & 0xf]; + statemt[1] = Sbox[statemt[5] >> 4][statemt[5] & 0xf]; + statemt[5] = Sbox[statemt[9] >> 4][statemt[9] & 0xf]; + statemt[9] = Sbox[statemt[13] >> 4][statemt[13] & 0xf]; + statemt[13] = Sbox[statemt[17] >> 4][statemt[17] & 0xf]; + statemt[17] = Sbox[statemt[21] >> 4][statemt[21] & 0xf]; + statemt[21] = temp; + + temp = Sbox[statemt[2] >> 4][statemt[2] & 0xf]; + statemt[2] = Sbox[statemt[10] >> 4][statemt[10] & 0xf]; + statemt[10] = Sbox[statemt[18] >> 4][statemt[18] & 0xf]; + statemt[18] = temp; + temp = Sbox[statemt[6] >> 4][statemt[6] & 0xf]; + statemt[6] = Sbox[statemt[14] >> 4][statemt[14] & 0xf]; + statemt[14] = Sbox[statemt[22] >> 4][statemt[22] & 0xf]; + statemt[22] = temp; + + temp = Sbox[statemt[3] >> 4][statemt[3] & 0xf]; + statemt[3] = Sbox[statemt[15] >> 4][statemt[15] & 0xf]; + statemt[15] = temp; + temp = Sbox[statemt[7] >> 4][statemt[7] & 0xf]; + statemt[7] = Sbox[statemt[19] >> 4][statemt[19] & 0xf]; + statemt[19] = temp; + temp = Sbox[statemt[11] >> 4][statemt[11] & 0xf]; + statemt[11] = Sbox[statemt[23] >> 4][statemt[23] & 0xf]; + statemt[23] = temp; + + statemt[0] = Sbox[statemt[0] >> 4][statemt[0] & 0xf]; + statemt[4] = Sbox[statemt[4] >> 4][statemt[4] & 0xf]; + statemt[8] = Sbox[statemt[8] >> 4][statemt[8] & 0xf]; + statemt[12] = Sbox[statemt[12] >> 4][statemt[12] & 0xf]; + statemt[16] = Sbox[statemt[16] >> 4][statemt[16] & 0xf]; + statemt[20] = Sbox[statemt[20] >> 4][statemt[20] & 0xf]; + break; + case 8: + temp = Sbox[statemt[1] >> 4][statemt[1] & 0xf]; + statemt[1] = Sbox[statemt[5] >> 4][statemt[5] & 0xf]; + statemt[5] = Sbox[statemt[9] >> 4][statemt[9] & 0xf]; + statemt[9] = Sbox[statemt[13] >> 4][statemt[13] & 0xf]; + statemt[13] = Sbox[statemt[17] >> 4][statemt[17] & 0xf]; + statemt[17] = Sbox[statemt[21] >> 4][statemt[21] & 0xf]; + statemt[21] = Sbox[statemt[25] >> 4][statemt[25] & 0xf]; + statemt[25] = Sbox[statemt[29] >> 4][statemt[29] & 0xf]; + statemt[29] = temp; + + temp = Sbox[statemt[2] >> 4][statemt[2] & 0xf]; + statemt[2] = Sbox[statemt[14] >> 4][statemt[14] & 0xf]; + statemt[14] = Sbox[statemt[26] >> 4][statemt[26] & 0xf]; + statemt[26] = Sbox[statemt[6] >> 4][statemt[6] & 0xf]; + statemt[6] = Sbox[statemt[18] >> 4][statemt[18] & 0xf]; + statemt[18] = Sbox[statemt[30] >> 4][statemt[30] & 0xf]; + statemt[30] = Sbox[statemt[10] >> 4][statemt[10] & 0xf]; + statemt[10] = Sbox[statemt[22] >> 4][statemt[22] & 0xf]; + statemt[22] = temp; + + temp = Sbox[statemt[3] >> 4][statemt[3] & 0xf]; + statemt[3] = Sbox[statemt[19] >> 4][statemt[19] & 0xf]; + statemt[19] = temp; + temp = Sbox[statemt[7] >> 4][statemt[7] & 0xf]; + statemt[7] = Sbox[statemt[23] >> 4][statemt[23] & 0xf]; + statemt[23] = temp; + temp = Sbox[statemt[11] >> 4][statemt[11] & 0xf]; + statemt[11] = Sbox[statemt[27] >> 4][statemt[27] & 0xf]; + statemt[27] = temp; + temp = Sbox[statemt[15] >> 4][statemt[15] & 0xf]; + statemt[15] = Sbox[statemt[31] >> 4][statemt[31] & 0xf]; + statemt[31] = temp; + + statemt[0] = Sbox[statemt[0] >> 4][statemt[0] & 0xf]; + statemt[4] = Sbox[statemt[4] >> 4][statemt[4] & 0xf]; + statemt[8] = Sbox[statemt[8] >> 4][statemt[8] & 0xf]; + statemt[12] = Sbox[statemt[12] >> 4][statemt[12] & 0xf]; + statemt[16] = Sbox[statemt[16] >> 4][statemt[16] & 0xf]; + statemt[20] = Sbox[statemt[20] >> 4][statemt[20] & 0xf]; + statemt[24] = Sbox[statemt[24] >> 4][statemt[24] & 0xf]; + statemt[28] = Sbox[statemt[28] >> 4][statemt[28] & 0xf]; + break; + } +} + +/* ********* InversShiftRow & ByteSub ********* */ +void +InversShiftRow_ByteSub (int statemt[32], int nb, const int invSbox[16][16]) +{ + int temp; + + switch (nb) + { + case 4: + temp = invSbox[statemt[13] >> 4][statemt[13] & 0xf]; + statemt[13] = invSbox[statemt[9] >> 4][statemt[9] & 0xf]; + statemt[9] = invSbox[statemt[5] >> 4][statemt[5] & 0xf]; + statemt[5] = invSbox[statemt[1] >> 4][statemt[1] & 0xf]; + statemt[1] = temp; + + temp = invSbox[statemt[14] >> 4][statemt[14] & 0xf]; + statemt[14] = invSbox[statemt[6] >> 4][statemt[6] & 0xf]; + statemt[6] = temp; + temp = invSbox[statemt[2] >> 4][statemt[2] & 0xf]; + statemt[2] = invSbox[statemt[10] >> 4][statemt[10] & 0xf]; + statemt[10] = temp; + + temp = invSbox[statemt[15] >> 4][statemt[15] & 0xf]; + statemt[15] = invSbox[statemt[3] >> 4][statemt[3] & 0xf]; + statemt[3] = invSbox[statemt[7] >> 4][statemt[7] & 0xf]; + statemt[7] = invSbox[statemt[11] >> 4][statemt[11] & 0xf]; + statemt[11] = temp; + + statemt[0] = invSbox[statemt[0] >> 4][statemt[0] & 0xf]; + statemt[4] = invSbox[statemt[4] >> 4][statemt[4] & 0xf]; + statemt[8] = invSbox[statemt[8] >> 4][statemt[8] & 0xf]; + statemt[12] = invSbox[statemt[12] >> 4][statemt[12] & 0xf]; + break; + case 6: + temp = invSbox[statemt[21] >> 4][statemt[21] & 0xf]; + statemt[21] = invSbox[statemt[17] >> 4][statemt[17] & 0xf]; + statemt[17] = invSbox[statemt[13] >> 4][statemt[13] & 0xf]; + statemt[13] = invSbox[statemt[9] >> 4][statemt[9] & 0xf]; + statemt[9] = invSbox[statemt[5] >> 4][statemt[5] & 0xf]; + statemt[5] = invSbox[statemt[1] >> 4][statemt[1] & 0xf]; + statemt[1] = temp; + + temp = invSbox[statemt[22] >> 4][statemt[22] & 0xf]; + statemt[22] = invSbox[statemt[14] >> 4][statemt[14] & 0xf]; + statemt[14] = invSbox[statemt[6] >> 4][statemt[6] & 0xf]; + statemt[6] = temp; + temp = invSbox[statemt[18] >> 4][statemt[18] & 0xf]; + statemt[18] = invSbox[statemt[10] >> 4][statemt[10] & 0xf]; + statemt[10] = invSbox[statemt[2] >> 4][statemt[2] & 0xf]; + statemt[2] = temp; + + temp = invSbox[statemt[15] >> 4][statemt[15] & 0xf]; + statemt[15] = invSbox[statemt[3] >> 4][statemt[3] & 0xf]; + statemt[3] = temp; + temp = invSbox[statemt[19] >> 4][statemt[19] & 0xf]; + statemt[19] = invSbox[statemt[7] >> 4][statemt[7] & 0xf]; + statemt[7] = temp; + temp = invSbox[statemt[23] >> 4][statemt[23] & 0xf]; + statemt[23] = invSbox[statemt[11] >> 4][statemt[11] & 0xf]; + statemt[11] = temp; + + statemt[0] = invSbox[statemt[0] >> 4][statemt[0] & 0xf]; + statemt[4] = invSbox[statemt[4] >> 4][statemt[4] & 0xf]; + statemt[8] = invSbox[statemt[8] >> 4][statemt[8] & 0xf]; + statemt[12] = invSbox[statemt[12] >> 4][statemt[12] & 0xf]; + statemt[16] = invSbox[statemt[16] >> 4][statemt[16] & 0xf]; + statemt[20] = invSbox[statemt[20] >> 4][statemt[20] & 0xf]; + break; + case 8: + temp = invSbox[statemt[29] >> 4][statemt[29] & 0xf]; + statemt[29] = invSbox[statemt[25] >> 4][statemt[25] & 0xf]; + statemt[25] = invSbox[statemt[21] >> 4][statemt[21] & 0xf]; + statemt[21] = invSbox[statemt[17] >> 4][statemt[17] & 0xf]; + statemt[17] = invSbox[statemt[13] >> 4][statemt[13] & 0xf]; + statemt[13] = invSbox[statemt[9] >> 4][statemt[9] & 0xf]; + statemt[9] = invSbox[statemt[5] >> 4][statemt[5] & 0xf]; + statemt[5] = invSbox[statemt[1] >> 4][statemt[1] & 0xf]; + statemt[1] = temp; + + temp = invSbox[statemt[30] >> 4][statemt[30] & 0xf]; + statemt[30] = invSbox[statemt[18] >> 4][statemt[18] & 0xf]; + statemt[18] = invSbox[statemt[6] >> 4][statemt[6] & 0xf]; + statemt[6] = invSbox[statemt[26] >> 4][statemt[26] & 0xf]; + statemt[26] = invSbox[statemt[14] >> 4][statemt[14] & 0xf]; + statemt[14] = invSbox[statemt[2] >> 4][statemt[2] & 0xf]; + statemt[2] = invSbox[statemt[22] >> 4][statemt[22] & 0xf]; + statemt[22] = invSbox[statemt[10] >> 4][statemt[10] & 0xf]; + statemt[10] = temp; + + temp = invSbox[statemt[31] >> 4][statemt[31] & 0xf]; + statemt[31] = invSbox[statemt[15] >> 4][statemt[15] & 0xf]; + statemt[15] = temp; + temp = invSbox[statemt[27] >> 4][statemt[27] & 0xf]; + statemt[27] = invSbox[statemt[11] >> 4][statemt[11] & 0xf]; + statemt[11] = temp; + temp = invSbox[statemt[23] >> 4][statemt[23] & 0xf]; + statemt[23] = invSbox[statemt[7] >> 4][statemt[7] & 0xf]; + statemt[7] = temp; + temp = invSbox[statemt[19] >> 4][statemt[19] & 0xf]; + statemt[19] = invSbox[statemt[3] >> 4][statemt[3] & 0xf]; + statemt[3] = temp; + + statemt[0] = invSbox[statemt[0] >> 4][statemt[0] & 0xf]; + statemt[4] = invSbox[statemt[4] >> 4][statemt[4] & 0xf]; + statemt[8] = invSbox[statemt[8] >> 4][statemt[8] & 0xf]; + statemt[12] = invSbox[statemt[12] >> 4][statemt[12] & 0xf]; + statemt[16] = invSbox[statemt[16] >> 4][statemt[16] & 0xf]; + statemt[20] = invSbox[statemt[20] >> 4][statemt[20] & 0xf]; + statemt[24] = invSbox[statemt[24] >> 4][statemt[24] & 0xf]; + statemt[28] = invSbox[statemt[28] >> 4][statemt[28] & 0xf]; + break; + } +} + +/* ******** MixColumn ********** */ +int +MixColumn_AddRoundKey (int statemt[32], int nb, int n, int word[4][120]) +{ + int ret[8 * 4], j; + register int x; + + for (j = 0; j < nb; ++j) + { + ret[j * 4] = (statemt[j * 4] << 1); + if ((ret[j * 4] >> 8) == 1) + ret[j * 4] ^= 283; + x = statemt[1 + j * 4]; + x ^= (x << 1); + if ((x >> 8) == 1) + ret[j * 4] ^= (x ^ 283); + else + ret[j * 4] ^= x; + ret[j * 4] ^= + statemt[2 + j * 4] ^ statemt[3 + j * 4] ^ word[0][j + nb * n]; + + ret[1 + j * 4] = (statemt[1 + j * 4] << 1); + if ((ret[1 + j * 4] >> 8) == 1) + ret[1 + j * 4] ^= 283; + x = statemt[2 + j * 4]; + x ^= (x << 1); + if ((x >> 8) == 1) + ret[1 + j * 4] ^= (x ^ 283); + else + ret[1 + j * 4] ^= x; + ret[1 + j * 4] ^= + statemt[3 + j * 4] ^ statemt[j * 4] ^ word[1][j + nb * n]; + + ret[2 + j * 4] = (statemt[2 + j * 4] << 1); + if ((ret[2 + j * 4] >> 8) == 1) + ret[2 + j * 4] ^= 283; + x = statemt[3 + j * 4]; + x ^= (x << 1); + if ((x >> 8) == 1) + ret[2 + j * 4] ^= (x ^ 283); + else + ret[2 + j * 4] ^= x; + ret[2 + j * 4] ^= + statemt[j * 4] ^ statemt[1 + j * 4] ^ word[2][j + nb * n]; + + ret[3 + j * 4] = (statemt[3 + j * 4] << 1); + if ((ret[3 + j * 4] >> 8) == 1) + ret[3 + j * 4] ^= 283; + x = statemt[j * 4]; + x ^= (x << 1); + if ((x >> 8) == 1) + ret[3 + j * 4] ^= (x ^ 283); + else + ret[3 + j * 4] ^= x; + ret[3 + j * 4] ^= + statemt[1 + j * 4] ^ statemt[2 + j * 4] ^ word[3][j + nb * n]; + } + for (j = 0; j < nb; ++j) + { + statemt[j * 4] = ret[j * 4]; + statemt[1 + j * 4] = ret[1 + j * 4]; + statemt[2 + j * 4] = ret[2 + j * 4]; + statemt[3 + j * 4] = ret[3 + j * 4]; + } + return 0; +} + +/* ******** InversMixColumn ********** */ +int +AddRoundKey_InversMixColumn (int statemt[32], int nb, int n, int word[4][120]) +{ + int ret[8 * 4], i, j; + register int x; + + for (j = 0; j < nb; ++j) + { + statemt[j * 4] ^= word[0][j + nb * n]; + statemt[1 + j * 4] ^= word[1][j + nb * n]; + statemt[2 + j * 4] ^= word[2][j + nb * n]; + statemt[3 + j * 4] ^= word[3][j + nb * n]; + } + for (j = 0; j < nb; ++j) + for (i = 0; i < 4; ++i) + { + x = (statemt[i + j * 4] << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[i + j * 4]; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[i + j * 4]; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + ret[i + j * 4] = x; + + x = (statemt[(i + 1) % 4 + j * 4] << 1); + if ((x >> 8) == 1) + x ^= 283; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[(i + 1) % 4 + j * 4]; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[(i + 1) % 4 + j * 4]; + ret[i + j * 4] ^= x; -#include "aes.h" -#include "aes_enc.c" -#include "aes_dec.c" -#include "aes_key.c" -#include "aes_func.c" + x = (statemt[(i + 2) % 4 + j * 4] << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[(i + 2) % 4 + j * 4]; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[(i + 2) % 4 + j * 4]; + ret[i + j * 4] ^= x; + + x = (statemt[(i + 3) % 4 + j * 4] << 1); + if ((x >> 8) == 1) + x ^= 283; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x = (x << 1); + if ((x >> 8) == 1) + x ^= 283; + x ^= statemt[(i + 3) % 4 + j * 4]; + ret[i + j * 4] ^= x; + } + for (i = 0; i < nb; ++i) + { + statemt[i * 4] = ret[i * 4]; + statemt[1 + i * 4] = ret[1 + i * 4]; + statemt[2 + i * 4] = ret[2 + i * 4]; + statemt[3 + i * 4] = ret[3 + i * 4]; + } + return 0; +} + +/* ******** AddRoundKey ********** */ +int +AddRoundKey (int statemt[32], int type, int n, int word[4][120]) +{ + int j, nb; + switch (type) + { + case 128128: + case 192128: + case 256128: + nb = 4; + break; + case 128192: + case 192192: + case 256192: + nb = 6; + break; + case 128256: + case 192256: + case 256256: + nb = 8; + break; + } + for (j = 0; j < nb; ++j) + { + statemt[j * 4] ^= word[0][j + nb * n]; + statemt[1 + j * 4] ^= word[1][j + nb * n]; + statemt[2 + j * 4] ^= word[2][j + nb * n]; + statemt[3 + j * 4] ^= word[3][j + nb * n]; + } + return 0; +} +int +encrypt (int statemt[32], int key[32], int type, int *main_result, const int Sbox[16][16]) +{ + int i; + int nb; + int round_val; + int word[4][120]; +/* ++--------------------------------------------------------------------------+ +| * Test Vector (added for CHStone) | +| out_enc_statemt : expected output data for "encrypt" | ++--------------------------------------------------------------------------+ +*/ + const int out_enc_statemt[16] = + { 0x39, 0x25, 0x84, 0x1d, 0x2, 0xdc, 0x9, 0xfb, 0xdc, 0x11, 0x85, 0x97, + 0x19, 0x6a, 0xb, 0x32 + }; + + KeySchedule (type, key, word, Sbox); + switch (type) + { + case 128128: + round_val = 0; + nb = 4; + break; + case 192128: + round_val = 2; + nb = 4; + break; + case 256128: + round_val = 4; + nb = 4; + break; + case 128192: + case 192192: + round_val = 2; + nb = 6; + break; + case 256192: + round_val = 4; + nb = 6; + break; + case 128256: + case 192256: + case 256256: + round_val = 4; + nb = 8; + break; + } + AddRoundKey (statemt, type, 0, word); + for (i = 1; i <= round_val + 9; ++i) + { + ByteSub_ShiftRow (statemt, nb, Sbox); + MixColumn_AddRoundKey (statemt, nb, i, word); + } + ByteSub_ShiftRow (statemt, nb, Sbox); + AddRoundKey (statemt, type, i, word); +/* + printf ("encrypted message \t"); + for (i = 0; i < nb * 4; ++i) + { + if (statemt[i] < 16) + printf ("0"); + printf ("%x", statemt[i]); + } +*/ + for (i = 0; i < 16; i++) + *main_result += (statemt[i] != out_enc_statemt[i]); + + return 0; +} + +int +decrypt (int statemt[32], int key[32], int type, int *main_result, const int Sbox[16][16]) +{ + int i; + int nb; + int round_val; + int word[4][120]; + const int invSbox[16][16] = { + {0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, + 0x81, 0xf3, 0xd7, 0xfb}, + {0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, + 0xc4, 0xde, 0xe9, 0xcb}, + {0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, + 0x42, 0xfa, 0xc3, 0x4e}, + {0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, + 0x6d, 0x8b, 0xd1, 0x25}, + {0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, + 0x5d, 0x65, 0xb6, 0x92}, + {0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, + 0xa7, 0x8d, 0x9d, 0x84}, + {0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, + 0xb8, 0xb3, 0x45, 0x06}, + {0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, + 0x01, 0x13, 0x8a, 0x6b}, + {0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, + 0xf0, 0xb4, 0xe6, 0x73}, + {0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, + 0x1c, 0x75, 0xdf, 0x6e}, + {0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, + 0xaa, 0x18, 0xbe, 0x1b}, + {0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, + 0x78, 0xcd, 0x5a, 0xf4}, + {0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, + 0x27, 0x80, 0xec, 0x5f}, + {0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, + 0x93, 0xc9, 0x9c, 0xef}, + {0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, + 0x83, 0x53, 0x99, 0x61}, + {0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, + 0x55, 0x21, 0x0c, 0x7d} + }; +/* ++--------------------------------------------------------------------------+ +| * Test Vector (added for CHStone) | +| out_enc_statemt : expected output data for "decrypt" | ++--------------------------------------------------------------------------+ +*/ + const int out_dec_statemt[16] = + { 0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, + 0xe0, 0x37, 0x7, 0x34 + }; + KeySchedule (type, key, word, Sbox); + + switch (type) + { + case 128128: + round_val = 10; + nb = 4; + break; + case 128192: + case 192192: + round_val = 12; + nb = 6; + break; + case 192128: + round_val = 12; + nb = 4; + break; + case 128256: + case 192256: + round_val = 14; + nb = 8; + break; + case 256128: + round_val = 14; + nb = 4; + break; + case 256192: + round_val = 14; + nb = 6; + break; + case 256256: + round_val = 14; + nb = 8; + break; + } + + AddRoundKey (statemt, type, round_val, word); + + InversShiftRow_ByteSub (statemt, nb, invSbox); + + for (i = round_val - 1; i >= 1; --i) + { + AddRoundKey_InversMixColumn (statemt, nb, i, word); + InversShiftRow_ByteSub (statemt, nb, invSbox); + } + + AddRoundKey (statemt, type, 0, word); +/* + printf ("\ndecrypto message\t"); + for (i = 0; i < ((type % 1000) / 8); ++i) + { + if (statemt[i] < 16) + printf ("0"); + printf ("%x", statemt[i]); + } +*/ + for (i = 0; i < 16; i++) + *main_result += (statemt[i] != out_dec_statemt[i]); + + return 0; +} /* ***************** main **************************** */ int -aes_main (void) +aes_main (int *res) { /* +--------------------------------------------------------------------------+ @@ -80,6 +770,8 @@ aes_main (void) | statemt, key : input data | +--------------------------------------------------------------------------+ */ + int key[32]; + int statemt[32]; statemt[0] = 50; statemt[1] = 67; statemt[2] = 246; @@ -113,17 +805,52 @@ aes_main (void) key[13] = 207; key[14] = 79; key[15] = 60; +const int Sbox[16][16] = { + {0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, + 0xfe, 0xd7, 0xab, 0x76}, + {0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, + 0x9c, 0xa4, 0x72, 0xc0}, + {0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, + 0x71, 0xd8, 0x31, 0x15}, + {0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, + 0xeb, 0x27, 0xb2, 0x75}, + {0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, + 0x29, 0xe3, 0x2f, 0x84}, + {0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, + 0x4a, 0x4c, 0x58, 0xcf}, + {0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, + 0x50, 0x3c, 0x9f, 0xa8}, + {0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, + 0x10, 0xff, 0xf3, 0xd2}, + {0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, + 0x64, 0x5d, 0x19, 0x73}, + {0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, + 0xde, 0x5e, 0x0b, 0xdb}, + {0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, + 0x91, 0x95, 0xe4, 0x79}, + {0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, + 0x65, 0x7a, 0xae, 0x08}, + {0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, + 0x4b, 0xbd, 0x8b, 0x8a}, + {0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, + 0x86, 0xc1, 0x1d, 0x9e}, + {0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, + 0xce, 0x55, 0x28, 0xdf}, + {0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, + 0xb0, 0x54, 0xbb, 0x16} +}; - encrypt (statemt, key, 128128); - decrypt (statemt, key, 128128); + encrypt (statemt, key, 128128, res, Sbox); + decrypt (statemt, key, 128128, res, Sbox); return 0; } int main () { + int main_result; main_result = 0; - aes_main (); - printf ("\n%d\n", main_result); + aes_main (&main_result); + //printf ("\n%d\n", main_result); return main_result; } -- cgit From 75c75c52cdaa71b268f0fadc4c31aba0e099abbc Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 25 Jun 2020 11:36:39 +0100 Subject: Add quartus tcl file --- scripts/quartus_synth.tcl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/quartus_synth.tcl diff --git a/scripts/quartus_synth.tcl b/scripts/quartus_synth.tcl new file mode 100644 index 0000000..971acc6 --- /dev/null +++ b/scripts/quartus_synth.tcl @@ -0,0 +1,28 @@ +# PRiME pre-KAPow kernel flow +# Performs pre-KAPow run steps for instrumenting arbitrary Verilog for power monitoring +# James Davis, 2015 + +load_package flow + +cd kernel + +project_new kernel +set_global_assignment -name FAMILY "Cyclone 10 GX" +set_global_assignment -name SYSTEMVERILOG_FILE kernel.v +set_global_assignment -name TOP_LEVEL_ENTITY top +set_global_assignment -name INI_VARS "qatm_force_vqm=on;" +set_instance_assignment -name VIRTUAL_PIN ON -to * + +execute_module -tool map + +execute_module -tool fit + +execute_module -tool eda -args "--simulation --tool=vcs" + +# set_global_assignment -name POWER_OUTPUT_SAF_NAME ${kernel}.asf +# set_global_assignment -name POWER_DEFAULT_INPUT_IO_TOGGLE_RATE "12.5 %" +# set_global_assignment -name POWER_REPORT_SIGNAL_ACTIVITY ON +# set_global_assignment -name POWER_REPORT_POWER_DISSIPATION ON +# execute_module -tool pow + +project_close -- cgit From ea0f077891a3935f1138f14796b323b1a9bdab1f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 25 Jun 2020 18:15:09 +0100 Subject: Add optimisations --- src/Compiler.v | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Compiler.v b/src/Compiler.v index 98ef429..f9fe686 100644 --- a/src/Compiler.v +++ b/src/Compiler.v @@ -76,11 +76,27 @@ Qed. Definition transf_backend (r : RTL.program) : res Verilog.program := OK r + @@ Tailcall.transf_program @@@ Inlining.transf_program + @@ Renumber.transf_program + @@ Constprop.transf_program + @@ Renumber.transf_program + @@@ CSE.transf_program + @@@ Deadcode.transf_program + @@@ Unusedglob.transform_program @@ print (print_RTL 1) @@@ HTLgen.transl_program @@ Veriloggen.transl_program. +(* Unoptimised below: *) +(*Definition transf_backend (r : RTL.program) : res Verilog.program := + OK r + @@@ Inlining.transf_program + @@ print (print_RTL 1) + @@@ HTLgen.transl_program + @@ Veriloggen.transl_program. +*) + Definition transf_frontend (p: Csyntax.program) : res RTL.program := OK p @@@ SimplExpr.transl_program -- cgit From 26f73ea7c9f77b6941075571cd1dc91e15c114c3 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Fri, 26 Jun 2020 11:53:18 +0100 Subject: working adpcm in coqup --- benchmarks/CHStone/adpcm/adpcm.c | 84 ++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/benchmarks/CHStone/adpcm/adpcm.c b/benchmarks/CHStone/adpcm/adpcm.c index b11eed9..bb44500 100755 --- a/benchmarks/CHStone/adpcm/adpcm.c +++ b/benchmarks/CHStone/adpcm/adpcm.c @@ -354,11 +354,46 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) 1448, 128, -624, 48, 212, -44, -44, 12 }; - int xl, xh; /* variables for receive quadrature mirror filter here */ int accumc[11], accumd[11]; + const int qq2_code2_table[4] = { + -7408, -1616, 7408, 1616 + }; + + const int qq4_code4_table[16] = { + 0, -20456, -12896, -8968, -6288, -4240, -2584, -1200, + 20456, 12896, 8968, 6288, 4240, 2584, 1200, 0 + }; + const int qq6_code6_table[64] = { + -136, -136, -136, -136, -24808, -21904, -19008, -16704, + -14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856, + -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576, + -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728, + 24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192, + 10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456, + 4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032, + 1688, 1360, 1040, 728, 432, 136, -432, -136 + }; + + + int delay_dhx[6]; + + int delay_bph[6]; + + int dec_del_bpl[6]; + + int dec_del_dltx[6]; + + /* variables used in filtez */ + int dec_del_bph[6]; + + int dec_del_dhx[6]; + + int delay_bpl[6]; + + int delay_dltx[6]; /* outputs of decode() */ int xout1, xout2; @@ -368,9 +403,6 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) int il, szl, spl, sl, el; - int delay_bpl[6]; - - int delay_dltx[6]; int nbl; /* delay line */ int al1, al2; @@ -384,31 +416,17 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) int sh; /* this comes from adaptive predictor */ int eh; - const int qq2_code2_table[4] = { - -7408, -1616, 7408, 1616 - }; - + int ah1, ah2; + int ph1, ph2; + int rh1, rh2; int dh, ih; int nbh, szh; int sph, ph, yh, rh; - int delay_dhx[6]; - - int delay_bph[6]; - - int ah1, ah2; - int ph1, ph2; - int rh1, rh2; - /* variables for decoder here */ int ilr, rl; int dec_deth, dec_detl, dec_dlt; - - int dec_del_bpl[6]; - - int dec_del_dltx[6]; - int dec_plt, dec_plt1, dec_plt2; int dec_szl, dec_spl, dec_sl; int dec_rlt1, dec_rlt2, dec_rlt; @@ -416,11 +434,6 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) int dl; int dec_nbl, dec_dh, dec_nbh; - /* variables used in filtez */ - int dec_del_bph[6]; - - int dec_del_dhx[6]; - int dec_szh; /* variables used in filtep */ int dec_rh1, dec_rh2; @@ -432,21 +445,6 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) int dec_ph1, dec_ph2; int i, j; - const int qq4_code4_table[16] = { - 0, -20456, -12896, -8968, -6288, -4240, -2584, -1200, - 20456, 12896, 8968, 6288, 4240, 2584, 1200, 0 - }; - const int qq6_code6_table[64] = { - -136, -136, -136, -136, -24808, -21904, -19008, -16704, - -14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856, - -7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576, - -3168, -2776, -2400, -2032, -1688, -1360, -1040, -728, - 24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192, - 10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456, - 4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032, - 1688, 1360, 1040, 728, 432, 136, -432, -136 - }; - /* reset, initialize required memory */ detl = dec_detl = 32; /* reset to min scale factor */ @@ -843,13 +841,13 @@ main () { main_result += 1; } - } + }/* for (i = 0; i < IN_END; i++) { if (result[i] != test_result[i]) { main_result += 1; } - } + }*/ return main_result; } -- cgit From 4b7ef5389cd21ddb3f4b98e457292d964ffb7936 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Fri, 26 Jun 2020 11:58:18 +0100 Subject: sha re-factoring --- benchmarks/CHStone/sha/sha_driver.c | 1313 ++++++++++++++++++++++++++++++++++- 1 file changed, 1307 insertions(+), 6 deletions(-) diff --git a/benchmarks/CHStone/sha/sha_driver.c b/benchmarks/CHStone/sha/sha_driver.c index 5cbb394..d533c52 100755 --- a/benchmarks/CHStone/sha/sha_driver.c +++ b/benchmarks/CHStone/sha/sha_driver.c @@ -25,25 +25,1326 @@ /* activated by defining USE_MODIFIED_SHA */ #include -#include "sha.h" -#include "sha.c" +/* NIST Secure Hash Algorithm */ +/* heavily modified from Peter C. Gutmann's implementation */ + +/* Useful defines & typedefs */ + +typedef unsigned char BYTE; +typedef unsigned int INT32; + +#define SHA_BLOCKSIZE 64 + +void sha_init (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi); +void sha_update (const BYTE *, int, INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]); +void sha_final (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]); + +void sha_stream (INT32 sha_info_digest[5]); +void sha_print (); + +#define BLOCK_SIZE 8192 +#define VSIZE 2 + +/* ++--------------------------------------------------------------------------+ +| * Test Vectors (added for CHStone) | +| indata, in_i : input data | ++--------------------------------------------------------------------------+ +*/ +#define f1(x,y,z) ((x & y) | (~x & z)) +#define f2(x,y,z) (x ^ y ^ z) +#define f3(x,y,z) ((x & y) | (x & z) | (y & z)) +#define f4(x,y,z) (x ^ y ^ z) + +/* SHA constants */ + +#define CONST1 0x5a827999L +#define CONST2 0x6ed9eba1L +#define CONST3 0x8f1bbcdcL +#define CONST4 0xca62c1d6L + +/* 32-bit rotate */ + +#define ROT32(x,n) ((x << n) | (x >> (32 - n))) + +#define FUNC(n,i) \ + temp = ROT32(A,5) + f##n(B,C,D) + E + W[i] + CONST##n; \ + E = D; D = C; C = ROT32(B,30); B = A; A = temp + +void +local_memset (INT32 * s, int c, int n, int e) +{ + INT32 uc; + INT32 *p; + int m; + + m = n >> 2; + uc = c; + p = (INT32 *) s; + while (e-- > 0) + { + p++; + } + while (m-- > 0) + { + *p++ = uc; + } +} + +void +local_memcpy (INT32 * s1, const BYTE * s2, int n) +{ + INT32 *p1; + BYTE *p2; + INT32 tmp; + int m; + m = n >> 2; + p1 = (INT32 *) s1; + p2 = (BYTE *) s2; + + while (m-- > 0) + { + tmp = 0; + tmp |= 0xFF & *p2++; + tmp |= (0xFF & *p2++) << 8; + tmp |= (0xFF & *p2++) << 16; + tmp |= (0xFF & *p2++) << 24; + *p1 = tmp; + p1++; + } +} + +/* do SHA transformation */ + +static void +sha_transform (INT32 sha_info_digest[5], INT32 sha_info_data[16]) +{ + int i; + INT32 temp, A, B, C, D, E, W[80]; + + for (i = 0; i < 16; ++i) + { + W[i] = sha_info_data[i]; + } + for (i = 16; i < 80; ++i) + { + W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + } + A = sha_info_digest[0]; + B = sha_info_digest[1]; + C = sha_info_digest[2]; + D = sha_info_digest[3]; + E = sha_info_digest[4]; + + for (i = 0; i < 20; ++i) + { + FUNC (1, i); + } + for (i = 20; i < 40; ++i) + { + FUNC (2, i); + } + for (i = 40; i < 60; ++i) + { + FUNC (3, i); + } + for (i = 60; i < 80; ++i) + { + FUNC (4, i); + } + + sha_info_digest[0] += A; + sha_info_digest[1] += B; + sha_info_digest[2] += C; + sha_info_digest[3] += D; + sha_info_digest[4] += E; +} + +/* initialize the SHA digest */ + +void +sha_init (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi) +{ + sha_info_digest[0] = 0x67452301L; + sha_info_digest[1] = 0xefcdab89L; + sha_info_digest[2] = 0x98badcfeL; + sha_info_digest[3] = 0x10325476L; + sha_info_digest[4] = 0xc3d2e1f0L; + *sha_info_count_lo = 0L; + *sha_info_count_hi = 0L; +} + +/* update the SHA digest */ + +void +sha_update (const BYTE * buffer, int count, INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]) +{ + if ((*sha_info_count_lo + ((INT32) count << 3)) < *sha_info_count_lo) + { + *sha_info_count_hi = *sha_info_count_hi + 1 ; + } + *sha_info_count_lo += (INT32) count << 3; + *sha_info_count_hi += (INT32) count >> 29; + while (count >= SHA_BLOCKSIZE) + { + local_memcpy (sha_info_data, buffer, SHA_BLOCKSIZE); + sha_transform (sha_info_digest, sha_info_data); + buffer += SHA_BLOCKSIZE; + count -= SHA_BLOCKSIZE; + } + local_memcpy (sha_info_data, buffer, count); +} + +/* finish computing the SHA digest */ + +void +sha_final (INT32 sha_info_digest[5], INT32 * sha_info_count_lo, INT32 * sha_info_count_hi, INT32 sha_info_data[16]) +{ + int count; + INT32 lo_bit_count; + INT32 hi_bit_count; + + + lo_bit_count = *sha_info_count_lo; + hi_bit_count = *sha_info_count_hi; + count = (int) ((lo_bit_count >> 3) & 0x3f); + sha_info_data[count++] = 0x80; + if (count > 56) + { + local_memset (sha_info_data, 0, 64 - count, count); + sha_transform (sha_info_digest, sha_info_data); + local_memset (sha_info_data, 0, 56, 0); + } + else + { + local_memset (sha_info_data, 0, 56 - count, count); + } + sha_info_data[14] = hi_bit_count; + sha_info_data[15] = lo_bit_count; + sha_transform (sha_info_digest, sha_info_data); +} + +/* compute the SHA digest of a FILE stream */ +void +sha_stream (INT32 sha_info_digest[5]) +{ + int i, j; + const BYTE *p; + INT32 sha_info_count_lo, sha_info_count_hi; /* 64-bit bit count */ + INT32 sha_info_data[16]; + const BYTE indata[VSIZE][BLOCK_SIZE] = { + {75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, + 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, + 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, + 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, + 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, + 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, + 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, + 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, + 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, + 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, + 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, + 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, + 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, + 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, + 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, + 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, + 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, + 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, + 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, + 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, + 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, + 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, + 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, + 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, + 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, + 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, + 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, + 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, + 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, + 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, + 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, + 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, + 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, + 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, + 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, + 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, + 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, + 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, + 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, + 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, + 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, + 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, + 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, + 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, + 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, + 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, + 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, + 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, + 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, + 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, + 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, + 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, + 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, + 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, + 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, + 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, + 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, + 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, + 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, + 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, + 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, + 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, + 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, + 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, + 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 79, 114, 119, 111, 114, 114, 121, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, + 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, + 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, + 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, + 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, + 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, + 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, + 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, + 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, + 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, + 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, + 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, + 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, + 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, + 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, + 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, + 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, + 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, + 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, + 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, + 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, + 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, + 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, + 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, + 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, + 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, + 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, + 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, + 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, + 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, + 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, + 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, + 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, + 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, + 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, + 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, + 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, + 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, + 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, + 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, + 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, + 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, + 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, + 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, + 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, + 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, + 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, + 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, + 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, + 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, + 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, + 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, + 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, + 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, + 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, + 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, + 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, + 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, + 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, + 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, + 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, + 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, + 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, + 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, + 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, + 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, + 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, + 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, + 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, + 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, + 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, + 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, + 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, + 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, + 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, + 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, + 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, + 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 75, 117, 114, 116, + 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, + 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, + 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, + 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, + 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, + 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, + 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, + 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, + 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, + 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, + 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, + 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, + 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, + 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, + 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, + 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, + 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, + 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, + 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, + 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, + 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, + 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, + 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, + 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, + 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, + 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, + 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, + 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, + 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, + 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, + 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, + 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, + 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, + 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, + 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, + 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, + 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, + 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, + 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, + 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117}, + {116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, + 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, + 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, + 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, + 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, + 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, + 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, + 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, + 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, + 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, + 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, + 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, + 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, + 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, + 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, + 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, + 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, + 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, + 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, + 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, + 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, + 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, + 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, + 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, + 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, + 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, + 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, + 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, + 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, + 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, + 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, + 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, + 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, + 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, + 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, + 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, + 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, + 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, + 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, + 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, + 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, + 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, + 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, + 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, + 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, + 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, + 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, + 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, + 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, + 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, + 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, + 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, + 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, + 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, + 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, + 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, + 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, + 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, + 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, + 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, + 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, + 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, + 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, + 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, + 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, + 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, + 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, + 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, + 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, + 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, + 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, + 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, + 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, + 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, + 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, + 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, + 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, + 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, + 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, + 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, + 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, + 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, + 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, + 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, + 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, + 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, + 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, + 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, + 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, + 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, + 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, + 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, + 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, + 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, + 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, + 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, + 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, + 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, + 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, + 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, + 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, + 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, + 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, + 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, + 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, + 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 75, 117, 114, 116, 86, 111, + 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, + 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, + 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, + 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, + 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, + 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, + 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, + 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, + 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, + 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, + 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, + 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, + 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, + 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, + 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, + 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, + 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, + 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, + 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, + 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, + 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, + 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 75, 117, + 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, 111, 109, 109, + 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, 101, 115, 115, + 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, 100, 103, 101, + 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, 99, 108, 97, + 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, 115, 99, 114, + 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, 102, 101, + 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, 112, 102, + 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, 110, 115, + 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, + 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, + 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, + 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, + 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, + 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, + 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, + 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, + 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, + 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, + 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, + 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, + 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, + 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, + 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, + 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, + 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, + 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, + 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, + 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, + 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, + 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, + 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, + 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, + 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, + 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, + 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, + 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, 116, 115, 67, + 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, 100, 100, 114, + 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, 115, 97, 110, + 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, 116, 104, 101, + 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, 100, 111, 102, + 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, 101, 116, 105, + 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, 101, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 75, 117, 114, 116, 86, 111, 110, 110, 101, 103, 117, + 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, 116, 65, + 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, 105, 101, + 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, 111, 102, + 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, 97, 114, + 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, 117, 108, + 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, 111, 110, + 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, 117, 114, + 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, + 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, + 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, + 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, + 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, + 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, + 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, + 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, + 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, + 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, + 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, + 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, + 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, + 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, + 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, + 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, + 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, + 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, + 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, + 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, + 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, + 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, + 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, + 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, + 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, + 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, + 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, + 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, + 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, + 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, + 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, 101, + 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, 110, + 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, 100, + 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, 110, + 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, 101, + 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, 111, + 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, 121, + 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, 116, + 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, + 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, + 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, + 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, + 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, + 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, + 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, + 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, + 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, + 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, + 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, + 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, + 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, + 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, + 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, + 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, + 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, + 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, + 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, + 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, + 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, + 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, + 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, + 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, + 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, + 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, + 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, + 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, + 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, + 110, 111, 119, 116, 104, 97, 116, 75, 117, 114, 116, 86, 111, 110, 110, + 101, 103, 117, 116, 115, 67, 111, 109, 109, 101, 110, 99, 101, 109, 101, + 110, 116, 65, 100, 100, 114, 101, 115, 115, 97, 116, 77, 73, 84, 76, 97, + 100, 105, 101, 115, 97, 110, 100, 103, 101, 110, 116, 108, 101, 109, 101, + 110, 111, 102, 116, 104, 101, 99, 108, 97, 115, 115, 111, 102, 57, 55, 87, + 101, 97, 114, 115, 117, 110, 115, 99, 114, 101, 101, 110, 73, 102, 73, 99, + 111, 117, 108, 100, 111, 102, 102, 101, 114, 121, 111, 117, 111, 110, 108, + 121, 111, 110, 101, 116, 105, 112, 102, 111, 114, 116, 104, 101, 102, 117, + 116, 117, 114, 101, 115, 117, 110, 115, 99, 114, 101, 101, 110, 119, 111, + 117, 108, 100, 98, 101, 105, 116, 84, 104, 101, 108, 111, 110, 103, 116, + 101, 114, 109, 98, 101, 110, 101, 102, 105, 116, 115, 111, 102, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 104, 97, 118, 101, 98, 101, 101, 110, + 112, 114, 111, 118, 101, 100, 98, 121, 115, 99, 105, 101, 110, 116, 105, + 115, 116, 115, 119, 104, 101, 114, 101, 97, 115, 116, 104, 101, 114, 101, + 115, 116, 111, 102, 109, 121, 97, 100, 118, 105, 99, 101, 104, 97, 115, + 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, 101, 114, 101, 108, 105, + 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, 111, 119, 110, 109, 101, 97, + 110, 100, 101, 114, 105, 110, 103, 101, 120, 112, 101, 114, 105, 101, 110, + 99, 101, 73, 119, 105, 108, 108, 100, 105, 115, 112, 101, 110, 115, 101, + 116, 104, 105, 115, 97, 100, 118, 105, 99, 101, 110, 111, 119, 69, 110, + 106, 111, 121, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, + 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, + 104, 79, 104, 110, 101, 118, 101, 114, 109, 105, 110, 100, 89, 111, 117, + 119, 105, 108, 108, 110, 111, 116, 117, 110, 100, 101, 114, 115, 116, 97, + 110, 100, 116, 104, 101, 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, + 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, + 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, 102, 97, 100, 101, + 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, 105, 110, 50, 48, + 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, 111, 111, 107, 98, + 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, 102, 121, 111, + 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, 97, 108, 108, + 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, 103, 114, 97, + 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, 112, 111, 115, + 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, 101, 102, 111, + 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, 97, 98, 117, + 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, 121, 108, 111, + 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, 116, 97, 115, + 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, 110, 101, 68, + 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, 116, 116, 104, + 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, 114, 121, 98, + 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 115, 117, 110, 115, 99, + 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, 116, 84, 104, + 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, 101, 102, 105, + 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, 110, 104, 97, + 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, 98, 121, 115, + 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, 114, 101, 97, + 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, 97, 100, 118, + 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, 109, 111, 114, + 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, 110, 109, 121, + 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, 103, 101, 120, + 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, 108, 100, 105, + 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, 118, 105, 99, + 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, 112, 111, 119, + 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, 101, 114, 109, + 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, 116, 117, 110, + 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, 111, 119, 101, + 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, + 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, + 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, + 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, + 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, + 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, + 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, + 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, + 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, + 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, + 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, + 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, + 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, + 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, + 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, + 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, + 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, 117, 114, 121, + 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, 121, 118, 101, + 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, 116, 109, 101, + 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, 108, 108, 108, + 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, 111, 116, 111, 115, 111, + 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, 110, 100, 114, 101, 99, + 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, 117, 99, 97, 110, 116, + 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, 119, 109, 117, 99, 104, + 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, 121, 108, 97, 121, 98, + 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, 100, 104, 111, 119, 102, + 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, 114, 101, 97, 108, 108, + 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, 97, 114, 101, 110, 111, + 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, 105, 109, 97, 103, 105, + 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, 121, 97, 98, 111, 117, + 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, 79, 114, 119, 111, 114, + 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, 104, 97, 116, 115, 117, + 110, 115, 99, 114, 101, 101, 110, 119, 111, 117, 108, 100, 98, 101, 105, + 116, 84, 104, 101, 108, 111, 110, 103, 116, 101, 114, 109, 98, 101, 110, + 101, 102, 105, 116, 115, 111, 102, 115, 117, 110, 115, 99, 114, 101, 101, + 110, 104, 97, 118, 101, 98, 101, 101, 110, 112, 114, 111, 118, 101, 100, + 98, 121, 115, 99, 105, 101, 110, 116, 105, 115, 116, 115, 119, 104, 101, + 114, 101, 97, 115, 116, 104, 101, 114, 101, 115, 116, 111, 102, 109, 121, + 97, 100, 118, 105, 99, 101, 104, 97, 115, 110, 111, 98, 97, 115, 105, 115, + 109, 111, 114, 101, 114, 101, 108, 105, 97, 98, 108, 101, 116, 104, 97, + 110, 109, 121, 111, 119, 110, 109, 101, 97, 110, 100, 101, 114, 105, 110, + 103, 101, 120, 112, 101, 114, 105, 101, 110, 99, 101, 73, 119, 105, 108, + 108, 100, 105, 115, 112, 101, 110, 115, 101, 116, 104, 105, 115, 97, 100, + 118, 105, 99, 101, 110, 111, 119, 69, 110, 106, 111, 121, 116, 104, 101, + 112, 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, + 102, 121, 111, 117, 114, 121, 111, 117, 116, 104, 79, 104, 110, 101, 118, + 101, 114, 109, 105, 110, 100, 89, 111, 117, 119, 105, 108, 108, 110, 111, + 116, 117, 110, 100, 101, 114, 115, 116, 97, 110, 100, 116, 104, 101, 112, + 111, 119, 101, 114, 97, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, + 121, 111, 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, + 104, 101, 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, + 117, 115, 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, + 111, 117, 108, 108, 108, 111, 111, 107, 98, 97, 99, 107, 97, 116, 112, 104, + 111, 116, 111, 115, 111, 102, 121, 111, 117, 114, 115, 101, 108, 102, 97, + 110, 100, 114, 101, 99, 97, 108, 108, 105, 110, 97, 119, 97, 121, 121, 111, + 117, 99, 97, 110, 116, 103, 114, 97, 115, 112, 110, 111, 119, 104, 111, + 119, 109, 117, 99, 104, 112, 111, 115, 115, 105, 98, 105, 108, 105, 116, + 121, 108, 97, 121, 98, 101, 102, 111, 114, 101, 121, 111, 117, 97, 110, + 100, 104, 111, 119, 102, 97, 98, 117, 108, 111, 117, 115, 121, 111, 117, + 114, 101, 97, 108, 108, 121, 108, 111, 111, 107, 101, 100, 89, 111, 117, + 97, 114, 101, 110, 111, 116, 97, 115, 102, 97, 116, 97, 115, 121, 111, 117, + 105, 109, 97, 103, 105, 110, 101, 68, 111, 110, 116, 119, 111, 114, 114, + 121, 97, 98, 111, 117, 116, 116, 104, 101, 102, 117, 116, 117, 114, 101, + 79, 114, 119, 111, 114, 114, 121, 98, 117, 116, 107, 110, 111, 119, 116, + 104, 97, 116, 110, 100, 98, 101, 97, 117, 116, 121, 111, 102, 121, 111, + 117, 114, 121, 111, 117, 116, 104, 117, 110, 116, 105, 108, 116, 104, 101, + 121, 118, 101, 102, 97, 100, 101, 100, 66, 117, 116, 116, 114, 117, 115, + 116, 109, 101, 105, 110, 50, 48, 121, 101, 97, 114, 115, 121, 111, 117, + 108, 108, 108, 111, 111} +}; +const int in_i[VSIZE] = { 8192, 8192 }; + + sha_init(sha_info_digest, &sha_info_count_lo, &sha_info_count_hi); + for (j = 0; j < VSIZE; j++) + { + i = in_i[j]; + p = &indata[j][0]; + sha_update (p, i, sha_info_digest, &sha_info_count_lo, &sha_info_count_hi, sha_info_data); + } + sha_final (sha_info_digest, &sha_info_count_lo, &sha_info_count_hi, sha_info_data); +} /* +--------------------------------------------------------------------------+ | * Test Vector (added for CHStone) | | outData : expected output data | +--------------------------------------------------------------------------+ */ -const INT32 outData[5] = - { 0x006a5a37UL, 0x93dc9485UL, 0x2c412112UL, 0x63f7ba43UL, 0xad73f922UL }; - int main () { + const INT32 outData[5] = + { 0x006a5a37UL, 0x93dc9485UL, 0x2c412112UL, 0x63f7ba43UL, 0xad73f922UL }; + INT32 sha_info_digest[5]; /* message digest */ + int i; int main_result; main_result = 0; - sha_stream (); + sha_stream (sha_info_digest); for (i = 0; i < 5; i++) { -- cgit From 270bbc0c280ec162bbb975543b66e57d368a3d60 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 27 Jun 2020 23:01:40 +0100 Subject: mods --- benchmarks/CHStone/adpcm/adpcm.c | 104 +++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 31 deletions(-) diff --git a/benchmarks/CHStone/adpcm/adpcm.c b/benchmarks/CHStone/adpcm/adpcm.c index bb44500..bcdc6dd 100755 --- a/benchmarks/CHStone/adpcm/adpcm.c +++ b/benchmarks/CHStone/adpcm/adpcm.c @@ -103,9 +103,9 @@ abs (int n) filtez (int *bpl, int *dlt) { int i; - int zl; - zl = (int) (*bpl++) * (*dlt++); - for (i = 1; i < 6; i++) + int zl = 0; + //zl = (int) (*bpl++) * (*dlt++); + for (i = 1; i < 7; i++) zl += (int) (*bpl++) * (*dlt++); return ((int) (zl >> 14)); /* x2 here */ @@ -118,9 +118,9 @@ filtez (int *bpl, int *dlt) filtep (int rlt1, int al1, int rlt2, int al2) { int pl, pl2; - pl = 2 * rlt1; + pl = rlt1 << 1 ; pl = (int) al1 *pl; - pl2 = 2 * rlt2; + pl2 = rlt2 << 1 ; pl += (int) al2 *pl2; return ((int) (pl >> 15)); } @@ -188,7 +188,10 @@ logscl (int il, int nbl) }; int wd; - wd = ((int) nbl * 127L) >> 7L; /* leak factor 127/128 */ + int tmp = nbl; + int val = tmp << 7; + val -= tmp; + wd = (val) >> 7L; /* leak factor 127/128 */ nbl = (int) wd + wl_code_table[il >> 2]; if (nbl < 0) nbl = 0; @@ -228,7 +231,10 @@ upzero (int dlt, int *dlti, int *bli) { for (i = 0; i < 6; i++) { - bli[i] = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ + int tmp = bli[i]; + int val = tmp << 8; + val -= tmp; + bli[i] = (int) (val) >> 8L; /* leak factor of 255/256 */ } } else @@ -239,7 +245,10 @@ upzero (int dlt, int *dlti, int *bli) wd2 = 128; else wd2 = -128; - wd3 = (int) ((255L * bli[i]) >> 8L); /* leak factor of 255/256 */ + int tmp = bli[i]; + int val = tmp << 8; + val -= tmp; + wd3 = (int) (val) >> 8L; /* leak factor of 255/256 */ bli[i] = wd2 + wd3; } } @@ -260,7 +269,7 @@ uppol2 (int al1, int al2, int plt, int plt1, int plt2) { int wd2, wd4; int apl2; - wd2 = 4L * (int) al1; + wd2 = (int) al1 << 2; if ((int) plt * plt1 >= 0L) wd2 = -wd2; /* check same sign */ wd2 = wd2 >> 7; /* gain of 1/128 */ @@ -272,7 +281,10 @@ uppol2 (int al1, int al2, int plt, int plt1, int plt2) { wd4 = wd2 - 128; } - apl2 = wd4 + (127L * (int) al2 >> 7L); /* leak factor of 127/128 */ + int tmp = al2; + int val = tmp << 7; + val -= tmp; + apl2 = wd4 + (val >> 7L); /* leak factor of 127/128 */ /* apl2 is limited to +-.75 */ if (apl2 > 12288) @@ -290,7 +302,10 @@ uppol1 (int al1, int apl2, int plt, int plt1) { int wd2; int wd3, apl1; - wd2 = ((int) al1 * 255L) >> 8L; /* leak factor of 255/256 */ + int tmp = al1; + int val = tmp << 8; + val -= tmp; + wd2 = (val) >> 8L; /* leak factor of 255/256 */ if ((int) plt * plt1 >= 0L) { apl1 = (int) wd2 + 192; /* same sign case */ @@ -319,7 +334,10 @@ logsch (int ih, int nbh) 798, -214, 798, -214 }; - wd = ((int) nbh * 127L) >> 7L; /* leak factor 127/128 */ + int tmp = nbh; + int val = tmp << 7; + val -= tmp; + wd = (val) >> 7L; /* leak factor 127/128 */ nbh = wd + wh_code_table[ih]; if (nbh < 0) nbh = 0; @@ -485,23 +503,32 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) int xin2 = test_data[i + 1]; const int *h_ptr; int *tqmf_ptr, *tqmf_ptr1; - int xa, xb; + int xa = 0, xb = 0; int decis; /* transmit quadrature mirror filters implemented here */ h_ptr = h; tqmf_ptr = tqmf; - xa = (int) (*tqmf_ptr++) * (*h_ptr++); - xb = (int) (*tqmf_ptr++) * (*h_ptr++); /* main multiply accumulate loop for samples and coefficients */ - for (int j = 0; j < 10; j++) + for (int j = 0; j < 12; j++) { - xa += (int) (*tqmf_ptr++) * (*h_ptr++); - xb += (int) (*tqmf_ptr++) * (*h_ptr++); + int opA1, opB1; + int opA2, opB2; + if(j==11){ + opA1 = (*tqmf_ptr++); + opB1 = (*h_ptr++); + opA2 = (*tqmf_ptr); + opB2 = (*h_ptr++); + } + else{ + opA1 = (*tqmf_ptr++); + opB1 = (*h_ptr++); + opA2 = (*tqmf_ptr++); + opB2 = (*h_ptr++); + } + xa += (int) opA1 * opB1; + xb += (int) opA2 * opB2; } - /* final mult/accumulate */ - xa += (int) (*tqmf_ptr++) * (*h_ptr++); - xb += (int) (*tqmf_ptr) * (*h_ptr++); /* update delay line tqmf */ tqmf_ptr1 = tqmf_ptr - 2; @@ -511,8 +538,8 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) *tqmf_ptr = xin2; /* scale outputs */ - xl = (xa + xb) >> 15; - xh = (xa - xb) >> 15; + int xl = (xa + xb) >> 15; + int xh = (xa - xb) >> 15; /* end of quadrature mirror filter code */ @@ -738,17 +765,32 @@ adpcm_main (const int test_data[SIZE], int compressed[SIZE], int result[SIZE]) h_ptr = h; ac_ptr = accumc; ad_ptr = accumd; - xa1 = (int) xd *(*h_ptr++); - xa2 = (int) xs *(*h_ptr++); /* main multiply accumulate loop for samples and coefficients */ - for (int j = 0; j < 10; j++) + for (int j = 0; j < 12; j++) { - xa1 += (int) (*ac_ptr++) * (*h_ptr++); - xa2 += (int) (*ad_ptr++) * (*h_ptr++); + int opA1, opB1; + int opA2, opB2; + if(i==0){ + opA1 = xd; + opB1 = (*h_ptr++); + opA2 = xs; + opB2 = (*h_ptr++); + } + else if(i==11){ + opA1 = (*ac_ptr++); + opB1 = (*h_ptr++); + opA2 = (*ad_ptr++); + opB2 = (*h_ptr++); + } + else{ + opA1 = (*ac_ptr); + opB1 = (*h_ptr++); + opA2 = (*ad_ptr); + opB2 = (*h_ptr++); + } + xa1 += (int) opA1 * opB1; + xa2 += (int) opA2 * opB2; } - /* final mult/accumulate */ - xa1 += (int) (*ac_ptr) * (*h_ptr++); - xa2 += (int) (*ad_ptr) * (*h_ptr++); /* scale by 2^14 */ xout1 = xa1 >> 14; -- cgit From 4c475a386caeaee3e3ef7682840c738cecdee941 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 27 Jun 2020 23:05:18 +0100 Subject: gsm2 --- benchmarks/CHStone/gsm2/gsm.c | 558 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 558 insertions(+) create mode 100755 benchmarks/CHStone/gsm2/gsm.c diff --git a/benchmarks/CHStone/gsm2/gsm.c b/benchmarks/CHStone/gsm2/gsm.c new file mode 100755 index 0000000..4e1c2d1 --- /dev/null +++ b/benchmarks/CHStone/gsm2/gsm.c @@ -0,0 +1,558 @@ +/* ++--------------------------------------------------------------------------+ +| CHStone : a suite of benchmark programs for C-based High-Level Synthesis | +| ======================================================================== | +| | +| * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, | +| H. Takada and K. Ishii | +| Nagoya University, Japan | +| | +| * Remark : | +| 1. This source code is modified to unify the formats of the benchmark | +| programs in CHStone. | +| 2. Test vectors are added for CHStone. | +| 3. If "main_result" is 0 at the end of the program, the program is | +| correctly executed. | +| 4. Please follow the copyright of each benchmark program. | ++--------------------------------------------------------------------------+ +*/ +//#include +typedef int word; /* 16 bit signed int */ +typedef long longword; /* 32 bit signed int */ + +#define MIN_WORD ((-32767)-1) +#define MAX_WORD ( 32767) + +#define SASR(x, by) ((x) >> (by)) + +#define GSM_MULT_R(a, b) gsm_mult_r(a, b) +#define GSM_MULT(a, b) gsm_mult(a, b) +#define GSM_ADD(a, b) gsm_add(a, b) +#define GSM_ABS(a) gsm_abs(a) + +#define saturate(x) \ + ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x)) + +word +gsm_add (word a, word b) +{ + longword sum; + sum = (longword) a + (longword) b; + return saturate (sum); +} + +word +gsm_mult (word a, word b) +{ + if (a == MIN_WORD && b == MIN_WORD) + return MAX_WORD; + else + return SASR ((longword) a * (longword) b, 15); +} + +word +gsm_mult_r (word a, word b) +{ + longword prod; + if (b == MIN_WORD && a == MIN_WORD) + return MAX_WORD; + else + { + prod = (longword) a *(longword) b + 16384; + prod >>= 15; + return prod & 0xFFFF; + } +} + +word +gsm_abs (word a) +{ + return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a; +} + +word +gsm_norm (longword a) +/* + * the number of left shifts needed to normalize the 32 bit + * variable L_var1 for positive values on the interval + * + * with minimum of + * minimum of 1073741824 (01000000000000000000000000000000) and + * maximum of 2147483647 (01111111111111111111111111111111) + * + * + * and for negative values on the interval with + * minimum of -2147483648 (-10000000000000000000000000000000) and + * maximum of -1073741824 ( -1000000000000000000000000000000). + * + * in order to normalize the result, the following + * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 ); + * + * (That's 'ffs', only from the left, not the right..) + */ +{ + const unsigned int bitoff[256] = { + 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + + if (a < 0) + { + if (a <= -1073741824) + return 0; + a = ~a; + } + + return a & 0xffff0000 ? + (a & 0xff000000 ? -1 + bitoff[0xFF & (a >> 24)] : + 7 + bitoff[0xFF & (a >> 16)]) + : (a & 0xff00 ? 15 + bitoff[0xFF & (a >> 8)] : 23 + bitoff[0xFF & a]); +} + +word +gsm_div (word num, word denum) +{ + longword L_num; + longword L_denum; + word div; + int k; + + L_num = num; + L_denum = denum; + div = 0; + k = 15; + /* The parameter num sometimes becomes zero. + * Although this is explicitly guarded against in 4.2.5, + * we assume that the result should then be zero as well. + */ + + if (num == 0) + return 0; + + while (k--) + { + div <<= 1; + L_num <<= 1; + + if (L_num >= L_denum) + { + L_num -= L_denum; + div++; + } + } + + return div; +} + +void +Autocorrelation (word * s /* [0..159] IN/OUT */ , + longword * L_ACF /* [0..8] OUT */ ) +/* + * The goal is to compute the array L_ACF[k]. The signal s[i] must + * be scaled in order to avoid an overflow situation. + */ +{ + register int k, i; + + word temp; + word smax; + word scalauto, n; + word *sp; + word sl; + + /* Search for the maximum. + */ + smax = 0; + for (k = 0; k <= 159; k++) + { + temp = GSM_ABS (s[k]); + if (temp > smax) + smax = temp; + } + + /* Computation of the scaling factor. + */ + if (smax == 0) + scalauto = 0; + else + scalauto = 4 - gsm_norm ((longword) smax << 16); /* sub(4,..) */ + + if (scalauto > 0 && scalauto <= 4) + { + n = scalauto; + for (k = 0; k <= 159; k++) + s[k] = GSM_MULT_R (s[k], 16384 >> (n - 1)); + } + + /* Compute the L_ACF[..]. + */ + { + sp = s; + sl = *sp; + +#define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]); + +#define NEXTI sl = *++sp + for (k = 8; k >= 0; k--) + L_ACF[k] = 0; + +int mask[36] = { +0, +0,1, +0,1,2, +0,1,2,3, +0,1,2,3,4, +0,1,2,3,4,5, +0,1,2,3,4,5,6, +0,1,2,3,4,5,6,7 +}; +int i; +int j; +for(i=1; i < 8; i++){ + for(j=0;j= 0; k--) + L_ACF[k] <<= 1; + + } + /* Rescaling of the array s[0..159] + */ + if (scalauto > 0) + for (k = 159; k >= 0; k--) + *s++ <<= scalauto; +} + +/* 4.2.5 */ + +void +Reflection_coefficients (longword * L_ACF /* 0...8 IN */ , + register word * r /* 0...7 OUT */ ) +{ + register int i, m, n; + register word temp; + word ACF[9]; /* 0..8 */ + word P[9]; /* 0..8 */ + word K[9]; /* 2..8 */ + + /* Schur recursion with 16 bits arithmetic. + */ + + if (L_ACF[0] == 0) + { + for (i = 8; i > 0; i--) + *r++ = 0; + return; + } + + temp = gsm_norm (L_ACF[0]); + for (i = 0; i <= 8; i++) + ACF[i] = SASR (L_ACF[i] << temp, 16); + + /* Initialize array P[..] and K[..] for the recursion. + */ + + for (i = 1; i <= 7; i++) + K[i] = ACF[i]; + for (i = 0; i <= 8; i++) + P[i] = ACF[i]; + + /* Compute reflection coefficients + */ + for (n = 1; n <= 8; n++, r++) + { + + temp = P[1]; + temp = GSM_ABS (temp); + if (P[0] < temp) + { + for (i = n; i <= 8; i++) + *r++ = 0; + return; + } + + *r = gsm_div (temp, P[0]); + + if (P[1] > 0) + *r = -*r; /* r[n] = sub(0, r[n]) */ + if (n == 8) + return; + + /* Schur recursion + */ + temp = GSM_MULT_R (P[1], *r); + P[0] = GSM_ADD (P[0], temp); + + for (m = 1; m <= 8 - n; m++) + { + temp = GSM_MULT_R (K[m], *r); + P[m] = GSM_ADD (P[m + 1], temp); + + temp = GSM_MULT_R (P[m + 1], *r); + K[m] = GSM_ADD (K[m], temp); + } + } +} + +/* 4.2.6 */ + +void +Transformation_to_Log_Area_Ratios (register word * r /* 0..7 IN/OUT */ ) +/* + * The following scaling for r[..] and LAR[..] has been used: + * + * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1. + * LAR[..] = integer( real_LAR[..] * 16384 ); + * with -1.625 <= real_LAR <= 1.625 + */ +{ + register word temp; + register int i; + + + /* Computation of the LAR[0..7] from the r[0..7] + */ + for (i = 1; i <= 8; i++, r++) + { + + temp = *r; + temp = GSM_ABS (temp); + + if (temp < 22118) + { + temp >>= 1; + } + else if (temp < 31130) + { + temp -= 11059; + } + else + { + temp -= 26112; + temp <<= 2; + } + + *r = *r < 0 ? -temp : temp; + } +} + +/* 4.2.7 */ + +void +Quantization_and_coding (register word * LAR /* [0..7] IN/OUT */ ) +{ + register word temp; + + + /* This procedure needs four tables; the following equations + * give the optimum scaling for the constants: + * + * A[0..7] = integer( real_A[0..7] * 1024 ) + * B[0..7] = integer( real_B[0..7] * 512 ) + * MAC[0..7] = maximum of the LARc[0..7] + * MIC[0..7] = minimum of the LARc[0..7] + */ + +# undef STEP +# define STEP( A, B, MAC, MIC ) \ + temp = GSM_MULT( A, *LAR ); \ + temp = GSM_ADD( temp, B ); \ + temp = GSM_ADD( temp, 256 ); \ + temp = SASR( temp, 9 ); \ + *LAR = temp>MAC ? MAC - MIC : (temp Date: Mon, 29 Jun 2020 10:14:44 +0100 Subject: Remove checks for translate_eff_addressing --- src/translation/HTLgen.v | 20 +++++--------------- src/translation/HTLgenproof.v | 4 ++-- src/translation/Veriloggenproof.v | 2 ++ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index a75ef5c..35b815e 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -292,26 +292,16 @@ Definition check_address_parameter_unsigned (p : Z) : bool := Definition translate_eff_addressing (a: Op.addressing) (args: list reg) : mon expr := match a, args with (* TODO: We should be more methodical here; what are the possibilities?*) | Op.Aindexed off, r1::nil => - if (check_address_parameter_signed off) - then ret (boplitz Vadd r1 off) - else error (Errors.msg "Veriloggen: translate_eff_addressing address misaligned") + ret (boplitz Vadd r1 off) | Op.Ascaled scale offset, r1::nil => - if (check_address_parameter_signed scale) && (check_address_parameter_signed offset) - then ret (Vbinop Vadd (boplitz Vmul r1 scale) (Vlit (ZToValue 32 offset))) - else error (Errors.msg "Veriloggen: translate_eff_addressing address misaligned") + ret (Vbinop Vadd (boplitz Vmul r1 scale) (Vlit (ZToValue 32 offset))) | Op.Aindexed2 offset, r1::r2::nil => - if (check_address_parameter_signed offset) - then ret (Vbinop Vadd (Vvar r1) (boplitz Vadd r2 offset)) - else error (Errors.msg "Veriloggen: translate_eff_addressing address misaligned") + ret (Vbinop Vadd (Vvar r1) (boplitz Vadd r2 offset)) | Op.Aindexed2scaled scale offset, r1::r2::nil => (* Typical for dynamic array addressing *) - if (check_address_parameter_signed scale) && (check_address_parameter_signed offset) - then ret (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) - else error (Errors.msg "Veriloggen: translate_eff_addressing address misaligned") + ret (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) | Op.Ainstack a, nil => (* We need to be sure that the base address is aligned *) let a := Integers.Ptrofs.unsigned a in - if (check_address_parameter_unsigned a) - then ret (Vlit (ZToValue 32 a)) - else error (Errors.msg "Veriloggen: translate_eff_addressing address misaligned") + ret (Vlit (ZToValue 32 a)) | _, _ => error (Errors.msg "Veriloggen: translate_eff_addressing unsuported addressing") end. diff --git a/src/translation/HTLgenproof.v b/src/translation/HTLgenproof.v index 2f296f2..3665775 100644 --- a/src/translation/HTLgenproof.v +++ b/src/translation/HTLgenproof.v @@ -420,7 +420,7 @@ Section CORRECTNESS. match_states S1 R1 -> exists R2, Smallstep.plus HTL.step tge R1 t R2 /\ match_states S2 R2. Proof. - induction 1; intros R1 MSTATE; try inv_state. +(* induction 1; intros R1 MSTATE; try inv_state. - (* Inop *) unfold match_prog in TRANSL. econstructor. @@ -2112,7 +2112,7 @@ Section CORRECTNESS. (* exact (AssocMap.empty value). *) (* exact (AssocMap.empty value). *) (* exact (AssocMap.empty value). *) - (* exact (AssocMap.empty value). *) + (* exact (AssocMap.empty value). *)*) Admitted. Hint Resolve transl_step_correct : htlproof. diff --git a/src/translation/Veriloggenproof.v b/src/translation/Veriloggenproof.v index db96949..518fe3a 100644 --- a/src/translation/Veriloggenproof.v +++ b/src/translation/Veriloggenproof.v @@ -72,9 +72,11 @@ Section CORRECTNESS. induction 1; intros R1 MSTATE; inv MSTATE; econstructor; split. - apply Smallstep.plus_one. econstructor. eassumption. trivial. * econstructor. econstructor. + Admitted. Theorem transf_program_correct: forward_simulation (HTL.semantics prog) (Verilog.semantics tprog). + Admitted. End CORRECTNESS. -- cgit From 0094d52ef6866680c7d635737266bee0577d8dab Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 11:03:32 +0100 Subject: polybench linear algebra tests --- .../polybench-syn/linear-algebra/blas/gemm.c | 111 ++++++++++++++ .../polybench-syn/linear-algebra/blas/gemver.c | 152 +++++++++++++++++++ .../polybench-syn/linear-algebra/blas/gesummv.c | 115 +++++++++++++++ .../polybench-syn/linear-algebra/blas/symm.c | 109 ++++++++++++++ .../polybench-syn/linear-algebra/blas/syr2k.c | 120 +++++++++++++++ .../polybench-syn/linear-algebra/blas/syrk.c | 106 +++++++++++++ .../polybench-syn/linear-algebra/blas/trmm.c | 96 ++++++++++++ .../linear-algebra/blas/trmm.preproc.c | 144 ++++++++++++++++++ .../polybench-syn/linear-algebra/kernels/2mm.c | 128 ++++++++++++++++ .../polybench-syn/linear-algebra/kernels/3mm.c | 141 ++++++++++++++++++ .../polybench-syn/linear-algebra/kernels/atas.c | 100 +++++++++++++ .../polybench-syn/linear-algebra/kernels/bicg.c | 115 +++++++++++++++ .../polybench-syn/linear-algebra/kernels/doitgen.c | 100 +++++++++++++ .../polybench-syn/linear-algebra/kernels/mvt.c | 117 +++++++++++++++ .../linear-algebra/solvers/cholesky.c | 125 ++++++++++++++++ .../polybench-syn/linear-algebra/solvers/durbin.c | 102 +++++++++++++ .../polybench-syn/linear-algebra/solvers/lu.c | 148 +++++++++++++++++++ .../polybench-syn/linear-algebra/solvers/ludcmp.c | 164 +++++++++++++++++++++ .../polybench-syn/linear-algebra/solvers/trisolv.c | 89 +++++++++++ 19 files changed, 2282 insertions(+) create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/gemm.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/gemver.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/gesummv.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/symm.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/syr2k.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/syrk.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/trmm.c create mode 100644 benchmarks/polybench-syn/linear-algebra/blas/trmm.preproc.c create mode 100644 benchmarks/polybench-syn/linear-algebra/kernels/2mm.c create mode 100644 benchmarks/polybench-syn/linear-algebra/kernels/3mm.c create mode 100644 benchmarks/polybench-syn/linear-algebra/kernels/atas.c create mode 100644 benchmarks/polybench-syn/linear-algebra/kernels/bicg.c create mode 100644 benchmarks/polybench-syn/linear-algebra/kernels/doitgen.c create mode 100644 benchmarks/polybench-syn/linear-algebra/kernels/mvt.c create mode 100644 benchmarks/polybench-syn/linear-algebra/solvers/cholesky.c create mode 100644 benchmarks/polybench-syn/linear-algebra/solvers/durbin.c create mode 100644 benchmarks/polybench-syn/linear-algebra/solvers/lu.c create mode 100644 benchmarks/polybench-syn/linear-algebra/solvers/ludcmp.c create mode 100644 benchmarks/polybench-syn/linear-algebra/solvers/trisolv.c diff --git a/benchmarks/polybench-syn/linear-algebra/blas/gemm.c b/benchmarks/polybench-syn/linear-algebra/blas/gemm.c new file mode 100644 index 0000000..5a28f08 --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/gemm.c @@ -0,0 +1,111 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* gemm.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array(int ni, int nj, int nk, + int *alpha, + int *beta, + int C[ 20 + 0][25 + 0], + int A[ 20 + 0][30 + 0], + int B[ 30 + 0][25 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 2; + *beta = 2; + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nj; plus(j)) + C[i][j] = (int) ((i*j+ONE) % ni) / ni; + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nk; plus(j)) + A[i][j] = (int) (i*(j+ONE) % nk) / nk; + for (i = 0; i < nk; plus(i)) + for (j = 0; j < nj; plus(j)) + B[i][j] = (int) (i*(j+ONE+ONE) % nj) / nj; +} + + + + +static +int print_array(int ni, int nj, + int C[ 20 + 0][25 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nj; plus(j)) { + res ^= C[i][j]; + } + return res; +} + +static +void kernel_gemm(int ni, int nj, int nk, + int alpha, + int beta, + int C[ 20 + 0][25 + 0], + int A[ 20 + 0][30 + 0], + int B[ 30 + 0][25 + 0]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (i = 0; i < ni; plus(i)) { + for (j = 0; j < nj; plus(j)) + C[i][j] *= beta; + for (k = 0; k < nk; plus(k)) { + for (j = 0; j < nj; plus(j)) + C[i][j] += alpha * A[i][k] * B[k][j]; + } + } +#pragma endscop + +} + + +int main() +{ + + int ni = 20; + int nj = 25; + int nk = 30; + + + int alpha; + int beta; + int C[20 + 0][25 + 0]; + int A[20 + 0][30 + 0]; + int B[30 + 0][25 + 0]; + + + init_array (ni, nj, nk, &alpha, &beta, + C, + A, + B); + + + kernel_gemm (ni, nj, nk, + alpha, beta, + C, + A, + B); + + + return + print_array(ni, nj, C); + + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/gemver.c b/benchmarks/polybench-syn/linear-algebra/blas/gemver.c new file mode 100644 index 0000000..a2711cb --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/gemver.c @@ -0,0 +1,152 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* gemver.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array (int n, + int *alpha, + int *beta, + int A[ 40 + 0][40 + 0], + int u1[ 40 + 0], + int v1[ 40 + 0], + int u2[ 40 + 0], + int v2[ 40 + 0], + int w[ 40 + 0], + int x[ 40 + 0], + int y[ 40 + 0], + int z[ 40 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 3; + *beta = 2; + + int fn = (int)n; + + for (i = 0; i < n; plus(i)) + { + u1[i] = i; + u2[i] = ((i+ONE)/fn)/2; + v1[i] = ((i+ONE)/fn)/4; + v2[i] = ((i+ONE)/fn)/6; + y[i] = ((i+ONE)/fn)/8; + z[i] = ((i+ONE)/fn)/9; + x[i] = 0; + w[i] = 0; + for (j = 0; j < n; plus(j)) + A[i][j] = (int) (i*j % n) / n; + } +} + + + + +static +int print_array(int n, + int w[ 40 + 0]) +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) { + res ^= w[i]; + } + return res; +} + + + + +static +void kernel_gemver(int n, + int alpha, + int beta, + int A[ 40 + 0][40 + 0], + int u1[ 40 + 0], + int v1[ 40 + 0], + int u2[ 40 + 0], + int v2[ 40 + 0], + int w[ 40 + 0], + int x[ 40 + 0], + int y[ 40 + 0], + int z[ 40 + 0]) +{ + int i, j; + int ONE = 1; + +#pragma scop + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + A[i][j] = A[i][j] + u1[i] * v1[j] + u2[i] * v2[j]; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + x[i] = x[i] + beta * A[j][i] * y[j]; + + for (i = 0; i < n; plus(i)) + x[i] = x[i] + z[i]; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + w[i] = w[i] + alpha * A[i][j] * x[j]; + +#pragma endscop +} + + +int main() +{ + + int n = 40; + + + int alpha; + int beta; + int A[40 + 0][40 + 0]; + int u1[40 + 0]; + int v1[40 + 0]; + int u2[40 + 0]; + int v2[40 + 0]; + int w[40 + 0]; + int x[40 + 0]; + int y[40 + 0]; + int z[40 + 0]; + + + + init_array (n, &alpha, &beta, + A, + u1, + v1, + u2, + v2, + w, + x, + y, + z); + + kernel_gemver (n, alpha, beta, + A, + u1, + v1, + u2, + v2, + w, + x, + y, + z); + + return print_array(n, w); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/gesummv.c b/benchmarks/polybench-syn/linear-algebra/blas/gesummv.c new file mode 100644 index 0000000..606a581 --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/gesummv.c @@ -0,0 +1,115 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* gesummv.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE + +static +void init_array(int n, + int *alpha, + int *beta, + int A[ 30 + 0][30 + 0], + int B[ 30 + 0][30 + 0], + int x[ 30 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 3; + *beta = 2; + for (i = 0; i < n; plus(i)) + { + x[i] = (int)( i % n) / n; + for (j = 0; j < n; plus(j)) { + A[i][j] = (int) ((i*j+ONE) % n) / n; + B[i][j] = (int) ((i*j+ONE+ONE) % n) / n; + } + } +} + + + + +static +int print_array(int n, + int y[ 30 + 0]) + +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) { + res ^= y[i]; + } + return res; +} + +static +void kernel_gesummv(int n, + int alpha, + int beta, + int A[ 30 + 0][30 + 0], + int B[ 30 + 0][30 + 0], + int tmp[ 30 + 0], + int x[ 30 + 0], + int y[ 30 + 0]) +{ + int i, j; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) + { + tmp[i] = 0; + y[i] = 0; + for (j = 0; j < n; plus(j)) + { + tmp[i] = A[i][j] * x[j] + tmp[i]; + y[i] = B[i][j] * x[j] + y[i]; + } + y[i] = alpha * tmp[i] + beta * y[i]; + } +#pragma endscop + +} + + +int main() +{ + + int n = 30; + + + int alpha; + int beta; + int A[30 + 0][30 + 0]; + int B[30 + 0][30 + 0]; + int tmp[30 + 0]; + int x[30 + 0]; + int y[30 + 0]; + + init_array (n, &alpha, &beta, + A, + B, + x); + + kernel_gesummv (n, alpha, beta, + A, + B, + tmp, + x, + y); + + + return print_array(n, y); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/symm.c b/benchmarks/polybench-syn/linear-algebra/blas/symm.c new file mode 100644 index 0000000..4a0039d --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/symm.c @@ -0,0 +1,109 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* symm.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array(int m, int n, + int *alpha, + int *beta, + int C[ 20 + 0][30 + 0], + int A[ 20 + 0][20 + 0], + int B[ 20 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 3; + *beta = 2; + for (i = 0; i < m; plus(i)) + for (j = 0; j < n; plus(j)) { + C[i][j] = (int) ((i+j) % 100) / m; + B[i][j] = (int) ((n+i-j) % 100) / m; + } + for (i = 0; i < m; plus(i)) { + for (j = 0; j <=i; plus(j)) + A[i][j] = (int) ((i+j) % 100) / m; + for (j = i+ONE; j < m; plus(j)) + A[i][j] = -999; + } +} + +static +int print_array(int m, int n, + int C[ 20 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < m; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= C[i][j]; + } + return res; +} + + +static +void kernel_symm(int m, int n, + int alpha, + int beta, + int C[ 20 + 0][30 + 0], + int A[ 20 + 0][20 + 0], + int B[ 20 + 0][30 + 0]) +{ + int ONE = 1; + int i, j, k; + int temp2; +#pragma scop + for (i = 0; i < m; plus(i)) + for (j = 0; j < n; plus(j) ) + { + temp2 = 0; + for (k = 0; k < i; plus(k)) { + C[k][j] += alpha*B[i][j] * A[i][k]; + temp2 += B[k][j] * A[i][k]; + } + C[i][j] = beta * C[i][j] + alpha*B[i][j] * A[i][i] + alpha * temp2; + } +#pragma endscop + +} + + +int main() +{ + + int m = 20; + int n = 30; + + int alpha; + int beta; + int C[20 + 0][30 + 0]; + int A[20 + 0][20 + 0]; + int B[20 + 0][30 + 0]; + + + init_array (m, n, &alpha, &beta, + C, + A, + B); + + kernel_symm (m, n, + alpha, beta, + C, + A, + B); + + return + print_array(m, n, C); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/syr2k.c b/benchmarks/polybench-syn/linear-algebra/blas/syr2k.c new file mode 100644 index 0000000..82b4d3b --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/syr2k.c @@ -0,0 +1,120 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* syr2k.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array(int n, int m, + int *alpha, + int *beta, + int C[ 30 + 0][30 + 0], + int A[ 30 + 0][20 + 0], + int B[ 30 + 0][20 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 3; + *beta = 2; + for (i = 0; i < n; plus(i)) + for (j = 0; j < m; plus(j)) { + A[i][j] = (int) ((i*j+ONE)%n) / n; + B[i][j] = (int) ((i*j+ONE+ONE)%m) / m; + } + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + C[i][j] = (int) ((i*j+4-ONE)%n) / m; + } +} + + + + +static +int print_array(int n, + int C[ 30 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= C[i][j]; + } + return res; +} + + +static +void kernel_syr2k(int n, int m, + int alpha, + int beta, + int C[ 30 + 0][30 + 0], + int A[ 30 + 0][20 + 0], + int B[ 30 + 0][20 + 0]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) { + for (j = 0; j <= i; plus(j)) + C[i][j] *= beta; + for (k = 0; k < m; plus(k)) + for (j = 0; j <= i; plus(j)) + { + C[i][j] += A[j][k]*alpha*B[i][k] + B[j][k]*alpha*A[i][k]; + } + } +#pragma endscop + +} + + +int main() +{ + + int n = 30; + int m = 20; + + + int alpha; + int beta; + int C[30 + 0][30 + 0]; + int A[30 + 0][20 + 0]; + int B[30 + 0][20 + 0]; + + + init_array (n, m, &alpha, &beta, + C, + A, + B); + + + ; + + + kernel_syr2k (n, m, + alpha, beta, + C, + A, + B); + + + ; + ; + + + + return print_array(n, C); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/syrk.c b/benchmarks/polybench-syn/linear-algebra/blas/syrk.c new file mode 100644 index 0000000..dbf2e6b --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/syrk.c @@ -0,0 +1,106 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* syrk.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array(int n, int m, + int *alpha, + int *beta, + int C[ 30 + 0][30 + 0], + int A[ 30 + 0][20 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 3; + *beta = 2; + for (i = 0; i < n; plus(i)) + for (j = 0; j < m; plus(j)) + A[i][j] = (int) ((i*j+ONE)%n) / n; + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + C[i][j] = (int) ((i*j+ONE+ONE)%m) / m; +} + + +static +int print_array(int n, + int C[ 30 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= C[i][j]; + } + return res; +} + + + + +static +void kernel_syrk(int n, int m, + int alpha, + int beta, + int C[ 30 + 0][30 + 0], + int A[ 30 + 0][20 + 0]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) { + for (j = 0; j <= i; plus(j)) + C[i][j] *= beta; + for (k = 0; k < m; plus(k)) { + for (j = 0; j <= i; plus(j)) + C[i][j] += alpha * A[i][k] * A[j][k]; + } + } +#pragma endscop + +} + + +int main() +{ + + int n = 30; + int m = 20; + + + int alpha; + int beta; + int C[30 + 0][30 + 0]; + int A[30 + 0][20 + 0]; + + + init_array (n, m, &alpha, &beta, C, A); + + + ; + + + kernel_syrk (n, m, alpha, beta, C, A); + + + ; + ; + + + + return print_array(n, C); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/trmm.c b/benchmarks/polybench-syn/linear-algebra/blas/trmm.c new file mode 100644 index 0000000..79b384d --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/trmm.c @@ -0,0 +1,96 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* trmm.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array(int m, int n, + int *alpha, + int A[ 20 + 0][20 + 0], + int B[ 20 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 3; + for (i = 0; i < m; plus(i)) { + for (j = 0; j < i; plus(j)) { + A[i][j] = (int)((i+j) % m)/m; + } + A[i][i] = 1; + for (j = 0; j < n; plus(j)) { + B[i][j] = (int)((n+(i-j)) % n)/n; + } + } + +} + + + + +static +int print_array(int m, int n, + int B[ 20 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < m; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= B[i][j]; + } + return res; +} + + + + +static +void kernel_trmm(int m, int n, + int alpha, + int A[ 20 + 0][20 + 0], + int B[ 20 + 0][30 + 0]) +{ + int i, j, k; + int ONE = 1; +#pragma scop + for (i = 0; i < m; plus(i)) + for (j = 0; j < n; plus(j)) { + for (k = i+ONE; k < m; plus(k)) + B[i][j] += A[k][i] * B[k][j]; + B[i][j] = alpha * B[i][j]; + } +#pragma endscop + +} + + +int main() +{ + + int m = 20; + int n = 30; + + + int alpha; + int A[20 + 0][20 + 0]; + int B[20 + 0][30 + 0]; + + + init_array (m, n, &alpha, A, B); + + + kernel_trmm (m, n, alpha, A, B); + + return print_array(m, n, B); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/blas/trmm.preproc.c b/benchmarks/polybench-syn/linear-algebra/blas/trmm.preproc.c new file mode 100644 index 0000000..9b8edfe --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/blas/trmm.preproc.c @@ -0,0 +1,144 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* trmm.c: this file is part of PolyBench/C */ + +#include +#include +#include +#include + +/* Include polybench common header. */ +#include +# 1 "trmm.c" +# 1 "" 1 +# 1 "" 3 +# 362 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "trmm.c" 2 +# 1 "utilities/polybench.h" 1 +# 30 "utilities/polybench.h" +# 1 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h" 1 3 4 +# 31 "utilities/polybench.h" 2 +# 231 "utilities/polybench.h" +extern void* polybench_alloc_data(unsigned long long int n, int elt_size); +extern void polybench_free_data(void* ptr); + + + + +extern void polybench_flush_cache(); +extern void polybench_prepare_instruments(); +# 2 "trmm.c" 2 + + +# 1 "./linear-algebra/blas/trmm/trmm.h" 1 +# 5 "trmm.c" 2 + + + +static +void init_array(int m, int n, + int *alpha, + int A[ 20 + 0][20 + 0], + int B[ 20 + 0][30 + 0]) +{ + int i, j; + + *alpha = 1.5; + for (i = 0; i < m; i++) { + for (j = 0; j < i; j++) { + A[i][j] = (int)((i+j) % m)/m; + } + A[i][i] = 1.0; + for (j = 0; j < n; j++) { + B[i][j] = (int)((n+(i-j)) % n)/n; + } + } + +} + + + + +static +void print_array(int m, int n, + int B[ 20 + 0][30 + 0]) +{ + int i, j; + + fprintf(stderr, "==BEGIN DUMP_ARRAYS==\n"); + fprintf(stderr, "begin dump: %s", "B"); + for (i = 0; i < m; i++) + for (j = 0; j < n; j++) { + if ((i * m + j) % 20 == 0) fprintf (stderr, "\n"); + fprintf (stderr, "%d ", B[i][j]); + } + fprintf(stderr, "\nend dump: %s\n", "B"); + fprintf(stderr, "==END DUMP_ARRAYS==\n"); +} + + + + +static +void kernel_trmm(int m, int n, + int alpha, + int A[ 20 + 0][20 + 0], + int B[ 20 + 0][30 + 0]) +{ + int i, j, k; +# 68 "trmm.c" +#pragma scop + for (i = 0; i < m; i++) + for (j = 0; j < n; j++) { + for (k = i+1; k < m; k++) + B[i][j] += A[k][i] * B[k][j]; + B[i][j] = alpha * B[i][j]; + } +#pragma endscop + +} + + +int main(int argc, char** argv) +{ + + int m = 20; + int n = 30; + + + int alpha; + int (*A)[20 + 0][20 + 0]; A = (int(*)[20 + 0][20 + 0])polybench_alloc_data ((20 + 0) * (20 + 0), sizeof(int));; + int (*B)[20 + 0][30 + 0]; B = (int(*)[20 + 0][30 + 0])polybench_alloc_data ((20 + 0) * (30 + 0), sizeof(int));; + + + init_array (m, n, &alpha, *A, *B); + + + ; + + + kernel_trmm (m, n, alpha, *A, *B); + + + ; + ; + + + + if (argc > 42 && ! strcmp(argv[0], "")) print_array(m, n, *B); + + + free((void*)A);; + free((void*)B);; + + return 0; +} diff --git a/benchmarks/polybench-syn/linear-algebra/kernels/2mm.c b/benchmarks/polybench-syn/linear-algebra/kernels/2mm.c new file mode 100644 index 0000000..391e9ac --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/kernels/2mm.c @@ -0,0 +1,128 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* 2mm.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array(int ni, int nj, int nk, int nl, + int *alpha, + int *beta, + int A[ 16 + 0][22 + 0], + int B[ 22 + 0][18 + 0], + int C[ 18 + 0][24 + 0], + int D[ 16 + 0][24 + 0]) +{ + int i, j; + int ONE = 1; + + *alpha = 2; + *beta = 2; + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nk; plus(j)) + A[i][j] = (int) ((i*j+ONE) % ni) / ni; + for (i = 0; i < nk; plus(i)) + for (j = 0; j < nj; plus(j)) + B[i][j] = (int) (i*(j+ONE) % nj) / nj; + for (i = 0; i < nj; plus(i)) + for (j = 0; j < nl; plus(j)) + C[i][j] = (int) ((i*(j+ONE+ONE+ONE)+ONE) % nl) / nl; + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nl; plus(j)) + D[i][j] = (int) (i*(j+ONE+ONE) % nk) / nk; +} + +static +int print_array(int ni, int nl, + int D[ 16 + 0][24 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nl; plus(j)) { + res ^= D[i][j]; + } + return res; +} + + + + +static +void kernel_2mm(int ni, int nj, int nk, int nl, + int alpha, + int beta, + int tmp[ 16 + 0][18 + 0], + int A[ 16 + 0][22 + 0], + int B[ 22 + 0][18 + 0], + int C[ 18 + 0][24 + 0], + int D[ 16 + 0][24 + 0]) +{ + int ONE = 1; + int i, j, k; + +#pragma scop + + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nj; plus(j)) + { + tmp[i][j] = 0; + for (k = 0; k < nk; plus(k)) + tmp[i][j] += alpha * A[i][k] * B[k][j]; + } + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nl; plus(j)) + { + D[i][j] *= beta; + for (k = 0; k < nj; plus(k)) + D[i][j] += tmp[i][k] * C[k][j]; + } +#pragma endscop + +} + + +int main() +{ + + int ni = 16; + int nj = 18; + int nk = 22; + int nl = 24; + + int alpha; + int beta; + int tmp[16 + 0][18 + 0]; + int A[16 + 0][22 + 0]; + int B[22 + 0][18 + 0]; + int C[18 + 0][24 + 0]; + int D[16 + 0][24 + 0]; + + + init_array (ni, nj, nk, nl, &alpha, &beta, + A, + B, + C, + D); + + + kernel_2mm (ni, nj, nk, nl, + alpha, beta, + tmp, + A, + B, + C, + D); + + + return print_array(ni, nl, D); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/kernels/3mm.c b/benchmarks/polybench-syn/linear-algebra/kernels/3mm.c new file mode 100644 index 0000000..e565fb5 --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/kernels/3mm.c @@ -0,0 +1,141 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* 3mm.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array(int ni, int nj, int nk, int nl, int nm, + int A[ 16 + 0][20 + 0], + int B[ 20 + 0][18 + 0], + int C[ 18 + 0][24 + 0], + int D[ 24 + 0][22 + 0]) +{ + int i, j; + int ONE = 1; + int TWO = 2; + int THREE = 3; + int FIVE = 5; + + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nk; plus(j)) + A[i][j] = (int) ((i*j+ONE) % ni) / (5*ni); + for (i = 0; i < nk; plus(i)) + for (j = 0; j < nj; plus(j)) + B[i][j] = (int) ((i*(j+ONE)+TWO) % nj) / (5*nj); + for (i = 0; i < nj; plus(i)) + for (j = 0; j < nm; plus(j)) + C[i][j] = (int) (i*(j+THREE) % nl) / (5*nl); + for (i = 0; i < nm; plus(i)) + for (j = 0; j < nl; plus(j)) + D[i][j] = (int) ((i*(j+TWO)+TWO) % nk) / (5*nk); +} + + + + +static +int print_array(int ni, int nl, + int G[ 16 + 0][22 + 0]) +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nl; plus(j)) { + res ^= G[i][j]; + } + return res; +} + + + + +static +void kernel_3mm(int ni, int nj, int nk, int nl, int nm, + int E[ 16 + 0][18 + 0], + int A[ 16 + 0][20 + 0], + int B[ 20 + 0][18 + 0], + int F[ 18 + 0][22 + 0], + int C[ 18 + 0][24 + 0], + int D[ 24 + 0][22 + 0], + int G[ 16 + 0][22 + 0]) +{ + int ONE = 1; + int i, j, k; + +#pragma scop + + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nj; plus(j)) + { + E[i][j] = 0; + for (k = 0; k < nk; plus(k)) + E[i][j] += A[i][k] * B[k][j]; + } + + for (i = 0; i < nj; plus(i)) + for (j = 0; j < nl; plus(j)) + { + F[i][j] = 0; + for (k = 0; k < nm; plus(k)) + F[i][j] += C[i][k] * D[k][j]; + } + + for (i = 0; i < ni; plus(i)) + for (j = 0; j < nl; plus(j)) + { + G[i][j] = 0; + for (k = 0; k < nj; plus(k)) + G[i][j] += E[i][k] * F[k][j]; + } +#pragma endscop + +} + + +int main() +{ + + int ni = 16; + int nj = 18; + int nk = 20; + int nl = 22; + int nm = 24; + + + int E[16 + 0][18 + 0]; + int A[16 + 0][20 + 0]; + int B[20 + 0][18 + 0]; + int F[18 + 0][22 + 0]; + int C[18 + 0][24 + 0]; + int D[24 + 0][22 + 0]; + int G[16 + 0][22 + 0]; + + + init_array (ni, nj, nk, nl, nm, + A, + B, + C, + D); + + kernel_3mm (ni, nj, nk, nl, nm, + E, + A, + B, + F, + C, + D, + G); + + + return print_array(ni, nl, G); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/kernels/atas.c b/benchmarks/polybench-syn/linear-algebra/kernels/atas.c new file mode 100644 index 0000000..a051046 --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/kernels/atas.c @@ -0,0 +1,100 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* atax.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array (int m, int n, + int A[ 38 + 0][42 + 0], + int x[ 42 + 0]) +{ + int ONE = 1; + int i, j; + int fn; + fn = (int)n; + + for (i = 0; i < n; plus(i)) + x[i] = ONE + (i / fn); + for (i = 0; i < m; plus(i)) + for (j = 0; j < n; plus(j)) + A[i][j] = (int) ((i+j) % n) / (5*m); +} + + + + +static +int print_array(int n, + int y[ 42 + 0]) + +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) { + res ^= y[i]; + } + return res; +} + + + + +static +void kernel_atax(int m, int n, + int A[ 38 + 0][42 + 0], + int x[ 42 + 0], + int y[ 42 + 0], + int tmp[ 38 + 0]) +{ + int i, j; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) + y[i] = 0; + for (i = 0; i < m; plus(i)) + { + tmp[i] = 0; + for (j = 0; j < n; plus(j)) + tmp[i] = tmp[i] + A[i][j] * x[j]; + for (j = 0; j < n; plus(j)) + y[j] = y[j] + A[i][j] * tmp[i]; + } +#pragma endscop + +} + + +int main() +{ + + int m = 38; + int n = 42; + + + int A[38 + 0][42 + 0]; + int x[42 + 0]; + int y[42 + 0]; + int tmp[38 + 0]; + + init_array (m, n, A, x); + + kernel_atax (m, n, + A, + x, + y, + tmp); + + + return print_array(n, y); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/kernels/bicg.c b/benchmarks/polybench-syn/linear-algebra/kernels/bicg.c new file mode 100644 index 0000000..48b7658 --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/kernels/bicg.c @@ -0,0 +1,115 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* bicg.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array (int m, int n, + int A[ 42 + 0][38 + 0], + int r[ 42 + 0], + int p[ 38 + 0]) +{ + int i, j; + int ONE = 1; + + for (i = 0; i < m; plus(i)) + p[i] = (int)(i % m) / m; + for (i = 0; i < n; plus(i)) { + r[i] = (int)(i % n) / n; + for (j = 0; j < m; plus(j)) + A[i][j] = (int) (i*(j+ONE) % n)/n; + } +} + + + + +static +int print_array(int m, int n, + int s[ 38 + 0], + int q[ 42 + 0]) + +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < m; plus(i)) { + res ^= s[i]; + } + for (i = 0; i < n; plus(i)) { + res ^= q[i]; + } + return res; +} + + + + +static +void kernel_bicg(int m, int n, + int A[ 42 + 0][38 + 0], + int s[ 38 + 0], + int q[ 42 + 0], + int p[ 38 + 0], + int r[ 42 + 0]) +{ + int i, j; + int ONE = 1; + +#pragma scop + for (i = 0; i < m; plus(i)) + s[i] = 0; + for (i = 0; i < n; plus(i)) + { + q[i] = 0; + for (j = 0; j < m; plus(j)) + { + s[j] = s[j] + r[i] * A[i][j]; + q[i] = q[i] + A[i][j] * p[j]; + } + } +#pragma endscop + +} + + +int main() +{ + + int n = 42; + int m = 38; + + + int A[42 + 0][38 + 0]; + int s[38 + 0]; + int q[42 + 0]; + int p[38 + 0]; + int r[42 + 0]; + + + init_array (m, n, + A, + r, + p); + + kernel_bicg (m, n, + A, + s, + q, + p, + r); + + + return print_array(m, n, s, q); + + +} diff --git a/benchmarks/polybench-syn/linear-algebra/kernels/doitgen.c b/benchmarks/polybench-syn/linear-algebra/kernels/doitgen.c new file mode 100644 index 0000000..20de1df --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/kernels/doitgen.c @@ -0,0 +1,100 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* doitgen.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array(int nr, int nq, int np, + int A[ 10 + 0][8 + 0][12 + 0], + int C4[ 12 + 0][12 + 0]) +{ + int i, j, k; + int ONE = 1; + + for (i = 0; i < nr; plus(i)) + for (j = 0; j < nq; plus(j)) + for (k = 0; k < np; plus(k)) + A[i][j][k] = (int) ((i*j + k)%np) / np; + for (i = 0; i < np; plus(i)) + for (j = 0; j < np; plus(j)) + C4[i][j] = (int) (i*j % np) / np; +} + + +static +int print_array(int nr, int nq, int np, + int A[ 10 + 0][8 + 0][12 + 0]) +{ + int i, j, k; + int ONE = 1; + int res = 0; + + for (i = 0; i < nr; plus(i)) + for (j = 0; j < nq; plus(j)) + for (k = 0; k < np; plus(k)) { + res ^= A[i][j][k]; + } + return res; +} + + + + +void kernel_doitgen(int nr, int nq, int np, + int A[ 10 + 0][8 + 0][12 + 0], + int C4[ 12 + 0][12 + 0], + int sum[ 12 + 0]) +{ + int r, q, p, s; + int ONE = 1; + +#pragma scop + for (r = 0; r < nr; plus(r)) + for (q = 0; q < nq; plus(q)) { + for (p = 0; p < np; plus(p)) { + sum[p] = 0; + for (s = 0; s < np; plus(s)) + sum[p] += A[r][q][s] * C4[s][p]; + } + for (p = 0; p < np; plus(p)) + A[r][q][p] = sum[p]; + } +#pragma endscop + +} + + +int main() +{ + + int nr = 10; + int nq = 8; + int np = 12; + + + int A[10 + 0][8 + 0][12 + 0]; + int sum[12 + 0]; + int C4[12 + 0][12 + 0]; + + + init_array (nr, nq, np, + A, + C4); + + + kernel_doitgen (nr, nq, np, + A, + C4, + sum); + + + + return print_array(nr, nq, np, A); +} diff --git a/benchmarks/polybench-syn/linear-algebra/kernels/mvt.c b/benchmarks/polybench-syn/linear-algebra/kernels/mvt.c new file mode 100644 index 0000000..aa68b1c --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/kernels/mvt.c @@ -0,0 +1,117 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* mvt.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE + +static +void init_array(int n, + int x1[ 40 + 0], + int x2[ 40 + 0], + int y_1[ 40 + 0], + int y_2[ 40 + 0], + int A[ 40 + 0][40 + 0]) +{ + int i, j; + int ONE = 1; + int THREE = 3; + + for (i = 0; i < n; plus(i)) + { + x1[i] = (int) (i % n) / n; + x2[i] = (int) ((i + ONE) % n) / n; + y_1[i] = (int) ((i + THREE) % n) / n; + y_2[i] = (int) ((i + 4) % n) / n; + for (j = 0; j < n; plus(j)) + A[i][j] = (int) (i*j % n) / n; + } +} + + + + +static +int print_array(int n, + int x1[ 40 + 0], + int x2[ 40 + 0]) + +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) { + res ^= x1[i]; + } + + for (i = 0; i < n; plus(i)) { + res ^= x2[i]; + } + return res; +} + + + + +static +void kernel_mvt(int n, + int x1[ 40 + 0], + int x2[ 40 + 0], + int y_1[ 40 + 0], + int y_2[ 40 + 0], + int A[ 40 + 0][40 + 0]) +{ + int i, j; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + x1[i] = x1[i] + A[i][j] * y_1[j]; + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + x2[i] = x2[i] + A[j][i] * y_2[j]; +#pragma endscop + +} + + +int main() +{ + + int n = 40; + + + int A[40 + 0][40 + 0]; + int x1[40 + 0]; + int x2[40 + 0]; + int y_1[40 + 0]; + int y_2[40 + 0]; + + + + init_array (n, + x1, + x2, + y_1, + y_2, + A); + + + kernel_mvt (n, + x1, + x2, + y_1, + y_2, + A); + + return print_array(n, x1, x2); + +} diff --git a/benchmarks/polybench-syn/linear-algebra/solvers/cholesky.c b/benchmarks/polybench-syn/linear-algebra/solvers/cholesky.c new file mode 100644 index 0000000..264251d --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/solvers/cholesky.c @@ -0,0 +1,125 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* cholesky.c: this file is part of PolyBench/C */ + +#include + +# define SQRT_FUN(x) sqrtf(x) + +#define plus(i) i = i + ONE +static +void init_array(int n, + int A[40][40]) +{ + int i, j; + int ONE = 1; + + for (i = 0; i < n; plus(i)) + { + for (j = 0; j <= i; plus(j)) + A[i][j] = (int)(-j % n) / n + ONE; + for (j = i + ONE; j < n; plus(j)) { + A[i][j] = 0; + } + A[i][i] = 1; + } + + + int r,s,t; + int B[40][40]; + for (r = 0; r < n; ++r) + for (s = 0; s < n; ++s) + B[r][s] = 0; + for (t = 0; t < n; ++t) + for (r = 0; r < n; ++r) + for (s = 0; s < n; ++s) + B[r][s] += A[r][t] * A[s][t]; + for (r = 0; r < n; ++r) + for (s = 0; s < n; ++s) + A[r][s] = B[r][s]; + +} + + + + +static +int check_array(int n, + int A[40][40]) + +{ + int res = 0; + int ONE = 1; + int i, j; + + for (i = 0; i < n; plus(i)) + for (j = 0; j <= i; plus(j)) { + if(A[i][j]!=0) res = 1; + } + return res; +} + + + + +static +void kernel_cholesky(int n, + int A[40][40]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) { + + for (j = 0; j < i; plus(j)) { + for (k = 0; k < j; plus(k)) { + A[i][j] -= A[i][k] * A[j][k]; + } + A[i][j] /= A[j][j]; + } + + for (k = 0; k < i; plus(k)) { + A[i][i] -= A[i][k] * A[i][k]; + } + int sq = 0; int val = 0; int cmp = A[i][i]; + printf("cmp %d\n",cmp); + while(sq <= cmp) { + val = val + ONE; + sq = val * val; + } + printf("val %d\n",val); + A[i][i] = val; + } +#pragma endscop + +} + + +int main(int argc, char** argv) +{ + + int n = 40; + + + int A[40][40]; + + + //init_array (n, A); + + + kernel_cholesky (n, A); + + + return check_array(n, A); + + + return 0; +} diff --git a/benchmarks/polybench-syn/linear-algebra/solvers/durbin.c b/benchmarks/polybench-syn/linear-algebra/solvers/durbin.c new file mode 100644 index 0000000..677c23c --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/solvers/durbin.c @@ -0,0 +1,102 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* durbin.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +/* Include polybench common header. */ +static +void init_array (int n, + int r[ 40 + 0]) +{ + int ONE = 1; + int i, j; + + for (i = 0; i < n; plus(i)) + { + r[i] = (n+ONE-i); + } +} + + + +static +int print_array(int n, + int y[ 40 + 0]) + +{ + int ONE = 1; + int i; + int res = 0; + + for (i = 0; i < n; plus(i)) { + res += y[i]; + } + return res; +} + +static +void kernel_durbin(int n, + int r[ 40 + 0], + int y[ 40 + 0]) +{ + int z[40]; + int alpha; + int beta; + int sum; + + int ONE = 1; + int i,k; + +#pragma scop + y[0] = -r[0]; + beta = 1; + alpha = -r[0]; + + for (k = 1; k < n; plus(k)) { + beta = (ONE-alpha*alpha)*beta; + sum = 0; + for (i=0; i + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* lu.c: this file is part of PolyBench/C */ + +//#include +//#include +//#include +//#include + +#define plus(i) i = i + ONE + +static +void init_array (int n, + int A[40][40]) +{ + int ONE = 1; + int i, j; + + for (i = 0; i < n; plus(i)) + { + for (j = 0; j <= i; plus(j)) + A[i][j] = (int)(-j % n) / n + ONE; + for (j = plus(i); j < n; plus(j)) { + A[i][j] = 0; + } + A[i][i] = 1; + } + + + + int r,s,t; + int B[40][40]; // B = (int(*)[40 + 0][40 + 0])polybench_alloc_data ((40 + 0) * (40 + 0), sizeof(int));; + for (r = 0; r < n; plus(r)) + for (s = 0; s < n; plus(s)) + B[r][s] = 0; + for (t = 0; t < n; plus(t)) + for (r = 0; r < n; plus(r)) + for (s = 0; s < n; plus(s)) + B[r][s] += A[r][t] * A[s][t]; + for (r = 0; r < n; plus(r)) + for (s = 0; s < n; plus(s)) + A[r][s] = B[r][s]; + //free((void*)B);; + +} + + + +/* +static +void print_array(int n, + int A[ 40 + 0][40 + 0]) + +{ + int i, j; + + fprintf(stderr, "==BEGIN DUMP_ARRAYS==\n"); + fprintf(stderr, "begin dump: %s", "A"); + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) { + if ((i * n + j) % 20 == 0) fprintf (stderr, "\n"); + fprintf (stderr, "%d ", A[i][j]); + } + fprintf(stderr, "\nend dump: %s\n", "A"); + fprintf(stderr, "==END DUMP_ARRAYS==\n"); +} +*/ + + + +static +void kernel_lu(int n, + int A[ 40][40]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) { + for (j = 0; j 42 && ! strcmp(argv[0], "")) + return check_array(n, A); + return 0; + + //free((void*)A);; +} diff --git a/benchmarks/polybench-syn/linear-algebra/solvers/ludcmp.c b/benchmarks/polybench-syn/linear-algebra/solvers/ludcmp.c new file mode 100644 index 0000000..e85316a --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/solvers/ludcmp.c @@ -0,0 +1,164 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* ludcmp.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE + +static +void init_array (int n, + int A[ 40 + 0][40 + 0], + int b[ 40 + 0], + int x[ 40 + 0], + int y[ 40 + 0]) +{ + int i, j; + int ONE = 1; + int TWO = 2; + int FOUR = 4; + int fn = (int)n; + + for (i = 0; i < n; plus(i)) + { + x[i] = 0; + y[i] = 0; + b[i] = (i+ONE)/fn/(TWO) + (FOUR); + } + + for (i = 0; i < n; plus(i)) + { + for (j = 0; j <= i; plus(j)) + A[i][j] = (int)(-j % n) / n + ONE; + for (j = i+ONE; j < n; plus(j)) { + A[i][j] = 0; + } + A[i][i] = 1; + } + + + + int r,s,t; + int B[40 + 0][40 + 0]; + for (r = 0; r < n; plus(r)) + for (s = 0; s < n; plus(s)) + B[r][s] = 0; + for (t = 0; t < n; plus(t)) + for (r = 0; r < n; plus(r)) + for (s = 0; s < n; plus(s)) + B[r][s] += A[r][t] * A[s][t]; + for (r = 0; r < n; plus(r)) + for (s = 0; s < n; plus(s)) + A[r][s] = B[r][s]; + +} + + + + +static +int check_array(int n, + int x[ 40 + 0]) + +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) { + res += x[i]; + } + return res; +} + + + + +static +void kernel_ludcmp(int n, + int A[ 40 + 0][40 + 0], + int b[ 40 + 0], + int x[ 40 + 0], + int y[ 40 + 0]) +{ + int i, j, k; + int ONE = 1; + + int w; + +#pragma scop + for (i = 0; i < n; plus(i)) { + for (j = 0; j =0; i=i-ONE) { + w = y[i]; + for (j = i+ONE; j < n; plus(j)) + w -= A[i][j] * x[j]; + x[i] = w / A[i][i]; + } +#pragma endscop + +} + + +int main() +{ + + int n = 40; + int ONE = 1; + + + int A[40 + 0][40 + 0]; + int b[40 + 0]; + int x[40 + 0]; + int y[40 + 0]; + + + + init_array (n, + A, + b, + x, + y); + + + ; + + + kernel_ludcmp (n, + A, + b, + x, + y); + + return check_array(n, x); + + + return 0; +} diff --git a/benchmarks/polybench-syn/linear-algebra/solvers/trisolv.c b/benchmarks/polybench-syn/linear-algebra/solvers/trisolv.c new file mode 100644 index 0000000..5e760e6 --- /dev/null +++ b/benchmarks/polybench-syn/linear-algebra/solvers/trisolv.c @@ -0,0 +1,89 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* trisolv.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array(int n, + int L[ 40 ][40 ], + int x[ 40 ], + int b[ 40 ]) +{ + int i, j; + int ONE = 1; + + for (i = 0; i < n; plus(i)) + { + x[i] = - 999; + b[i] = i ; + for (j = 0; j <= i; plus(j)) + L[i][j] = (int) (i+n-j+ONE)*(ONE+ONE)/n; + } +} + + + + +static +int check_array(int n, + int x[ 40]) + +{ + int i; + int res = 0; + int ONE = 1; + for (i = 0; i < n; plus(i)) { + res += x[i]; + } + return res; +} + + + + +static +void kernel_trisolv(int n, + int L[ 40 + 0][40 + 0], + int x[ 40 + 0], + int b[ 40 + 0]) +{ + int i, j; + int ONE = 1; + +#pragma scop + for (i = 0; i < n; plus(i)) + { + x[i] = b[i]; + for (j = 0; j Date: Sat, 4 Jul 2020 11:14:55 +0100 Subject: modulus bug --- benchmarks/polybench-syn/linear-algebra/blas/symm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/benchmarks/polybench-syn/linear-algebra/blas/symm.c b/benchmarks/polybench-syn/linear-algebra/blas/symm.c index 4a0039d..a5e8539 100644 --- a/benchmarks/polybench-syn/linear-algebra/blas/symm.c +++ b/benchmarks/polybench-syn/linear-algebra/blas/symm.c @@ -20,17 +20,18 @@ void init_array(int m, int n, { int i, j; int ONE = 1; + int HUND = 100; *alpha = 3; *beta = 2; for (i = 0; i < m; plus(i)) for (j = 0; j < n; plus(j)) { - C[i][j] = (int) ((i+j) % 100) / m; - B[i][j] = (int) ((n+i-j) % 100) / m; + C[i][j] = (int) ((i+j) % HUND) / m; + B[i][j] = (int) ((n+i-j) % HUND) / m; } for (i = 0; i < m; plus(i)) { for (j = 0; j <=i; plus(j)) - A[i][j] = (int) ((i+j) % 100) / m; + A[i][j] = (int) ((i+j) % HUND) / m; for (j = i+ONE; j < m; plus(j)) A[i][j] = -999; } -- cgit From b428befe01c0182be71f5da183677316eba38e31 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 12:02:26 +0100 Subject: polybench data mining --- benchmarks/polybench-syn/data-mining/covariance.c | 107 ++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 benchmarks/polybench-syn/data-mining/covariance.c diff --git a/benchmarks/polybench-syn/data-mining/covariance.c b/benchmarks/polybench-syn/data-mining/covariance.c new file mode 100644 index 0000000..08cf94a --- /dev/null +++ b/benchmarks/polybench-syn/data-mining/covariance.c @@ -0,0 +1,107 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* covariance.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array (int m, int n, + int *float_n, + int data[ 32 + 0][28 + 0]) +{ + int i, j; + int ONE = 1; + + *float_n = (int)n; + + for (i = 0; i < 32; plus(i)) + for (j = 0; j < 28; plus(j)) + data[i][j] = ((int) i*j) / 28; +} + + + + +static +int print_array(int m, + int cov[ 28 + 0][28 + 0]) + +{ + int i, j; + int ONE = 1; + int res = 0; + for (i = 0; i < m; plus(i)) + for (j = 0; j < m; plus(j)) { + res ^= cov[i][j]; + } + return res; +} + + + + +static +void kernel_covariance(int m, int n, + int float_n, + int data[ 32 + 0][28 + 0], + int cov[ 28 + 0][28 + 0], + int mean[ 28 + 0]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (j = 0; j < m; plus(j)) + { + mean[j] = 0; + for (i = 0; i < n; plus(i)) + mean[j] += data[i][j]; + mean[j] /= float_n; + } + + for (i = 0; i < n; plus(i)) + for (j = 0; j < m; plus(j)) + data[i][j] -= mean[j]; + + for (i = 0; i < m; plus(i)) + for (j = i; j < m; plus(j)) + { + cov[i][j] = 0; + for (k = 0; k < n; plus(k)) + cov[i][j] += data[k][i] * data[k][j]; + cov[i][j] /= (float_n - ONE); + cov[j][i] = cov[i][j]; + } +#pragma endscop + +} + + +int main() +{ + + int n = 32; + int m = 28; + + + int float_n; + int data[32 + 0][28 + 0]; + int mean[28 + 0]; + int cov[28 + 0][28 + 0]; + + init_array (m, n, &float_n, data); + + kernel_covariance (m, n, float_n, + data, + cov, + mean); + + return print_array(m, cov); + +} -- cgit From a0fb7e582f6e844adfaa04e56e7ae7387d043833 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 12:03:42 +0100 Subject: div bug --- benchmarks/polybench-syn/data-mining/covariance.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks/polybench-syn/data-mining/covariance.c b/benchmarks/polybench-syn/data-mining/covariance.c index 08cf94a..63f2320 100644 --- a/benchmarks/polybench-syn/data-mining/covariance.c +++ b/benchmarks/polybench-syn/data-mining/covariance.c @@ -17,12 +17,13 @@ void init_array (int m, int n, { int i, j; int ONE = 1; + int DIV = 28; *float_n = (int)n; for (i = 0; i < 32; plus(i)) for (j = 0; j < 28; plus(j)) - data[i][j] = ((int) i*j) / 28; + data[i][j] = ((int) i*j) / DIV; } -- cgit From c7ffca253cf1767ae1416160e1a50bb5450c339f Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 4 Jul 2020 12:08:34 +0100 Subject: Remove mulhs and mulhu --- src/translation/HTLgen.v | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 4cde0c8..9a82aa8 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -324,8 +324,8 @@ Definition translate_instr (op : Op.operation) (args : list reg) : mon expr := | Op.Osub, r1::r2::nil => ret (bop Vsub r1 r2) | Op.Omul, r1::r2::nil => ret (bop Vmul r1 r2) | Op.Omulimm n, r::nil => ret (boplit Vmul r n) - | Op.Omulhs, r1::r2::nil => ret (bop Vmul r1 r2) - | Op.Omulhu, r1::r2::nil => ret (bop Vmul r1 r2) + | Op.Omulhs, r1::r2::nil => error (Errors.msg "Htlgen: Instruction not implemented: mulhs") + | Op.Omulhu, r1::r2::nil => error (Errors.msg "Htlgen: Instruction not implemented: mulhu") | Op.Odiv, r1::r2::nil => ret (bop Vdiv r1 r2) | Op.Odivu, r1::r2::nil => ret (bop Vdivu r1 r2) | Op.Omod, r1::r2::nil => ret (bop Vmod r1 r2) -- cgit From c3201cc91cb16d9f9944df553d2a691b62bc66ca Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 13:43:27 +0100 Subject: polybench stencils --- benchmarks/polybench-syn/stencils/adi.c | 129 +++++++++++++++++++++++++ benchmarks/polybench-syn/stencils/fdtd-2d.c | 131 ++++++++++++++++++++++++++ benchmarks/polybench-syn/stencils/heat-3d.c | 107 +++++++++++++++++++++ benchmarks/polybench-syn/stencils/jacobi-1d.c | 97 +++++++++++++++++++ benchmarks/polybench-syn/stencils/jacobi-2d.c | 100 ++++++++++++++++++++ benchmarks/polybench-syn/stencils/seidel-2d.c | 84 +++++++++++++++++ 6 files changed, 648 insertions(+) create mode 100644 benchmarks/polybench-syn/stencils/adi.c create mode 100644 benchmarks/polybench-syn/stencils/fdtd-2d.c create mode 100644 benchmarks/polybench-syn/stencils/heat-3d.c create mode 100644 benchmarks/polybench-syn/stencils/jacobi-1d.c create mode 100644 benchmarks/polybench-syn/stencils/jacobi-2d.c create mode 100644 benchmarks/polybench-syn/stencils/seidel-2d.c diff --git a/benchmarks/polybench-syn/stencils/adi.c b/benchmarks/polybench-syn/stencils/adi.c new file mode 100644 index 0000000..cc54e11 --- /dev/null +++ b/benchmarks/polybench-syn/stencils/adi.c @@ -0,0 +1,129 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* adi.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array (int n, + int u[ 20 + 0][20 + 0]) +{ + int i, j; + + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) + { + u[i][j] = (int)(i + n-j) / n; + } +} + + + + +static +int print_array(int n, + int u[ 20 + 0][20 + 0]) + +{ + int i, j; + int res = 0; + + for (i = 0; i < n; i++) + for (j = 0; j < n; j++) { + res ^= u[i][j]; + } + return res; +} +static +void kernel_adi(int tsteps, int n, + int u[ 20 + 0][20 + 0], + int v[ 20 + 0][20 + 0], + int p[ 20 + 0][20 + 0], + int q[ 20 + 0][20 + 0]) +{ + int t, i, j; + int DX, DY, DT; + int B1, B2; + int mul1, mul2; + int a, b, c, d, e, f; + +#pragma scop + + DX = 1/(int)n; + DY = 1/(int)n; + DT = 1/(int)tsteps; + B1 = 2; + B2 = 1; + mul1 = B1 * DT / (DX * DX); + mul2 = B2 * DT / (DY * DY); + + a = -mul1 / 2; + b = 1+mul1; + c = a; + d = -mul2 / 2; + e = 1+mul2; + f = d; + + for (t=1; t<=tsteps; t++) { + + for (i=1; i=1; j--) { + v[j][i] = p[i][j] * v[j+1][i] + q[i][j]; + } + } + + for (i=1; i=1; j--) { + u[i][j] = p[i][j] * u[i][j+1] + q[i][j]; + } + } + } +#pragma endscop +} + + +int main(int argc, char** argv) +{ + + int n = 20; + int tsteps = 20; + + + int u[20 + 0][20 + 0]; + int v[20 + 0][20 + 0]; + int p[20 + 0][20 + 0]; + int q[20 + 0][20 + 0]; + + + + init_array (n, u); + + kernel_adi (tsteps, n, u, v, p, q); + + return print_array(n, u); + +} diff --git a/benchmarks/polybench-syn/stencils/fdtd-2d.c b/benchmarks/polybench-syn/stencils/fdtd-2d.c new file mode 100644 index 0000000..cee6b03 --- /dev/null +++ b/benchmarks/polybench-syn/stencils/fdtd-2d.c @@ -0,0 +1,131 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* fdtd-2d.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array (int tmax, + int nx, + int ny, + int ex[ 20 + 0][30 + 0], + int ey[ 20 + 0][30 + 0], + int hz[ 20 + 0][30 + 0], + int _fict_[ 20 + 0]) +{ + int i, j; + int ONE = 1; + int TWO = 1; + int THREE = 1; + + for (i = 0; i < tmax; plus(i)) + _fict_[i] = (int) i; + for (i = 0; i < nx; plus(i)) + for (j = 0; j < ny; plus(j)) + { + ex[i][j] = ((int) i*(j+ONE)) / nx; + ey[i][j] = ((int) i*(j+TWO)) / ny; + hz[i][j] = ((int) i*(j+THREE)) / nx; + } + +} + + + + +static +int print_array(int nx, + int ny, + int ex[ 20 + 0][30 + 0], + int ey[ 20 + 0][30 + 0], + int hz[ 20 + 0][30 + 0]) +{ + int i, j; + int res = 0; + int ONE = 1; + + for (i = 0; i < nx; plus(i)) + for (j = 0; j < ny; plus(j)) { + res ^= ex[i][j]; + } + for (i = 0; i < nx; plus(i)) + for (j = 0; j < ny; plus(j)) { + res ^= ey[i][j]; + } + for (i = 0; i < nx; plus(i)) + for (j = 0; j < ny; plus(j)) { + res ^= hz[i][j]; + } + + return res; +} + + +static +void kernel_fdtd_2d(int tmax, + int nx, + int ny, + int ex[ 20 + 0][30 + 0], + int ey[ 20 + 0][30 + 0], + int hz[ 20 + 0][30 + 0], + int _fict_[ 20 + 0]) +{ + int t, i, j; + int ONE = 1; + +#pragma scop + + for(t = 0; t < tmax; t=t+ONE) + { + for (j = 0; j < ny; plus(j)) + ey[0][j] = _fict_[t]; + for (i = 1; i < nx; plus(i)) + for (j = 0; j < ny; plus(j)) + ey[i][j] = ey[i][j] - ((hz[i][j]-(hz[i-ONE][j])>>1)); + for (i = 0; i < nx; plus(i)) + for (j = 1; j < ny; plus(j)) + ex[i][j] = ex[i][j] - ((hz[i][j]-(hz[i][j-ONE])>>1)); + for (i = 0; i < nx - ONE; plus(i)) + for (j = 0; j < ny - ONE; plus(j)){ + int tmp = (ex[i][j+ONE] - ex[i][j] + + ey[i+ONE][j] - ey[i][j]); + hz[i][j] = hz[i][j] - tmp >> 1 - tmp >> 2; + } + } + +#pragma endscop +} + + +int main() +{ + + int tmax = 20; + int nx = 20; + int ny = 30; + + + int ex[20 + 0][30 + 0]; + int ey[20 + 0][30 + 0]; + int hz[20 + 0][30 + 0]; + int _fict_[20 + 0]; + + init_array (tmax, nx, ny, + ex, + ey, + hz, + _fict_); + kernel_fdtd_2d (tmax, nx, ny, + ex, + ey, + hz, + _fict_); + + return print_array(nx, ny, ex, ey, hz); +} diff --git a/benchmarks/polybench-syn/stencils/heat-3d.c b/benchmarks/polybench-syn/stencils/heat-3d.c new file mode 100644 index 0000000..6529e8b --- /dev/null +++ b/benchmarks/polybench-syn/stencils/heat-3d.c @@ -0,0 +1,107 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* heat-3d.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array (int n, + int A[ 10 + 0][10 + 0][10 + 0], + int B[ 10 + 0][10 + 0][10 + 0]) +{ + int i, j, k; + int ONE = 1; + int TEN = 10; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + for (k = 0; k < n; plus(k)) + A[i][j][k] = B[i][j][k] = (int) (i + j + (n-k))* TEN / (n); +} + + + + +static +int print_array(int n, + int A[ 10 + 0][10 + 0][10 + 0]) + +{ + int i, j, k; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + for (k = 0; k < n; plus(k)) { + res ^= A[i][j][k]; + } + return res; +} + + + + +static +void kernel_heat_3d(int tsteps, + int n, + int A[ 10 + 0][10 + 0][10 + 0], + int B[ 10 + 0][10 + 0][10 + 0]) +{ + int t, i, j, k; + int ONE = 1; + int TWO = 2; + int FOUR = 4; + +#pragma scop + for (t = 1; t <= 5; plus(t)) { + for (i = 1; i < n-ONE; plus(i)) { + for (j = 1; j < n-ONE; plus(j)) { + for (k = 1; k < n-ONE; plus(k)) { + B[i][j][k] = (A[i+ONE][j][k] - TWO * A[i][j][k] + A[i-ONE][j][k]) >> FOUR + + (A[i][j+ONE][k] - TWO * A[i][j][k] + A[i][j-ONE][k]) >> 4 + + (A[i][j][k+ONE] - TWO * A[i][j][k] + A[i][j][k-ONE]) >> 4 + + A[i][j][k] + ; + } + } + } + for (i = 1; i < n-ONE; plus(i)) { + for (j = 1; j < n-ONE; plus(j)) { + for (k = 1; k < n-ONE; plus(k)) { + A[i][j][k] = (B[i+ONE][j][k] - TWO * B[i][j][k] + B[i-ONE][j][k]) >> 4 + + (B[i][j+ONE][k] - TWO * B[i][j][k] + B[i][j-ONE][k]) >> 4 + + (B[i][j][k+ONE] - TWO * B[i][j][k] + B[i][j][k-ONE]) >> 4 + + B[i][j][k]; + //; + } + } + } + } +#pragma endscop +} + + +int main() +{ + + int n = 10; + int tsteps = 20; + + + int A[10 + 0][10 + 0][10 + 0]; + int B[10 + 0][10 + 0][10 + 0]; + + init_array (n, A, B); + + kernel_heat_3d (tsteps, n, A, B); + + return print_array(n, A); + +} diff --git a/benchmarks/polybench-syn/stencils/jacobi-1d.c b/benchmarks/polybench-syn/stencils/jacobi-1d.c new file mode 100644 index 0000000..1c3cf79 --- /dev/null +++ b/benchmarks/polybench-syn/stencils/jacobi-1d.c @@ -0,0 +1,97 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* jacobi-1d.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array (int n, + int A[ 30 + 0], + int B[ 30 + 0]) +{ + int i; + int ONE = 1; + int TWO = 2; + int THREE = 3; + + for (i = 0; i < n; plus(i)) + { + A[i] = ((int) i+TWO) / n; + B[i] = ((int) i+THREE) / n; + } +} + + + + +static +int print_array(int n, + int A[ 30 + 0]) + +{ + int i; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + { + res ^= A[i]; + } + return res; +} + + + + +static +void kernel_jacobi_1d(int tsteps, + int n, + int A[ 30 + 0], + int B[ 30 + 0]) +{ + int t, i; + int ONE = 1; + +#pragma scop + for (t = 0; t < tsteps; plus(t)) + { + for (i = 1; i < n - ONE; plus(i)){ + B[i] = (A[i-ONE] + A[i] + A[i + ONE]); + B[i] = B[i] >> 2; + } + for (i = 1; i < n - ONE; plus(i)){ + A[i] = (B[i-ONE] + B[i] + B[i + ONE]); + A[i] = A[i] >> 2; + } + } +#pragma endscop + +} + + +int main() +{ + + int n = 30; + int tsteps = 20; + + + int A[30 + 0]; + int B[30 + 0]; + + + + init_array (n, A, B); + + kernel_jacobi_1d(tsteps, n, A, B); + + return print_array(n, A); + +} diff --git a/benchmarks/polybench-syn/stencils/jacobi-2d.c b/benchmarks/polybench-syn/stencils/jacobi-2d.c new file mode 100644 index 0000000..758a83a --- /dev/null +++ b/benchmarks/polybench-syn/stencils/jacobi-2d.c @@ -0,0 +1,100 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* jacobi-2d.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array (int n, + int A[ 30 + 0][30 + 0], + int B[ 30 + 0][30 + 0]) +{ + int i, j; + int ONE = 1; + int TWO = 2; + int THREE = 3; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + { + A[i][j] = ((int) i*(j+TWO) + TWO) / n; + B[i][j] = ((int) i*(j+THREE) + THREE) / n; + } +} + + + + +static +int print_array(int n, + int A[ 30 + 0][30 + 0]) + +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= A[i][j]; + } + return res; +} + + + + +static +void kernel_jacobi_2d(int tsteps, + int n, + int A[ 30 + 0][30 + 0], + int B[ 30 + 0][30 + 0]) +{ + int t, i, j; + int ONE = 1; + +#pragma scop + for (t = 0; t < tsteps; plus(t)) + { + for (i = 1; i < n - ONE; plus(i)) + for (j = 1; j < n - ONE; plus(j)){ + B[i][j] = (A[i][j] + A[i][j-ONE] + A[i][ONE+j] + A[ONE+i][j] + A[i-ONE][j]); + B[i][j] = B[i][j] >> 2; + } + for (i = 1; i < n - ONE; plus(i)) + for (j = 1; j < n - ONE; plus(j)){ + A[i][j] = (B[i][j] + B[i][j-ONE] + B[i][ONE+j] + B[ONE+i][j] + B[i-ONE][j]); + A[i][j] = A[i][j] >> 2; + } + } +#pragma endscop + +} + + +int main() +{ + + int n = 30; + int tsteps = 20; + + + int A[30 + 0][30 + 0]; + int B[30 + 0][30 + 0]; + + + + init_array (n, A, B); + + kernel_jacobi_2d(tsteps, n, A, B); + + return print_array(n, A); + +} diff --git a/benchmarks/polybench-syn/stencils/seidel-2d.c b/benchmarks/polybench-syn/stencils/seidel-2d.c new file mode 100644 index 0000000..022ed6c --- /dev/null +++ b/benchmarks/polybench-syn/stencils/seidel-2d.c @@ -0,0 +1,84 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* seidel-2d.c: this file is part of PolyBench/C */ + +#define plus(i) i = i + ONE +static +void init_array (int n, + int A[ 40 + 0][40 + 0]) +{ + int i, j; + int ONE = 1; + int TWO = 2; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + A[i][j] = ((int) i*(j+TWO) + TWO) / n; +} + + + + +static +int print_array(int n, + int A[ 40 + 0][40 + 0]) + +{ + int i, j; + int ONE = 1; + int res = 0; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= A[i][j]; + } + return res; +} + + + + +static +void kernel_seidel_2d(int tsteps, + int n, + int A[ 40 + 0][40 + 0]) +{ + int t, i, j; + int ONE = 1; + int TWO = 2; + +#pragma scop + for (t = 0; t <= tsteps - ONE; plus(t)) + for (i = ONE; i<= n - TWO; plus(i)) + for (j = ONE; j <= n - TWO; plus(j)) + A[i][j] = (A[i-ONE][j-ONE] + A[i-ONE][j] + A[i-ONE][j+ONE] + + A[i][j-ONE] + A[i][j] + A[i][j+ONE] + + A[i+ONE][j-ONE] + A[i+ONE][j] + A[i+ONE][j+ONE])/9; +#pragma endscop + +} + + +int main() +{ + + int n = 40; + int tsteps = 5; + + + int A[40 + 0][40 + 0]; + + init_array (n, A); + + kernel_seidel_2d (tsteps, n, A); + + return print_array(n, A); + +} -- cgit From dd896636c7a1a2a8ad45f07bf081b8f6374f9fd8 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 13:44:44 +0100 Subject: div bug --- benchmarks/polybench-syn/stencils/seidel-2d.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmarks/polybench-syn/stencils/seidel-2d.c b/benchmarks/polybench-syn/stencils/seidel-2d.c index 022ed6c..d4c7f98 100644 --- a/benchmarks/polybench-syn/stencils/seidel-2d.c +++ b/benchmarks/polybench-syn/stencils/seidel-2d.c @@ -53,6 +53,7 @@ void kernel_seidel_2d(int tsteps, int t, i, j; int ONE = 1; int TWO = 2; + int NINE = 9; #pragma scop for (t = 0; t <= tsteps - ONE; plus(t)) @@ -60,7 +61,7 @@ void kernel_seidel_2d(int tsteps, for (j = ONE; j <= n - TWO; plus(j)) A[i][j] = (A[i-ONE][j-ONE] + A[i-ONE][j] + A[i-ONE][j+ONE] + A[i][j-ONE] + A[i][j] + A[i][j+ONE] - + A[i+ONE][j-ONE] + A[i+ONE][j] + A[i+ONE][j+ONE])/9; + + A[i+ONE][j-ONE] + A[i+ONE][j] + A[i+ONE][j+ONE])/NINE; #pragma endscop } -- cgit From c62c0f75b5df4063c19d6a73378a4f3b49738a3d Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 14:18:10 +0100 Subject: polybench medley --- benchmarks/polybench-syn/medley/floyd-warshall.c | 89 +++++++++++++++++++ benchmarks/polybench-syn/medley/nussinov.c | 104 +++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 benchmarks/polybench-syn/medley/floyd-warshall.c create mode 100644 benchmarks/polybench-syn/medley/nussinov.c diff --git a/benchmarks/polybench-syn/medley/floyd-warshall.c b/benchmarks/polybench-syn/medley/floyd-warshall.c new file mode 100644 index 0000000..46f6774 --- /dev/null +++ b/benchmarks/polybench-syn/medley/floyd-warshall.c @@ -0,0 +1,89 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* floyd-warshall.c: this file is part of PolyBench/C */ + + +#define plus(i) i = i + ONE +static +void init_array (int n, + int path[ 60 + 0][60 + 0]) +{ + int i, j; + int ONE = 1; + int N7 = 7; + int N11 = 11; + int N13 = 13; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + path[i][j] = i*j%N7+ONE; + if ((i+j)%N13 == 0 || (i+j)%N7==0 || (i+j)%N11 == 0) + path[i][j] = 999; + } +} + + + + +static +int print_array(int n, + int path[ 60 + 0][60 + 0]) + +{ + int i, j; + int res = 0; + int ONE = 1; + + for (i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) { + res ^= path[i][j]; + } + return res; +} + + + + +static +void kernel_floyd_warshall(int n, + int path[ 60 + 0][60 + 0]) +{ + int i, j, k; + int ONE = 1; + +#pragma scop + for (k = 0; k < n; plus(k)) + { + for(i = 0; i < n; plus(i)) + for (j = 0; j < n; plus(j)) + path[i][j] = path[i][j] < path[i][k] + path[k][j] ? + path[i][j] : path[i][k] + path[k][j]; + } +#pragma endscop + +} + + +int main() +{ + + int n = 60; + + + int path[60 + 0][60 + 0]; + + init_array (n, path); + + kernel_floyd_warshall (n, path); + + return print_array(n, path); + + return 0; +} diff --git a/benchmarks/polybench-syn/medley/nussinov.c b/benchmarks/polybench-syn/medley/nussinov.c new file mode 100644 index 0000000..fd33ec4 --- /dev/null +++ b/benchmarks/polybench-syn/medley/nussinov.c @@ -0,0 +1,104 @@ +/** + * This version is stamped on May 10, 2016 + * + * Contact: + * Louis-Noel Pouchet + * Tomofumi Yuki + * + * Web address: http://polybench.sourceforge.net + */ +/* nussinov.c: this file is part of PolyBench/C */ + +typedef int base; + +#define plus(i) i = i + ONE +static +void init_array (int n, + base seq[ 60 + 0], + int table[ 60 + 0][60 + 0]) +{ + int i, j; + int ONE = 1; + + + for (i=0; i = 0; i=i-ONE) { + for (j=i+ONE; j=0) + table[i][j] = ((table[i][j] >= table[i][j-ONE]) ? table[i][j] : table[i][j-ONE]); + if (i+ONE= table[i+ONE][j]) ? table[i][j] : table[i+ONE][j]); + + if (j-ONE>=0 && i+ONE= table[i+ONE][j-ONE]+(((seq[i])+(seq[j])) == THREE ? ONE : 0)) ? table[i][j] : table[i+ONE][j-ONE]+(((seq[i])+(seq[j])) == THREE ? ONE : 0)); + else + table[i][j] = ((table[i][j] >= table[i+ONE][j-ONE]) ? table[i][j] : table[i+ONE][j-ONE]); + } + + for (k=i+ONE; k= table[i][k] + table[k+ONE][j]) ? table[i][j] : table[i][k] + table[k+ONE][j]); + } + } + } +#pragma endscop + +} + + +int main() +{ + + int n = 60; + + + base (seq)[60 + 0]; + int (table)[60 + 0][60 + 0]; + + + init_array (n, seq, table); + + kernel_nussinov (n, seq, table); + + return print_array(n, table); + +} -- cgit From c0be24c8e577d54c11f8cf06512a14a7583a9bb1 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Sat, 4 Jul 2020 14:25:27 +0100 Subject: shift bug --- benchmarks/polybench-syn/stencils/jacobi-2d.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/benchmarks/polybench-syn/stencils/jacobi-2d.c b/benchmarks/polybench-syn/stencils/jacobi-2d.c index 758a83a..3a5b43c 100644 --- a/benchmarks/polybench-syn/stencils/jacobi-2d.c +++ b/benchmarks/polybench-syn/stencils/jacobi-2d.c @@ -59,6 +59,7 @@ void kernel_jacobi_2d(int tsteps, { int t, i, j; int ONE = 1; + int TWO = 2; #pragma scop for (t = 0; t < tsteps; plus(t)) @@ -66,12 +67,12 @@ void kernel_jacobi_2d(int tsteps, for (i = 1; i < n - ONE; plus(i)) for (j = 1; j < n - ONE; plus(j)){ B[i][j] = (A[i][j] + A[i][j-ONE] + A[i][ONE+j] + A[ONE+i][j] + A[i-ONE][j]); - B[i][j] = B[i][j] >> 2; + B[i][j] = B[i][j] >> TWO; } for (i = 1; i < n - ONE; plus(i)) for (j = 1; j < n - ONE; plus(j)){ A[i][j] = (B[i][j] + B[i][j-ONE] + B[i][ONE+j] + B[ONE+i][j] + B[i-ONE][j]); - A[i][j] = A[i][j] >> 2; + A[i][j] = A[i][j] >> TWO; } } #pragma endscop @@ -83,7 +84,7 @@ int main() { int n = 30; - int tsteps = 20; + int tsteps = 5; int A[30 + 0][30 + 0]; -- cgit From ec97745e4675b72cbabd2a3bd12d6efdd8bfa6d6 Mon Sep 17 00:00:00 2001 From: James Pollard Date: Mon, 6 Jul 2020 15:33:04 +0100 Subject: Implemented algorithm for new byte-addressed stack. --- src/common/Coquplib.v | 2 + src/common/IntegerExtra.v | 36 +- src/common/Monad.v | 4 + src/extraction/Extraction.v | 4 +- src/translation/HTLgen.v | 88 +- src/translation/HTLgenproof.v | 4311 +++++++++++++++++++++-------------------- src/translation/HTLgenspec.v | 918 ++++----- src/verilog/PrintHTL.ml | 2 +- src/verilog/PrintVerilog.ml | 10 +- src/verilog/PrintVerilog.mli | 4 +- src/verilog/Verilog.v | 33 +- 11 files changed, 2730 insertions(+), 2682 deletions(-) diff --git a/src/common/Coquplib.v b/src/common/Coquplib.v index 2295ff6..469eddc 100644 --- a/src/common/Coquplib.v +++ b/src/common/Coquplib.v @@ -235,3 +235,5 @@ Definition debug_show {A B : Type} `{Show A} (a : A) (b : B) : B := Definition debug_show_msg {A B : Type} `{Show A} (s : string) (a : A) (b : B) : B := let unused := debug_print (s ++ show a) in b. + +Notation "f $ x" := (f x) (at level 60, right associativity, only parsing). diff --git a/src/common/IntegerExtra.v b/src/common/IntegerExtra.v index fe7d94f..8e32c2c 100644 --- a/src/common/IntegerExtra.v +++ b/src/common/IntegerExtra.v @@ -298,44 +298,48 @@ Module IntExtra. (or (shl (repr (Byte.unsigned c)) (repr Byte.zwordsize)) (repr (Byte.unsigned d)))). - Definition byte1 (n: int) : byte := Byte.repr (unsigned n). + Definition byte0 (n: int) : byte := Byte.repr $ unsigned n. + Definition ibyte0 (n: int) : int := Int.repr $ Byte.unsigned $ byte0 n. - Definition byte2 (n: int) : byte := Byte.repr (unsigned (shru n (repr Byte.zwordsize))). + Definition byte1 (n: int) : byte := Byte.repr $ unsigned $ shru n $ repr Byte.zwordsize. + Definition ibyte1 (n: int) : int := Int.repr $ Byte.unsigned $ byte1 n. - Definition byte3 (n: int) : byte := Byte.repr (unsigned (shru n (repr (2 * Byte.zwordsize)))). + Definition byte2 (n: int) : byte := Byte.repr $ unsigned $ shru n $ repr (2 * Byte.zwordsize). + Definition ibyte2 (n: int) : int := Int.repr $ Byte.unsigned $ byte2 n. - Definition byte4 (n: int) : byte := Byte.repr (unsigned (shru n (repr (3 * Byte.zwordsize)))). + Definition byte3 (n: int) : byte := Byte.repr $ unsigned $ shru n $ repr (3 * Byte.zwordsize). + Definition ibyte3 (n: int) : int := Int.repr $ Byte.unsigned $ byte3 n. - Lemma bits_byte1: - forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte1 n) i = testbit n i. + Lemma bits_byte0: + forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte0 n) i = testbit n i. Proof. - intros. unfold byte1. rewrite Byte.testbit_repr; auto. + intros. unfold byte0. rewrite Byte.testbit_repr; auto. Qed. - Lemma bits_byte2: - forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte2 n) i = testbit n (i + Byte.zwordsize). + Lemma bits_byte1: + forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte1 n) i = testbit n (i + Byte.zwordsize). Proof. - intros. unfold byte2. rewrite Byte.testbit_repr; auto. + intros. unfold byte1. rewrite Byte.testbit_repr; auto. assert (zwordsize = 4 * Byte.zwordsize) by reflexivity. fold (testbit (shru n (repr Byte.zwordsize)) i). rewrite bits_shru. change (unsigned (repr Byte.zwordsize)) with Byte.zwordsize. apply zlt_true. omega. omega. Qed. - Lemma bits_byte3: - forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte3 n) i = testbit n (i + (2 * Byte.zwordsize)). + Lemma bits_byte2: + forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte2 n) i = testbit n (i + (2 * Byte.zwordsize)). Proof. - intros. unfold byte3. rewrite Byte.testbit_repr; auto. + intros. unfold byte2. rewrite Byte.testbit_repr; auto. assert (zwordsize = 4 * Byte.zwordsize) by reflexivity. fold (testbit (shru n (repr (2 * Byte.zwordsize))) i). rewrite bits_shru. change (unsigned (repr (2 * Byte.zwordsize))) with (2 * Byte.zwordsize). apply zlt_true. omega. omega. Qed. - Lemma bits_byte4: - forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte4 n) i = testbit n (i + (3 * Byte.zwordsize)). + Lemma bits_byte3: + forall n i, 0 <= i < Byte.zwordsize -> Byte.testbit (byte3 n) i = testbit n (i + (3 * Byte.zwordsize)). Proof. - intros. unfold byte4. rewrite Byte.testbit_repr; auto. + intros. unfold byte3. rewrite Byte.testbit_repr; auto. assert (zwordsize = 4 * Byte.zwordsize) by reflexivity. fold (testbit (shru n (repr (3 * Byte.zwordsize))) i). rewrite bits_shru. change (unsigned (repr (3 * Byte.zwordsize))) with (3 * Byte.zwordsize). diff --git a/src/common/Monad.v b/src/common/Monad.v index 8517186..628963e 100644 --- a/src/common/Monad.v +++ b/src/common/Monad.v @@ -20,6 +20,10 @@ Module MonadExtra(M : Monad). Module MonadNotation. + Notation "A ; B" := + (bind A (fun _ => B)) + (at level 200, B at level 200). + Notation "'do' X <- A ; B" := (bind A (fun X => B)) (at level 200, X ident, A at level 100, B at level 200). diff --git a/src/extraction/Extraction.v b/src/extraction/Extraction.v index df21dc4..5d10cd7 100644 --- a/src/extraction/Extraction.v +++ b/src/extraction/Extraction.v @@ -16,7 +16,7 @@ * along with this program. If not, see . *) -From coqup Require Verilog Value Compiler. +From coqup Require Verilog ValueInt Compiler. From Coq Require DecidableClass. @@ -167,7 +167,7 @@ Set Extraction AccessOpaque. Cd "src/extraction". Separate Extraction - Verilog.module Value.uvalueToZ coqup.Compiler.transf_hls + Verilog.module ValueInt.uvalueToZ coqup.Compiler.transf_hls Compiler.transf_c_program Compiler.transf_cminor_program Cexec.do_initial_state Cexec.do_step Cexec.at_final_state diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index e02d759..995977c 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -292,26 +292,16 @@ Definition check_address_parameter_unsigned (p : Z) : bool := Definition translate_eff_addressing (a: Op.addressing) (args: list reg) : mon expr := match a, args with (* TODO: We should be more methodical here; what are the possibilities?*) | Op.Aindexed off, r1::nil => - if (check_address_parameter_signed off) - then ret (boplitz Vadd r1 off) - else error (Errors.msg "Veriloggen: translate_eff_addressing (Aindexed): address misaligned") + ret (boplitz Vadd r1 off) | Op.Ascaled scale offset, r1::nil => - if (check_address_parameter_signed scale) && (check_address_parameter_signed offset) - then ret (Vbinop Vadd (boplitz Vmul r1 scale) (Vlit (ZToValue offset))) - else error (Errors.msg "Veriloggen: translate_eff_addressing (Ascaled): address misaligned") + ret (Vbinop Vadd (boplitz Vmul r1 scale) (Vlit (ZToValue offset))) | Op.Aindexed2 offset, r1::r2::nil => - if (check_address_parameter_signed offset) - then ret (Vbinop Vadd (Vvar r1) (boplitz Vadd r2 offset)) - else error (Errors.msg "Veriloggen: translate_eff_addressing (Aindexed2): address misaligned") + ret (Vbinop Vadd (Vvar r1) (boplitz Vadd r2 offset)) | Op.Aindexed2scaled scale offset, r1::r2::nil => (* Typical for dynamic array addressing *) - if (check_address_parameter_signed scale) && (check_address_parameter_signed offset) - then ret (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) - else error (Errors.msg "Veriloggen: translate_eff_addressing (Aindexed2scaled): address misaligned") + ret (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) | Op.Ainstack a, nil => (* We need to be sure that the base address is aligned *) let a := Integers.Ptrofs.unsigned a in - if (check_address_parameter_unsigned a) - then ret (Vlit (ZToValue a)) - else error (Errors.msg "Veriloggen: translate_eff_addressing (Ainstack): address misaligned") + ret (Vlit (ZToValue a)) | _, _ => error (Errors.msg "Veriloggen: translate_eff_addressing unsuported addressing") end. @@ -390,27 +380,27 @@ Definition add_branch_instr (e: expr) (n n1 n2: node) : mon unit := | _, _ => Error (Errors.msg "Htlgen: add_branch_instr") end. -Definition translate_arr_access (mem : AST.memory_chunk) (addr : Op.addressing) - (args : list reg) (stack : reg) : mon expr := - match mem, addr, args with (* TODO: We should be more methodical here; what are the possibilities?*) - | Mint32, Op.Aindexed off, r1::nil => - if (check_address_parameter_signed off) - then ret (Vvari stack (Vbinop Vdivu (boplitz Vadd r1 off) (Vlit (ZToValue 4)))) - else error (Errors.msg "HTLgen: translate_arr_access address misaligned") - | Mint32, Op.Aindexed2scaled scale offset, r1::r2::nil => (* Typical for dynamic array addressing *) - if (check_address_parameter_signed scale) && (check_address_parameter_signed offset) - then ret (Vvari stack - (Vbinop Vdivu - (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) - (Vlit (ZToValue 4)))) - else error (Errors.msg "HTLgen: translate_arr_access address misaligned") - | Mint32, Op.Ainstack a, nil => (* We need to be sure that the base address is aligned *) - let a := Integers.Ptrofs.unsigned a in - if (check_address_parameter_unsigned a) - then ret (Vvari stack (Vlit (ZToValue (a / 4)))) - else error (Errors.msg "HTLgen: eff_addressing misaligned stack offset") - | _, _, _ => error (Errors.msg "HTLgen: translate_arr_access unsuported addressing") - end. +(* Definition translate_arr_access (mem : AST.memory_chunk) (addr : Op.addressing) *) +(* (args : list reg) (stack : reg) : mon expr := *) +(* match mem, addr, args with (* TODO: We should be more methodical here; what are the possibilities?*) *) +(* | Mint32, Op.Aindexed off, r1::nil => *) +(* if (check_address_parameter_signed off) *) +(* then ret (Vvari stack (Vbinop Vdivu (boplitz Vadd r1 off) (Vlit (ZToValue 4)))) *) +(* else error (Errors.msg "HTLgen: translate_arr_access address misaligned") *) +(* | Mint32, Op.Aindexed2scaled scale offset, r1::r2::nil => (* Typical for dynamic array addressing *) *) +(* if (check_address_parameter_signed scale) && (check_address_parameter_signed offset) *) +(* then ret (Vvari stack *) +(* (Vbinop Vdivu *) +(* (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) *) +(* (Vlit (ZToValue 4)))) *) +(* else error (Errors.msg "HTLgen: translate_arr_access address misaligned") *) +(* | Mint32, Op.Ainstack a, nil => (* We need to be sure that the base address is aligned *) *) +(* let a := Integers.Ptrofs.unsigned a in *) +(* if (check_address_parameter_unsigned a) *) +(* then ret (Vvari stack (Vlit (ZToValue (a / 4)))) *) +(* else error (Errors.msg "HTLgen: eff_addressing misaligned stack offset") *) +(* | _, _, _ => error (Errors.msg "HTLgen: translate_arr_access unsuported addressing") *) +(* end. *) Fixpoint enumerate (i : nat) (ns : list node) {struct ns} : list (nat * node) := match ns with @@ -424,6 +414,22 @@ Definition tbl_to_case_expr (st : reg) (ns : list node) : list (expr * stmnt) := end) (enumerate 0 ns). +Definition add_single_cycle_load (n n' : node) (stack : reg) (addr : expr) (dst : reg) : mon unit := + let l0 := Vnonblock (Vvarb0 dst) (Vvari stack addr) in + let l1 := Vnonblock (Vvarb1 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 1)) in + let l2 := Vnonblock (Vvarb2 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) in + let l3 := Vnonblock (Vvarb3 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) in + let instr := Vseq l0 $ Vseq l1 $ Vseq l2 $ l3 + in add_instr n n' instr. + +Definition add_single_cycle_store (n n' : node) (stack : reg) (addr : expr) (src : reg) : mon unit := + let l0 := Vnonblock (Vvari stack addr) (Vvarb0 src) in + let l1 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 1)) (Vvarb1 src) in + let l2 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb2 src) in + let l3 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb3 src) in + let instr := Vseq l0 $ Vseq l1 $ Vseq l2 $ l3 + in add_instr n n' instr. + Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon unit := match ni with (n, i) => @@ -434,12 +440,12 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni do _ <- declare_reg None dst 32; add_instr n n' (nonblock dst instr) | Iload mem addr args dst n' => - do src <- translate_arr_access mem addr args stack; + do addr' <- translate_eff_addressing addr args; do _ <- declare_reg None dst 32; - add_instr n n' (nonblock dst src) + add_single_cycle_load n n' stack addr' dst | Istore mem addr args src n' => - do dst <- translate_arr_access mem addr args stack; - add_instr n n' (Vnonblock dst (Vvar src)) (* TODO: Could juse use add_instr? reg exists. *) + do addr' <- translate_eff_addressing addr args; + add_single_cycle_store n n' stack addr' src | Icall _ _ _ _ _ => error (Errors.msg "Calls are not implemented.") | Itailcall _ _ _ => error (Errors.msg "Tailcalls are not implemented.") | Ibuiltin _ _ _ _ => error (Errors.msg "Builtin functions not implemented.") @@ -543,7 +549,7 @@ Definition transf_module (f: function) : mon module := if stack_correct f.(fn_stacksize) then do fin <- create_reg (Some Voutput) 1; do rtrn <- create_reg (Some Voutput) 32; - do (stack, stack_len) <- create_arr None 32 (Z.to_nat (f.(fn_stacksize) / 4)); + do (stack, stack_len) <- create_arr None 8 (Z.to_nat f.(fn_stacksize)); do _ <- collectlist (transf_instr fin rtrn stack) (Maps.PTree.elements f.(RTL.fn_code)); do _ <- collectlist (fun r => declare_reg (Some Vinput) r 32) f.(RTL.fn_params); do start <- create_reg (Some Vinput) 1; diff --git a/src/translation/HTLgenproof.v b/src/translation/HTLgenproof.v index 305c14f..e404c82 100644 --- a/src/translation/HTLgenproof.v +++ b/src/translation/HTLgenproof.v @@ -31,2158 +31,2159 @@ Hint Resolve AssocMap.gso : htlproof. Hint Unfold find_assocmap AssocMapExt.get_default : htlproof. -Inductive match_assocmaps : RTL.function -> RTL.regset -> assocmap -> Prop := - match_assocmap : forall f rs am, - (forall r, Ple r (RTL.max_reg_function f) -> - val_value_lessdef (Registers.Regmap.get r rs) am#r) -> - match_assocmaps f rs am. -Hint Constructors match_assocmaps : htlproof. - -Definition state_st_wf (m : HTL.module) (s : HTL.state) := - forall st asa asr res, - s = HTL.State res m st asa asr -> - asa!(m.(HTL.mod_st)) = Some (posToValue st). -Hint Unfold state_st_wf : htlproof. - -Inductive match_arrs (m : HTL.module) (f : RTL.function) (sp : Values.val) (mem : mem) : - Verilog.assocmap_arr -> Prop := -| match_arr : forall asa stack, - asa ! (m.(HTL.mod_stk)) = Some stack /\ - stack.(arr_length) = Z.to_nat (f.(RTL.fn_stacksize) / 4) /\ - (forall ptr, - 0 <= ptr < Z.of_nat m.(HTL.mod_stk_len) -> - opt_val_value_lessdef (Mem.loadv AST.Mint32 mem - (Values.Val.offset_ptr sp (Integers.Ptrofs.repr (4 * ptr)))) - (Option.default (NToValue 0) - (Option.join (array_get_error (Z.to_nat ptr) stack)))) -> - match_arrs m f sp mem asa. - -Definition stack_based (v : Values.val) (sp : Values.block) : Prop := - match v with - | Values.Vptr sp' off => sp' = sp - | _ => True - end. - -Definition reg_stack_based_pointers (sp : Values.block) (rs : Registers.Regmap.t Values.val) : Prop := - forall r, stack_based (Registers.Regmap.get r rs) sp. - -Definition arr_stack_based_pointers (spb : Values.block) (m : mem) (stack_length : Z) - (sp : Values.val) : Prop := - forall ptr, - 0 <= ptr < (stack_length / 4) -> - stack_based (Option.default - Values.Vundef - (Mem.loadv AST.Mint32 m - (Values.Val.offset_ptr sp (Integers.Ptrofs.repr (4 * ptr))))) - spb. - -Definition stack_bounds (sp : Values.val) (hi : Z) (m : mem) : Prop := - forall ptr v, - hi <= ptr <= Integers.Ptrofs.max_unsigned -> - Z.modulo ptr 4 = 0 -> - Mem.loadv AST.Mint32 m (Values.Val.offset_ptr sp (Integers.Ptrofs.repr ptr )) = None /\ - Mem.storev AST.Mint32 m (Values.Val.offset_ptr sp (Integers.Ptrofs.repr ptr )) v = None. - -Inductive match_frames : list RTL.stackframe -> list HTL.stackframe -> Prop := -| match_frames_nil : - match_frames nil nil. - - Lemma assumption_32bit : - forall v, - valueToPos (posToValue v) = v. - Proof. - Admitted. - -Inductive match_states : RTL.state -> HTL.state -> Prop := -| match_state : forall asa asr sf f sp sp' rs mem m st res - (MASSOC : match_assocmaps f rs asr) - (TF : tr_module f m) - (WF : state_st_wf m (HTL.State res m st asr asa)) - (MF : match_frames sf res) - (MARR : match_arrs m f sp mem asa) - (SP : sp = Values.Vptr sp' (Integers.Ptrofs.repr 0)) - (RSBP : reg_stack_based_pointers sp' rs) - (ASBP : arr_stack_based_pointers sp' mem (f.(RTL.fn_stacksize)) sp) - (BOUNDS : stack_bounds sp (f.(RTL.fn_stacksize)) mem), - match_states (RTL.State sf f sp st rs mem) - (HTL.State res m st asr asa) -| match_returnstate : - forall - v v' stack mem res - (MF : match_frames stack res), - val_value_lessdef v v' -> - match_states (RTL.Returnstate stack v mem) (HTL.Returnstate res v') -| match_initial_call : - forall f m m0 - (TF : tr_module f m), - match_states (RTL.Callstate nil (AST.Internal f) nil m0) (HTL.Callstate nil m nil). -Hint Constructors match_states : htlproof. - -Definition match_prog (p: RTL.program) (tp: HTL.program) := - Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq p tp /\ - main_is_internal p = true. - -Definition match_prog_matches : - forall p tp, - match_prog p tp -> - Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq p tp. - Proof. intros. unfold match_prog in H. tauto. Qed. - -Lemma transf_program_match: - forall p tp, HTLgen.transl_program p = Errors.OK tp -> match_prog p tp. -Proof. - intros. unfold transl_program in H. - destruct (main_is_internal p) eqn:?; try discriminate. - unfold match_prog. split. - apply Linking.match_transform_partial_program; auto. - assumption. -Qed. - -Lemma regs_lessdef_add_greater : - forall f rs1 rs2 n v, - Plt (RTL.max_reg_function f) n -> - match_assocmaps f rs1 rs2 -> - match_assocmaps f rs1 (AssocMap.set n v rs2). -Proof. - inversion 2; subst. - intros. constructor. - intros. unfold find_assocmap. unfold AssocMapExt.get_default. - rewrite AssocMap.gso. eauto. - apply Pos.le_lt_trans with _ _ n in H2. - unfold not. intros. subst. eapply Pos.lt_irrefl. eassumption. assumption. -Qed. -Hint Resolve regs_lessdef_add_greater : htlproof. - -Lemma regs_lessdef_add_match : - forall f rs am r v v', - val_value_lessdef v v' -> - match_assocmaps f rs am -> - match_assocmaps f (Registers.Regmap.set r v rs) (AssocMap.set r v' am). -Proof. - inversion 2; subst. - constructor. intros. - destruct (peq r0 r); subst. - rewrite Registers.Regmap.gss. - unfold find_assocmap. unfold AssocMapExt.get_default. - rewrite AssocMap.gss. assumption. - - rewrite Registers.Regmap.gso; try assumption. - unfold find_assocmap. unfold AssocMapExt.get_default. - rewrite AssocMap.gso; eauto. -Qed. -Hint Resolve regs_lessdef_add_match : htlproof. - -Lemma list_combine_none : - forall n l, - length l = n -> - list_combine Verilog.merge_cell (list_repeat None n) l = l. -Proof. - induction n; intros; crush. - - symmetry. apply length_zero_iff_nil. auto. - - destruct l; crush. - rewrite list_repeat_cons. - crush. f_equal. - eauto. -Qed. - -Lemma combine_none : - forall n a, - a.(arr_length) = n -> - arr_contents (combine Verilog.merge_cell (arr_repeat None n) a) = arr_contents a. -Proof. - intros. - unfold combine. - crush. - - rewrite <- (arr_wf a) in H. - apply list_combine_none. - assumption. -Qed. - -Lemma list_combine_lookup_first : - forall l1 l2 n, - length l1 = length l2 -> - nth_error l1 n = Some None -> - nth_error (list_combine Verilog.merge_cell l1 l2) n = nth_error l2 n. -Proof. - induction l1; intros; crush. - - rewrite nth_error_nil in H0. - discriminate. - - destruct l2 eqn:EQl2. crush. - simpl in H. invert H. - destruct n; simpl in *. - invert H0. simpl. reflexivity. - eauto. -Qed. - -Lemma combine_lookup_first : - forall a1 a2 n, - a1.(arr_length) = a2.(arr_length) -> - array_get_error n a1 = Some None -> - array_get_error n (combine Verilog.merge_cell a1 a2) = array_get_error n a2. -Proof. - intros. - - unfold array_get_error in *. - apply list_combine_lookup_first; eauto. - rewrite a1.(arr_wf). rewrite a2.(arr_wf). - assumption. -Qed. - -Lemma list_combine_lookup_second : - forall l1 l2 n x, - length l1 = length l2 -> - nth_error l1 n = Some (Some x) -> - nth_error (list_combine Verilog.merge_cell l1 l2) n = Some (Some x). -Proof. - induction l1; intros; crush; auto. - - destruct l2 eqn:EQl2. crush. - simpl in H. invert H. - destruct n; simpl in *. - invert H0. simpl. reflexivity. - eauto. -Qed. - -Lemma combine_lookup_second : - forall a1 a2 n x, - a1.(arr_length) = a2.(arr_length) -> - array_get_error n a1 = Some (Some x) -> - array_get_error n (combine Verilog.merge_cell a1 a2) = Some (Some x). -Proof. - intros. - - unfold array_get_error in *. - apply list_combine_lookup_second; eauto. - rewrite a1.(arr_wf). rewrite a2.(arr_wf). - assumption. -Qed. - -Ltac inv_state := - match goal with - MSTATE : match_states _ _ |- _ => - inversion MSTATE; - match goal with - TF : tr_module _ _ |- _ => - inversion TF; - match goal with - TC : forall _ _, - Maps.PTree.get _ _ = Some _ -> tr_code _ _ _ _ _ _ _ _ _, - H : Maps.PTree.get _ _ = Some _ |- _ => - apply TC in H; inversion H; - match goal with - TI : context[tr_instr] |- _ => - inversion TI - end - end - end -end; subst. - -Ltac unfold_func H := - match type of H with - | ?f = _ => unfold f in H; repeat (unfold_match H) - | ?f _ = _ => unfold f in H; repeat (unfold_match H) - | ?f _ _ = _ => unfold f in H; repeat (unfold_match H) - | ?f _ _ _ = _ => unfold f in H; repeat (unfold_match H) - | ?f _ _ _ _ = _ => unfold f in H; repeat (unfold_match H) - end. - -Lemma init_reg_assoc_empty : - forall f l, - match_assocmaps f (RTL.init_regs nil l) (HTL.init_regs nil l). -Proof. - induction l; simpl; constructor; intros. - - rewrite Registers.Regmap.gi. unfold find_assocmap. - unfold AssocMapExt.get_default. rewrite AssocMap.gempty. - constructor. - - - rewrite Registers.Regmap.gi. unfold find_assocmap. - unfold AssocMapExt.get_default. rewrite AssocMap.gempty. - constructor. -Qed. - -Lemma arr_lookup_some: - forall (z : Z) (r0 : Registers.reg) (r : Verilog.reg) (asr : assocmap) (asa : Verilog.assocmap_arr) - (stack : Array (option value)) (H5 : asa ! r = Some stack) n, - exists x, Verilog.arr_assocmap_lookup asa r n = Some x. -Proof. - intros z r0 r asr asa stack H5 n. - eexists. - unfold Verilog.arr_assocmap_lookup. rewrite H5. reflexivity. -Qed. -Hint Resolve arr_lookup_some : htlproof. - -Section CORRECTNESS. - - Variable prog : RTL.program. - Variable tprog : HTL.program. - - Hypothesis TRANSL : match_prog prog tprog. - - Lemma TRANSL' : - Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq prog tprog. - Proof. intros; apply match_prog_matches; assumption. Qed. - - Let ge : RTL.genv := Globalenvs.Genv.globalenv prog. - Let tge : HTL.genv := Globalenvs.Genv.globalenv tprog. - - Lemma symbols_preserved: - forall (s: AST.ident), Genv.find_symbol tge s = Genv.find_symbol ge s. - Proof. intros. eapply (Genv.find_symbol_match TRANSL'). Qed. - - Lemma function_ptr_translated: - forall (b: Values.block) (f: RTL.fundef), - Genv.find_funct_ptr ge b = Some f -> - exists tf, - Genv.find_funct_ptr tge b = Some tf /\ transl_fundef f = Errors.OK tf. - Proof. - intros. exploit (Genv.find_funct_ptr_match TRANSL'); eauto. - intros (cu & tf & P & Q & R); exists tf; auto. - Qed. - - Lemma functions_translated: - forall (v: Values.val) (f: RTL.fundef), - Genv.find_funct ge v = Some f -> - exists tf, - Genv.find_funct tge v = Some tf /\ transl_fundef f = Errors.OK tf. - Proof. - intros. exploit (Genv.find_funct_match TRANSL'); eauto. - intros (cu & tf & P & Q & R); exists tf; auto. - Qed. - - Lemma senv_preserved: - Senv.equiv (Genv.to_senv ge) (Genv.to_senv tge). - Proof - (Genv.senv_transf_partial TRANSL'). - Hint Resolve senv_preserved : htlproof. - - Lemma ptrofs_inj : - forall a b, - Ptrofs.unsigned a = Ptrofs.unsigned b -> a = b. - Proof. - intros. rewrite <- Ptrofs.repr_unsigned. symmetry. rewrite <- Ptrofs.repr_unsigned. - rewrite H. auto. - Qed. - - Lemma eval_correct : - forall s sp op rs m v e asr asa f f' stk s' i pc res0 pc' args res ml st, - match_states (RTL.State stk f sp pc rs m) (HTL.State res ml st asr asa) -> - (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> - Op.eval_operation ge sp op - (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) m = Some v -> - translate_instr op args s = OK e s' i -> - exists v', Verilog.expr_runp f' asr asa e v' /\ val_value_lessdef v v'. - Proof. - intros s sp op rs m v e asr asa f f' stk s' i pc pc' res0 args res ml st MSTATE INSTR EVAL TR_INSTR. - inv MSTATE. inv MASSOC. unfold translate_instr in TR_INSTR; repeat (unfold_match TR_INSTR); inv TR_INSTR; - unfold Op.eval_operation in EVAL; repeat (unfold_match EVAL); simplify. - - inv Heql. - assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H in HPle. eexists. split; try constructor; eauto. - - eexists. split. constructor. constructor. auto. - - inv Heql. - assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H in HPle. - eexists. split. econstructor; eauto. constructor. trivial. - unfold Verilog.unop_run. unfold Values.Val.neg. destruct (Registers.Regmap.get r rs) eqn:?; constructor. - inv HPle. auto. - - inv Heql. - assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - assert (HPle0 : Ple r0 (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H in HPle. apply H in HPle0. - eexists. split. econstructor; eauto. constructor. trivial. - constructor. trivial. simplify. inv HPle. inv HPle0; constructor; auto. - + inv HPle0. constructor. unfold valueToPtr. Search Integers.Ptrofs.sub Integers.int. - pose proof Integers.Ptrofs.agree32_sub. unfold Integers.Ptrofs.agree32 in H3. - Print Integers.Ptrofs.agree32. unfold Ptrofs.of_int. simpl. - apply ptrofs_inj. assert (Archi.ptr64 = false) by auto. eapply H3 in H4. - rewrite Ptrofs.unsigned_repr. apply H4. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - apply Int.unsigned_range_2. - auto. rewrite Ptrofs.unsigned_repr. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - apply Int.unsigned_range_2. rewrite Ptrofs.unsigned_repr. auto. - replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - apply Int.unsigned_range_2. - Admitted. - - Lemma eval_cond_correct : - forall cond (args : list Registers.reg) s1 c s' i rs args m b f asr asa, - translate_condition cond args s1 = OK c s' i -> - Op.eval_condition - cond - (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) - m = Some b -> - Verilog.expr_runp f asr asa c (boolToValue b). - Admitted. - - (** The proof of semantic preservation for the translation of instructions - is a simulation argument based on diagrams of the following form: -<< - match_states - code st rs ---------------- State m st assoc - || | - || | - || | - \/ v - code st rs' --------------- State m st assoc' - match_states ->> - where [tr_code c data control fin rtrn st] is assumed to hold. - - The precondition and postcondition is that that should hold is [match_assocmaps rs assoc]. - *) - - Definition transl_instr_prop (instr : RTL.instruction) : Prop := - forall m asr asa fin rtrn st stmt trans res, - tr_instr fin rtrn st (m.(HTL.mod_stk)) instr stmt trans -> - exists asr' asa', - HTL.step tge (HTL.State res m st asr asa) Events.E0 (HTL.State res m st asr' asa'). - - Opaque combine. - - Ltac tac0 := - match goal with - | [ |- context[valueToPos (posToValue _)] ] => rewrite assumption_32bit - - | [ |- context[Verilog.merge_arrs _ _] ] => unfold Verilog.merge_arrs - | [ |- context[Verilog.merge_arr] ] => unfold Verilog.merge_arr - | [ |- context[Verilog.merge_regs _ _] ] => unfold Verilog.merge_regs; crush; unfold_merge - | [ |- context[reg_stack_based_pointers] ] => unfold reg_stack_based_pointers; intros - | [ |- context[Verilog.arr_assocmap_set _ _ _ _] ] => unfold Verilog.arr_assocmap_set - - | [ |- context[HTL.empty_stack] ] => unfold HTL.empty_stack - - | [ |- context[_ # ?d <- _ ! ?d] ] => rewrite AssocMap.gss - | [ |- context[_ # ?d <- _ ! ?s] ] => rewrite AssocMap.gso - | [ |- context[(AssocMap.empty _) ! _] ] => rewrite AssocMap.gempty - - | [ |- context[array_get_error _ (combine Verilog.merge_cell (arr_repeat None _) _)] ] => - rewrite combine_lookup_first - - | [ |- state_st_wf _ _ ] => unfold state_st_wf; inversion 1 - | [ |- context[match_states _ _] ] => econstructor; auto - | [ |- match_arrs _ _ _ _ _ ] => econstructor; auto - | [ |- match_assocmaps _ _ _ # _ <- (posToValue _) ] => - apply regs_lessdef_add_greater; [> unfold Plt; lia | assumption] - - | [ H : ?asa ! ?r = Some _ |- Verilog.arr_assocmap_lookup ?asa ?r _ = Some _ ] => - unfold Verilog.arr_assocmap_lookup; setoid_rewrite H; f_equal - | [ |- context[(AssocMap.combine _ _ _) ! _] ] => - try (rewrite AssocMap.gcombine; [> | reflexivity]) - - | [ |- context[Registers.Regmap.get ?d (Registers.Regmap.set ?d _ _)] ] => - rewrite Registers.Regmap.gss - | [ |- context[Registers.Regmap.get ?s (Registers.Regmap.set ?d _ _)] ] => - destruct (Pos.eq_dec s d) as [EQ|EQ]; - [> rewrite EQ | rewrite Registers.Regmap.gso; auto] - - | [ H : opt_val_value_lessdef _ _ |- _ ] => invert H - | [ H : context[Z.of_nat (Z.to_nat _)] |- _ ] => rewrite Z2Nat.id in H; [> solve crush |] - | [ H : _ ! _ = Some _ |- _] => setoid_rewrite H - end. - - Ltac small_tac := repeat (crush; try array; try ptrofs); crush; auto. - Ltac big_tac := repeat (crush; try array; try ptrofs; try tac0); crush; auto. - - Lemma transl_inop_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : RTL.regset) (m : mem) (pc' : RTL.node), - (RTL.fn_code f) ! pc = Some (RTL.Inop pc') -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. - Proof. - intros s f sp pc rs m pc' H R1 MSTATE. - inv_state. - - unfold match_prog in TRANSL. - econstructor. - split. - apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - apply assumption_32bit. - (* processing of state *) - econstructor. - crush. - econstructor. - econstructor. - econstructor. - - all: invert MARR; big_tac. - Unshelve. - constructor. - Qed. - Hint Resolve transl_inop_correct : htlproof. - - Lemma transl_iop_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (op : Op.operation) (args : list Registers.reg) - (res0 : Registers.reg) (pc' : RTL.node) (v : Values.val), - (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> - Op.eval_operation ge sp op (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some v -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.State s f sp pc' (Registers.Regmap.set res0 v rs) m) R2. - Proof. - intros s f sp pc rs m op args res0 pc' v H H0 R1 MSTATE. - inv_state. - exploit eval_correct; eauto. intros. inversion H1. inversion H2. - econstructor. split. - apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - apply assumption_32bit. - econstructor; simpl; trivial. - constructor; trivial. - econstructor; simpl; eauto. - simpl. econstructor. econstructor. - apply H3. simplify. - - all: big_tac. - - assert (Ple res0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_def; eauto; simpl; auto). - - unfold Ple in H10. lia. - apply regs_lessdef_add_match. assumption. - apply regs_lessdef_add_greater. unfold Plt; lia. assumption. - assert (Ple res0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_def; eauto; simpl; auto). - unfold Ple in H12; lia. - unfold_merge. simpl. - rewrite AssocMap.gso. - apply AssocMap.gss. - apply st_greater_than_res. - - (*match_states*) - assert (pc' = valueToPos (posToValue 32 pc')). auto using assumption_32bit. - rewrite <- H1. - constructor; auto. - unfold_merge. - apply regs_lessdef_add_match. - constructor. - apply regs_lessdef_add_greater. - apply greater_than_max_func. - assumption. - - unfold state_st_wf. intros. inversion H2. subst. - unfold_merge. - rewrite AssocMap.gso. - apply AssocMap.gss. - apply st_greater_than_res. - - + econstructor. split. - apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - econstructor; simpl; trivial. - constructor; trivial. - econstructor; simpl; eauto. - eapply eval_correct; eauto. - constructor. rewrite valueToInt_intToValue. trivial. - unfold_merge. simpl. - rewrite AssocMap.gso. - apply AssocMap.gss. - apply st_greater_than_res. - - match_states - assert (pc' = valueToPos (posToValue 32 pc')). auto using assumption_32bit. - rewrite <- H1. - constructor. - unfold_merge. - apply regs_lessdef_add_match. - constructor. - symmetry. apply valueToInt_intToValue. - apply regs_lessdef_add_greater. - apply greater_than_max_func. - assumption. assumption. - - unfold state_st_wf. intros. inversion H2. subst. - unfold_merge. - rewrite AssocMap.gso. - apply AssocMap.gss. - apply st_greater_than_res. - assumption. - Admitted. - Hint Resolve transl_iop_correct : htlproof. - - Ltac tac := - repeat match goal with - | [ _ : error _ _ = OK _ _ _ |- _ ] => discriminate - | [ _ : context[if (?x && ?y) then _ else _] |- _ ] => - let EQ1 := fresh "EQ" in - let EQ2 := fresh "EQ" in - destruct x eqn:EQ1; destruct y eqn:EQ2; simpl in * - | [ _ : context[if ?x then _ else _] |- _ ] => - let EQ := fresh "EQ" in - destruct x eqn:EQ; simpl in * - | [ H : ret _ _ = _ |- _ ] => invert H - | [ _ : context[match ?x with | _ => _ end] |- _ ] => destruct x - end. - - Ltac inv_arr_access := - match goal with - | [ _ : translate_arr_access ?chunk ?addr ?args _ _ = OK ?c _ _ |- _] => - destruct c, chunk, addr, args; crush; tac; crush - end. - - Lemma transl_iload_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) - (addr : Op.addressing) (args : list Registers.reg) (dst : Registers.reg) - (pc' : RTL.node) (a v : Values.val), - (RTL.fn_code f) ! pc = Some (RTL.Iload chunk addr args dst pc') -> - Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> - Mem.loadv chunk m a = Some v -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.State s f sp pc' (Registers.Regmap.set dst v rs) m) R2. - Proof. - intros s f sp pc rs m chunk addr args dst pc' a v H H0 H1 R1 MSTATE. - inv_state. inv_arr_access. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. - - rewrite ARCHI in H1. crush. - subst. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - apply H6 in HPler0. - invert HPler0; try congruence. - rewrite EQr0 in H8. - invert H8. - clear H0. clear H6. - - unfold check_address_parameter_signed in *; - unfold check_address_parameter_unsigned in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Read bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - rewrite <- EXPR_OK. - - specialize (H7 (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4)))). - exploit H7; big_tac. - - (** RSBP preservation *) - unfold arr_stack_based_pointers in ASBP. - specialize (ASBP (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). - exploit ASBP; big_tac. - rewrite NORMALISE in H0. rewrite H1 in H0. assumption. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - pose proof (RSBP r1) as RSBPr1. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; - destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. - - rewrite ARCHI in H1. crush. - subst. - clear RSBPr1. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - pose proof (H0 r1). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - assert (HPler1 : Ple r1 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H6 in HPler0. - apply H8 in HPler1. - invert HPler0; invert HPler1; try congruence. - rewrite EQr0 in H9. - rewrite EQr1 in H11. - invert H9. invert H11. - clear H0. clear H6. clear H8. - - unfold check_address_parameter_signed in *; - unfold check_address_parameter_unsigned in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int - (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) - (Integers.Int.repr z0)))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush; try lia. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - apply IntExtra.add_mod; crush. - apply IntExtra.mul_mod2; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Read bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - rewrite <- EXPR_OK. - - specialize (H7 (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4)))). - exploit H7; big_tac. - - (** RSBP preservation *) - unfold arr_stack_based_pointers in ASBP. - specialize (ASBP (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). - exploit ASBP; big_tac. - rewrite NORMALISE in H0. rewrite H1 in H0. assumption. - - + invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - rewrite ARCHI in H0. crush. - - unfold check_address_parameter_unsigned in *; - unfold check_address_parameter_signed in *; crush. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - rewrite ZERO in H1. clear ZERO. - rewrite Integers.Ptrofs.add_zero_l in H1. - - remember i0 as OFFSET. - - (** Modular preservation proof *) - rename H0 into MOD_PRESERVE. - - (** Read bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - rewrite <- EXPR_OK. - - specialize (H7 (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4)))). - exploit H7; big_tac. - - (** RSBP preservation *) - unfold arr_stack_based_pointers in ASBP. - specialize (ASBP (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). - exploit ASBP; big_tac. - rewrite NORMALISE in H0. rewrite H1 in H0. assumption. - Admitted. - Hint Resolve transl_iload_correct : htlproof. - - Lemma transl_istore_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) - (addr : Op.addressing) (args : list Registers.reg) (src : Registers.reg) - (pc' : RTL.node) (a : Values.val) (m' : mem), - (RTL.fn_code f) ! pc = Some (RTL.Istore chunk addr args src pc') -> - Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> - Mem.storev chunk m a (Registers.Regmap.get src rs) = Some m' -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m') R2. - Proof. - intros s f sp pc rs m chunk addr args src pc' a m' H H0 H1 R1 MSTATES. - inv_state. inv_arr_access. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. - - rewrite ARCHI in H1. crush. - subst. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - apply H6 in HPler0. - invert HPler0; try congruence. - rewrite EQr0 in H8. - invert H8. - clear H0. clear H6. - - unfold check_address_parameter_unsigned in *; - unfold check_address_parameter_signed in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush; try lia. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Write bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - inversion MASSOC; revert HeqOFFSET; subst; clear MASSOC; intros HeqOFFSET. - - econstructor. - repeat split; crush. - unfold HTL.empty_stack. - crush. - unfold Verilog.merge_arrs. - - rewrite AssocMap.gcombine. - 2: { reflexivity. } - unfold Verilog.arr_assocmap_set. - rewrite AssocMap.gss. - unfold Verilog.merge_arr. - rewrite AssocMap.gss. - setoid_rewrite H5. - reflexivity. - - rewrite combine_length. - rewrite <- array_set_len. - unfold arr_repeat. crush. - apply list_repeat_len. - - rewrite <- array_set_len. - unfold arr_repeat. crush. - rewrite list_repeat_len. - rewrite H4. reflexivity. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. - - destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). - - erewrite Mem.load_store_same. - 2: { rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite e. - rewrite Integers.Ptrofs.unsigned_repr. - exact H1. - apply Integers.Ptrofs.unsigned_range_2. } - constructor. - erewrite combine_lookup_second. - simpl. - assert (Ple src (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - apply H0 in H13. - destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; constructor; invert H13; eauto. - - rewrite <- array_set_len. - unfold arr_repeat. crush. - rewrite list_repeat_len. auto. - - assert (4 * ptr / 4 = Integers.Ptrofs.unsigned OFFSET / 4) by (f_equal; assumption). - rewrite Z.mul_comm in H13. - rewrite Z_div_mult in H13; try lia. - replace 4 with (Integers.Ptrofs.unsigned (Integers.Ptrofs.repr 4)) in H13 by reflexivity. - rewrite <- PtrofsExtra.divu_unsigned in H13; unfold_constants; try lia. - rewrite H13. rewrite EXPR_OK. - rewrite array_get_error_set_bound. - reflexivity. - unfold arr_length, arr_repeat. simpl. - rewrite list_repeat_len. lia. - - erewrite Mem.load_store_other with (m1 := m). - 2: { exact H1. } - 2: { right. - rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite Integers.Ptrofs.unsigned_repr. - simpl. - destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. - right. - apply ZExtra.mod_0_bounds; try lia. - apply ZLib.Z_mod_mult'. - rewrite Z2Nat.id in H15; try lia. - apply Zmult_lt_compat_r with (p := 4) in H15; try lia. - rewrite ZLib.div_mul_undo in H15; try lia. - split; try lia. - apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. - } - - rewrite <- EXPR_OK. - rewrite PtrofsExtra.divu_unsigned; auto; try (unfold_constants; lia). - destruct (ptr ==Z Integers.Ptrofs.unsigned OFFSET / 4). - apply Z.mul_cancel_r with (p := 4) in e; try lia. - rewrite ZLib.div_mul_undo in e; try lia. - rewrite combine_lookup_first. - eapply H7; eauto. - - rewrite <- array_set_len. - unfold arr_repeat. crush. - rewrite list_repeat_len. auto. - rewrite array_gso. - unfold array_get_error. - unfold arr_repeat. - crush. - apply list_repeat_lookup. - lia. - unfold_constants. - intro. - apply Z2Nat.inj_iff in H13; try lia. - apply Z.div_pos; try lia. - apply Integers.Ptrofs.unsigned_range. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - unfold arr_stack_based_pointers. - intros. - destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). - - crush. - erewrite Mem.load_store_same. - 2: { rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite e. - rewrite Integers.Ptrofs.unsigned_repr. - exact H1. - apply Integers.Ptrofs.unsigned_range_2. } - crush. - destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; try constructor. - destruct (Archi.ptr64); try discriminate. - pose proof (RSBP src). rewrite EQ_SRC in H0. - assumption. - - simpl. - erewrite Mem.load_store_other with (m1 := m). - 2: { exact H1. } - 2: { right. - rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite Integers.Ptrofs.unsigned_repr. - simpl. - destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. - right. - apply ZExtra.mod_0_bounds; try lia. - apply ZLib.Z_mod_mult'. - invert H0. - apply Zmult_lt_compat_r with (p := 4) in H14; try lia. - rewrite ZLib.div_mul_undo in H14; try lia. - split; try lia. - apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. - } - apply ASBP; assumption. - - unfold stack_bounds in *. intros. - simpl. - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - erewrite Mem.load_store_other with (m1 := m). - 2: { exact H1. } - 2: { right. right. simpl. - rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite Integers.Ptrofs.unsigned_repr; crush; try lia. - apply ZExtra.mod_0_bounds; crush; try lia. } - crush. - exploit (BOUNDS ptr); try lia. intros. crush. - exploit (BOUNDS ptr v); try lia. intros. - invert H0. - match goal with | |- ?x = _ => destruct x eqn:EQ end; try reflexivity. - assert (Mem.valid_access m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) Writable). - { pose proof H1. eapply Mem.store_valid_access_2 in H0. - exact H0. eapply Mem.store_valid_access_3. eassumption. } - pose proof (Mem.valid_access_store m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) v). - apply X in H0. invert H0. congruence. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - pose proof (RSBP r1) as RSBPr1. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; - destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. - - rewrite ARCHI in H1. crush. - subst. - clear RSBPr1. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - pose proof (H0 r1). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - assert (HPler1 : Ple r1 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H6 in HPler0. - apply H8 in HPler1. - invert HPler0; invert HPler1; try congruence. - rewrite EQr0 in H9. - rewrite EQr1 in H11. - invert H9. invert H11. - clear H0. clear H6. clear H8. - - unfold check_address_parameter_signed in *; - unfold check_address_parameter_unsigned in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int - (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) - (Integers.Int.repr z0)))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush; try lia. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - apply IntExtra.add_mod; crush. - apply IntExtra.mul_mod2; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Write bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. - assert (Mem.valid_access m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) Writable). - { pose proof H1. eapply Mem.store_valid_access_2 in H0. - exact H0. eapply Mem.store_valid_access_3. eassumption. } - pose proof (Mem.valid_access_store m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) v). - apply X in H0. invert H0. congruence. - - + invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - rewrite ARCHI in H0. crush. - - unfold check_address_parameter_unsigned in *; - unfold check_address_parameter_signed in *; crush. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - rewrite ZERO in H1. clear ZERO. - rewrite Integers.Ptrofs.add_zero_l in H1. - - remember i0 as OFFSET. - - (** Modular preservation proof *) - rename H0 into MOD_PRESERVE. - - (** Write bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. - assert (Mem.valid_access m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) Writable). - { pose proof H1. eapply Mem.store_valid_access_2 in H0. - exact H0. eapply Mem.store_valid_access_3. eassumption. } - pose proof (Mem.valid_access_store m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) v). - apply X in H0. invert H0. congruence. - Admitted. - Hint Resolve transl_istore_correct : htlproof. - - Lemma transl_icond_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (cond : Op.condition) (args : list Registers.reg) - (ifso ifnot : RTL.node) (b : bool) (pc' : RTL.node), - (RTL.fn_code f) ! pc = Some (RTL.Icond cond args ifso ifnot) -> - Op.eval_condition cond (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some b -> - pc' = (if b then ifso else ifnot) -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. - Proof. - intros s f sp pc rs m cond args ifso ifnot b pc' H H0 H1 R1 MSTATE. - inv_state. - - eexists. split. apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - apply assumption_32bit. - eapply Verilog.stmnt_runp_Vnonblock_reg with - (rhsval := if b then posToValue 32 ifso else posToValue 32 ifnot). - constructor. - - simpl. - destruct b. - eapply Verilog.erun_Vternary_true. - eapply eval_cond_correct; eauto. - constructor. - apply boolToValue_ValueToBool. - eapply Verilog.erun_Vternary_false. - eapply eval_cond_correct; eauto. - constructor. - apply boolToValue_ValueToBool. - constructor. - - big_tac. - - invert MARR. - destruct b; rewrite assumption_32bit; big_tac. - - Unshelve. - constructor. - Qed. - Hint Resolve transl_icond_correct : htlproof. - - Lemma transl_ijumptable_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (arg : Registers.reg) (tbl : list RTL.node) - (n : Integers.Int.int) (pc' : RTL.node), - (RTL.fn_code f) ! pc = Some (RTL.Ijumptable arg tbl) -> - Registers.Regmap.get arg rs = Values.Vint n -> - list_nth_z tbl (Integers.Int.unsigned n) = Some pc' -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. - Proof. - intros s f sp pc rs m arg tbl n pc' H H0 H1 R1 MSTATE. - Admitted. - Hint Resolve transl_ijumptable_correct : htlproof. - - Lemma transl_ireturn_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (stk : Values.block) - (pc : positive) (rs : RTL.regset) (m : mem) (or : option Registers.reg) - (m' : mem), - (RTL.fn_code f) ! pc = Some (RTL.Ireturn or) -> - Mem.free m stk 0 (RTL.fn_stacksize f) = Some m' -> - forall R1 : HTL.state, - match_states (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.Returnstate s (Registers.regmap_optget or Values.Vundef rs) m') R2. - Proof. - intros s f stk pc rs m or m' H H0 R1 MSTATE. - inv_state. - - - econstructor. split. - eapply Smallstep.plus_two. - - eapply HTL.step_module; eauto. - apply assumption_32bit. - constructor. - econstructor; simpl; trivial. - econstructor; simpl; trivial. - constructor. - econstructor; simpl; trivial. - constructor. - - constructor. constructor. - - unfold state_st_wf in WF; big_tac; eauto. - - apply HTL.step_finish. - unfold Verilog.merge_regs. - unfold_merge; simpl. - rewrite AssocMap.gso. - apply AssocMap.gss. lia. - apply AssocMap.gss. - rewrite Events.E0_left. reflexivity. - - constructor; auto. - constructor. - - (* FIXME: Duplication *) - - econstructor. split. - eapply Smallstep.plus_two. - eapply HTL.step_module; eauto. - apply assumption_32bit. - constructor. - econstructor; simpl; trivial. - econstructor; simpl; trivial. - constructor. constructor. constructor. - constructor. constructor. constructor. - - unfold state_st_wf in WF; big_tac; eauto. - - apply HTL.step_finish. - unfold Verilog.merge_regs. - unfold_merge. - rewrite AssocMap.gso. - apply AssocMap.gss. simpl; lia. - apply AssocMap.gss. - rewrite Events.E0_left. trivial. - - constructor; auto. - - simpl. inversion MASSOC. subst. - unfold find_assocmap, AssocMapExt.get_default. rewrite AssocMap.gso. - apply H1. eapply RTL.max_reg_function_use. eauto. simpl; tauto. - assert (HPle : Ple r (RTL.max_reg_function f)). - eapply RTL.max_reg_function_use. eassumption. simpl; auto. - apply ZExtra.Ple_not_eq. apply ZExtra.Ple_Plt_Succ. assumption. - - Unshelve. - all: constructor. - Qed. - Hint Resolve transl_ireturn_correct : htlproof. - - Lemma transl_callstate_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (args : list Values.val) - (m : mem) (m' : Mem.mem') (stk : Values.block), - Mem.alloc m 0 (RTL.fn_stacksize f) = (m', stk) -> - forall R1 : HTL.state, - match_states (RTL.Callstate s (AST.Internal f) args m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states - (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) (RTL.fn_entrypoint f) - (RTL.init_regs args (RTL.fn_params f)) m') R2. - Proof. - intros s f args m m' stk H R1 MSTATE. - - inversion MSTATE; subst. inversion TF; subst. - econstructor. split. apply Smallstep.plus_one. - eapply HTL.step_call. crush. - - apply match_state with (sp' := stk); eauto. - - all: big_tac. - - apply regs_lessdef_add_greater. - unfold Plt; lia. - apply init_reg_assoc_empty. - - constructor. - - destruct (Mem.load AST.Mint32 m' stk - (Integers.Ptrofs.unsigned (Integers.Ptrofs.add - Integers.Ptrofs.zero - (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. - pose proof Mem.load_alloc_same as LOAD_ALLOC. - pose proof H as ALLOC. - eapply LOAD_ALLOC in ALLOC. - 2: { exact LOAD. } - ptrofs. rewrite LOAD. - rewrite ALLOC. - repeat constructor. - - ptrofs. rewrite LOAD. - repeat constructor. - - unfold reg_stack_based_pointers. intros. - unfold RTL.init_regs; crush. - destruct (RTL.fn_params f); - rewrite Registers.Regmap.gi; constructor. - - unfold arr_stack_based_pointers. intros. - crush. - destruct (Mem.load AST.Mint32 m' stk - (Integers.Ptrofs.unsigned (Integers.Ptrofs.add - Integers.Ptrofs.zero - (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. - pose proof Mem.load_alloc_same as LOAD_ALLOC. - pose proof H as ALLOC. - eapply LOAD_ALLOC in ALLOC. - 2: { exact LOAD. } - rewrite ALLOC. - repeat constructor. - constructor. - - Transparent Mem.alloc. (* TODO: Since there are opaque there's probably a lemma. *) - Transparent Mem.load. - Transparent Mem.store. - unfold stack_bounds. - split. - - unfold Mem.alloc in H. - invert H. - crush. - unfold Mem.load. - intros. - match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. - invert v0. unfold Mem.range_perm in H4. - unfold Mem.perm in H4. crush. - unfold Mem.perm_order' in H4. - small_tac. - exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. - rewrite Maps.PMap.gss in H8. - match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. - crush. - apply proj_sumbool_true in H10. lia. - - unfold Mem.alloc in H. - invert H. - crush. - unfold Mem.store. - intros. - match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. - invert v0. unfold Mem.range_perm in H4. - unfold Mem.perm in H4. crush. - unfold Mem.perm_order' in H4. - small_tac. - exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. - rewrite Maps.PMap.gss in H8. - match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. - crush. - apply proj_sumbool_true in H10. lia. - Opaque Mem.alloc. - Opaque Mem.load. - Opaque Mem.store. - Qed. - Hint Resolve transl_callstate_correct : htlproof. - - Lemma transl_returnstate_correct: - forall (res0 : Registers.reg) (f : RTL.function) (sp : Values.val) (pc : RTL.node) - (rs : RTL.regset) (s : list RTL.stackframe) (vres : Values.val) (m : mem) - (R1 : HTL.state), - match_states (RTL.Returnstate (RTL.Stackframe res0 f sp pc rs :: s) vres m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.State s f sp pc (Registers.Regmap.set res0 vres rs) m) R2. - Proof. - intros res0 f sp pc rs s vres m R1 MSTATE. - inversion MSTATE. inversion MF. - Qed. - Hint Resolve transl_returnstate_correct : htlproof. - - Lemma option_inv : - forall A x y, - @Some A x = Some y -> x = y. - Proof. intros. inversion H. trivial. Qed. - - Lemma main_tprog_internal : - forall b, - Globalenvs.Genv.find_symbol tge tprog.(AST.prog_main) = Some b -> - exists f, Genv.find_funct_ptr (Genv.globalenv tprog) b = Some (AST.Internal f). - Proof. - intros. - destruct TRANSL. unfold main_is_internal in H1. - repeat (unfold_match H1). replace b with b0. - exploit function_ptr_translated; eauto. intros [tf [A B]]. - unfold transl_fundef, AST.transf_partial_fundef, Errors.bind in B. - unfold_match B. inv B. econstructor. apply A. - - apply option_inv. rewrite <- Heqo. rewrite <- H. - rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). - trivial. symmetry; eapply Linking.match_program_main; eauto. - Qed. - - Lemma transl_initial_states : - forall s1 : Smallstep.state (RTL.semantics prog), - Smallstep.initial_state (RTL.semantics prog) s1 -> - exists s2 : Smallstep.state (HTL.semantics tprog), - Smallstep.initial_state (HTL.semantics tprog) s2 /\ match_states s1 s2. - Proof. - induction 1. - destruct TRANSL. unfold main_is_internal in H4. - repeat (unfold_match H4). - assert (f = AST.Internal f1). apply option_inv. - rewrite <- Heqo0. rewrite <- H1. replace b with b0. - auto. apply option_inv. rewrite <- H0. rewrite <- Heqo. - trivial. - exploit function_ptr_translated; eauto. - intros [tf [A B]]. - unfold transl_fundef, Errors.bind in B. - unfold AST.transf_partial_fundef, Errors.bind in B. - repeat (unfold_match B). inversion B. subst. - exploit main_tprog_internal; eauto; intros. - rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). - apply Heqo. symmetry; eapply Linking.match_program_main; eauto. - inversion H5. - econstructor; split. econstructor. - apply (Genv.init_mem_transf_partial TRANSL'); eauto. - replace (AST.prog_main tprog) with (AST.prog_main prog). - rewrite symbols_preserved; eauto. - symmetry; eapply Linking.match_program_main; eauto. - apply H6. - - constructor. - apply transl_module_correct. - assert (Some (AST.Internal x) = Some (AST.Internal m)). - replace (AST.fundef HTL.module) with (HTL.fundef). - rewrite <- H6. setoid_rewrite <- A. trivial. - trivial. inv H7. assumption. - Qed. - Hint Resolve transl_initial_states : htlproof. - - Lemma transl_final_states : - forall (s1 : Smallstep.state (RTL.semantics prog)) - (s2 : Smallstep.state (HTL.semantics tprog)) - (r : Integers.Int.int), - match_states s1 s2 -> - Smallstep.final_state (RTL.semantics prog) s1 r -> - Smallstep.final_state (HTL.semantics tprog) s2 r. - Proof. - intros. inv H0. inv H. inv H4. invert MF. constructor. reflexivity. - Qed. - Hint Resolve transl_final_states : htlproof. - - Theorem transl_step_correct: - forall (S1 : RTL.state) t S2, - RTL.step ge S1 t S2 -> - forall (R1 : HTL.state), - match_states S1 R1 -> - exists R2, Smallstep.plus HTL.step tge R1 t R2 /\ match_states S2 R2. - Proof. - induction 1; eauto with htlproof; (intros; inv_state). - Qed. - Hint Resolve transl_step_correct : htlproof. - - Theorem transf_program_correct: - Smallstep.forward_simulation (RTL.semantics prog) (HTL.semantics tprog). - Proof. - eapply Smallstep.forward_simulation_plus; eauto with htlproof. - apply senv_preserved. - Qed. - -End CORRECTNESS. +(* Inductive match_assocmaps : RTL.function -> RTL.regset -> assocmap -> Prop := *) +(* match_assocmap : forall f rs am, *) +(* (forall r, Ple r (RTL.max_reg_function f) -> *) +(* val_value_lessdef (Registers.Regmap.get r rs) am#r) -> *) +(* match_assocmaps f rs am. *) +(* Hint Constructors match_assocmaps : htlproof. *) + +(* Definition state_st_wf (m : HTL.module) (s : HTL.state) := *) +(* forall st asa asr res, *) +(* s = HTL.State res m st asa asr -> *) +(* asa!(m.(HTL.mod_st)) = Some (posToValue st). *) +(* Hint Unfold state_st_wf : htlproof. *) + +(* Inductive match_arrs (m : HTL.module) (f : RTL.function) (sp : Values.val) (mem : mem) : *) +(* Verilog.assocmap_arr -> Prop := *) +(* | match_arr : forall asa stack, *) +(* asa ! (m.(HTL.mod_stk)) = Some stack /\ *) +(* stack.(arr_length) = Z.to_nat (f.(RTL.fn_stacksize) / 4) /\ *) +(* (forall ptr, *) +(* 0 <= ptr < Z.of_nat m.(HTL.mod_stk_len) -> *) +(* opt_val_value_lessdef (Mem.loadv AST.Mint32 mem *) +(* (Values.Val.offset_ptr sp (Integers.Ptrofs.repr (4 * ptr)))) *) +(* (Option.default (NToValue 0) *) +(* (Option.join (array_get_error (Z.to_nat ptr) stack)))) -> *) +(* match_arrs m f sp mem asa. *) + +(* Definition stack_based (v : Values.val) (sp : Values.block) : Prop := *) +(* match v with *) +(* | Values.Vptr sp' off => sp' = sp *) +(* | _ => True *) +(* end. *) + +(* Definition reg_stack_based_pointers (sp : Values.block) (rs : Registers.Regmap.t Values.val) : Prop := *) +(* forall r, stack_based (Registers.Regmap.get r rs) sp. *) + +(* Definition arr_stack_based_pointers (spb : Values.block) (m : mem) (stack_length : Z) *) +(* (sp : Values.val) : Prop := *) +(* forall ptr, *) +(* 0 <= ptr < (stack_length / 4) -> *) +(* stack_based (Option.default *) +(* Values.Vundef *) +(* (Mem.loadv AST.Mint32 m *) +(* (Values.Val.offset_ptr sp (Integers.Ptrofs.repr (4 * ptr))))) *) +(* spb. *) + +(* Definition stack_bounds (sp : Values.val) (hi : Z) (m : mem) : Prop := *) +(* forall ptr v, *) +(* hi <= ptr <= Integers.Ptrofs.max_unsigned -> *) +(* Z.modulo ptr 4 = 0 -> *) +(* Mem.loadv AST.Mint32 m (Values.Val.offset_ptr sp (Integers.Ptrofs.repr ptr )) = None /\ *) +(* Mem.storev AST.Mint32 m (Values.Val.offset_ptr sp (Integers.Ptrofs.repr ptr )) v = None. *) + +(* Inductive match_frames : list RTL.stackframe -> list HTL.stackframe -> Prop := *) +(* | match_frames_nil : *) +(* match_frames nil nil. *) + +(* Lemma assumption_32bit : *) +(* forall v, *) +(* valueToPos (posToValue v) = v. *) +(* Proof. *) +(* Admitted. *) + +(* Inductive match_states : RTL.state -> HTL.state -> Prop := *) +(* | match_state : forall asa asr sf f sp sp' rs mem m st res *) +(* (MASSOC : match_assocmaps f rs asr) *) +(* (TF : tr_module f m) *) +(* (WF : state_st_wf m (HTL.State res m st asr asa)) *) +(* (MF : match_frames sf res) *) +(* (MARR : match_arrs m f sp mem asa) *) +(* (SP : sp = Values.Vptr sp' (Integers.Ptrofs.repr 0)) *) +(* (RSBP : reg_stack_based_pointers sp' rs) *) +(* (ASBP : arr_stack_based_pointers sp' mem (f.(RTL.fn_stacksize)) sp) *) +(* (BOUNDS : stack_bounds sp (f.(RTL.fn_stacksize)) mem), *) +(* match_states (RTL.State sf f sp st rs mem) *) +(* (HTL.State res m st asr asa) *) +(* | match_returnstate : *) +(* forall *) +(* v v' stack mem res *) +(* (MF : match_frames stack res), *) +(* val_value_lessdef v v' -> *) +(* match_states (RTL.Returnstate stack v mem) (HTL.Returnstate res v') *) +(* | match_initial_call : *) +(* forall f m m0 *) +(* (TF : tr_module f m), *) +(* match_states (RTL.Callstate nil (AST.Internal f) nil m0) (HTL.Callstate nil m nil). *) +(* Hint Constructors match_states : htlproof. *) + +(* Definition match_prog (p: RTL.program) (tp: HTL.program) := *) +(* Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq p tp /\ *) +(* main_is_internal p = true. *) + +(* Definition match_prog_matches : *) +(* forall p tp, *) +(* match_prog p tp -> *) +(* Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq p tp. *) +(* Proof. intros. unfold match_prog in H. tauto. Qed. *) + +(* Lemma transf_program_match: *) +(* forall p tp, HTLgen.transl_program p = Errors.OK tp -> match_prog p tp. *) +(* Proof. *) +(* intros. unfold transl_program in H. *) +(* destruct (main_is_internal p) eqn:?; try discriminate. *) +(* unfold match_prog. split. *) +(* apply Linking.match_transform_partial_program; auto. *) +(* assumption. *) +(* Qed. *) + +(* Lemma regs_lessdef_add_greater : *) +(* forall f rs1 rs2 n v, *) +(* Plt (RTL.max_reg_function f) n -> *) +(* match_assocmaps f rs1 rs2 -> *) +(* match_assocmaps f rs1 (AssocMap.set n v rs2). *) +(* Proof. *) +(* inversion 2; subst. *) +(* intros. constructor. *) +(* intros. unfold find_assocmap. unfold AssocMapExt.get_default. *) +(* rewrite AssocMap.gso. eauto. *) +(* apply Pos.le_lt_trans with _ _ n in H2. *) +(* unfold not. intros. subst. eapply Pos.lt_irrefl. eassumption. assumption. *) +(* Qed. *) +(* Hint Resolve regs_lessdef_add_greater : htlproof. *) + +(* Lemma regs_lessdef_add_match : *) +(* forall f rs am r v v', *) +(* val_value_lessdef v v' -> *) +(* match_assocmaps f rs am -> *) +(* match_assocmaps f (Registers.Regmap.set r v rs) (AssocMap.set r v' am). *) +(* Proof. *) +(* inversion 2; subst. *) +(* constructor. intros. *) +(* destruct (peq r0 r); subst. *) +(* rewrite Registers.Regmap.gss. *) +(* unfold find_assocmap. unfold AssocMapExt.get_default. *) +(* rewrite AssocMap.gss. assumption. *) + +(* rewrite Registers.Regmap.gso; try assumption. *) +(* unfold find_assocmap. unfold AssocMapExt.get_default. *) +(* rewrite AssocMap.gso; eauto. *) +(* Qed. *) +(* Hint Resolve regs_lessdef_add_match : htlproof. *) + +(* Lemma list_combine_none : *) +(* forall n l, *) +(* length l = n -> *) +(* list_combine Verilog.merge_cell (list_repeat None n) l = l. *) +(* Proof. *) +(* induction n; intros; crush. *) +(* - symmetry. apply length_zero_iff_nil. auto. *) +(* - destruct l; crush. *) +(* rewrite list_repeat_cons. *) +(* crush. f_equal. *) +(* eauto. *) +(* Qed. *) + +(* Lemma combine_none : *) +(* forall n a, *) +(* a.(arr_length) = n -> *) +(* arr_contents (combine Verilog.merge_cell (arr_repeat None n) a) = arr_contents a. *) +(* Proof. *) +(* intros. *) +(* unfold combine. *) +(* crush. *) + +(* rewrite <- (arr_wf a) in H. *) +(* apply list_combine_none. *) +(* assumption. *) +(* Qed. *) + +(* Lemma list_combine_lookup_first : *) +(* forall l1 l2 n, *) +(* length l1 = length l2 -> *) +(* nth_error l1 n = Some None -> *) +(* nth_error (list_combine Verilog.merge_cell l1 l2) n = nth_error l2 n. *) +(* Proof. *) +(* induction l1; intros; crush. *) + +(* rewrite nth_error_nil in H0. *) +(* discriminate. *) + +(* destruct l2 eqn:EQl2. crush. *) +(* simpl in H. invert H. *) +(* destruct n; simpl in *. *) +(* invert H0. simpl. reflexivity. *) +(* eauto. *) +(* Qed. *) + +(* Lemma combine_lookup_first : *) +(* forall a1 a2 n, *) +(* a1.(arr_length) = a2.(arr_length) -> *) +(* array_get_error n a1 = Some None -> *) +(* array_get_error n (combine Verilog.merge_cell a1 a2) = array_get_error n a2. *) +(* Proof. *) +(* intros. *) + +(* unfold array_get_error in *. *) +(* apply list_combine_lookup_first; eauto. *) +(* rewrite a1.(arr_wf). rewrite a2.(arr_wf). *) +(* assumption. *) +(* Qed. *) + +(* Lemma list_combine_lookup_second : *) +(* forall l1 l2 n x, *) +(* length l1 = length l2 -> *) +(* nth_error l1 n = Some (Some x) -> *) +(* nth_error (list_combine Verilog.merge_cell l1 l2) n = Some (Some x). *) +(* Proof. *) +(* induction l1; intros; crush; auto. *) + +(* destruct l2 eqn:EQl2. crush. *) +(* simpl in H. invert H. *) +(* destruct n; simpl in *. *) +(* invert H0. simpl. reflexivity. *) +(* eauto. *) +(* Qed. *) + +(* Lemma combine_lookup_second : *) +(* forall a1 a2 n x, *) +(* a1.(arr_length) = a2.(arr_length) -> *) +(* array_get_error n a1 = Some (Some x) -> *) +(* array_get_error n (combine Verilog.merge_cell a1 a2) = Some (Some x). *) +(* Proof. *) +(* intros. *) + +(* unfold array_get_error in *. *) +(* apply list_combine_lookup_second; eauto. *) +(* rewrite a1.(arr_wf). rewrite a2.(arr_wf). *) +(* assumption. *) +(* Qed. *) + +(* Ltac inv_state := *) +(* match goal with *) +(* MSTATE : match_states _ _ |- _ => *) +(* inversion MSTATE; *) +(* match goal with *) +(* TF : tr_module _ _ |- _ => *) +(* inversion TF; *) +(* match goal with *) +(* TC : forall _ _, *) +(* Maps.PTree.get _ _ = Some _ -> tr_code _ _ _ _ _ _ _ _ _, *) +(* H : Maps.PTree.get _ _ = Some _ |- _ => *) +(* apply TC in H; inversion H; *) +(* match goal with *) +(* TI : context[tr_instr] |- _ => *) +(* inversion TI *) +(* end *) +(* end *) +(* end *) +(* end; subst. *) + +(* Ltac unfold_func H := *) +(* match type of H with *) +(* | ?f = _ => unfold f in H; repeat (unfold_match H) *) +(* | ?f _ = _ => unfold f in H; repeat (unfold_match H) *) +(* | ?f _ _ = _ => unfold f in H; repeat (unfold_match H) *) +(* | ?f _ _ _ = _ => unfold f in H; repeat (unfold_match H) *) +(* | ?f _ _ _ _ = _ => unfold f in H; repeat (unfold_match H) *) +(* end. *) + +(* Lemma init_reg_assoc_empty : *) +(* forall f l, *) +(* match_assocmaps f (RTL.init_regs nil l) (HTL.init_regs nil l). *) +(* Proof. *) +(* induction l; simpl; constructor; intros. *) +(* - rewrite Registers.Regmap.gi. unfold find_assocmap. *) +(* unfold AssocMapExt.get_default. rewrite AssocMap.gempty. *) +(* constructor. *) + +(* - rewrite Registers.Regmap.gi. unfold find_assocmap. *) +(* unfold AssocMapExt.get_default. rewrite AssocMap.gempty. *) +(* constructor. *) +(* Qed. *) + +(* Lemma arr_lookup_some: *) +(* forall (z : Z) (r0 : Registers.reg) (r : Verilog.reg) (asr : assocmap) (asa : Verilog.assocmap_arr) *) +(* (stack : Array (option value)) (H5 : asa ! r = Some stack) n, *) +(* exists x, Verilog.arr_assocmap_lookup asa r n = Some x. *) +(* Proof. *) +(* intros z r0 r asr asa stack H5 n. *) +(* eexists. *) +(* unfold Verilog.arr_assocmap_lookup. rewrite H5. reflexivity. *) +(* Qed. *) +(* Hint Resolve arr_lookup_some : htlproof. *) + +(* Section CORRECTNESS. *) + +(* Variable prog : RTL.program. *) +(* Variable tprog : HTL.program. *) + +(* Hypothesis TRANSL : match_prog prog tprog. *) + +(* Lemma TRANSL' : *) +(* Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq prog tprog. *) +(* Proof. intros; apply match_prog_matches; assumption. Qed. *) + +(* Let ge : RTL.genv := Globalenvs.Genv.globalenv prog. *) +(* Let tge : HTL.genv := Globalenvs.Genv.globalenv tprog. *) + +(* Lemma symbols_preserved: *) +(* forall (s: AST.ident), Genv.find_symbol tge s = Genv.find_symbol ge s. *) +(* Proof. intros. eapply (Genv.find_symbol_match TRANSL'). Qed. *) + +(* Lemma function_ptr_translated: *) +(* forall (b: Values.block) (f: RTL.fundef), *) +(* Genv.find_funct_ptr ge b = Some f -> *) +(* exists tf, *) +(* Genv.find_funct_ptr tge b = Some tf /\ transl_fundef f = Errors.OK tf. *) +(* Proof. *) +(* intros. exploit (Genv.find_funct_ptr_match TRANSL'); eauto. *) +(* intros (cu & tf & P & Q & R); exists tf; auto. *) +(* Qed. *) + +(* Lemma functions_translated: *) +(* forall (v: Values.val) (f: RTL.fundef), *) +(* Genv.find_funct ge v = Some f -> *) +(* exists tf, *) +(* Genv.find_funct tge v = Some tf /\ transl_fundef f = Errors.OK tf. *) +(* Proof. *) +(* intros. exploit (Genv.find_funct_match TRANSL'); eauto. *) +(* intros (cu & tf & P & Q & R); exists tf; auto. *) +(* Qed. *) + +(* Lemma senv_preserved: *) +(* Senv.equiv (Genv.to_senv ge) (Genv.to_senv tge). *) +(* Proof *) +(* (Genv.senv_transf_partial TRANSL'). *) +(* Hint Resolve senv_preserved : htlproof. *) + +(* Lemma ptrofs_inj : *) +(* forall a b, *) +(* Ptrofs.unsigned a = Ptrofs.unsigned b -> a = b. *) +(* Proof. *) +(* intros. rewrite <- Ptrofs.repr_unsigned. symmetry. rewrite <- Ptrofs.repr_unsigned. *) +(* rewrite H. auto. *) +(* Qed. *) + +(* Lemma eval_correct : *) +(* forall s sp op rs m v e asr asa f f' stk s' i pc res0 pc' args res ml st, *) +(* match_states (RTL.State stk f sp pc rs m) (HTL.State res ml st asr asa) -> *) +(* (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> *) +(* Op.eval_operation ge sp op *) +(* (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) m = Some v -> *) +(* translate_instr op args s = OK e s' i -> *) +(* exists v', Verilog.expr_runp f' asr asa e v' /\ val_value_lessdef v v'. *) +(* Proof. *) +(* intros s sp op rs m v e asr asa f f' stk s' i pc pc' res0 args res ml st MSTATE INSTR EVAL TR_INSTR. *) +(* inv MSTATE. inv MASSOC. unfold translate_instr in TR_INSTR; repeat (unfold_match TR_INSTR); inv TR_INSTR; *) +(* unfold Op.eval_operation in EVAL; repeat (unfold_match EVAL); simplify. *) +(* - inv Heql. *) +(* assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) +(* apply H in HPle. eexists. split; try constructor; eauto. *) +(* - eexists. split. constructor. constructor. auto. *) +(* - inv Heql. *) +(* assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) +(* apply H in HPle. *) +(* eexists. split. econstructor; eauto. constructor. trivial. *) +(* unfold Verilog.unop_run. unfold Values.Val.neg. destruct (Registers.Regmap.get r rs) eqn:?; constructor. *) +(* inv HPle. auto. *) +(* - inv Heql. *) +(* assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) +(* assert (HPle0 : Ple r0 (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) +(* apply H in HPle. apply H in HPle0. *) +(* eexists. split. econstructor; eauto. constructor. trivial. *) +(* constructor. trivial. simplify. inv HPle. inv HPle0; constructor; auto. *) +(* + inv HPle0. constructor. unfold valueToPtr. Search Integers.Ptrofs.sub Integers.int. *) +(* pose proof Integers.Ptrofs.agree32_sub. unfold Integers.Ptrofs.agree32 in H3. *) +(* Print Integers.Ptrofs.agree32. unfold Ptrofs.of_int. simpl. *) +(* apply ptrofs_inj. assert (Archi.ptr64 = false) by auto. eapply H3 in H4. *) +(* rewrite Ptrofs.unsigned_repr. apply H4. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* apply Int.unsigned_range_2. *) +(* auto. rewrite Ptrofs.unsigned_repr. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* apply Int.unsigned_range_2. rewrite Ptrofs.unsigned_repr. auto. *) +(* replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* apply Int.unsigned_range_2. *) +(* Admitted. *) + +(* Lemma eval_cond_correct : *) +(* forall cond (args : list Registers.reg) s1 c s' i rs args m b f asr asa, *) +(* translate_condition cond args s1 = OK c s' i -> *) +(* Op.eval_condition *) +(* cond *) +(* (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) *) +(* m = Some b -> *) +(* Verilog.expr_runp f asr asa c (boolToValue b). *) +(* Admitted. *) + +(* (** The proof of semantic preservation for the translation of instructions *) +(* is a simulation argument based on diagrams of the following form: *) +(* << *) +(* match_states *) +(* code st rs ---------------- State m st assoc *) +(* || | *) +(* || | *) +(* || | *) +(* \/ v *) +(* code st rs' --------------- State m st assoc' *) +(* match_states *) +(* >> *) +(* where [tr_code c data control fin rtrn st] is assumed to hold. *) + +(* The precondition and postcondition is that that should hold is [match_assocmaps rs assoc]. *) +(* *) *) + +(* Definition transl_instr_prop (instr : RTL.instruction) : Prop := *) +(* forall m asr asa fin rtrn st stmt trans res, *) +(* tr_instr fin rtrn st (m.(HTL.mod_stk)) instr stmt trans -> *) +(* exists asr' asa', *) +(* HTL.step tge (HTL.State res m st asr asa) Events.E0 (HTL.State res m st asr' asa'). *) + +(* Opaque combine. *) + +(* Ltac tac0 := *) +(* match goal with *) +(* | [ |- context[valueToPos (posToValue _)] ] => rewrite assumption_32bit *) + +(* | [ |- context[Verilog.merge_arrs _ _] ] => unfold Verilog.merge_arrs *) +(* | [ |- context[Verilog.merge_arr] ] => unfold Verilog.merge_arr *) +(* | [ |- context[Verilog.merge_regs _ _] ] => unfold Verilog.merge_regs; crush; unfold_merge *) +(* | [ |- context[reg_stack_based_pointers] ] => unfold reg_stack_based_pointers; intros *) +(* | [ |- context[Verilog.arr_assocmap_set _ _ _ _] ] => unfold Verilog.arr_assocmap_set *) + +(* | [ |- context[HTL.empty_stack] ] => unfold HTL.empty_stack *) + +(* | [ |- context[_ # ?d <- _ ! ?d] ] => rewrite AssocMap.gss *) +(* | [ |- context[_ # ?d <- _ ! ?s] ] => rewrite AssocMap.gso *) +(* | [ |- context[(AssocMap.empty _) ! _] ] => rewrite AssocMap.gempty *) + +(* | [ |- context[array_get_error _ (combine Verilog.merge_cell (arr_repeat None _) _)] ] => *) +(* rewrite combine_lookup_first *) + +(* | [ |- state_st_wf _ _ ] => unfold state_st_wf; inversion 1 *) +(* | [ |- context[match_states _ _] ] => econstructor; auto *) +(* | [ |- match_arrs _ _ _ _ _ ] => econstructor; auto *) +(* | [ |- match_assocmaps _ _ _ # _ <- (posToValue _) ] => *) +(* apply regs_lessdef_add_greater; [> unfold Plt; lia | assumption] *) + +(* | [ H : ?asa ! ?r = Some _ |- Verilog.arr_assocmap_lookup ?asa ?r _ = Some _ ] => *) +(* unfold Verilog.arr_assocmap_lookup; setoid_rewrite H; f_equal *) +(* | [ |- context[(AssocMap.combine _ _ _) ! _] ] => *) +(* try (rewrite AssocMap.gcombine; [> | reflexivity]) *) + +(* | [ |- context[Registers.Regmap.get ?d (Registers.Regmap.set ?d _ _)] ] => *) +(* rewrite Registers.Regmap.gss *) +(* | [ |- context[Registers.Regmap.get ?s (Registers.Regmap.set ?d _ _)] ] => *) +(* destruct (Pos.eq_dec s d) as [EQ|EQ]; *) +(* [> rewrite EQ | rewrite Registers.Regmap.gso; auto] *) + +(* | [ H : opt_val_value_lessdef _ _ |- _ ] => invert H *) +(* | [ H : context[Z.of_nat (Z.to_nat _)] |- _ ] => rewrite Z2Nat.id in H; [> solve crush |] *) +(* | [ H : _ ! _ = Some _ |- _] => setoid_rewrite H *) +(* end. *) + +(* Ltac small_tac := repeat (crush; try array; try ptrofs); crush; auto. *) +(* Ltac big_tac := repeat (crush; try array; try ptrofs; try tac0); crush; auto. *) + + (* Lemma transl_inop_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) + (* (rs : RTL.regset) (m : mem) (pc' : RTL.node), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Inop pc') -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f sp pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. *) + (* Proof. *) + (* intros s f sp pc rs m pc' H R1 MSTATE. *) + (* inv_state. *) + + (* unfold match_prog in TRANSL. *) + (* econstructor. *) + (* split. *) + (* apply Smallstep.plus_one. *) + (* eapply HTL.step_module; eauto. *) + (* apply assumption_32bit. *) + (* (* processing of state *) *) + (* econstructor. *) + (* crush. *) + (* econstructor. *) + (* econstructor. *) + (* econstructor. *) + + (* all: invert MARR; big_tac. *) + (* Unshelve. *) + (* constructor. *) + (* Qed. *) + (* Hint Resolve transl_inop_correct : htlproof. *) + + (* Lemma transl_iop_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) + (* (rs : Registers.Regmap.t Values.val) (m : mem) (op : Op.operation) (args : list Registers.reg) *) + (* (res0 : Registers.reg) (pc' : RTL.node) (v : Values.val), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> *) + (* Op.eval_operation ge sp op (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some v -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f sp pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) + (* match_states (RTL.State s f sp pc' (Registers.Regmap.set res0 v rs) m) R2. *) + (* Proof. *) + (* intros s f sp pc rs m op args res0 pc' v H H0 R1 MSTATE. *) + (* inv_state. *) + (* exploit eval_correct; eauto. intros. inversion H1. inversion H2. *) + (* econstructor. split. *) + (* apply Smallstep.plus_one. *) + (* eapply HTL.step_module; eauto. *) + (* apply assumption_32bit. *) + (* econstructor; simpl; trivial. *) + (* constructor; trivial. *) + (* econstructor; simpl; eauto. *) + (* simpl. econstructor. econstructor. *) + (* apply H3. simplify. *) + + (* all: big_tac. *) + + (* assert (Ple res0 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_def; eauto; simpl; auto). *) + + (* unfold Ple in H10. lia. *) + (* apply regs_lessdef_add_match. assumption. *) + (* apply regs_lessdef_add_greater. unfold Plt; lia. assumption. *) + (* assert (Ple res0 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_def; eauto; simpl; auto). *) + (* unfold Ple in H12; lia. *) + (* unfold_merge. simpl. *) + (* rewrite AssocMap.gso. *) + (* apply AssocMap.gss. *) + (* apply st_greater_than_res. *) + + (* (*match_states*) *) + (* assert (pc' = valueToPos (posToValue 32 pc')). auto using assumption_32bit. *) + (* rewrite <- H1. *) + (* constructor; auto. *) + (* unfold_merge. *) + (* apply regs_lessdef_add_match. *) + (* constructor. *) + (* apply regs_lessdef_add_greater. *) + (* apply greater_than_max_func. *) + (* assumption. *) + + (* unfold state_st_wf. intros. inversion H2. subst. *) + (* unfold_merge. *) + (* rewrite AssocMap.gso. *) + (* apply AssocMap.gss. *) + (* apply st_greater_than_res. *) + + (* + econstructor. split. *) + (* apply Smallstep.plus_one. *) + (* eapply HTL.step_module; eauto. *) + (* econstructor; simpl; trivial. *) + (* constructor; trivial. *) + (* econstructor; simpl; eauto. *) + (* eapply eval_correct; eauto. *) + (* constructor. rewrite valueToInt_intToValue. trivial. *) + (* unfold_merge. simpl. *) + (* rewrite AssocMap.gso. *) + (* apply AssocMap.gss. *) + (* apply st_greater_than_res. *) + + (* match_states *) + (* assert (pc' = valueToPos (posToValue 32 pc')). auto using assumption_32bit. *) + (* rewrite <- H1. *) + (* constructor. *) + (* unfold_merge. *) + (* apply regs_lessdef_add_match. *) + (* constructor. *) + (* symmetry. apply valueToInt_intToValue. *) + (* apply regs_lessdef_add_greater. *) + (* apply greater_than_max_func. *) + (* assumption. assumption. *) + + (* unfold state_st_wf. intros. inversion H2. subst. *) + (* unfold_merge. *) + (* rewrite AssocMap.gso. *) + (* apply AssocMap.gss. *) + (* apply st_greater_than_res. *) + (* assumption. *) + (* Admitted. *) + (* Hint Resolve transl_iop_correct : htlproof. *) + + (* Ltac tac := *) + (* repeat match goal with *) + (* | [ _ : error _ _ = OK _ _ _ |- _ ] => discriminate *) + (* | [ _ : context[if (?x && ?y) then _ else _] |- _ ] => *) + (* let EQ1 := fresh "EQ" in *) + (* let EQ2 := fresh "EQ" in *) + (* destruct x eqn:EQ1; destruct y eqn:EQ2; simpl in * *) + (* | [ _ : context[if ?x then _ else _] |- _ ] => *) + (* let EQ := fresh "EQ" in *) + (* destruct x eqn:EQ; simpl in * *) + (* | [ H : ret _ _ = _ |- _ ] => invert H *) + (* | [ _ : context[match ?x with | _ => _ end] |- _ ] => destruct x *) + (* end. *) + + (* Ltac inv_arr_access := *) + (* match goal with *) + (* | [ _ : translate_arr_access ?chunk ?addr ?args _ _ = OK ?c _ _ |- _] => *) + (* destruct c, chunk, addr, args; crush; tac; crush *) + (* end. *) + + (* Lemma transl_iload_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) + (* (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) *) + (* (addr : Op.addressing) (args : list Registers.reg) (dst : Registers.reg) *) + (* (pc' : RTL.node) (a v : Values.val), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Iload chunk addr args dst pc') -> *) + (* Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> *) + (* Mem.loadv chunk m a = Some v -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f sp pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) + (* match_states (RTL.State s f sp pc' (Registers.Regmap.set dst v rs) m) R2. *) + (* Proof. *) + (* intros s f sp pc rs m chunk addr args dst pc' a v H H0 H1 R1 MSTATE. *) + (* inv_state. inv_arr_access. *) + + (* + (** Preamble *) *) + (* invert MARR. crush. *) + + (* unfold Op.eval_addressing in H0. *) + (* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + + (* unfold reg_stack_based_pointers in RSBP. *) + (* pose proof (RSBP r0) as RSBPr0. *) + + (* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. *) + + (* rewrite ARCHI in H1. crush. *) + (* subst. *) + + (* pose proof MASSOC as MASSOC'. *) + (* invert MASSOC'. *) + (* pose proof (H0 r0). *) + (* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) + (* apply H6 in HPler0. *) + (* invert HPler0; try congruence. *) + (* rewrite EQr0 in H8. *) + (* invert H8. *) + (* clear H0. clear H6. *) + + (* unfold check_address_parameter_signed in *; *) + (* unfold check_address_parameter_unsigned in *; crush. *) + + (* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) + (* (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. *) + + (* (** Modular preservation proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) + (* { rewrite HeqOFFSET. *) + (* apply PtrofsExtra.add_mod; crush. *) + (* rewrite Integers.Ptrofs.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. *) + (* apply PtrofsExtra.of_int_mod. *) + (* rewrite Integers.Int.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. } *) + + (* (** Read bounds proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. *) + (* { destruct (Integers.Ptrofs.unsigned OFFSET *) + (* assert (Z.to_nat *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4))) *) + (* = *) + (* valueToNat x) *) + (* as EXPR_OK by admit *) + (* end. *) + (* rewrite <- EXPR_OK. *) + + (* specialize (H7 (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4)))). *) + (* exploit H7; big_tac. *) + + (* (** RSBP preservation *) *) + (* unfold arr_stack_based_pointers in ASBP. *) + (* specialize (ASBP (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). *) + (* exploit ASBP; big_tac. *) + (* rewrite NORMALISE in H0. rewrite H1 in H0. assumption. *) + + (* + (** Preamble *) *) + (* invert MARR. crush. *) + + (* unfold Op.eval_addressing in H0. *) + (* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + + (* unfold reg_stack_based_pointers in RSBP. *) + (* pose proof (RSBP r0) as RSBPr0. *) + (* pose proof (RSBP r1) as RSBPr1. *) + + (* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; *) + (* destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. *) + + (* rewrite ARCHI in H1. crush. *) + (* subst. *) + (* clear RSBPr1. *) + + (* pose proof MASSOC as MASSOC'. *) + (* invert MASSOC'. *) + (* pose proof (H0 r0). *) + (* pose proof (H0 r1). *) + (* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) + (* assert (HPler1 : Ple r1 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) + (* apply H6 in HPler0. *) + (* apply H8 in HPler1. *) + (* invert HPler0; invert HPler1; try congruence. *) + (* rewrite EQr0 in H9. *) + (* rewrite EQr1 in H11. *) + (* invert H9. invert H11. *) + (* clear H0. clear H6. clear H8. *) + + (* unfold check_address_parameter_signed in *; *) + (* unfold check_address_parameter_unsigned in *; crush. *) + + (* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) + (* (Integers.Ptrofs.of_int *) + (* (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) *) + (* (Integers.Int.repr z0)))) as OFFSET. *) + + (* (** Modular preservation proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) + (* { rewrite HeqOFFSET. *) + (* apply PtrofsExtra.add_mod; crush; try lia. *) + (* rewrite Integers.Ptrofs.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. *) + (* apply PtrofsExtra.of_int_mod. *) + (* apply IntExtra.add_mod; crush. *) + (* apply IntExtra.mul_mod2; crush. *) + (* rewrite Integers.Int.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. *) + (* rewrite Integers.Int.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. } *) + + (* (** Read bounds proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. *) + (* { destruct (Integers.Ptrofs.unsigned OFFSET *) + (* assert (Z.to_nat *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4))) *) + (* = *) + (* valueToNat x) *) + (* as EXPR_OK by admit *) + (* end. *) + (* rewrite <- EXPR_OK. *) + + (* specialize (H7 (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4)))). *) + (* exploit H7; big_tac. *) + + (* (** RSBP preservation *) *) + (* unfold arr_stack_based_pointers in ASBP. *) + (* specialize (ASBP (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). *) + (* exploit ASBP; big_tac. *) + (* rewrite NORMALISE in H0. rewrite H1 in H0. assumption. *) + + (* + invert MARR. crush. *) + + (* unfold Op.eval_addressing in H0. *) + (* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + (* rewrite ARCHI in H0. crush. *) + + (* unfold check_address_parameter_unsigned in *; *) + (* unfold check_address_parameter_signed in *; crush. *) + + (* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) + (* rewrite ZERO in H1. clear ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l in H1. *) + + (* remember i0 as OFFSET. *) + + (* (** Modular preservation proof *) *) + (* rename H0 into MOD_PRESERVE. *) + + (* (** Read bounds proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. *) + (* { destruct (Integers.Ptrofs.unsigned OFFSET *) + (* assert (Z.to_nat *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4))) *) + (* = *) + (* valueToNat x) *) + (* as EXPR_OK by admit *) + (* end. *) + (* rewrite <- EXPR_OK. *) + + (* specialize (H7 (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4)))). *) + (* exploit H7; big_tac. *) + + (* (** RSBP preservation *) *) + (* unfold arr_stack_based_pointers in ASBP. *) + (* specialize (ASBP (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). *) + (* exploit ASBP; big_tac. *) + (* rewrite NORMALISE in H0. rewrite H1 in H0. assumption. *) + (* Admitted. *) + (* Hint Resolve transl_iload_correct : htlproof. *) + + (* Lemma transl_istore_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) + (* (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) *) + (* (addr : Op.addressing) (args : list Registers.reg) (src : Registers.reg) *) + (* (pc' : RTL.node) (a : Values.val) (m' : mem), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Istore chunk addr args src pc') -> *) + (* Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> *) + (* Mem.storev chunk m a (Registers.Regmap.get src rs) = Some m' -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f sp pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m') R2. *) + (* Proof. *) + (* intros s f sp pc rs m chunk addr args src pc' a m' H H0 H1 R1 MSTATES. *) + (* inv_state. inv_arr_access. *) + + (* + (** Preamble *) *) + (* invert MARR. crush. *) + + (* unfold Op.eval_addressing in H0. *) + (* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + + (* unfold reg_stack_based_pointers in RSBP. *) + (* pose proof (RSBP r0) as RSBPr0. *) + + (* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. *) + + (* rewrite ARCHI in H1. crush. *) + (* subst. *) + + (* pose proof MASSOC as MASSOC'. *) + (* invert MASSOC'. *) + (* pose proof (H0 r0). *) + (* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) + (* apply H6 in HPler0. *) + (* invert HPler0; try congruence. *) + (* rewrite EQr0 in H8. *) + (* invert H8. *) + (* clear H0. clear H6. *) + + (* unfold check_address_parameter_unsigned in *; *) + (* unfold check_address_parameter_signed in *; crush. *) + + (* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) + (* (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. *) + + (* (** Modular preservation proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) + (* { rewrite HeqOFFSET. *) + (* apply PtrofsExtra.add_mod; crush; try lia. *) + (* rewrite Integers.Ptrofs.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. *) + (* apply PtrofsExtra.of_int_mod. *) + (* rewrite Integers.Int.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. } *) + + (* (** Write bounds proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. *) + (* { destruct (Integers.Ptrofs.unsigned OFFSET *) + (* assert (Z.to_nat *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.divu *) + (* OFFSET *) + (* (Integers.Ptrofs.repr 4))) *) + (* = *) + (* valueToNat x) *) + (* as EXPR_OK by admit *) + (* end. *) + + (* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) + (* inversion MASSOC; revert HeqOFFSET; subst; clear MASSOC; intros HeqOFFSET. *) + + (* econstructor. *) + (* repeat split; crush. *) + (* unfold HTL.empty_stack. *) + (* crush. *) + (* unfold Verilog.merge_arrs. *) + + (* rewrite AssocMap.gcombine. *) + (* 2: { reflexivity. } *) + (* unfold Verilog.arr_assocmap_set. *) + (* rewrite AssocMap.gss. *) + (* unfold Verilog.merge_arr. *) + (* rewrite AssocMap.gss. *) + (* setoid_rewrite H5. *) + (* reflexivity. *) + + (* rewrite combine_length. *) + (* rewrite <- array_set_len. *) + (* unfold arr_repeat. crush. *) + (* apply list_repeat_len. *) + + (* rewrite <- array_set_len. *) + (* unfold arr_repeat. crush. *) + (* rewrite list_repeat_len. *) + (* rewrite H4. reflexivity. *) + + (* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) + (* (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. *) + + (* destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). *) + + (* erewrite Mem.load_store_same. *) + (* 2: { rewrite ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l. *) + (* rewrite e. *) + (* rewrite Integers.Ptrofs.unsigned_repr. *) + (* exact H1. *) + (* apply Integers.Ptrofs.unsigned_range_2. } *) + (* constructor. *) + (* erewrite combine_lookup_second. *) + (* simpl. *) + (* assert (Ple src (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) + (* apply H0 in H13. *) + (* destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; constructor; invert H13; eauto. *) + + (* rewrite <- array_set_len. *) + (* unfold arr_repeat. crush. *) + (* rewrite list_repeat_len. auto. *) + + (* assert (4 * ptr / 4 = Integers.Ptrofs.unsigned OFFSET / 4) by (f_equal; assumption). *) + (* rewrite Z.mul_comm in H13. *) + (* rewrite Z_div_mult in H13; try lia. *) + (* replace 4 with (Integers.Ptrofs.unsigned (Integers.Ptrofs.repr 4)) in H13 by reflexivity. *) + (* rewrite <- PtrofsExtra.divu_unsigned in H13; unfold_constants; try lia. *) + (* rewrite H13. rewrite EXPR_OK. *) + (* rewrite array_get_error_set_bound. *) + (* reflexivity. *) + (* unfold arr_length, arr_repeat. simpl. *) + (* rewrite list_repeat_len. lia. *) + + (* erewrite Mem.load_store_other with (m1 := m). *) + (* 2: { exact H1. } *) + (* 2: { right. *) + (* rewrite ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l. *) + (* rewrite Integers.Ptrofs.unsigned_repr. *) + (* simpl. *) + (* destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. *) + (* right. *) + (* apply ZExtra.mod_0_bounds; try lia. *) + (* apply ZLib.Z_mod_mult'. *) + (* rewrite Z2Nat.id in H15; try lia. *) + (* apply Zmult_lt_compat_r with (p := 4) in H15; try lia. *) + (* rewrite ZLib.div_mul_undo in H15; try lia. *) + (* split; try lia. *) + (* apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. *) + (* } *) + + (* rewrite <- EXPR_OK. *) + (* rewrite PtrofsExtra.divu_unsigned; auto; try (unfold_constants; lia). *) + (* destruct (ptr ==Z Integers.Ptrofs.unsigned OFFSET / 4). *) + (* apply Z.mul_cancel_r with (p := 4) in e; try lia. *) + (* rewrite ZLib.div_mul_undo in e; try lia. *) + (* rewrite combine_lookup_first. *) + (* eapply H7; eauto. *) + + (* rewrite <- array_set_len. *) + (* unfold arr_repeat. crush. *) + (* rewrite list_repeat_len. auto. *) + (* rewrite array_gso. *) + (* unfold array_get_error. *) + (* unfold arr_repeat. *) + (* crush. *) + (* apply list_repeat_lookup. *) + (* lia. *) + (* unfold_constants. *) + (* intro. *) + (* apply Z2Nat.inj_iff in H13; try lia. *) + (* apply Z.div_pos; try lia. *) + (* apply Integers.Ptrofs.unsigned_range. *) + + (* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) + (* unfold arr_stack_based_pointers. *) + (* intros. *) + (* destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). *) + + (* crush. *) + (* erewrite Mem.load_store_same. *) + (* 2: { rewrite ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l. *) + (* rewrite e. *) + (* rewrite Integers.Ptrofs.unsigned_repr. *) + (* exact H1. *) + (* apply Integers.Ptrofs.unsigned_range_2. } *) + (* crush. *) + (* destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; try constructor. *) + (* destruct (Archi.ptr64); try discriminate. *) + (* pose proof (RSBP src). rewrite EQ_SRC in H0. *) + (* assumption. *) + + (* simpl. *) + (* erewrite Mem.load_store_other with (m1 := m). *) + (* 2: { exact H1. } *) + (* 2: { right. *) + (* rewrite ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l. *) + (* rewrite Integers.Ptrofs.unsigned_repr. *) + (* simpl. *) + (* destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. *) + (* right. *) + (* apply ZExtra.mod_0_bounds; try lia. *) + (* apply ZLib.Z_mod_mult'. *) + (* invert H0. *) + (* apply Zmult_lt_compat_r with (p := 4) in H14; try lia. *) + (* rewrite ZLib.div_mul_undo in H14; try lia. *) + (* split; try lia. *) + (* apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. *) + (* } *) + (* apply ASBP; assumption. *) + + (* unfold stack_bounds in *. intros. *) + (* simpl. *) + (* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) + (* erewrite Mem.load_store_other with (m1 := m). *) + (* 2: { exact H1. } *) + (* 2: { right. right. simpl. *) + (* rewrite ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l. *) + (* rewrite Integers.Ptrofs.unsigned_repr; crush; try lia. *) + (* apply ZExtra.mod_0_bounds; crush; try lia. } *) + (* crush. *) + (* exploit (BOUNDS ptr); try lia. intros. crush. *) + (* exploit (BOUNDS ptr v); try lia. intros. *) + (* invert H0. *) + (* match goal with | |- ?x = _ => destruct x eqn:EQ end; try reflexivity. *) + (* assert (Mem.valid_access m AST.Mint32 sp' *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) + (* (Integers.Ptrofs.repr ptr))) Writable). *) + (* { pose proof H1. eapply Mem.store_valid_access_2 in H0. *) + (* exact H0. eapply Mem.store_valid_access_3. eassumption. } *) + (* pose proof (Mem.valid_access_store m AST.Mint32 sp' *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) + (* (Integers.Ptrofs.repr ptr))) v). *) + (* apply X in H0. invert H0. congruence. *) + + (* + (** Preamble *) *) + (* invert MARR. crush. *) + + (* unfold Op.eval_addressing in H0. *) + (* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + + (* unfold reg_stack_based_pointers in RSBP. *) + (* pose proof (RSBP r0) as RSBPr0. *) + (* pose proof (RSBP r1) as RSBPr1. *) + + (* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; *) + (* destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. *) + + (* rewrite ARCHI in H1. crush. *) + (* subst. *) + (* clear RSBPr1. *) + + (* pose proof MASSOC as MASSOC'. *) + (* invert MASSOC'. *) + (* pose proof (H0 r0). *) + (* pose proof (H0 r1). *) + (* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) + (* assert (HPler1 : Ple r1 (RTL.max_reg_function f)) *) + (* by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) + (* apply H6 in HPler0. *) + (* apply H8 in HPler1. *) + (* invert HPler0; invert HPler1; try congruence. *) + (* rewrite EQr0 in H9. *) + (* rewrite EQr1 in H11. *) + (* invert H9. invert H11. *) + (* clear H0. clear H6. clear H8. *) + + (* unfold check_address_parameter_signed in *; *) + (* unfold check_address_parameter_unsigned in *; crush. *) + + (* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) + (* (Integers.Ptrofs.of_int *) + (* (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) *) + (* (Integers.Int.repr z0)))) as OFFSET. *) + + (* (** Modular preservation proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) + (* { rewrite HeqOFFSET. *) + (* apply PtrofsExtra.add_mod; crush; try lia. *) + (* rewrite Integers.Ptrofs.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. *) + (* apply PtrofsExtra.of_int_mod. *) + (* apply IntExtra.add_mod; crush. *) + (* apply IntExtra.mul_mod2; crush. *) + (* rewrite Integers.Int.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. *) + (* rewrite Integers.Int.unsigned_repr_eq. *) + (* rewrite <- Zmod_div_mod; crush. } *) + + (* (** Write bounds proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. *) + (* { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. *) + (* assert (Mem.valid_access m AST.Mint32 sp' *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) + (* (Integers.Ptrofs.repr ptr))) Writable). *) + (* { pose proof H1. eapply Mem.store_valid_access_2 in H0. *) + (* exact H0. eapply Mem.store_valid_access_3. eassumption. } *) + (* pose proof (Mem.valid_access_store m AST.Mint32 sp' *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) + (* (Integers.Ptrofs.repr ptr))) v). *) + (* apply X in H0. invert H0. congruence. *) + + (* + invert MARR. crush. *) + + (* unfold Op.eval_addressing in H0. *) + (* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + (* rewrite ARCHI in H0. crush. *) + + (* unfold check_address_parameter_unsigned in *; *) + (* unfold check_address_parameter_signed in *; crush. *) + + (* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) + (* rewrite ZERO in H1. clear ZERO. *) + (* rewrite Integers.Ptrofs.add_zero_l in H1. *) + + (* remember i0 as OFFSET. *) + + (* (** Modular preservation proof *) *) + (* rename H0 into MOD_PRESERVE. *) + + (* (** Write bounds proof *) *) + (* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. *) + (* { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. *) + (* assert (Mem.valid_access m AST.Mint32 sp' *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) + (* (Integers.Ptrofs.repr ptr))) Writable). *) + (* { pose proof H1. eapply Mem.store_valid_access_2 in H0. *) + (* exact H0. eapply Mem.store_valid_access_3. eassumption. } *) + (* pose proof (Mem.valid_access_store m AST.Mint32 sp' *) + (* (Integers.Ptrofs.unsigned *) + (* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) + (* (Integers.Ptrofs.repr ptr))) v). *) + (* apply X in H0. invert H0. congruence. *) + (* Admitted. *) + (* Hint Resolve transl_istore_correct : htlproof. *) + + (* Lemma transl_icond_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) + (* (rs : Registers.Regmap.t Values.val) (m : mem) (cond : Op.condition) (args : list Registers.reg) *) + (* (ifso ifnot : RTL.node) (b : bool) (pc' : RTL.node), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Icond cond args ifso ifnot) -> *) + (* Op.eval_condition cond (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some b -> *) + (* pc' = (if b then ifso else ifnot) -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f sp pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. *) + (* Proof. *) + (* intros s f sp pc rs m cond args ifso ifnot b pc' H H0 H1 R1 MSTATE. *) + (* inv_state. *) + + (* eexists. split. apply Smallstep.plus_one. *) + (* eapply HTL.step_module; eauto. *) + (* apply assumption_32bit. *) + (* eapply Verilog.stmnt_runp_Vnonblock_reg with *) + (* (rhsval := if b then posToValue 32 ifso else posToValue 32 ifnot). *) + (* constructor. *) + + (* simpl. *) + (* destruct b. *) + (* eapply Verilog.erun_Vternary_true. *) + (* eapply eval_cond_correct; eauto. *) + (* constructor. *) + (* apply boolToValue_ValueToBool. *) + (* eapply Verilog.erun_Vternary_false. *) + (* eapply eval_cond_correct; eauto. *) + (* constructor. *) + (* apply boolToValue_ValueToBool. *) + (* constructor. *) + + (* big_tac. *) + + (* invert MARR. *) + (* destruct b; rewrite assumption_32bit; big_tac. *) + + (* Unshelve. *) + (* constructor. *) + (* Qed. *) + (* Hint Resolve transl_icond_correct : htlproof. *) + + (* Lemma transl_ijumptable_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) + (* (rs : Registers.Regmap.t Values.val) (m : mem) (arg : Registers.reg) (tbl : list RTL.node) *) + (* (n : Integers.Int.int) (pc' : RTL.node), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Ijumptable arg tbl) -> *) + (* Registers.Regmap.get arg rs = Values.Vint n -> *) + (* list_nth_z tbl (Integers.Int.unsigned n) = Some pc' -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f sp pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. *) + (* Proof. *) + (* intros s f sp pc rs m arg tbl n pc' H H0 H1 R1 MSTATE. *) + (* Admitted. *) + (* Hint Resolve transl_ijumptable_correct : htlproof. *) + + (* Lemma transl_ireturn_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (stk : Values.block) *) + (* (pc : positive) (rs : RTL.regset) (m : mem) (or : option Registers.reg) *) + (* (m' : mem), *) + (* (RTL.fn_code f) ! pc = Some (RTL.Ireturn or) -> *) + (* Mem.free m stk 0 (RTL.fn_stacksize f) = Some m' -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) pc rs m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) + (* match_states (RTL.Returnstate s (Registers.regmap_optget or Values.Vundef rs) m') R2. *) + (* Proof. *) + (* intros s f stk pc rs m or m' H H0 R1 MSTATE. *) + (* inv_state. *) + + (* - econstructor. split. *) + (* eapply Smallstep.plus_two. *) + + (* eapply HTL.step_module; eauto. *) + (* apply assumption_32bit. *) + (* constructor. *) + (* econstructor; simpl; trivial. *) + (* econstructor; simpl; trivial. *) + (* constructor. *) + (* econstructor; simpl; trivial. *) + (* constructor. *) + + (* constructor. constructor. *) + + (* unfold state_st_wf in WF; big_tac; eauto. *) + + (* apply HTL.step_finish. *) + (* unfold Verilog.merge_regs. *) + (* unfold_merge; simpl. *) + (* rewrite AssocMap.gso. *) + (* apply AssocMap.gss. lia. *) + (* apply AssocMap.gss. *) + (* rewrite Events.E0_left. reflexivity. *) + + (* constructor; auto. *) + (* constructor. *) + + (* (* FIXME: Duplication *) *) + (* - econstructor. split. *) + (* eapply Smallstep.plus_two. *) + (* eapply HTL.step_module; eauto. *) + (* apply assumption_32bit. *) + (* constructor. *) + (* econstructor; simpl; trivial. *) + (* econstructor; simpl; trivial. *) + (* constructor. constructor. constructor. *) + (* constructor. constructor. constructor. *) + + (* unfold state_st_wf in WF; big_tac; eauto. *) + + (* apply HTL.step_finish. *) + (* unfold Verilog.merge_regs. *) + (* unfold_merge. *) + (* rewrite AssocMap.gso. *) + (* apply AssocMap.gss. simpl; lia. *) + (* apply AssocMap.gss. *) + (* rewrite Events.E0_left. trivial. *) + + (* constructor; auto. *) + + (* simpl. inversion MASSOC. subst. *) + (* unfold find_assocmap, AssocMapExt.get_default. rewrite AssocMap.gso. *) + (* apply H1. eapply RTL.max_reg_function_use. eauto. simpl; tauto. *) + (* assert (HPle : Ple r (RTL.max_reg_function f)). *) + (* eapply RTL.max_reg_function_use. eassumption. simpl; auto. *) + (* apply ZExtra.Ple_not_eq. apply ZExtra.Ple_Plt_Succ. assumption. *) + + (* Unshelve. *) + (* all: constructor. *) + (* Qed. *) + (* Hint Resolve transl_ireturn_correct : htlproof. *) + + (* Lemma transl_callstate_correct: *) + (* forall (s : list RTL.stackframe) (f : RTL.function) (args : list Values.val) *) + (* (m : mem) (m' : Mem.mem') (stk : Values.block), *) + (* Mem.alloc m 0 (RTL.fn_stacksize f) = (m', stk) -> *) + (* forall R1 : HTL.state, *) + (* match_states (RTL.Callstate s (AST.Internal f) args m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) + (* match_states *) + (* (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) (RTL.fn_entrypoint f) *) + (* (RTL.init_regs args (RTL.fn_params f)) m') R2. *) + (* Proof. *) + (* intros s f args m m' stk H R1 MSTATE. *) + + (* inversion MSTATE; subst. inversion TF; subst. *) + (* econstructor. split. apply Smallstep.plus_one. *) + (* eapply HTL.step_call. crush. *) + + (* apply match_state with (sp' := stk); eauto. *) + + (* all: big_tac. *) + + (* apply regs_lessdef_add_greater. *) + (* unfold Plt; lia. *) + (* apply init_reg_assoc_empty. *) + + (* constructor. *) + + (* destruct (Mem.load AST.Mint32 m' stk *) + (* (Integers.Ptrofs.unsigned (Integers.Ptrofs.add *) + (* Integers.Ptrofs.zero *) + (* (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. *) + (* pose proof Mem.load_alloc_same as LOAD_ALLOC. *) + (* pose proof H as ALLOC. *) + (* eapply LOAD_ALLOC in ALLOC. *) + (* 2: { exact LOAD. } *) + (* ptrofs. rewrite LOAD. *) + (* rewrite ALLOC. *) + (* repeat constructor. *) + + (* ptrofs. rewrite LOAD. *) + (* repeat constructor. *) + + (* unfold reg_stack_based_pointers. intros. *) + (* unfold RTL.init_regs; crush. *) + (* destruct (RTL.fn_params f); *) + (* rewrite Registers.Regmap.gi; constructor. *) + + (* unfold arr_stack_based_pointers. intros. *) + (* crush. *) + (* destruct (Mem.load AST.Mint32 m' stk *) + (* (Integers.Ptrofs.unsigned (Integers.Ptrofs.add *) + (* Integers.Ptrofs.zero *) + (* (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. *) + (* pose proof Mem.load_alloc_same as LOAD_ALLOC. *) + (* pose proof H as ALLOC. *) + (* eapply LOAD_ALLOC in ALLOC. *) + (* 2: { exact LOAD. } *) + (* rewrite ALLOC. *) + (* repeat constructor. *) + (* constructor. *) + + (* Transparent Mem.alloc. (* TODO: Since there are opaque there's probably a lemma. *) *) + (* Transparent Mem.load. *) + (* Transparent Mem.store. *) + (* unfold stack_bounds. *) + (* split. *) + + (* unfold Mem.alloc in H. *) + (* invert H. *) + (* crush. *) + (* unfold Mem.load. *) + (* intros. *) + (* match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. *) + (* invert v0. unfold Mem.range_perm in H4. *) + (* unfold Mem.perm in H4. crush. *) + (* unfold Mem.perm_order' in H4. *) + (* small_tac. *) + (* exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. *) + (* rewrite Maps.PMap.gss in H8. *) + (* match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. *) + (* crush. *) + (* apply proj_sumbool_true in H10. lia. *) + + (* unfold Mem.alloc in H. *) + (* invert H. *) + (* crush. *) + (* unfold Mem.store. *) + (* intros. *) + (* match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. *) + (* invert v0. unfold Mem.range_perm in H4. *) + (* unfold Mem.perm in H4. crush. *) + (* unfold Mem.perm_order' in H4. *) + (* small_tac. *) + (* exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. *) + (* rewrite Maps.PMap.gss in H8. *) + (* match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. *) + (* crush. *) + (* apply proj_sumbool_true in H10. lia. *) + (* Opaque Mem.alloc. *) + (* Opaque Mem.load. *) + (* Opaque Mem.store. *) + (* Qed. *) + (* Hint Resolve transl_callstate_correct : htlproof. *) + + (* Lemma transl_returnstate_correct: *) + (* forall (res0 : Registers.reg) (f : RTL.function) (sp : Values.val) (pc : RTL.node) *) + (* (rs : RTL.regset) (s : list RTL.stackframe) (vres : Values.val) (m : mem) *) + (* (R1 : HTL.state), *) + (* match_states (RTL.Returnstate (RTL.Stackframe res0 f sp pc rs :: s) vres m) R1 -> *) + (* exists R2 : HTL.state, *) + (* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) + (* match_states (RTL.State s f sp pc (Registers.Regmap.set res0 vres rs) m) R2. *) + (* Proof. *) + (* intros res0 f sp pc rs s vres m R1 MSTATE. *) + (* inversion MSTATE. inversion MF. *) + (* Qed. *) + (* Hint Resolve transl_returnstate_correct : htlproof. *) + + (* Lemma option_inv : *) + (* forall A x y, *) + (* @Some A x = Some y -> x = y. *) + (* Proof. intros. inversion H. trivial. Qed. *) + + (* Lemma main_tprog_internal : *) + (* forall b, *) + (* Globalenvs.Genv.find_symbol tge tprog.(AST.prog_main) = Some b -> *) + (* exists f, Genv.find_funct_ptr (Genv.globalenv tprog) b = Some (AST.Internal f). *) + (* Proof. *) + (* intros. *) + (* destruct TRANSL. unfold main_is_internal in H1. *) + (* repeat (unfold_match H1). replace b with b0. *) + (* exploit function_ptr_translated; eauto. intros [tf [A B]]. *) + (* unfold transl_fundef, AST.transf_partial_fundef, Errors.bind in B. *) + (* unfold_match B. inv B. econstructor. apply A. *) + + (* apply option_inv. rewrite <- Heqo. rewrite <- H. *) + (* rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). *) + (* trivial. symmetry; eapply Linking.match_program_main; eauto. *) + (* Qed. *) + + (* Lemma transl_initial_states : *) + (* forall s1 : Smallstep.state (RTL.semantics prog), *) + (* Smallstep.initial_state (RTL.semantics prog) s1 -> *) + (* exists s2 : Smallstep.state (HTL.semantics tprog), *) + (* Smallstep.initial_state (HTL.semantics tprog) s2 /\ match_states s1 s2. *) + (* Proof. *) + (* induction 1. *) + (* destruct TRANSL. unfold main_is_internal in H4. *) + (* repeat (unfold_match H4). *) + (* assert (f = AST.Internal f1). apply option_inv. *) + (* rewrite <- Heqo0. rewrite <- H1. replace b with b0. *) + (* auto. apply option_inv. rewrite <- H0. rewrite <- Heqo. *) + (* trivial. *) + (* exploit function_ptr_translated; eauto. *) + (* intros [tf [A B]]. *) + (* unfold transl_fundef, Errors.bind in B. *) + (* unfold AST.transf_partial_fundef, Errors.bind in B. *) + (* repeat (unfold_match B). inversion B. subst. *) + (* exploit main_tprog_internal; eauto; intros. *) + (* rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). *) + (* apply Heqo. symmetry; eapply Linking.match_program_main; eauto. *) + (* inversion H5. *) + (* econstructor; split. econstructor. *) + (* apply (Genv.init_mem_transf_partial TRANSL'); eauto. *) + (* replace (AST.prog_main tprog) with (AST.prog_main prog). *) + (* rewrite symbols_preserved; eauto. *) + (* symmetry; eapply Linking.match_program_main; eauto. *) + (* apply H6. *) + + (* constructor. *) + (* apply transl_module_correct. *) + (* assert (Some (AST.Internal x) = Some (AST.Internal m)). *) + (* replace (AST.fundef HTL.module) with (HTL.fundef). *) + (* rewrite <- H6. setoid_rewrite <- A. trivial. *) + (* trivial. inv H7. assumption. *) + (* Qed. *) + (* Hint Resolve transl_initial_states : htlproof. *) + + (* Lemma transl_final_states : *) + (* forall (s1 : Smallstep.state (RTL.semantics prog)) *) + (* (s2 : Smallstep.state (HTL.semantics tprog)) *) + (* (r : Integers.Int.int), *) + (* match_states s1 s2 -> *) + (* Smallstep.final_state (RTL.semantics prog) s1 r -> *) + (* Smallstep.final_state (HTL.semantics tprog) s2 r. *) + (* Proof. *) + (* intros. inv H0. inv H. inv H4. invert MF. constructor. reflexivity. *) + (* Qed. *) + (* Hint Resolve transl_final_states : htlproof. *) + + (* Theorem transl_step_correct: *) + (* forall (S1 : RTL.state) t S2, *) + (* RTL.step ge S1 t S2 -> *) + (* forall (R1 : HTL.state), *) + (* match_states S1 R1 -> *) + (* exists R2, Smallstep.plus HTL.step tge R1 t R2 /\ match_states S2 R2. *) + (* Proof. *) + (* induction 1; eauto with htlproof; (intros; inv_state). *) + (* Qed. *) + (* Hint Resolve transl_step_correct : htlproof. *) + +(* Theorem transf_program_correct: *) +(* Smallstep.forward_simulation (RTL.semantics prog) (HTL.semantics tprog). *) +(* Proof. *) +(* Admitted. *) +(* (* eapply Smallstep.forward_simulation_plus; eauto with htlproof. *) *) +(* (* apply senv_preserved. *) *) +(* (* Qed. *) *) + +(* End CORRECTNESS. *) diff --git a/src/translation/HTLgenspec.v b/src/translation/HTLgenspec.v index a9626c4..4662cf4 100644 --- a/src/translation/HTLgenspec.v +++ b/src/translation/HTLgenspec.v @@ -148,462 +148,462 @@ Inductive tr_instr (fin rtrn st stk : reg) : RTL.instruction -> stmnt -> stmnt - tr_instr fin rtrn st stk (RTL.Ijumptable r tbl) (Vskip) (Vcase (Vvar r) cexpr (Some Vskip)). Hint Constructors tr_instr : htlspec. -Inductive tr_code (c : RTL.code) (pc : RTL.node) (i : RTL.instruction) (stmnts trans : PTree.t stmnt) - (fin rtrn st stk : reg) : Prop := - tr_code_intro : - forall s t, - c!pc = Some i -> - stmnts!pc = Some s -> - trans!pc = Some t -> - tr_instr fin rtrn st stk i s t -> - tr_code c pc i stmnts trans fin rtrn st stk. -Hint Constructors tr_code : htlspec. - -Inductive tr_module (f : RTL.function) : module -> Prop := - tr_module_intro : - forall data control fin rtrn st stk stk_len m start rst clk scldecls arrdecls wf, - m = (mkmodule f.(RTL.fn_params) - data - control - f.(RTL.fn_entrypoint) - st stk stk_len fin rtrn start rst clk scldecls arrdecls wf) -> - (forall pc i, Maps.PTree.get pc f.(RTL.fn_code) = Some i -> - tr_code f.(RTL.fn_code) pc i data control fin rtrn st stk) -> - stk_len = Z.to_nat (f.(RTL.fn_stacksize) / 4) -> - Z.modulo (f.(RTL.fn_stacksize)) 4 = 0 -> - 0 <= f.(RTL.fn_stacksize) < Integers.Ptrofs.modulus -> - st = ((RTL.max_reg_function f) + 1)%positive -> - fin = ((RTL.max_reg_function f) + 2)%positive -> - rtrn = ((RTL.max_reg_function f) + 3)%positive -> - stk = ((RTL.max_reg_function f) + 4)%positive -> - start = ((RTL.max_reg_function f) + 5)%positive -> - rst = ((RTL.max_reg_function f) + 6)%positive -> - clk = ((RTL.max_reg_function f) + 7)%positive -> - tr_module f m. -Hint Constructors tr_module : htlspec. - -Lemma create_reg_datapath_trans : - forall sz s s' x i iop, - create_reg iop sz s = OK x s' i -> - s.(st_datapath) = s'.(st_datapath). -Proof. intros. monadInv H. trivial. Qed. -Hint Resolve create_reg_datapath_trans : htlspec. - -Lemma create_reg_controllogic_trans : - forall sz s s' x i iop, - create_reg iop sz s = OK x s' i -> - s.(st_controllogic) = s'.(st_controllogic). -Proof. intros. monadInv H. trivial. Qed. -Hint Resolve create_reg_controllogic_trans : htlspec. - -Lemma declare_reg_datapath_trans : - forall sz s s' x i iop r, - declare_reg iop r sz s = OK x s' i -> - s.(st_datapath) = s'.(st_datapath). -Proof. intros. monadInv H. trivial. Qed. -Hint Resolve create_reg_datapath_trans : htlspec. - -Lemma declare_reg_controllogic_trans : - forall sz s s' x i iop r, - declare_reg iop r sz s = OK x s' i -> - s.(st_controllogic) = s'.(st_controllogic). -Proof. intros. monadInv H. trivial. Qed. -Hint Resolve create_reg_controllogic_trans : htlspec. - -Lemma declare_reg_freshreg_trans : - forall sz s s' x i iop r, - declare_reg iop r sz s = OK x s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. inversion 1; auto. Qed. -Hint Resolve declare_reg_freshreg_trans : htlspec. - -Lemma create_arr_datapath_trans : - forall sz ln s s' x i iop, - create_arr iop sz ln s = OK x s' i -> - s.(st_datapath) = s'.(st_datapath). -Proof. intros. monadInv H. trivial. Qed. -Hint Resolve create_arr_datapath_trans : htlspec. - -Lemma create_arr_controllogic_trans : - forall sz ln s s' x i iop, - create_arr iop sz ln s = OK x s' i -> - s.(st_controllogic) = s'.(st_controllogic). -Proof. intros. monadInv H. trivial. Qed. -Hint Resolve create_arr_controllogic_trans : htlspec. - -Lemma get_refl_x : - forall s s' x i, - get s = OK x s' i -> - s = x. -Proof. inversion 1. trivial. Qed. -Hint Resolve get_refl_x : htlspec. - -Lemma get_refl_s : - forall s s' x i, - get s = OK x s' i -> - s = s'. -Proof. inversion 1. trivial. Qed. -Hint Resolve get_refl_s : htlspec. - -Ltac inv_incr := - repeat match goal with - | [ H: create_reg _ _ ?s = OK _ ?s' _ |- _ ] => - let H1 := fresh "H" in - assert (H1 := H); eapply create_reg_datapath_trans in H; - eapply create_reg_controllogic_trans in H1 - | [ H: create_arr _ _ _ ?s = OK _ ?s' _ |- _ ] => - let H1 := fresh "H" in - assert (H1 := H); eapply create_arr_datapath_trans in H; - eapply create_arr_controllogic_trans in H1 - | [ H: get ?s = OK _ _ _ |- _ ] => - let H1 := fresh "H" in - assert (H1 := H); apply get_refl_x in H; apply get_refl_s in H1; - subst - | [ H: st_prop _ _ |- _ ] => unfold st_prop in H; destruct H - | [ H: st_incr _ _ |- _ ] => destruct st_incr - end. - -Lemma collect_controllogic_trans : - forall A f l cs cs' ci, - (forall s s' x i y, f y s = OK x s' i -> s.(st_controllogic) = s'.(st_controllogic)) -> - @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_controllogic) = cs'.(st_controllogic). -Proof. - induction l; intros; monadInv H0. - - trivial. - - apply H in EQ. rewrite EQ. eauto. -Qed. - -Lemma collect_datapath_trans : - forall A f l cs cs' ci, - (forall s s' x i y, f y s = OK x s' i -> s.(st_datapath) = s'.(st_datapath)) -> - @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_datapath) = cs'.(st_datapath). -Proof. - induction l; intros; monadInv H0. - - trivial. - - apply H in EQ. rewrite EQ. eauto. -Qed. - -Lemma collect_freshreg_trans : - forall A f l cs cs' ci, - (forall s s' x i y, f y s = OK x s' i -> s.(st_freshreg) = s'.(st_freshreg)) -> - @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_freshreg) = cs'.(st_freshreg). -Proof. - induction l; intros; monadInv H0. - - trivial. - - apply H in EQ. rewrite EQ. eauto. -Qed. - -Lemma collect_declare_controllogic_trans : - forall io n l s s' i, - HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> - s.(st_controllogic) = s'.(st_controllogic). -Proof. - intros. eapply collect_controllogic_trans; try eassumption. - intros. eapply declare_reg_controllogic_trans. simpl in H0. eassumption. -Qed. - -Lemma collect_declare_datapath_trans : - forall io n l s s' i, - HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> - s.(st_datapath) = s'.(st_datapath). -Proof. - intros. eapply collect_datapath_trans; try eassumption. - intros. eapply declare_reg_datapath_trans. simpl in H0. eassumption. -Qed. - -Lemma collect_declare_freshreg_trans : - forall io n l s s' i, - HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - intros. eapply collect_freshreg_trans; try eassumption. - inversion 1. auto. -Qed. - -Ltac unfold_match H := - match type of H with - | context[match ?g with _ => _ end] => destruct g eqn:?; try discriminate - end. - -Lemma translate_eff_addressing_freshreg_trans : - forall op args s r s' i, - translate_eff_addressing op args s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. -Qed. -Hint Resolve translate_eff_addressing_freshreg_trans : htlspec. - -Lemma translate_comparison_freshreg_trans : - forall op args s r s' i, - translate_comparison op args s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. -Qed. -Hint Resolve translate_comparison_freshreg_trans : htlspec. - -Lemma translate_comparison_imm_freshreg_trans : - forall op args s r s' i n, - translate_comparison_imm op args n s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. -Qed. -Hint Resolve translate_comparison_imm_freshreg_trans : htlspec. - -Lemma translate_condition_freshreg_trans : - forall op args s r s' i, - translate_condition op args s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. -Qed. -Hint Resolve translate_condition_freshreg_trans : htlspec. - -Lemma translate_instr_freshreg_trans : - forall op args s r s' i, - translate_instr op args s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. - monadInv H1. eauto with htlspec. -Qed. -Hint Resolve translate_instr_freshreg_trans : htlspec. - -Lemma translate_arr_access_freshreg_trans : - forall mem addr args st s r s' i, - translate_arr_access mem addr args st s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - intros. unfold translate_arr_access in H. repeat (unfold_match H); inv H; eauto with htlspec. -Qed. -Hint Resolve translate_arr_access_freshreg_trans : htlspec. - -Lemma add_instr_freshreg_trans : - forall n n' st s r s' i, - add_instr n n' st s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. intros. unfold add_instr in H. repeat (unfold_match H). inv H. auto. Qed. -Hint Resolve add_instr_freshreg_trans : htlspec. - -Lemma add_branch_instr_freshreg_trans : - forall n n0 n1 e s r s' i, - add_branch_instr e n n0 n1 s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. intros. unfold add_branch_instr in H. repeat (unfold_match H). inv H. auto. Qed. -Hint Resolve add_branch_instr_freshreg_trans : htlspec. - -Lemma add_node_skip_freshreg_trans : - forall n1 n2 s r s' i, - add_node_skip n1 n2 s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. intros. unfold add_node_skip in H. repeat (unfold_match H). inv H. auto. Qed. -Hint Resolve add_node_skip_freshreg_trans : htlspec. - -Lemma add_instr_skip_freshreg_trans : - forall n1 n2 s r s' i, - add_instr_skip n1 n2 s = OK r s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. intros. unfold add_instr_skip in H. repeat (unfold_match H). inv H. auto. Qed. -Hint Resolve add_instr_skip_freshreg_trans : htlspec. - -Lemma transf_instr_freshreg_trans : - forall fin ret st instr s v s' i, - transf_instr fin ret st instr s = OK v s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - intros. destruct instr eqn:?. subst. unfold transf_instr in H. - destruct i0; try (monadInv H); try (unfold_match H); eauto with htlspec. - - apply add_instr_freshreg_trans in EQ2. apply translate_instr_freshreg_trans in EQ. - apply declare_reg_freshreg_trans in EQ1. congruence. - - apply add_instr_freshreg_trans in EQ2. apply translate_arr_access_freshreg_trans in EQ. - apply declare_reg_freshreg_trans in EQ1. congruence. - - apply add_instr_freshreg_trans in EQ0. apply translate_arr_access_freshreg_trans in EQ. congruence. - - apply translate_condition_freshreg_trans in EQ. apply add_branch_instr_freshreg_trans in EQ0. - congruence. - - inv EQ. apply add_node_skip_freshreg_trans in EQ0. congruence. -Qed. -Hint Resolve transf_instr_freshreg_trans : htlspec. - -Lemma collect_trans_instr_freshreg_trans : - forall fin ret st l s s' i, - HTLMonadExtra.collectlist (transf_instr fin ret st) l s = OK tt s' i -> - s.(st_freshreg) = s'.(st_freshreg). -Proof. - intros. eapply collect_freshreg_trans; try eassumption. - eauto with htlspec. -Qed. - -Ltac rewrite_states := - match goal with - | [ H: ?x ?s = ?x ?s' |- _ ] => - let c1 := fresh "c" in - let c2 := fresh "c" in - remember (?x ?s) as c1; remember (?x ?s') as c2; try subst - end. - -Ltac inv_add_instr' H := - match type of H with - | ?f _ _ _ = OK _ _ _ => unfold f in H - | ?f _ _ _ _ = OK _ _ _ => unfold f in H - | ?f _ _ _ _ _ = OK _ _ _ => unfold f in H - end; repeat unfold_match H; inversion H. - -Ltac inv_add_instr := - lazymatch goal with - | H: context[add_instr_skip _ _ _] |- _ => - inv_add_instr' H - | H: context[add_instr_skip _ _] |- _ => - monadInv H; inv_incr; inv_add_instr - | H: context[add_instr _ _ _ _] |- _ => - inv_add_instr' H - | H: context[add_instr _ _ _] |- _ => - monadInv H; inv_incr; inv_add_instr - | H: context[add_branch_instr _ _ _ _ _] |- _ => - inv_add_instr' H - | H: context[add_branch_instr _ _ _ _] |- _ => - monadInv H; inv_incr; inv_add_instr - | H: context[add_node_skip _ _ _] |- _ => - inv_add_instr' H - | H: context[add_node_skip _ _] |- _ => - monadInv H; inv_incr; inv_add_instr - end. - -Ltac destruct_optional := - match goal with H: option ?r |- _ => destruct H end. - -Lemma iter_expand_instr_spec : - forall l fin rtrn stack s s' i x c, - HTLMonadExtra.collectlist (transf_instr fin rtrn stack) l s = OK x s' i -> - list_norepet (List.map fst l) -> - (forall pc instr, In (pc, instr) l -> c!pc = Some instr) -> - (forall pc instr, In (pc, instr) l -> - c!pc = Some instr -> - tr_code c pc instr s'.(st_datapath) s'.(st_controllogic) fin rtrn s'.(st_st) stack). -Proof. - induction l; simpl; intros; try contradiction. - destruct a as [pc1 instr1]; simpl in *. inv H0. monadInv H. inv_incr. - destruct (peq pc pc1). - - subst. - destruct instr1 eqn:?; try discriminate; - try destruct_optional; inv_add_instr; econstructor; try assumption. - + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + inversion H2. inversion H9. rewrite H. apply tr_instr_Inop. - eapply in_map with (f := fst) in H9. contradiction. - - + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. - + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. - + inversion H2. inversion H14. unfold nonblock. replace (st_st s4) with (st_st s2) by congruence. - econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. - - + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. - + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. - + inversion H2. inversion H14. rewrite <- e2. replace (st_st s2) with (st_st s0) by congruence. - econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. - - + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct H2. - * inversion H2. - replace (st_st s2) with (st_st s0) by congruence. - eauto with htlspec. - * apply in_map with (f := fst) in H2. contradiction. - - + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct H2. - * inversion H2. - replace (st_st s2) with (st_st s0) by congruence. - eauto with htlspec. - * apply in_map with (f := fst) in H2. contradiction. - - + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. - + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. - + inversion H2. - * inversion H14. constructor. congruence. - * apply in_map with (f := fst) in H14. contradiction. - - + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + inversion H2. - * inversion H9. - replace (st_st s2) with (st_st s0) by congruence. - eauto with htlspec. - * apply in_map with (f := fst) in H9. contradiction. - - + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. - + inversion H2. - * inversion H9. - replace (st_st s2) with (st_st s0) by congruence. - eauto with htlspec. - * apply in_map with (f := fst) in H9. contradiction. - - - eapply IHl. apply EQ0. assumption. - destruct H2. inversion H2. subst. contradiction. - intros. specialize H1 with pc0 instr0. destruct H1. tauto. trivial. - destruct H2. inv H2. contradiction. assumption. assumption. -Qed. -Hint Resolve iter_expand_instr_spec : htlspec. - -Lemma create_arr_inv : forall w x y z a b c d, - create_arr w x y z = OK (a, b) c d -> - y = b /\ a = z.(st_freshreg) /\ c.(st_freshreg) = Pos.succ (z.(st_freshreg)). -Proof. - inversion 1; split; auto. -Qed. - -Lemma create_reg_inv : forall a b s r s' i, - create_reg a b s = OK r s' i -> - r = s.(st_freshreg) /\ s'.(st_freshreg) = Pos.succ (s.(st_freshreg)). -Proof. - inversion 1; auto. -Qed. - -Theorem transl_module_correct : - forall f m, - transl_module f = Errors.OK m -> tr_module f m. -Proof. - intros until m. - unfold transl_module. - unfold run_mon. - destruct (transf_module f (max_state f)) eqn:?; try discriminate. - intros. inv H. - inversion s; subst. - - unfold transf_module in *. - unfold stack_correct in *. - destruct (0 <=? RTL.fn_stacksize f) eqn:STACK_BOUND_LOW; - destruct (RTL.fn_stacksize f *) +(* stmnts!pc = Some s -> *) +(* trans!pc = Some t -> *) +(* tr_instr fin rtrn st stk i s t -> *) +(* tr_code c pc i stmnts trans fin rtrn st stk. *) +(* Hint Constructors tr_code : htlspec. *) + +(* Inductive tr_module (f : RTL.function) : module -> Prop := *) +(* tr_module_intro : *) +(* forall data control fin rtrn st stk stk_len m start rst clk scldecls arrdecls wf, *) +(* m = (mkmodule f.(RTL.fn_params) *) +(* data *) +(* control *) +(* f.(RTL.fn_entrypoint) *) +(* st stk stk_len fin rtrn start rst clk scldecls arrdecls wf) -> *) +(* (forall pc i, Maps.PTree.get pc f.(RTL.fn_code) = Some i -> *) +(* tr_code f.(RTL.fn_code) pc i data control fin rtrn st stk) -> *) +(* stk_len = Z.to_nat (f.(RTL.fn_stacksize) / 4) -> *) +(* Z.modulo (f.(RTL.fn_stacksize)) 4 = 0 -> *) +(* 0 <= f.(RTL.fn_stacksize) < Integers.Ptrofs.modulus -> *) +(* st = ((RTL.max_reg_function f) + 1)%positive -> *) +(* fin = ((RTL.max_reg_function f) + 2)%positive -> *) +(* rtrn = ((RTL.max_reg_function f) + 3)%positive -> *) +(* stk = ((RTL.max_reg_function f) + 4)%positive -> *) +(* start = ((RTL.max_reg_function f) + 5)%positive -> *) +(* rst = ((RTL.max_reg_function f) + 6)%positive -> *) +(* clk = ((RTL.max_reg_function f) + 7)%positive -> *) +(* tr_module f m. *) +(* Hint Constructors tr_module : htlspec. *) + +(* Lemma create_reg_datapath_trans : *) +(* forall sz s s' x i iop, *) +(* create_reg iop sz s = OK x s' i -> *) +(* s.(st_datapath) = s'.(st_datapath). *) +(* Proof. intros. monadInv H. trivial. Qed. *) +(* Hint Resolve create_reg_datapath_trans : htlspec. *) + +(* Lemma create_reg_controllogic_trans : *) +(* forall sz s s' x i iop, *) +(* create_reg iop sz s = OK x s' i -> *) +(* s.(st_controllogic) = s'.(st_controllogic). *) +(* Proof. intros. monadInv H. trivial. Qed. *) +(* Hint Resolve create_reg_controllogic_trans : htlspec. *) + +(* Lemma declare_reg_datapath_trans : *) +(* forall sz s s' x i iop r, *) +(* declare_reg iop r sz s = OK x s' i -> *) +(* s.(st_datapath) = s'.(st_datapath). *) +(* Proof. intros. monadInv H. trivial. Qed. *) +(* Hint Resolve create_reg_datapath_trans : htlspec. *) + +(* Lemma declare_reg_controllogic_trans : *) +(* forall sz s s' x i iop r, *) +(* declare_reg iop r sz s = OK x s' i -> *) +(* s.(st_controllogic) = s'.(st_controllogic). *) +(* Proof. intros. monadInv H. trivial. Qed. *) +(* Hint Resolve create_reg_controllogic_trans : htlspec. *) + +(* Lemma declare_reg_freshreg_trans : *) +(* forall sz s s' x i iop r, *) +(* declare_reg iop r sz s = OK x s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. inversion 1; auto. Qed. *) +(* Hint Resolve declare_reg_freshreg_trans : htlspec. *) + +(* Lemma create_arr_datapath_trans : *) +(* forall sz ln s s' x i iop, *) +(* create_arr iop sz ln s = OK x s' i -> *) +(* s.(st_datapath) = s'.(st_datapath). *) +(* Proof. intros. monadInv H. trivial. Qed. *) +(* Hint Resolve create_arr_datapath_trans : htlspec. *) + +(* Lemma create_arr_controllogic_trans : *) +(* forall sz ln s s' x i iop, *) +(* create_arr iop sz ln s = OK x s' i -> *) +(* s.(st_controllogic) = s'.(st_controllogic). *) +(* Proof. intros. monadInv H. trivial. Qed. *) +(* Hint Resolve create_arr_controllogic_trans : htlspec. *) + +(* Lemma get_refl_x : *) +(* forall s s' x i, *) +(* get s = OK x s' i -> *) +(* s = x. *) +(* Proof. inversion 1. trivial. Qed. *) +(* Hint Resolve get_refl_x : htlspec. *) + +(* Lemma get_refl_s : *) +(* forall s s' x i, *) +(* get s = OK x s' i -> *) +(* s = s'. *) +(* Proof. inversion 1. trivial. Qed. *) +(* Hint Resolve get_refl_s : htlspec. *) + +(* Ltac inv_incr := *) +(* repeat match goal with *) +(* | [ H: create_reg _ _ ?s = OK _ ?s' _ |- _ ] => *) +(* let H1 := fresh "H" in *) +(* assert (H1 := H); eapply create_reg_datapath_trans in H; *) +(* eapply create_reg_controllogic_trans in H1 *) +(* | [ H: create_arr _ _ _ ?s = OK _ ?s' _ |- _ ] => *) +(* let H1 := fresh "H" in *) +(* assert (H1 := H); eapply create_arr_datapath_trans in H; *) +(* eapply create_arr_controllogic_trans in H1 *) +(* | [ H: get ?s = OK _ _ _ |- _ ] => *) +(* let H1 := fresh "H" in *) +(* assert (H1 := H); apply get_refl_x in H; apply get_refl_s in H1; *) +(* subst *) +(* | [ H: st_prop _ _ |- _ ] => unfold st_prop in H; destruct H *) +(* | [ H: st_incr _ _ |- _ ] => destruct st_incr *) +(* end. *) + +(* Lemma collect_controllogic_trans : *) +(* forall A f l cs cs' ci, *) +(* (forall s s' x i y, f y s = OK x s' i -> s.(st_controllogic) = s'.(st_controllogic)) -> *) +(* @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_controllogic) = cs'.(st_controllogic). *) +(* Proof. *) +(* induction l; intros; monadInv H0. *) +(* - trivial. *) +(* - apply H in EQ. rewrite EQ. eauto. *) +(* Qed. *) + +(* Lemma collect_datapath_trans : *) +(* forall A f l cs cs' ci, *) +(* (forall s s' x i y, f y s = OK x s' i -> s.(st_datapath) = s'.(st_datapath)) -> *) +(* @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_datapath) = cs'.(st_datapath). *) +(* Proof. *) +(* induction l; intros; monadInv H0. *) +(* - trivial. *) +(* - apply H in EQ. rewrite EQ. eauto. *) +(* Qed. *) + +(* Lemma collect_freshreg_trans : *) +(* forall A f l cs cs' ci, *) +(* (forall s s' x i y, f y s = OK x s' i -> s.(st_freshreg) = s'.(st_freshreg)) -> *) +(* @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_freshreg) = cs'.(st_freshreg). *) +(* Proof. *) +(* induction l; intros; monadInv H0. *) +(* - trivial. *) +(* - apply H in EQ. rewrite EQ. eauto. *) +(* Qed. *) + +(* Lemma collect_declare_controllogic_trans : *) +(* forall io n l s s' i, *) +(* HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> *) +(* s.(st_controllogic) = s'.(st_controllogic). *) +(* Proof. *) +(* intros. eapply collect_controllogic_trans; try eassumption. *) +(* intros. eapply declare_reg_controllogic_trans. simpl in H0. eassumption. *) +(* Qed. *) + +(* Lemma collect_declare_datapath_trans : *) +(* forall io n l s s' i, *) +(* HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> *) +(* s.(st_datapath) = s'.(st_datapath). *) +(* Proof. *) +(* intros. eapply collect_datapath_trans; try eassumption. *) +(* intros. eapply declare_reg_datapath_trans. simpl in H0. eassumption. *) +(* Qed. *) + +(* Lemma collect_declare_freshreg_trans : *) +(* forall io n l s s' i, *) +(* HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* intros. eapply collect_freshreg_trans; try eassumption. *) +(* inversion 1. auto. *) +(* Qed. *) + +(* Ltac unfold_match H := *) +(* match type of H with *) +(* | context[match ?g with _ => _ end] => destruct g eqn:?; try discriminate *) +(* end. *) + +(* Lemma translate_eff_addressing_freshreg_trans : *) +(* forall op args s r s' i, *) +(* translate_eff_addressing op args s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. *) +(* Qed. *) +(* Hint Resolve translate_eff_addressing_freshreg_trans : htlspec. *) + +(* Lemma translate_comparison_freshreg_trans : *) +(* forall op args s r s' i, *) +(* translate_comparison op args s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. *) +(* Qed. *) +(* Hint Resolve translate_comparison_freshreg_trans : htlspec. *) + +(* Lemma translate_comparison_imm_freshreg_trans : *) +(* forall op args s r s' i n, *) +(* translate_comparison_imm op args n s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. *) +(* Qed. *) +(* Hint Resolve translate_comparison_imm_freshreg_trans : htlspec. *) + +(* Lemma translate_condition_freshreg_trans : *) +(* forall op args s r s' i, *) +(* translate_condition op args s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. *) +(* Qed. *) +(* Hint Resolve translate_condition_freshreg_trans : htlspec. *) + +(* Lemma translate_instr_freshreg_trans : *) +(* forall op args s r s' i, *) +(* translate_instr op args s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. *) +(* monadInv H1. eauto with htlspec. *) +(* Qed. *) +(* Hint Resolve translate_instr_freshreg_trans : htlspec. *) + +(* Lemma translate_arr_access_freshreg_trans : *) +(* forall mem addr args st s r s' i, *) +(* translate_arr_access mem addr args st s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* intros. unfold translate_arr_access in H. repeat (unfold_match H); inv H; eauto with htlspec. *) +(* Qed. *) +(* Hint Resolve translate_arr_access_freshreg_trans : htlspec. *) + +(* Lemma add_instr_freshreg_trans : *) +(* forall n n' st s r s' i, *) +(* add_instr n n' st s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. intros. unfold add_instr in H. repeat (unfold_match H). inv H. auto. Qed. *) +(* Hint Resolve add_instr_freshreg_trans : htlspec. *) + +(* Lemma add_branch_instr_freshreg_trans : *) +(* forall n n0 n1 e s r s' i, *) +(* add_branch_instr e n n0 n1 s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. intros. unfold add_branch_instr in H. repeat (unfold_match H). inv H. auto. Qed. *) +(* Hint Resolve add_branch_instr_freshreg_trans : htlspec. *) + +(* Lemma add_node_skip_freshreg_trans : *) +(* forall n1 n2 s r s' i, *) +(* add_node_skip n1 n2 s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. intros. unfold add_node_skip in H. repeat (unfold_match H). inv H. auto. Qed. *) +(* Hint Resolve add_node_skip_freshreg_trans : htlspec. *) + +(* Lemma add_instr_skip_freshreg_trans : *) +(* forall n1 n2 s r s' i, *) +(* add_instr_skip n1 n2 s = OK r s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. intros. unfold add_instr_skip in H. repeat (unfold_match H). inv H. auto. Qed. *) +(* Hint Resolve add_instr_skip_freshreg_trans : htlspec. *) + +(* Lemma transf_instr_freshreg_trans : *) +(* forall fin ret st instr s v s' i, *) +(* transf_instr fin ret st instr s = OK v s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* intros. destruct instr eqn:?. subst. unfold transf_instr in H. *) +(* destruct i0; try (monadInv H); try (unfold_match H); eauto with htlspec. *) +(* - apply add_instr_freshreg_trans in EQ2. apply translate_instr_freshreg_trans in EQ. *) +(* apply declare_reg_freshreg_trans in EQ1. congruence. *) +(* - apply add_instr_freshreg_trans in EQ2. apply translate_arr_access_freshreg_trans in EQ. *) +(* apply declare_reg_freshreg_trans in EQ1. congruence. *) +(* - apply add_instr_freshreg_trans in EQ0. apply translate_arr_access_freshreg_trans in EQ. congruence. *) +(* - apply translate_condition_freshreg_trans in EQ. apply add_branch_instr_freshreg_trans in EQ0. *) +(* congruence. *) +(* - inv EQ. apply add_node_skip_freshreg_trans in EQ0. congruence. *) +(* Qed. *) +(* Hint Resolve transf_instr_freshreg_trans : htlspec. *) + +(* Lemma collect_trans_instr_freshreg_trans : *) +(* forall fin ret st l s s' i, *) +(* HTLMonadExtra.collectlist (transf_instr fin ret st) l s = OK tt s' i -> *) +(* s.(st_freshreg) = s'.(st_freshreg). *) +(* Proof. *) +(* intros. eapply collect_freshreg_trans; try eassumption. *) +(* eauto with htlspec. *) +(* Qed. *) + +(* Ltac rewrite_states := *) +(* match goal with *) +(* | [ H: ?x ?s = ?x ?s' |- _ ] => *) +(* let c1 := fresh "c" in *) +(* let c2 := fresh "c" in *) +(* remember (?x ?s) as c1; remember (?x ?s') as c2; try subst *) +(* end. *) + +(* Ltac inv_add_instr' H := *) +(* match type of H with *) +(* | ?f _ _ _ = OK _ _ _ => unfold f in H *) +(* | ?f _ _ _ _ = OK _ _ _ => unfold f in H *) +(* | ?f _ _ _ _ _ = OK _ _ _ => unfold f in H *) +(* end; repeat unfold_match H; inversion H. *) + +(* Ltac inv_add_instr := *) +(* lazymatch goal with *) +(* | H: context[add_instr_skip _ _ _] |- _ => *) +(* inv_add_instr' H *) +(* | H: context[add_instr_skip _ _] |- _ => *) +(* monadInv H; inv_incr; inv_add_instr *) +(* | H: context[add_instr _ _ _ _] |- _ => *) +(* inv_add_instr' H *) +(* | H: context[add_instr _ _ _] |- _ => *) +(* monadInv H; inv_incr; inv_add_instr *) +(* | H: context[add_branch_instr _ _ _ _ _] |- _ => *) +(* inv_add_instr' H *) +(* | H: context[add_branch_instr _ _ _ _] |- _ => *) +(* monadInv H; inv_incr; inv_add_instr *) +(* | H: context[add_node_skip _ _ _] |- _ => *) +(* inv_add_instr' H *) +(* | H: context[add_node_skip _ _] |- _ => *) +(* monadInv H; inv_incr; inv_add_instr *) +(* end. *) + +(* Ltac destruct_optional := *) +(* match goal with H: option ?r |- _ => destruct H end. *) + +(* Lemma iter_expand_instr_spec : *) +(* forall l fin rtrn stack s s' i x c, *) +(* HTLMonadExtra.collectlist (transf_instr fin rtrn stack) l s = OK x s' i -> *) +(* list_norepet (List.map fst l) -> *) +(* (forall pc instr, In (pc, instr) l -> c!pc = Some instr) -> *) +(* (forall pc instr, In (pc, instr) l -> *) +(* c!pc = Some instr -> *) +(* tr_code c pc instr s'.(st_datapath) s'.(st_controllogic) fin rtrn s'.(st_st) stack). *) +(* Proof. *) +(* induction l; simpl; intros; try contradiction. *) +(* destruct a as [pc1 instr1]; simpl in *. inv H0. monadInv H. inv_incr. *) +(* destruct (peq pc pc1). *) +(* - subst. *) +(* destruct instr1 eqn:?; try discriminate; *) +(* try destruct_optional; inv_add_instr; econstructor; try assumption. *) +(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + inversion H2. inversion H9. rewrite H. apply tr_instr_Inop. *) +(* eapply in_map with (f := fst) in H9. contradiction. *) + +(* + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) +(* + inversion H2. inversion H14. unfold nonblock. replace (st_st s4) with (st_st s2) by congruence. *) +(* econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. *) + +(* + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) +(* + inversion H2. inversion H14. rewrite <- e2. replace (st_st s2) with (st_st s0) by congruence. *) +(* econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. *) + +(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct H2. *) +(* * inversion H2. *) +(* replace (st_st s2) with (st_st s0) by congruence. *) +(* eauto with htlspec. *) +(* * apply in_map with (f := fst) in H2. contradiction. *) + +(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct H2. *) +(* * inversion H2. *) +(* replace (st_st s2) with (st_st s0) by congruence. *) +(* eauto with htlspec. *) +(* * apply in_map with (f := fst) in H2. contradiction. *) + +(* + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) +(* + inversion H2. *) +(* * inversion H14. constructor. congruence. *) +(* * apply in_map with (f := fst) in H14. contradiction. *) + +(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + inversion H2. *) +(* * inversion H9. *) +(* replace (st_st s2) with (st_st s0) by congruence. *) +(* eauto with htlspec. *) +(* * apply in_map with (f := fst) in H9. contradiction. *) + +(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) +(* + inversion H2. *) +(* * inversion H9. *) +(* replace (st_st s2) with (st_st s0) by congruence. *) +(* eauto with htlspec. *) +(* * apply in_map with (f := fst) in H9. contradiction. *) + +(* - eapply IHl. apply EQ0. assumption. *) +(* destruct H2. inversion H2. subst. contradiction. *) +(* intros. specialize H1 with pc0 instr0. destruct H1. tauto. trivial. *) +(* destruct H2. inv H2. contradiction. assumption. assumption. *) +(* Qed. *) +(* Hint Resolve iter_expand_instr_spec : htlspec. *) + +(* Lemma create_arr_inv : forall w x y z a b c d, *) +(* create_arr w x y z = OK (a, b) c d -> *) +(* y = b /\ a = z.(st_freshreg) /\ c.(st_freshreg) = Pos.succ (z.(st_freshreg)). *) +(* Proof. *) +(* inversion 1; split; auto. *) +(* Qed. *) + +(* Lemma create_reg_inv : forall a b s r s' i, *) +(* create_reg a b s = OK r s' i -> *) +(* r = s.(st_freshreg) /\ s'.(st_freshreg) = Pos.succ (s.(st_freshreg)). *) +(* Proof. *) +(* inversion 1; auto. *) +(* Qed. *) + +(* Theorem transl_module_correct : *) +(* forall f m, *) +(* transl_module f = Errors.OK m -> tr_module f m. *) +(* Proof. *) +(* intros until m. *) +(* unfold transl_module. *) +(* unfold run_mon. *) +(* destruct (transf_module f (max_state f)) eqn:?; try discriminate. *) +(* intros. inv H. *) +(* inversion s; subst. *) + +(* unfold transf_module in *. *) +(* unfold stack_correct in *. *) +(* destruct (0 <=? RTL.fn_stacksize f) eqn:STACK_BOUND_LOW; *) +(* destruct (RTL.fn_stacksize f . *) -open Value +open ValueInt open Datatypes open Camlcoq open AST diff --git a/src/verilog/PrintVerilog.ml b/src/verilog/PrintVerilog.ml index 5265c97..db78ad5 100644 --- a/src/verilog/PrintVerilog.ml +++ b/src/verilog/PrintVerilog.ml @@ -17,7 +17,7 @@ *) open Verilog -open Value +open ValueInt open Datatypes open Camlcoq @@ -70,11 +70,17 @@ let unop = function let register a = sprintf "reg_%d" (P.to_int a) -let literal l = sprintf "%d'd%d" (Nat.to_int l.vsize) (Z.to_int (uvalueToZ l)) +let literal l = sprintf "32'd%d" (Z.to_int (uvalueToZ l)) + +let byte n s = sprintf "reg_%d[%d:%d]" (P.to_int s) (7 + n * 8) (n * 8) let rec pprint_expr = function | Vlit l -> literal l | Vvar s -> register s + | Vvarb0 s -> byte 0 s + | Vvarb1 s -> byte 1 s + | Vvarb2 s -> byte 2 s + | Vvarb3 s -> byte 3 s | Vvari (s, i) -> concat [register s; "["; pprint_expr i; "]"] | Vinputvar s -> register s | Vunop (u, e) -> concat ["("; unop u; pprint_expr e; ")"] diff --git a/src/verilog/PrintVerilog.mli b/src/verilog/PrintVerilog.mli index 62bf63f..5fd8fe9 100644 --- a/src/verilog/PrintVerilog.mli +++ b/src/verilog/PrintVerilog.mli @@ -18,8 +18,8 @@ val pprint_stmnt : int -> Verilog.stmnt -> string -val print_value : out_channel -> Value.value -> unit +val print_value : out_channel -> ValueInt.value -> unit val print_program : bool -> out_channel -> Verilog.program -> unit -val print_result : out_channel -> (BinNums.positive * Value.value) list -> unit +val print_result : out_channel -> (BinNums.positive * ValueInt.value) list -> unit diff --git a/src/verilog/Verilog.v b/src/verilog/Verilog.v index 064474a..921d9fd 100644 --- a/src/verilog/Verilog.v +++ b/src/verilog/Verilog.v @@ -29,7 +29,7 @@ Require Import Lia. Import ListNotations. -From coqup Require Import common.Coquplib common.Show verilog.ValueInt AssocMap Array. +From coqup Require Import common.Coquplib common.Show verilog.ValueInt IntegerExtra AssocMap Array. From compcert Require Events. From compcert Require Import Integers Errors Smallstep Globalenvs. @@ -154,9 +154,13 @@ Inductive unop : Type := (** ** Expressions *) Inductive expr : Type := -| Vlit : value -> expr -| Vvar : reg -> expr -| Vvari : reg -> expr -> expr +| Vlit : value -> expr (** literal *) +| Vvar : reg -> expr (** reg *) +| Vvarb0 : reg -> expr (** 1st byte projection of reg *) +| Vvarb1 : reg -> expr +| Vvarb2 : reg -> expr +| Vvarb3 : reg -> expr +| Vvari : reg -> expr -> expr (** array *) | Vinputvar : reg -> expr | Vbinop : binop -> expr -> expr -> expr | Vunop : unop -> expr -> expr @@ -340,6 +344,22 @@ Inductive expr_runp : fext -> assocmap -> assocmap_arr -> expr -> value -> Prop forall fext reg stack v r, reg#r = v -> expr_runp fext reg stack (Vvar r) v + | erun_Vvarb0 : + forall fext reg stack v r, + reg#r = v -> + expr_runp fext reg stack (Vvarb0 r) (IntExtra.ibyte0 v) + | erun_Vvarb1 : + forall fext reg stack v r, + reg#r = v -> + expr_runp fext reg stack (Vvarb1 r) (IntExtra.ibyte1 v) + | erun_Vvarb2 : + forall fext reg stack v r, + reg#r = v -> + expr_runp fext reg stack (Vvarb2 r) (IntExtra.ibyte2 v) + | erun_Vvarb3 : + forall fext reg stack v r, + reg#r = v -> + expr_runp fext reg stack (Vvarb3 r) (IntExtra.ibyte3 v) | erun_Vvari : forall fext reg stack v iexp i r, expr_runp fext reg stack iexp i -> @@ -429,6 +449,7 @@ Definition access_fext (f : fext) (r : reg) : res value := Inductive location : Type := | LocReg (_ : reg) +| LocRegB (_ : reg) (_ : nat) | LocArray (_ : reg) (_ : nat). Inductive location_is : fext -> assocmap -> assocmap_arr -> expr -> location -> Prop := @@ -775,6 +796,10 @@ Proof. repeat (try match goal with | [ H : expr_runp _ _ _ (Vlit _) _ |- _ ] => invert H | [ H : expr_runp _ _ _ (Vvar _) _ |- _ ] => invert H + | [ H : expr_runp _ _ _ (Vvarb0 _) _ |- _ ] => invert H + | [ H : expr_runp _ _ _ (Vvarb1 _) _ |- _ ] => invert H + | [ H : expr_runp _ _ _ (Vvarb2 _) _ |- _ ] => invert H + | [ H : expr_runp _ _ _ (Vvarb3 _) _ |- _ ] => invert H | [ H : expr_runp _ _ _ (Vvari _ _) _ |- _ ] => invert H | [ H : expr_runp _ _ _ (Vinputvar _) _ |- _ ] => invert H | [ H : expr_runp _ _ _ (Vbinop _ _ _) _ |- _ ] => invert H -- cgit From ea44bd696dcfb446f5f980f16d7df41b21357698 Mon Sep 17 00:00:00 2001 From: James Pollard Date: Mon, 6 Jul 2020 19:27:51 +0100 Subject: Fix HTLgenspec. --- src/translation/HTLgen.v | 18 +- src/translation/HTLgenspec.v | 925 +++++++++++++++++++++---------------------- 2 files changed, 467 insertions(+), 476 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 995977c..09af28a 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -414,21 +414,19 @@ Definition tbl_to_case_expr (st : reg) (ns : list node) : list (expr * stmnt) := end) (enumerate 0 ns). -Definition add_single_cycle_load (n n' : node) (stack : reg) (addr : expr) (dst : reg) : mon unit := +Definition create_single_cycle_load (stack : reg) (addr : expr) (dst : reg) : stmnt := let l0 := Vnonblock (Vvarb0 dst) (Vvari stack addr) in let l1 := Vnonblock (Vvarb1 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 1)) in let l2 := Vnonblock (Vvarb2 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) in - let l3 := Vnonblock (Vvarb3 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) in - let instr := Vseq l0 $ Vseq l1 $ Vseq l2 $ l3 - in add_instr n n' instr. + let l3 := Vnonblock (Vvarb3 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) + in Vseq l0 $ Vseq l1 $ Vseq l2 $ l3. -Definition add_single_cycle_store (n n' : node) (stack : reg) (addr : expr) (src : reg) : mon unit := +Definition create_single_cycle_store (stack : reg) (addr : expr) (src : reg) : stmnt := let l0 := Vnonblock (Vvari stack addr) (Vvarb0 src) in let l1 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 1)) (Vvarb1 src) in let l2 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb2 src) in - let l3 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb3 src) in - let instr := Vseq l0 $ Vseq l1 $ Vseq l2 $ l3 - in add_instr n n' instr. + let l3 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb3 src) + in Vseq l0 $ Vseq l1 $ Vseq l2 $ l3. Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon unit := match ni with @@ -442,10 +440,10 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni | Iload mem addr args dst n' => do addr' <- translate_eff_addressing addr args; do _ <- declare_reg None dst 32; - add_single_cycle_load n n' stack addr' dst + add_instr n n' $ create_single_cycle_load stack addr' dst | Istore mem addr args src n' => do addr' <- translate_eff_addressing addr args; - add_single_cycle_store n n' stack addr' src + add_instr n n' $ create_single_cycle_store stack addr' src | Icall _ _ _ _ _ => error (Errors.msg "Calls are not implemented.") | Itailcall _ _ _ => error (Errors.msg "Tailcalls are not implemented.") | Ibuiltin _ _ _ _ => error (Errors.msg "Builtin functions not implemented.") diff --git a/src/translation/HTLgenspec.v b/src/translation/HTLgenspec.v index 4662cf4..bbcde14 100644 --- a/src/translation/HTLgenspec.v +++ b/src/translation/HTLgenspec.v @@ -134,476 +134,469 @@ Inductive tr_instr (fin rtrn st stk : reg) : RTL.instruction -> stmnt -> stmnt - tr_instr fin rtrn st stk (RTL.Ireturn (Some r)) (Vseq (block fin (Vlit (ZToValue 1%Z))) (block rtrn (Vvar r))) Vskip | tr_instr_Iload : - forall mem addr args s s' i c dst n, - translate_arr_access mem addr args stk s = OK c s' i -> - tr_instr fin rtrn st stk (RTL.Iload mem addr args dst n) (nonblock dst c) (state_goto st n) + forall mem addr args s s' i e dst n, + translate_eff_addressing addr args s = OK e s' i -> + tr_instr fin rtrn st stk (RTL.Iload mem addr args dst n) + (create_single_cycle_load stk e dst) (state_goto st n) | tr_instr_Istore : - forall mem addr args s s' i c src n, - translate_arr_access mem addr args stk s = OK c s' i -> - tr_instr fin rtrn st stk (RTL.Istore mem addr args src n) (Vnonblock c (Vvar src)) - (state_goto st n) + forall mem addr args s s' i e src n, + translate_eff_addressing addr args s = OK e s' i -> + tr_instr fin rtrn st stk (RTL.Istore mem addr args src n) + (create_single_cycle_store stk e src) (state_goto st n) | tr_instr_Ijumptable : forall cexpr tbl r, cexpr = tbl_to_case_expr st tbl -> tr_instr fin rtrn st stk (RTL.Ijumptable r tbl) (Vskip) (Vcase (Vvar r) cexpr (Some Vskip)). Hint Constructors tr_instr : htlspec. -(* Inductive tr_code (c : RTL.code) (pc : RTL.node) (i : RTL.instruction) (stmnts trans : PTree.t stmnt) *) -(* (fin rtrn st stk : reg) : Prop := *) -(* tr_code_intro : *) -(* forall s t, *) -(* c!pc = Some i -> *) -(* stmnts!pc = Some s -> *) -(* trans!pc = Some t -> *) -(* tr_instr fin rtrn st stk i s t -> *) -(* tr_code c pc i stmnts trans fin rtrn st stk. *) -(* Hint Constructors tr_code : htlspec. *) - -(* Inductive tr_module (f : RTL.function) : module -> Prop := *) -(* tr_module_intro : *) -(* forall data control fin rtrn st stk stk_len m start rst clk scldecls arrdecls wf, *) -(* m = (mkmodule f.(RTL.fn_params) *) -(* data *) -(* control *) -(* f.(RTL.fn_entrypoint) *) -(* st stk stk_len fin rtrn start rst clk scldecls arrdecls wf) -> *) -(* (forall pc i, Maps.PTree.get pc f.(RTL.fn_code) = Some i -> *) -(* tr_code f.(RTL.fn_code) pc i data control fin rtrn st stk) -> *) -(* stk_len = Z.to_nat (f.(RTL.fn_stacksize) / 4) -> *) -(* Z.modulo (f.(RTL.fn_stacksize)) 4 = 0 -> *) -(* 0 <= f.(RTL.fn_stacksize) < Integers.Ptrofs.modulus -> *) -(* st = ((RTL.max_reg_function f) + 1)%positive -> *) -(* fin = ((RTL.max_reg_function f) + 2)%positive -> *) -(* rtrn = ((RTL.max_reg_function f) + 3)%positive -> *) -(* stk = ((RTL.max_reg_function f) + 4)%positive -> *) -(* start = ((RTL.max_reg_function f) + 5)%positive -> *) -(* rst = ((RTL.max_reg_function f) + 6)%positive -> *) -(* clk = ((RTL.max_reg_function f) + 7)%positive -> *) -(* tr_module f m. *) -(* Hint Constructors tr_module : htlspec. *) - -(* Lemma create_reg_datapath_trans : *) -(* forall sz s s' x i iop, *) -(* create_reg iop sz s = OK x s' i -> *) -(* s.(st_datapath) = s'.(st_datapath). *) -(* Proof. intros. monadInv H. trivial. Qed. *) -(* Hint Resolve create_reg_datapath_trans : htlspec. *) - -(* Lemma create_reg_controllogic_trans : *) -(* forall sz s s' x i iop, *) -(* create_reg iop sz s = OK x s' i -> *) -(* s.(st_controllogic) = s'.(st_controllogic). *) -(* Proof. intros. monadInv H. trivial. Qed. *) -(* Hint Resolve create_reg_controllogic_trans : htlspec. *) - -(* Lemma declare_reg_datapath_trans : *) -(* forall sz s s' x i iop r, *) -(* declare_reg iop r sz s = OK x s' i -> *) -(* s.(st_datapath) = s'.(st_datapath). *) -(* Proof. intros. monadInv H. trivial. Qed. *) -(* Hint Resolve create_reg_datapath_trans : htlspec. *) - -(* Lemma declare_reg_controllogic_trans : *) -(* forall sz s s' x i iop r, *) -(* declare_reg iop r sz s = OK x s' i -> *) -(* s.(st_controllogic) = s'.(st_controllogic). *) -(* Proof. intros. monadInv H. trivial. Qed. *) -(* Hint Resolve create_reg_controllogic_trans : htlspec. *) - -(* Lemma declare_reg_freshreg_trans : *) -(* forall sz s s' x i iop r, *) -(* declare_reg iop r sz s = OK x s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. inversion 1; auto. Qed. *) -(* Hint Resolve declare_reg_freshreg_trans : htlspec. *) - -(* Lemma create_arr_datapath_trans : *) -(* forall sz ln s s' x i iop, *) -(* create_arr iop sz ln s = OK x s' i -> *) -(* s.(st_datapath) = s'.(st_datapath). *) -(* Proof. intros. monadInv H. trivial. Qed. *) -(* Hint Resolve create_arr_datapath_trans : htlspec. *) - -(* Lemma create_arr_controllogic_trans : *) -(* forall sz ln s s' x i iop, *) -(* create_arr iop sz ln s = OK x s' i -> *) -(* s.(st_controllogic) = s'.(st_controllogic). *) -(* Proof. intros. monadInv H. trivial. Qed. *) -(* Hint Resolve create_arr_controllogic_trans : htlspec. *) - -(* Lemma get_refl_x : *) -(* forall s s' x i, *) -(* get s = OK x s' i -> *) -(* s = x. *) -(* Proof. inversion 1. trivial. Qed. *) -(* Hint Resolve get_refl_x : htlspec. *) - -(* Lemma get_refl_s : *) -(* forall s s' x i, *) -(* get s = OK x s' i -> *) -(* s = s'. *) -(* Proof. inversion 1. trivial. Qed. *) -(* Hint Resolve get_refl_s : htlspec. *) - -(* Ltac inv_incr := *) -(* repeat match goal with *) -(* | [ H: create_reg _ _ ?s = OK _ ?s' _ |- _ ] => *) -(* let H1 := fresh "H" in *) -(* assert (H1 := H); eapply create_reg_datapath_trans in H; *) -(* eapply create_reg_controllogic_trans in H1 *) -(* | [ H: create_arr _ _ _ ?s = OK _ ?s' _ |- _ ] => *) -(* let H1 := fresh "H" in *) -(* assert (H1 := H); eapply create_arr_datapath_trans in H; *) -(* eapply create_arr_controllogic_trans in H1 *) -(* | [ H: get ?s = OK _ _ _ |- _ ] => *) -(* let H1 := fresh "H" in *) -(* assert (H1 := H); apply get_refl_x in H; apply get_refl_s in H1; *) -(* subst *) -(* | [ H: st_prop _ _ |- _ ] => unfold st_prop in H; destruct H *) -(* | [ H: st_incr _ _ |- _ ] => destruct st_incr *) -(* end. *) - -(* Lemma collect_controllogic_trans : *) -(* forall A f l cs cs' ci, *) -(* (forall s s' x i y, f y s = OK x s' i -> s.(st_controllogic) = s'.(st_controllogic)) -> *) -(* @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_controllogic) = cs'.(st_controllogic). *) -(* Proof. *) -(* induction l; intros; monadInv H0. *) -(* - trivial. *) -(* - apply H in EQ. rewrite EQ. eauto. *) -(* Qed. *) - -(* Lemma collect_datapath_trans : *) -(* forall A f l cs cs' ci, *) -(* (forall s s' x i y, f y s = OK x s' i -> s.(st_datapath) = s'.(st_datapath)) -> *) -(* @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_datapath) = cs'.(st_datapath). *) -(* Proof. *) -(* induction l; intros; monadInv H0. *) -(* - trivial. *) -(* - apply H in EQ. rewrite EQ. eauto. *) -(* Qed. *) - -(* Lemma collect_freshreg_trans : *) -(* forall A f l cs cs' ci, *) -(* (forall s s' x i y, f y s = OK x s' i -> s.(st_freshreg) = s'.(st_freshreg)) -> *) -(* @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_freshreg) = cs'.(st_freshreg). *) -(* Proof. *) -(* induction l; intros; monadInv H0. *) -(* - trivial. *) -(* - apply H in EQ. rewrite EQ. eauto. *) -(* Qed. *) - -(* Lemma collect_declare_controllogic_trans : *) -(* forall io n l s s' i, *) -(* HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> *) -(* s.(st_controllogic) = s'.(st_controllogic). *) -(* Proof. *) -(* intros. eapply collect_controllogic_trans; try eassumption. *) -(* intros. eapply declare_reg_controllogic_trans. simpl in H0. eassumption. *) -(* Qed. *) - -(* Lemma collect_declare_datapath_trans : *) -(* forall io n l s s' i, *) -(* HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> *) -(* s.(st_datapath) = s'.(st_datapath). *) -(* Proof. *) -(* intros. eapply collect_datapath_trans; try eassumption. *) -(* intros. eapply declare_reg_datapath_trans. simpl in H0. eassumption. *) -(* Qed. *) - -(* Lemma collect_declare_freshreg_trans : *) -(* forall io n l s s' i, *) -(* HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* intros. eapply collect_freshreg_trans; try eassumption. *) -(* inversion 1. auto. *) -(* Qed. *) - -(* Ltac unfold_match H := *) -(* match type of H with *) -(* | context[match ?g with _ => _ end] => destruct g eqn:?; try discriminate *) -(* end. *) - -(* Lemma translate_eff_addressing_freshreg_trans : *) -(* forall op args s r s' i, *) -(* translate_eff_addressing op args s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. *) -(* Qed. *) -(* Hint Resolve translate_eff_addressing_freshreg_trans : htlspec. *) - -(* Lemma translate_comparison_freshreg_trans : *) -(* forall op args s r s' i, *) -(* translate_comparison op args s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. *) -(* Qed. *) -(* Hint Resolve translate_comparison_freshreg_trans : htlspec. *) - -(* Lemma translate_comparison_imm_freshreg_trans : *) -(* forall op args s r s' i n, *) -(* translate_comparison_imm op args n s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. *) -(* Qed. *) -(* Hint Resolve translate_comparison_imm_freshreg_trans : htlspec. *) - -(* Lemma translate_condition_freshreg_trans : *) -(* forall op args s r s' i, *) -(* translate_condition op args s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. *) -(* Qed. *) -(* Hint Resolve translate_condition_freshreg_trans : htlspec. *) - -(* Lemma translate_instr_freshreg_trans : *) -(* forall op args s r s' i, *) -(* translate_instr op args s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. *) -(* monadInv H1. eauto with htlspec. *) -(* Qed. *) -(* Hint Resolve translate_instr_freshreg_trans : htlspec. *) - -(* Lemma translate_arr_access_freshreg_trans : *) -(* forall mem addr args st s r s' i, *) -(* translate_arr_access mem addr args st s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* intros. unfold translate_arr_access in H. repeat (unfold_match H); inv H; eauto with htlspec. *) -(* Qed. *) -(* Hint Resolve translate_arr_access_freshreg_trans : htlspec. *) - -(* Lemma add_instr_freshreg_trans : *) -(* forall n n' st s r s' i, *) -(* add_instr n n' st s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. intros. unfold add_instr in H. repeat (unfold_match H). inv H. auto. Qed. *) -(* Hint Resolve add_instr_freshreg_trans : htlspec. *) - -(* Lemma add_branch_instr_freshreg_trans : *) -(* forall n n0 n1 e s r s' i, *) -(* add_branch_instr e n n0 n1 s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. intros. unfold add_branch_instr in H. repeat (unfold_match H). inv H. auto. Qed. *) -(* Hint Resolve add_branch_instr_freshreg_trans : htlspec. *) - -(* Lemma add_node_skip_freshreg_trans : *) -(* forall n1 n2 s r s' i, *) -(* add_node_skip n1 n2 s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. intros. unfold add_node_skip in H. repeat (unfold_match H). inv H. auto. Qed. *) -(* Hint Resolve add_node_skip_freshreg_trans : htlspec. *) - -(* Lemma add_instr_skip_freshreg_trans : *) -(* forall n1 n2 s r s' i, *) -(* add_instr_skip n1 n2 s = OK r s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. intros. unfold add_instr_skip in H. repeat (unfold_match H). inv H. auto. Qed. *) -(* Hint Resolve add_instr_skip_freshreg_trans : htlspec. *) - -(* Lemma transf_instr_freshreg_trans : *) -(* forall fin ret st instr s v s' i, *) -(* transf_instr fin ret st instr s = OK v s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* intros. destruct instr eqn:?. subst. unfold transf_instr in H. *) -(* destruct i0; try (monadInv H); try (unfold_match H); eauto with htlspec. *) -(* - apply add_instr_freshreg_trans in EQ2. apply translate_instr_freshreg_trans in EQ. *) -(* apply declare_reg_freshreg_trans in EQ1. congruence. *) -(* - apply add_instr_freshreg_trans in EQ2. apply translate_arr_access_freshreg_trans in EQ. *) -(* apply declare_reg_freshreg_trans in EQ1. congruence. *) -(* - apply add_instr_freshreg_trans in EQ0. apply translate_arr_access_freshreg_trans in EQ. congruence. *) -(* - apply translate_condition_freshreg_trans in EQ. apply add_branch_instr_freshreg_trans in EQ0. *) -(* congruence. *) -(* - inv EQ. apply add_node_skip_freshreg_trans in EQ0. congruence. *) -(* Qed. *) -(* Hint Resolve transf_instr_freshreg_trans : htlspec. *) - -(* Lemma collect_trans_instr_freshreg_trans : *) -(* forall fin ret st l s s' i, *) -(* HTLMonadExtra.collectlist (transf_instr fin ret st) l s = OK tt s' i -> *) -(* s.(st_freshreg) = s'.(st_freshreg). *) -(* Proof. *) -(* intros. eapply collect_freshreg_trans; try eassumption. *) -(* eauto with htlspec. *) -(* Qed. *) - -(* Ltac rewrite_states := *) -(* match goal with *) -(* | [ H: ?x ?s = ?x ?s' |- _ ] => *) -(* let c1 := fresh "c" in *) -(* let c2 := fresh "c" in *) -(* remember (?x ?s) as c1; remember (?x ?s') as c2; try subst *) -(* end. *) - -(* Ltac inv_add_instr' H := *) -(* match type of H with *) -(* | ?f _ _ _ = OK _ _ _ => unfold f in H *) -(* | ?f _ _ _ _ = OK _ _ _ => unfold f in H *) -(* | ?f _ _ _ _ _ = OK _ _ _ => unfold f in H *) -(* end; repeat unfold_match H; inversion H. *) - -(* Ltac inv_add_instr := *) -(* lazymatch goal with *) -(* | H: context[add_instr_skip _ _ _] |- _ => *) -(* inv_add_instr' H *) -(* | H: context[add_instr_skip _ _] |- _ => *) -(* monadInv H; inv_incr; inv_add_instr *) -(* | H: context[add_instr _ _ _ _] |- _ => *) -(* inv_add_instr' H *) -(* | H: context[add_instr _ _ _] |- _ => *) -(* monadInv H; inv_incr; inv_add_instr *) -(* | H: context[add_branch_instr _ _ _ _ _] |- _ => *) -(* inv_add_instr' H *) -(* | H: context[add_branch_instr _ _ _ _] |- _ => *) -(* monadInv H; inv_incr; inv_add_instr *) -(* | H: context[add_node_skip _ _ _] |- _ => *) -(* inv_add_instr' H *) -(* | H: context[add_node_skip _ _] |- _ => *) -(* monadInv H; inv_incr; inv_add_instr *) -(* end. *) - -(* Ltac destruct_optional := *) -(* match goal with H: option ?r |- _ => destruct H end. *) - -(* Lemma iter_expand_instr_spec : *) -(* forall l fin rtrn stack s s' i x c, *) -(* HTLMonadExtra.collectlist (transf_instr fin rtrn stack) l s = OK x s' i -> *) -(* list_norepet (List.map fst l) -> *) -(* (forall pc instr, In (pc, instr) l -> c!pc = Some instr) -> *) -(* (forall pc instr, In (pc, instr) l -> *) -(* c!pc = Some instr -> *) -(* tr_code c pc instr s'.(st_datapath) s'.(st_controllogic) fin rtrn s'.(st_st) stack). *) -(* Proof. *) -(* induction l; simpl; intros; try contradiction. *) -(* destruct a as [pc1 instr1]; simpl in *. inv H0. monadInv H. inv_incr. *) -(* destruct (peq pc pc1). *) -(* - subst. *) -(* destruct instr1 eqn:?; try discriminate; *) -(* try destruct_optional; inv_add_instr; econstructor; try assumption. *) -(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + inversion H2. inversion H9. rewrite H. apply tr_instr_Inop. *) -(* eapply in_map with (f := fst) in H9. contradiction. *) - -(* + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) -(* + inversion H2. inversion H14. unfold nonblock. replace (st_st s4) with (st_st s2) by congruence. *) -(* econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. *) - -(* + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) -(* + inversion H2. inversion H14. rewrite <- e2. replace (st_st s2) with (st_st s0) by congruence. *) -(* econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. *) - -(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct H2. *) -(* * inversion H2. *) -(* replace (st_st s2) with (st_st s0) by congruence. *) -(* eauto with htlspec. *) -(* * apply in_map with (f := fst) in H2. contradiction. *) - -(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct H2. *) -(* * inversion H2. *) -(* replace (st_st s2) with (st_st s0) by congruence. *) -(* eauto with htlspec. *) -(* * apply in_map with (f := fst) in H2. contradiction. *) - -(* + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. *) -(* + inversion H2. *) -(* * inversion H14. constructor. congruence. *) -(* * apply in_map with (f := fst) in H14. contradiction. *) - -(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + inversion H2. *) -(* * inversion H9. *) -(* replace (st_st s2) with (st_st s0) by congruence. *) -(* eauto with htlspec. *) -(* * apply in_map with (f := fst) in H9. contradiction. *) - -(* + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. *) -(* + inversion H2. *) -(* * inversion H9. *) -(* replace (st_st s2) with (st_st s0) by congruence. *) -(* eauto with htlspec. *) -(* * apply in_map with (f := fst) in H9. contradiction. *) - -(* - eapply IHl. apply EQ0. assumption. *) -(* destruct H2. inversion H2. subst. contradiction. *) -(* intros. specialize H1 with pc0 instr0. destruct H1. tauto. trivial. *) -(* destruct H2. inv H2. contradiction. assumption. assumption. *) -(* Qed. *) -(* Hint Resolve iter_expand_instr_spec : htlspec. *) - -(* Lemma create_arr_inv : forall w x y z a b c d, *) -(* create_arr w x y z = OK (a, b) c d -> *) -(* y = b /\ a = z.(st_freshreg) /\ c.(st_freshreg) = Pos.succ (z.(st_freshreg)). *) -(* Proof. *) -(* inversion 1; split; auto. *) -(* Qed. *) - -(* Lemma create_reg_inv : forall a b s r s' i, *) -(* create_reg a b s = OK r s' i -> *) -(* r = s.(st_freshreg) /\ s'.(st_freshreg) = Pos.succ (s.(st_freshreg)). *) -(* Proof. *) -(* inversion 1; auto. *) -(* Qed. *) - -(* Theorem transl_module_correct : *) -(* forall f m, *) -(* transl_module f = Errors.OK m -> tr_module f m. *) -(* Proof. *) -(* intros until m. *) -(* unfold transl_module. *) -(* unfold run_mon. *) -(* destruct (transf_module f (max_state f)) eqn:?; try discriminate. *) -(* intros. inv H. *) -(* inversion s; subst. *) - -(* unfold transf_module in *. *) -(* unfold stack_correct in *. *) -(* destruct (0 <=? RTL.fn_stacksize f) eqn:STACK_BOUND_LOW; *) -(* destruct (RTL.fn_stacksize f + stmnts!pc = Some s -> + trans!pc = Some t -> + tr_instr fin rtrn st stk i s t -> + tr_code c pc i stmnts trans fin rtrn st stk. +Hint Constructors tr_code : htlspec. + +Inductive tr_module (f : RTL.function) : module -> Prop := + tr_module_intro : + forall data control fin rtrn st stk stk_len m start rst clk scldecls arrdecls wf, + m = (mkmodule f.(RTL.fn_params) + data + control + f.(RTL.fn_entrypoint) + st stk stk_len fin rtrn start rst clk scldecls arrdecls wf) -> + (forall pc i, Maps.PTree.get pc f.(RTL.fn_code) = Some i -> + tr_code f.(RTL.fn_code) pc i data control fin rtrn st stk) -> + stk_len = Z.to_nat f.(RTL.fn_stacksize) -> + Z.modulo (f.(RTL.fn_stacksize)) 4 = 0 -> + 0 <= f.(RTL.fn_stacksize) < Integers.Ptrofs.modulus -> + st = ((RTL.max_reg_function f) + 1)%positive -> + fin = ((RTL.max_reg_function f) + 2)%positive -> + rtrn = ((RTL.max_reg_function f) + 3)%positive -> + stk = ((RTL.max_reg_function f) + 4)%positive -> + start = ((RTL.max_reg_function f) + 5)%positive -> + rst = ((RTL.max_reg_function f) + 6)%positive -> + clk = ((RTL.max_reg_function f) + 7)%positive -> + tr_module f m. +Hint Constructors tr_module : htlspec. + +Lemma create_reg_datapath_trans : + forall sz s s' x i iop, + create_reg iop sz s = OK x s' i -> + s.(st_datapath) = s'.(st_datapath). +Proof. intros. monadInv H. trivial. Qed. +Hint Resolve create_reg_datapath_trans : htlspec. + +Lemma create_reg_controllogic_trans : + forall sz s s' x i iop, + create_reg iop sz s = OK x s' i -> + s.(st_controllogic) = s'.(st_controllogic). +Proof. intros. monadInv H. trivial. Qed. +Hint Resolve create_reg_controllogic_trans : htlspec. + +Lemma declare_reg_datapath_trans : + forall sz s s' x i iop r, + declare_reg iop r sz s = OK x s' i -> + s.(st_datapath) = s'.(st_datapath). +Proof. intros. monadInv H. trivial. Qed. +Hint Resolve create_reg_datapath_trans : htlspec. + +Lemma declare_reg_controllogic_trans : + forall sz s s' x i iop r, + declare_reg iop r sz s = OK x s' i -> + s.(st_controllogic) = s'.(st_controllogic). +Proof. intros. monadInv H. trivial. Qed. +Hint Resolve create_reg_controllogic_trans : htlspec. + +Lemma declare_reg_freshreg_trans : + forall sz s s' x i iop r, + declare_reg iop r sz s = OK x s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. inversion 1; auto. Qed. +Hint Resolve declare_reg_freshreg_trans : htlspec. + +Lemma create_arr_datapath_trans : + forall sz ln s s' x i iop, + create_arr iop sz ln s = OK x s' i -> + s.(st_datapath) = s'.(st_datapath). +Proof. intros. monadInv H. trivial. Qed. +Hint Resolve create_arr_datapath_trans : htlspec. + +Lemma create_arr_controllogic_trans : + forall sz ln s s' x i iop, + create_arr iop sz ln s = OK x s' i -> + s.(st_controllogic) = s'.(st_controllogic). +Proof. intros. monadInv H. trivial. Qed. +Hint Resolve create_arr_controllogic_trans : htlspec. + +Lemma get_refl_x : + forall s s' x i, + get s = OK x s' i -> + s = x. +Proof. inversion 1. trivial. Qed. +Hint Resolve get_refl_x : htlspec. + +Lemma get_refl_s : + forall s s' x i, + get s = OK x s' i -> + s = s'. +Proof. inversion 1. trivial. Qed. +Hint Resolve get_refl_s : htlspec. + +Ltac inv_incr := + repeat match goal with + | [ H: create_reg _ _ ?s = OK _ ?s' _ |- _ ] => + let H1 := fresh "H" in + assert (H1 := H); eapply create_reg_datapath_trans in H; + eapply create_reg_controllogic_trans in H1 + | [ H: create_arr _ _ _ ?s = OK _ ?s' _ |- _ ] => + let H1 := fresh "H" in + assert (H1 := H); eapply create_arr_datapath_trans in H; + eapply create_arr_controllogic_trans in H1 + | [ H: get ?s = OK _ _ _ |- _ ] => + let H1 := fresh "H" in + assert (H1 := H); apply get_refl_x in H; apply get_refl_s in H1; + subst + | [ H: st_prop _ _ |- _ ] => unfold st_prop in H; destruct H + | [ H: st_incr _ _ |- _ ] => destruct st_incr + end. + +Lemma collect_controllogic_trans : + forall A f l cs cs' ci, + (forall s s' x i y, f y s = OK x s' i -> s.(st_controllogic) = s'.(st_controllogic)) -> + @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_controllogic) = cs'.(st_controllogic). +Proof. + induction l; intros; monadInv H0. + - trivial. + - apply H in EQ. rewrite EQ. eauto. +Qed. + +Lemma collect_datapath_trans : + forall A f l cs cs' ci, + (forall s s' x i y, f y s = OK x s' i -> s.(st_datapath) = s'.(st_datapath)) -> + @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_datapath) = cs'.(st_datapath). +Proof. + induction l; intros; monadInv H0. + - trivial. + - apply H in EQ. rewrite EQ. eauto. +Qed. + +Lemma collect_freshreg_trans : + forall A f l cs cs' ci, + (forall s s' x i y, f y s = OK x s' i -> s.(st_freshreg) = s'.(st_freshreg)) -> + @HTLMonadExtra.collectlist A f l cs = OK tt cs' ci -> cs.(st_freshreg) = cs'.(st_freshreg). +Proof. + induction l; intros; monadInv H0. + - trivial. + - apply H in EQ. rewrite EQ. eauto. +Qed. + +Lemma collect_declare_controllogic_trans : + forall io n l s s' i, + HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> + s.(st_controllogic) = s'.(st_controllogic). +Proof. + intros. eapply collect_controllogic_trans; try eassumption. + intros. eapply declare_reg_controllogic_trans. simpl in H0. eassumption. +Qed. + +Lemma collect_declare_datapath_trans : + forall io n l s s' i, + HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> + s.(st_datapath) = s'.(st_datapath). +Proof. + intros. eapply collect_datapath_trans; try eassumption. + intros. eapply declare_reg_datapath_trans. simpl in H0. eassumption. +Qed. + +Lemma collect_declare_freshreg_trans : + forall io n l s s' i, + HTLMonadExtra.collectlist (fun r : reg => declare_reg io r n) l s = OK tt s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + intros. eapply collect_freshreg_trans; try eassumption. + inversion 1. auto. +Qed. + +Ltac unfold_match H := + match type of H with + | context[match ?g with _ => _ end] => destruct g eqn:?; try discriminate + end. + +Lemma translate_eff_addressing_freshreg_trans : + forall op args s r s' i, + translate_eff_addressing op args s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. +Qed. +Hint Resolve translate_eff_addressing_freshreg_trans : htlspec. + +Lemma translate_comparison_freshreg_trans : + forall op args s r s' i, + translate_comparison op args s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. +Qed. +Hint Resolve translate_comparison_freshreg_trans : htlspec. + +Lemma translate_comparison_imm_freshreg_trans : + forall op args s r s' i n, + translate_comparison_imm op args n s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. +Qed. +Hint Resolve translate_comparison_imm_freshreg_trans : htlspec. + +Lemma translate_condition_freshreg_trans : + forall op args s r s' i, + translate_condition op args s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. +Qed. +Hint Resolve translate_condition_freshreg_trans : htlspec. + +Lemma translate_instr_freshreg_trans : + forall op args s r s' i, + translate_instr op args s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + destruct op; intros; simpl in *; repeat (unfold_match H); inv H; eauto with htlspec. + monadInv H1. eauto with htlspec. +Qed. +Hint Resolve translate_instr_freshreg_trans : htlspec. + +Lemma add_instr_freshreg_trans : + forall n n' st s r s' i, + add_instr n n' st s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. intros. unfold add_instr in H. repeat (unfold_match H). inv H. auto. Qed. +Hint Resolve add_instr_freshreg_trans : htlspec. + +Lemma add_branch_instr_freshreg_trans : + forall n n0 n1 e s r s' i, + add_branch_instr e n n0 n1 s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. intros. unfold add_branch_instr in H. repeat (unfold_match H). inv H. auto. Qed. +Hint Resolve add_branch_instr_freshreg_trans : htlspec. + +Lemma add_node_skip_freshreg_trans : + forall n1 n2 s r s' i, + add_node_skip n1 n2 s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. intros. unfold add_node_skip in H. repeat (unfold_match H). inv H. auto. Qed. +Hint Resolve add_node_skip_freshreg_trans : htlspec. + +Lemma add_instr_skip_freshreg_trans : + forall n1 n2 s r s' i, + add_instr_skip n1 n2 s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. intros. unfold add_instr_skip in H. repeat (unfold_match H). inv H. auto. Qed. +Hint Resolve add_instr_skip_freshreg_trans : htlspec. + +Lemma transf_instr_freshreg_trans : + forall fin ret st instr s v s' i, + transf_instr fin ret st instr s = OK v s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + intros. destruct instr eqn:?. subst. unfold transf_instr in H. + destruct i0; try (monadInv H); try (unfold_match H); eauto with htlspec. + - apply add_instr_freshreg_trans in EQ2. apply translate_instr_freshreg_trans in EQ. + apply declare_reg_freshreg_trans in EQ1. congruence. + - apply add_instr_freshreg_trans in EQ2. apply translate_eff_addressing_freshreg_trans in EQ. + apply declare_reg_freshreg_trans in EQ1. congruence. + - apply add_instr_freshreg_trans in EQ0. apply translate_eff_addressing_freshreg_trans in EQ. + congruence. + - apply translate_condition_freshreg_trans in EQ. apply add_branch_instr_freshreg_trans in EQ0. + congruence. + - inv EQ. apply add_node_skip_freshreg_trans in EQ0. congruence. +Qed. +Hint Resolve transf_instr_freshreg_trans : htlspec. + +Lemma collect_trans_instr_freshreg_trans : + forall fin ret st l s s' i, + HTLMonadExtra.collectlist (transf_instr fin ret st) l s = OK tt s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + intros. eapply collect_freshreg_trans; try eassumption. + eauto with htlspec. +Qed. + +Ltac rewrite_states := + match goal with + | [ H: ?x ?s = ?x ?s' |- _ ] => + let c1 := fresh "c" in + let c2 := fresh "c" in + remember (?x ?s) as c1; remember (?x ?s') as c2; try subst + end. + +Ltac inv_add_instr' H := + match type of H with + | ?f _ _ _ = OK _ _ _ => unfold f in H + | ?f _ _ _ _ = OK _ _ _ => unfold f in H + | ?f _ _ _ _ _ = OK _ _ _ => unfold f in H + end; repeat unfold_match H; inversion H. + +Ltac inv_add_instr := + lazymatch goal with + | H: context[add_instr_skip _ _ _] |- _ => + inv_add_instr' H + | H: context[add_instr_skip _ _] |- _ => + monadInv H; inv_incr; inv_add_instr + | H: context[add_instr _ _ _ _] |- _ => + inv_add_instr' H + | H: context[add_instr _ _ _] |- _ => + monadInv H; inv_incr; inv_add_instr + | H: context[add_branch_instr _ _ _ _ _] |- _ => + inv_add_instr' H + | H: context[add_branch_instr _ _ _ _] |- _ => + monadInv H; inv_incr; inv_add_instr + | H: context[add_node_skip _ _ _] |- _ => + inv_add_instr' H + | H: context[add_node_skip _ _] |- _ => + monadInv H; inv_incr; inv_add_instr + end. + +Ltac destruct_optional := + match goal with H: option ?r |- _ => destruct H end. + +Lemma iter_expand_instr_spec : + forall l fin rtrn stack s s' i x c, + HTLMonadExtra.collectlist (transf_instr fin rtrn stack) l s = OK x s' i -> + list_norepet (List.map fst l) -> + (forall pc instr, In (pc, instr) l -> c!pc = Some instr) -> + (forall pc instr, In (pc, instr) l -> + c!pc = Some instr -> + tr_code c pc instr s'.(st_datapath) s'.(st_controllogic) fin rtrn s'.(st_st) stack). +Proof. + induction l; simpl; intros; try contradiction. + destruct a as [pc1 instr1]; simpl in *. inv H0. monadInv H. inv_incr. + destruct (peq pc pc1). + - subst. + destruct instr1 eqn:?; try discriminate; + try destruct_optional; inv_add_instr; econstructor; try assumption. + + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + inversion H2. inversion H9. rewrite H. apply tr_instr_Inop. + eapply in_map with (f := fst) in H9. contradiction. + + + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + + inversion H2. inversion H14. unfold nonblock. replace (st_st s4) with (st_st s2) by congruence. + econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. + + + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + + inversion H2. inversion H14. rewrite <- e2. replace (st_st s2) with (st_st s0) by congruence. + econstructor. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. + + + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct H2. + * inversion H2. + replace (st_st s2) with (st_st s0) by congruence. + eauto with htlspec. + * apply in_map with (f := fst) in H2. contradiction. + + + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct H2. + * inversion H2. + replace (st_st s2) with (st_st s0) by congruence. + eauto with htlspec. + * apply in_map with (f := fst) in H2. contradiction. + + + destruct o with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + + inversion H2. + * inversion H14. constructor. congruence. + * apply in_map with (f := fst) in H14. contradiction. + + + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + inversion H2. + * inversion H9. + replace (st_st s2) with (st_st s0) by congruence. + eauto with htlspec. + * apply in_map with (f := fst) in H9. contradiction. + + + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + + inversion H2. + * inversion H9. + replace (st_st s2) with (st_st s0) by congruence. + eauto with htlspec. + * apply in_map with (f := fst) in H9. contradiction. + + - eapply IHl. apply EQ0. assumption. + destruct H2. inversion H2. subst. contradiction. + intros. specialize H1 with pc0 instr0. destruct H1. tauto. trivial. + destruct H2. inv H2. contradiction. assumption. assumption. +Qed. +Hint Resolve iter_expand_instr_spec : htlspec. + +Lemma create_arr_inv : forall w x y z a b c d, + create_arr w x y z = OK (a, b) c d -> + y = b /\ a = z.(st_freshreg) /\ c.(st_freshreg) = Pos.succ (z.(st_freshreg)). +Proof. + inversion 1; split; auto. +Qed. + +Lemma create_reg_inv : forall a b s r s' i, + create_reg a b s = OK r s' i -> + r = s.(st_freshreg) /\ s'.(st_freshreg) = Pos.succ (s.(st_freshreg)). +Proof. + inversion 1; auto. +Qed. + +Theorem transl_module_correct : + forall f m, + transl_module f = Errors.OK m -> tr_module f m. +Proof. + intros until m. + unfold transl_module. + unfold run_mon. + destruct (transf_module f (max_state f)) eqn:?; try discriminate. + intros. inv H. + inversion s; subst. + + unfold transf_module in *. + unfold stack_correct in *. + destruct (0 <=? RTL.fn_stacksize f) eqn:STACK_BOUND_LOW; + destruct (RTL.fn_stacksize f Date: Mon, 6 Jul 2020 20:29:36 +0100 Subject: Remove alignment requirement for lessdef. --- src/verilog/ValueInt.v | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/verilog/ValueInt.v b/src/verilog/ValueInt.v index aa99fbd..80c512f 100644 --- a/src/verilog/ValueInt.v +++ b/src/verilog/ValueInt.v @@ -77,13 +77,10 @@ Definition ptrToValue (i : ptrofs) : value := Ptrofs.to_int i. Definition valueToPtr (i : value) : Integers.ptrofs := Ptrofs.of_int i. -Search Ptrofs.of_int Ptrofs.to_int. Definition valToValue (v : Values.val) : option value := match v with | Values.Vint i => Some (intToValue i) - | Values.Vptr b off => if Z.eqb (Z.modulo (uvalueToZ (ptrToValue off)) 4) 0%Z - then Some (ptrToValue off) - else None + | Values.Vptr b off => Some (ptrToValue off) | Values.Vundef => Some (ZToValue 0%Z) | _ => None end. @@ -117,7 +114,6 @@ Inductive val_value_lessdef: val -> value -> Prop := | val_value_lessdef_ptr: forall b off v', off = valueToPtr v' -> - (Z.modulo (uvalueToZ v') 4) = 0%Z -> val_value_lessdef (Vptr b off) v' | lessdef_undef: forall v, val_value_lessdef Vundef v. @@ -162,8 +158,6 @@ Proof. destruct v; try discriminate; constructor. unfold valToValue in H. inversion H. unfold valueToInt. unfold intToValue in H1. auto. - inv H. destruct (uvalueToZ (ptrToValue i) mod 4 =? 0); try discriminate. - inv H1. symmetry. unfold valueToPtr, ptrToValue. apply Ptrofs.of_int_to_int. trivial. - inv H. destruct (uvalueToZ (ptrToValue i) mod 4 =? 0) eqn:?; try discriminate. - inv H1. apply Z.eqb_eq. apply Heqb0. + inv H. symmetry. + unfold valueToPtr, ptrToValue. apply Ptrofs.of_int_to_int. trivial. Qed. -- cgit From e1d9c228bece9926d42e49d3d8b7f4a1fe726b44 Mon Sep 17 00:00:00 2001 From: James Pollard Date: Mon, 6 Jul 2020 20:54:40 +0100 Subject: Check chunk size during translation. --- src/translation/HTLgen.v | 30 +++++++++++++++++++----------- src/translation/HTLgenspec.v | 22 ++++++++++++++-------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 65b6627..04de548 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -442,17 +442,25 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni do _ <- declare_reg None dst 32; add_instr n n' (nonblock dst instr) else error (Errors.msg "State is larger than 2^32.") - | Iload mem addr args dst n' => - if Z.leb (Z.pos n') Integers.Int.max_unsigned - then do addr' <- translate_eff_addressing addr args; - do _ <- declare_reg None dst 32; - add_instr n n' $ create_single_cycle_load stack addr' dst - else error (Errors.msg "State is larger than 2^32.") - | Istore mem addr args src n' => - if Z.leb (Z.pos n') Integers.Int.max_unsigned - then do addr' <- translate_eff_addressing addr args; - add_instr n n' $ create_single_cycle_store stack addr' src - else error (Errors.msg "State is larger than 2^32.") + | Iload chunk addr args dst n' => + match chunk with + | Mint32 => + if Z.leb (Z.pos n') Integers.Int.max_unsigned + then do addr' <- translate_eff_addressing addr args; + do _ <- declare_reg None dst 32; + add_instr n n' $ create_single_cycle_load stack addr' dst + else error (Errors.msg "State is larger than 2^32.") + | _ => error (Errors.msg "Iload invalid chunk size.") + end + | Istore chunk addr args src n' => + match chunk with + | Mint32 => + if Z.leb (Z.pos n') Integers.Int.max_unsigned + then do addr' <- translate_eff_addressing addr args; + add_instr n n' $ create_single_cycle_store stack addr' src + else error (Errors.msg "State is larger than 2^32.") + | _ => error (Errors.msg "Istore invalid chunk size.") + end | Icall _ _ _ _ _ => error (Errors.msg "Calls are not implemented.") | Itailcall _ _ _ => error (Errors.msg "Tailcalls are not implemented.") | Ibuiltin _ _ _ _ => error (Errors.msg "Builtin functions not implemented.") diff --git a/src/translation/HTLgenspec.v b/src/translation/HTLgenspec.v index aba5d0c..dda91ca 100644 --- a/src/translation/HTLgenspec.v +++ b/src/translation/HTLgenspec.v @@ -138,16 +138,18 @@ Inductive tr_instr (fin rtrn st stk : reg) : RTL.instruction -> stmnt -> stmnt - tr_instr fin rtrn st stk (RTL.Ireturn (Some r)) (Vseq (block fin (Vlit (ZToValue 1%Z))) (block rtrn (Vvar r))) Vskip | tr_instr_Iload : - forall mem addr args s s' i e dst n, + forall chunk addr args s s' i e dst n, Z.pos n <= Int.max_unsigned -> + chunk = AST.Mint32 -> translate_eff_addressing addr args s = OK e s' i -> - tr_instr fin rtrn st stk (RTL.Iload mem addr args dst n) + tr_instr fin rtrn st stk (RTL.Iload chunk addr args dst n) (create_single_cycle_load stk e dst) (state_goto st n) | tr_instr_Istore : - forall mem addr args s s' i e src n, + forall chunk addr args s s' i e src n, Z.pos n <= Int.max_unsigned -> + chunk = AST.Mint32 -> translate_eff_addressing addr args s = OK e s' i -> - tr_instr fin rtrn st stk (RTL.Istore mem addr args src n) + tr_instr fin rtrn st stk (RTL.Istore chunk addr args src n) (create_single_cycle_store stk e src) (state_goto st n) | tr_instr_Ijumptable : forall cexpr tbl r, @@ -415,10 +417,12 @@ Proof. destruct i0; try (monadInv H); try (unfold_match H); eauto with htlspec. - monadInv H. apply add_instr_freshreg_trans in EQ2. apply translate_instr_freshreg_trans in EQ. apply declare_reg_freshreg_trans in EQ1. congruence. - - monadInv H. apply add_instr_freshreg_trans in EQ2. + - destruct (Z.pos n0 <=? Int.max_unsigned); try discriminate. + monadInv H. apply add_instr_freshreg_trans in EQ2. apply translate_eff_addressing_freshreg_trans in EQ. apply declare_reg_freshreg_trans in EQ1. congruence. - - monadInv H. apply add_instr_freshreg_trans in EQ0. + - destruct (Z.pos n0 <=? Int.max_unsigned); try discriminate. + monadInv H. apply add_instr_freshreg_trans in EQ0. apply translate_eff_addressing_freshreg_trans in EQ. congruence. - monadInv H. apply translate_condition_freshreg_trans in EQ. apply add_branch_instr_freshreg_trans in EQ0. @@ -491,7 +495,8 @@ Proof. destruct (peq pc pc1). - subst. destruct instr1 eqn:?; try discriminate; - try destruct_optional; inv_add_instr; econstructor; try assumption. + try destruct_optional; try (destruct m; try discriminate); + inv_add_instr; econstructor; try assumption. + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + destruct o0 with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. + inversion H2. inversion H9. rewrite H. apply tr_instr_Inop. @@ -508,6 +513,7 @@ Proof. + destruct o0 with pc1; destruct H16; simpl in *; rewrite AssocMap.gss in H14; eauto; congruence. + inversion H2. inversion H14. rewrite <- e2. replace (st_st s2) with (st_st s0) by congruence. econstructor. apply Z.leb_le; assumption. + reflexivity. apply EQ1. eapply in_map with (f := fst) in H14. contradiction. + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. @@ -516,7 +522,7 @@ Proof. * inversion H2. replace (st_st s2) with (st_st s0) by congruence. econstructor. apply Z.leb_le; assumption. - eauto with htlspec. + eauto with htlspec. eassumption. * apply in_map with (f := fst) in H2. contradiction. + destruct o with pc1; destruct H11; simpl in *; rewrite AssocMap.gss in H9; eauto; congruence. -- cgit From b0e1a1383890d9b0a14ffaabce4c3d6453eb0a9c Mon Sep 17 00:00:00 2001 From: James Pollard Date: Mon, 6 Jul 2020 21:05:05 +0100 Subject: Reduce number of array addressing modes. --- src/translation/HTLgen.v | 16 ++++++++++++++-- src/translation/HTLgenspec.v | 17 +++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 04de548..35203f8 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -402,6 +402,18 @@ Definition add_branch_instr (e: expr) (n n1 n2: node) : mon unit := (* | _, _, _ => error (Errors.msg "HTLgen: translate_arr_access unsuported addressing") *) (* end. *) +Definition translate_arr_addressing (a: Op.addressing) (args: list reg) : mon expr := + match a, args with (* TODO: We should be more methodical here; what are the possibilities?*) + | Op.Aindexed off, r1::nil => + ret (boplitz Vadd r1 off) + | Op.Aindexed2scaled scale offset, r1::r2::nil => (* Typical for dynamic array addressing *) + ret (Vbinop Vadd (boplitz Vadd r1 offset) (boplitz Vmul r2 scale)) + | Op.Ainstack a, nil => (* We need to be sure that the base address is aligned *) + let a := Integers.Ptrofs.unsigned a in + ret (Vlit (ZToValue a)) + | _, _ => error (Errors.msg "Veriloggen: translate_arr_addressing unsuported addressing") + end. + Fixpoint enumerate (i : nat) (ns : list node) {struct ns} : list (nat * node) := match ns with | n :: ns' => (i, n) :: enumerate (i+1) ns' @@ -446,7 +458,7 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni match chunk with | Mint32 => if Z.leb (Z.pos n') Integers.Int.max_unsigned - then do addr' <- translate_eff_addressing addr args; + then do addr' <- translate_arr_addressing addr args; do _ <- declare_reg None dst 32; add_instr n n' $ create_single_cycle_load stack addr' dst else error (Errors.msg "State is larger than 2^32.") @@ -456,7 +468,7 @@ Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon uni match chunk with | Mint32 => if Z.leb (Z.pos n') Integers.Int.max_unsigned - then do addr' <- translate_eff_addressing addr args; + then do addr' <- translate_arr_addressing addr args; add_instr n n' $ create_single_cycle_store stack addr' src else error (Errors.msg "State is larger than 2^32.") | _ => error (Errors.msg "Istore invalid chunk size.") diff --git a/src/translation/HTLgenspec.v b/src/translation/HTLgenspec.v index dda91ca..1b04b1f 100644 --- a/src/translation/HTLgenspec.v +++ b/src/translation/HTLgenspec.v @@ -141,14 +141,14 @@ Inductive tr_instr (fin rtrn st stk : reg) : RTL.instruction -> stmnt -> stmnt - forall chunk addr args s s' i e dst n, Z.pos n <= Int.max_unsigned -> chunk = AST.Mint32 -> - translate_eff_addressing addr args s = OK e s' i -> + translate_arr_addressing addr args s = OK e s' i -> tr_instr fin rtrn st stk (RTL.Iload chunk addr args dst n) (create_single_cycle_load stk e dst) (state_goto st n) | tr_instr_Istore : forall chunk addr args s s' i e src n, Z.pos n <= Int.max_unsigned -> chunk = AST.Mint32 -> - translate_eff_addressing addr args s = OK e s' i -> + translate_arr_addressing addr args s = OK e s' i -> tr_instr fin rtrn st stk (RTL.Istore chunk addr args src n) (create_single_cycle_store stk e src) (state_goto st n) | tr_instr_Ijumptable : @@ -343,6 +343,15 @@ Proof. Qed. Hint Resolve translate_eff_addressing_freshreg_trans : htlspec. +Lemma translate_arr_addressing_freshreg_trans : + forall op args s r s' i, + translate_arr_addressing op args s = OK r s' i -> + s.(st_freshreg) = s'.(st_freshreg). +Proof. + destruct op; intros; simpl in *; repeat (unfold_match H); inv H; auto. +Qed. +Hint Resolve translate_eff_addressing_freshreg_trans : htlspec. + Lemma translate_comparison_freshreg_trans : forall op args s r s' i, translate_comparison op args s = OK r s' i -> @@ -419,11 +428,11 @@ Proof. apply declare_reg_freshreg_trans in EQ1. congruence. - destruct (Z.pos n0 <=? Int.max_unsigned); try discriminate. monadInv H. apply add_instr_freshreg_trans in EQ2. - apply translate_eff_addressing_freshreg_trans in EQ. + apply translate_arr_addressing_freshreg_trans in EQ. apply declare_reg_freshreg_trans in EQ1. congruence. - destruct (Z.pos n0 <=? Int.max_unsigned); try discriminate. monadInv H. apply add_instr_freshreg_trans in EQ0. - apply translate_eff_addressing_freshreg_trans in EQ. congruence. + apply translate_arr_addressing_freshreg_trans in EQ. congruence. - monadInv H. apply translate_condition_freshreg_trans in EQ. apply add_branch_instr_freshreg_trans in EQ0. congruence. -- cgit From 897b2b15a810e996895dda0d863dcefb27dfabaf Mon Sep 17 00:00:00 2001 From: James Pollard Date: Mon, 6 Jul 2020 23:20:00 +0100 Subject: Concatenation style loads. --- src/translation/HTLgen.v | 8 ++--- src/verilog/PrintVerilog.ml | 10 +++++- src/verilog/Verilog.v | 85 +++++++++++++++++++++++---------------------- 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 35203f8..d1c1363 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -427,17 +427,13 @@ Definition tbl_to_case_expr (st : reg) (ns : list node) : list (expr * stmnt) := (enumerate 0 ns). Definition create_single_cycle_load (stack : reg) (addr : expr) (dst : reg) : stmnt := - let l0 := Vnonblock (Vvarb0 dst) (Vvari stack addr) in - let l1 := Vnonblock (Vvarb1 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 1)) in - let l2 := Vnonblock (Vvarb2 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) in - let l3 := Vnonblock (Vvarb3 dst) (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) - in Vseq l0 $ Vseq l1 $ Vseq l2 $ l3. + Vnonblock (Vvar dst) (Vload stack addr). Definition create_single_cycle_store (stack : reg) (addr : expr) (src : reg) : stmnt := let l0 := Vnonblock (Vvari stack addr) (Vvarb0 src) in let l1 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 1)) (Vvarb1 src) in let l2 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb2 src) in - let l3 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 2)) (Vvarb3 src) + let l3 := Vnonblock (Vvari stack $ Vbinop Vadd addr (Vlit $ ZToValue 3)) (Vvarb3 src) in Vseq l0 $ Vseq l1 $ Vseq l2 $ l3. Definition transf_instr (fin rtrn stack: reg) (ni: node * instruction) : mon unit := diff --git a/src/verilog/PrintVerilog.ml b/src/verilog/PrintVerilog.ml index db78ad5..7f3eb29 100644 --- a/src/verilog/PrintVerilog.ml +++ b/src/verilog/PrintVerilog.ml @@ -72,9 +72,16 @@ let register a = sprintf "reg_%d" (P.to_int a) let literal l = sprintf "32'd%d" (Z.to_int (uvalueToZ l)) +let literal_int i = sprintf "32'd%d" i + let byte n s = sprintf "reg_%d[%d:%d]" (P.to_int s) (7 + n * 8) (n * 8) -let rec pprint_expr = function + +let rec pprint_expr = + let array_byte r i = function + | 0 -> concat [register r; "["; pprint_expr i; "]"] + | n -> concat [register r; "["; pprint_expr i; " + "; literal_int n; "][7:0]"] + in function | Vlit l -> literal l | Vvar s -> register s | Vvarb0 s -> byte 0 s @@ -86,6 +93,7 @@ let rec pprint_expr = function | Vunop (u, e) -> concat ["("; unop u; pprint_expr e; ")"] | Vbinop (op, a, b) -> concat [pprint_binop (pprint_expr a) (pprint_expr b) op] | Vternary (c, t, f) -> concat ["("; pprint_expr c; " ? "; pprint_expr t; " : "; pprint_expr f; ")"] + | Vload (s, i) -> concat ["{"; array_byte s i 3; ", "; array_byte s i 2; ", "; array_byte s i 1; ", "; array_byte s i 0; "}"] let rec pprint_stmnt i = let pprint_case (e, s) = concat [ indent (i + 1); pprint_expr e; ": begin\n"; pprint_stmnt (i + 2) s; diff --git a/src/verilog/Verilog.v b/src/verilog/Verilog.v index 108ac72..94e6184 100644 --- a/src/verilog/Verilog.v +++ b/src/verilog/Verilog.v @@ -164,7 +164,8 @@ Inductive expr : Type := | Vinputvar : reg -> expr | Vbinop : binop -> expr -> expr -> expr | Vunop : unop -> expr -> expr -| Vternary : expr -> expr -> expr -> expr. +| Vternary : expr -> expr -> expr -> expr +| Vload : reg -> expr -> expr. (** 4-byte concatenation load *) Definition posToExpr (p : positive) : expr := Vlit (posToValue p). @@ -338,61 +339,61 @@ Definition unop_run (op : unop) (v1 : value) : value := Inductive expr_runp : fext -> assocmap -> assocmap_arr -> expr -> value -> Prop := | erun_Vlit : - forall fext reg stack v, - expr_runp fext reg stack (Vlit v) v + forall fext asr asa v, + expr_runp fext asr asa (Vlit v) v | erun_Vvar : - forall fext reg stack v r, - reg#r = v -> - expr_runp fext reg stack (Vvar r) v + forall fext asr asa v r, + asr#r = v -> + expr_runp fext asr asa (Vvar r) v | erun_Vvarb0 : - forall fext reg stack v r, - reg#r = v -> - expr_runp fext reg stack (Vvarb0 r) (IntExtra.ibyte0 v) + forall fext asr asa v r, + asr#r = v -> + expr_runp fext asr asa (Vvarb0 r) (IntExtra.ibyte0 v) | erun_Vvarb1 : - forall fext reg stack v r, - reg#r = v -> - expr_runp fext reg stack (Vvarb1 r) (IntExtra.ibyte1 v) + forall fext asr asa v r, + asr#r = v -> + expr_runp fext asr asa (Vvarb1 r) (IntExtra.ibyte1 v) | erun_Vvarb2 : - forall fext reg stack v r, - reg#r = v -> - expr_runp fext reg stack (Vvarb2 r) (IntExtra.ibyte2 v) + forall fext asr asa v r, + asr#r = v -> + expr_runp fext asr asa (Vvarb2 r) (IntExtra.ibyte2 v) | erun_Vvarb3 : - forall fext reg stack v r, - reg#r = v -> - expr_runp fext reg stack (Vvarb3 r) (IntExtra.ibyte3 v) + forall fext asr asa v r, + asr#r = v -> + expr_runp fext asr asa (Vvarb3 r) (IntExtra.ibyte3 v) | erun_Vvari : - forall fext reg stack v iexp i r, - expr_runp fext reg stack iexp i -> - arr_assocmap_lookup stack r (valueToNat i) = Some v -> - expr_runp fext reg stack (Vvari r iexp) v + forall fext asr asa v iexp i r, + expr_runp fext asr asa iexp i -> + arr_assocmap_lookup asa r (valueToNat i) = Some v -> + expr_runp fext asr asa (Vvari r iexp) v | erun_Vinputvar : - forall fext reg stack r v, + forall fext asr asa r v, fext!r = Some v -> - expr_runp fext reg stack (Vinputvar r) v + expr_runp fext asr asa (Vinputvar r) v | erun_Vbinop : - forall fext reg stack op l r lv rv resv, - expr_runp fext reg stack l lv -> - expr_runp fext reg stack r rv -> + forall fext asr asa op l r lv rv resv, + expr_runp fext asr asa l lv -> + expr_runp fext asr asa r rv -> Some resv = binop_run op lv rv -> - expr_runp fext reg stack (Vbinop op l r) resv + expr_runp fext asr asa (Vbinop op l r) resv | erun_Vunop : - forall fext reg stack u vu op oper resv, - expr_runp fext reg stack u vu -> + forall fext asr asa u vu op oper resv, + expr_runp fext asr asa u vu -> oper = unop_run op -> resv = oper vu -> - expr_runp fext reg stack (Vunop op u) resv + expr_runp fext asr asa (Vunop op u) resv | erun_Vternary_true : - forall fext reg stack c ts fs vc vt, - expr_runp fext reg stack c vc -> - expr_runp fext reg stack ts vt -> + forall fext asr asa c ts fs vc vt, + expr_runp fext asr asa c vc -> + expr_runp fext asr asa ts vt -> valueToBool vc = true -> - expr_runp fext reg stack (Vternary c ts fs) vt + expr_runp fext asr asa (Vternary c ts fs) vt | erun_Vternary_false : - forall fext reg stack c ts fs vc vf, - expr_runp fext reg stack c vc -> - expr_runp fext reg stack fs vf -> + forall fext asr asa c ts fs vc vf, + expr_runp fext asr asa c vc -> + expr_runp fext asr asa fs vf -> valueToBool vc = false -> - expr_runp fext reg stack (Vternary c ts fs) vf. + expr_runp fext asr asa (Vternary c ts fs) vf. Hint Constructors expr_runp : verilog. Definition handle_opt {A : Type} (err : errmsg) (val : option A) @@ -449,12 +450,11 @@ Definition access_fext (f : fext) (r : reg) : res value := Inductive location : Type := | LocReg (_ : reg) -| LocRegB (_ : reg) (_ : nat) | LocArray (_ : reg) (_ : nat). Inductive location_is : fext -> assocmap -> assocmap_arr -> expr -> location -> Prop := -| Base : forall f asr asa r, location_is f asr asa (Vvar r) (LocReg r) -| Indexed : forall f asr asa r iexp iv, +| Reg : forall f asr asa r, location_is f asr asa (Vvar r) (LocReg r) +| RegIndexed : forall f asr asa r iexp iv, expr_runp f asr asa iexp iv -> location_is f asr asa (Vvari r iexp) (LocArray r (valueToNat iv)). @@ -807,6 +807,7 @@ Proof. | [ H : expr_runp _ _ _ (Vbinop _ _ _) _ |- _ ] => invert H | [ H : expr_runp _ _ _ (Vunop _ _) _ |- _ ] => invert H | [ H : expr_runp _ _ _ (Vternary _ _ _) _ |- _ ] => invert H + | [ H : expr_runp _ _ _ (Vload _ _) _ |- _ ] => invert H | [ H1 : forall asr asa v, expr_runp _ asr asa ?e v -> _, H2 : expr_runp _ _ _ ?e _ |- _ ] => -- cgit From b3208d9a581e7575c41d545964f4f85c6f3b4d66 Mon Sep 17 00:00:00 2001 From: James Pollard Date: Tue, 7 Jul 2020 13:24:59 +0100 Subject: Get Coqup compiling again on dev-nadesh. --- src/Compiler.v | 4 +- src/translation/HTLgen.v | 4 +- src/translation/HTLgenproof.v | 3867 +++++++++++++++++++++-------------------- 3 files changed, 1938 insertions(+), 1937 deletions(-) diff --git a/src/Compiler.v b/src/Compiler.v index 26e2f1f..0a8617d 100644 --- a/src/Compiler.v +++ b/src/Compiler.v @@ -149,8 +149,8 @@ Proof. exists p7; split. apply Inliningproof.transf_program_match; auto. exists p8; split. apply HTLgenproof.transf_program_match; auto. exists p9; split. apply Veriloggenproof.transf_program_match; auto. - inv T. reflexivity. -Qed. + (* inv T. reflexivity. *) +Admitted. Remark forward_simulation_identity: forall sem, forward_simulation sem sem. diff --git a/src/translation/HTLgen.v b/src/translation/HTLgen.v index 32b6e04..babbc01 100644 --- a/src/translation/HTLgen.v +++ b/src/translation/HTLgen.v @@ -275,8 +275,8 @@ Definition translate_condition (c : Op.condition) (args : list reg) : mon expr : | Op.Ccompu c, _ => translate_comparison c args | Op.Ccompimm c i, _ => translate_comparison_imm c args i | Op.Ccompuimm c i, _ => translate_comparison_imm c args i - | Op.Cmaskzero n, r::nil => ret (Vbinop Veq (boplit Vand r n) (Vlit (ZToValue 32 0))) - | Op.Cmasknotzero n, r::nil => ret (Vbinop Vne (boplit Vand r n) (Vlit (ZToValue 32 0))) + | Op.Cmaskzero n, r::nil => ret (Vbinop Veq (boplit Vand r n) (Vlit (ZToValue 0))) + | Op.Cmasknotzero n, r::nil => ret (Vbinop Vne (boplit Vand r n) (Vlit (ZToValue 0))) | _, _ => error (Errors.msg "Htlgen: condition instruction not implemented: other") end. diff --git a/src/translation/HTLgenproof.v b/src/translation/HTLgenproof.v index 51c0fa1..813a94b 100644 --- a/src/translation/HTLgenproof.v +++ b/src/translation/HTLgenproof.v @@ -342,1942 +342,1943 @@ Section CORRECTNESS. Hypothesis TRANSL : match_prog prog tprog. - Lemma TRANSL' : - Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq prog tprog. - Proof. intros; apply match_prog_matches; assumption. Qed. - - Let ge : RTL.genv := Globalenvs.Genv.globalenv prog. - Let tge : HTL.genv := Globalenvs.Genv.globalenv tprog. - - Lemma symbols_preserved: - forall (s: AST.ident), Genv.find_symbol tge s = Genv.find_symbol ge s. - Proof. intros. eapply (Genv.find_symbol_match TRANSL'). Qed. - - Lemma function_ptr_translated: - forall (b: Values.block) (f: RTL.fundef), - Genv.find_funct_ptr ge b = Some f -> - exists tf, - Genv.find_funct_ptr tge b = Some tf /\ transl_fundef f = Errors.OK tf. - Proof. - intros. exploit (Genv.find_funct_ptr_match TRANSL'); eauto. - intros (cu & tf & P & Q & R); exists tf; auto. - Qed. - - Lemma functions_translated: - forall (v: Values.val) (f: RTL.fundef), - Genv.find_funct ge v = Some f -> - exists tf, - Genv.find_funct tge v = Some tf /\ transl_fundef f = Errors.OK tf. - Proof. - intros. exploit (Genv.find_funct_match TRANSL'); eauto. - intros (cu & tf & P & Q & R); exists tf; auto. - Qed. - - Lemma senv_preserved: - Senv.equiv (Genv.to_senv ge) (Genv.to_senv tge). - Proof - (Genv.senv_transf_partial TRANSL'). - Hint Resolve senv_preserved : htlproof. - - Lemma ptrofs_inj : - forall a b, - Ptrofs.unsigned a = Ptrofs.unsigned b -> a = b. - Proof. - intros. rewrite <- Ptrofs.repr_unsigned. symmetry. rewrite <- Ptrofs.repr_unsigned. - rewrite H. auto. - Qed. - - Lemma op_stack_based : - forall F V sp v m args rs op ge pc' res0 pc f e fin rtrn st stk, - tr_instr fin rtrn st stk (RTL.Iop op args res0 pc') - (Verilog.Vnonblock (Verilog.Vvar res0) e) - (state_goto st pc') -> - reg_stack_based_pointers sp rs -> - (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> - @Op.eval_operation F V ge (Values.Vptr sp Ptrofs.zero) op - (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some v -> - stack_based v sp. - Proof. - Ltac solve_no_ptr := - match goal with - | H: reg_stack_based_pointers ?sp ?rs |- stack_based (Registers.Regmap.get ?r ?rs) _ => - solve [apply H] - | H1: reg_stack_based_pointers ?sp ?rs, H2: Registers.Regmap.get _ _ = Values.Vptr ?b ?i - |- context[Values.Vptr ?b _] => - let H := fresh "H" in - assert (H: stack_based (Values.Vptr b i) sp) by (rewrite <- H2; apply H1); simplify; solve [auto] - | |- context[Registers.Regmap.get ?lr ?lrs] => - destruct (Registers.Regmap.get lr lrs) eqn:?; simplify; auto - | |- stack_based (?f _) _ => unfold f - | |- stack_based (?f _ _) _ => unfold f - | |- stack_based (?f _ _ _) _ => unfold f - | |- stack_based (?f _ _ _ _) _ => unfold f - | H: ?f _ _ = Some _ |- _ => - unfold f in H; repeat (unfold_match H); inv H - | H: ?f _ _ _ _ _ _ = Some _ |- _ => - unfold f in H; repeat (unfold_match H); inv H - | H: map (fun r : positive => Registers.Regmap.get r _) ?args = _ |- _ => - destruct args; inv H - | |- context[if ?c then _ else _] => destruct c; try discriminate - | H: match _ with _ => _ end = Some _ |- _ => repeat (unfold_match H) - | |- context[match ?g with _ => _ end] => destruct g; try discriminate - | |- _ => simplify; solve [auto] - end. - intros F V sp v m args rs op g pc' res0 pc f e fin rtrn st stk INSTR RSBP SEL EVAL. - inv INSTR. unfold translate_instr in H5. - unfold_match H5; repeat (unfold_match H5); repeat (simplify; solve_no_ptr). - Qed. - - Lemma int_inj : - forall x y, - Int.unsigned x = Int.unsigned y -> - x = y. - Proof. - intros. rewrite <- Int.repr_unsigned at 1. rewrite <- Int.repr_unsigned. - rewrite <- H. trivial. - Qed. - - Lemma eval_correct : - forall s sp op rs m v e asr asa f f' stk s' i pc res0 pc' args res ml st, - match_states (RTL.State stk f sp pc rs m) (HTL.State res ml st asr asa) -> - (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> - Op.eval_operation ge sp op - (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) m = Some v -> - translate_instr op args s = OK e s' i -> - exists v', Verilog.expr_runp f' asr asa e v' /\ val_value_lessdef v v'. - Proof. - Ltac eval_correct_tac := - match goal with - | |- context[valueToPtr] => unfold valueToPtr - | |- context[valueToInt] => unfold valueToInt - | |- context[bop] => unfold bop - | |- context[boplit] => unfold boplit - | |- val_value_lessdef Values.Vundef _ => solve [constructor] - | H : val_value_lessdef _ _ |- val_value_lessdef (Values.Vint _) _ => constructor; inv H - | |- val_value_lessdef (Values.Vint _) _ => constructor; auto - | H : context[RTL.max_reg_function ?f] - |- context[_ (Registers.Regmap.get ?r ?rs) (Registers.Regmap.get ?r0 ?rs)] => - let HPle1 := fresh "HPle" in - let HPle2 := fresh "HPle" in - assert (HPle1 : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - assert (HPle2 : Ple r0 (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - apply H in HPle1; apply H in HPle2; eexists; split; - [econstructor; eauto; constructor; trivial | inv HPle1; inv HPle2; try (constructor; auto)] - | H : context[RTL.max_reg_function ?f] - |- context[_ (Registers.Regmap.get ?r ?rs) _] => - let HPle1 := fresh "HPle" in - assert (HPle1 : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - apply H in HPle1; eexists; split; - [econstructor; eauto; constructor; trivial | inv HPle1; try (constructor; auto)] - | H : _ :: _ = _ :: _ |- _ => inv H - | |- context[match ?d with _ => _ end] => destruct d eqn:?; try discriminate - | |- Verilog.expr_runp _ _ _ _ _ => econstructor - | |- val_value_lessdef (?f _ _) _ => unfold f - | |- val_value_lessdef (?f _) _ => unfold f - | H : ?f (Registers.Regmap.get _ _) _ = Some _ |- _ => - unfold f in H; repeat (unfold_match H) - | H1 : Registers.Regmap.get ?r ?rs = Values.Vint _, H2 : val_value_lessdef (Registers.Regmap.get ?r ?rs) _ - |- _ => rewrite H1 in H2; inv H2 - | |- _ => eexists; split; try constructor; solve [eauto] - | H : context[RTL.max_reg_function ?f] |- context[_ (Verilog.Vvar ?r) (Verilog.Vvar ?r0)] => - let HPle1 := fresh "H" in - let HPle2 := fresh "H" in - assert (HPle1 : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - assert (HPle2 : Ple r0 (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - apply H in HPle1; apply H in HPle2; eexists; split; try constructor; eauto - | H : context[RTL.max_reg_function ?f] |- context[Verilog.Vvar ?r] => - let HPle := fresh "H" in - assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - apply H in HPle; eexists; split; try constructor; eauto - | |- context[if ?c then _ else _] => destruct c eqn:?; try discriminate - end. - intros s sp op rs m v e asr asa f f' stk s' i pc pc' res0 args res ml st MSTATE INSTR EVAL TR_INSTR. - inv MSTATE. inv MASSOC. unfold translate_instr in TR_INSTR; repeat (unfold_match TR_INSTR); inv TR_INSTR; - unfold Op.eval_operation in EVAL; repeat (unfold_match EVAL); inv EVAL; - repeat (simplify; eval_correct_tac; unfold valueToInt in *). - - pose proof Integers.Ptrofs.agree32_sub as H2; unfold Integers.Ptrofs.agree32 in H2. - unfold Ptrofs.of_int. simpl. - apply ptrofs_inj. assert (Archi.ptr64 = false) by auto. eapply H2 in H3. - rewrite Ptrofs.unsigned_repr. apply H3. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - apply Int.unsigned_range_2. - auto. rewrite Ptrofs.unsigned_repr. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - apply Int.unsigned_range_2. rewrite Ptrofs.unsigned_repr. auto. - replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - apply Int.unsigned_range_2. - - pose proof Integers.Ptrofs.agree32_sub as AGR; unfold Integers.Ptrofs.agree32 in AGR. - assert (ARCH: Archi.ptr64 = false) by auto. eapply AGR in ARCH. - apply int_inj. unfold Ptrofs.to_int. rewrite Int.unsigned_repr. - apply ARCH. Search Ptrofs.unsigned. pose proof Ptrofs.unsigned_range_2. - replace Ptrofs.max_unsigned with Int.max_unsigned; auto. - pose proof Ptrofs.agree32_of_int. unfold Ptrofs.agree32 in H2. - eapply H2 in ARCH. apply ARCH. - pose proof Ptrofs.agree32_of_int. unfold Ptrofs.agree32 in H2. - eapply H2 in ARCH. apply ARCH. - - admit. (* mulhs *) - - admit. (* mulhu *) - - rewrite H0 in Heqb. rewrite H1 in Heqb. discriminate. - - rewrite Heqb in Heqb0. discriminate. - - rewrite H0 in Heqb. rewrite H1 in Heqb. discriminate. - - rewrite Heqb in Heqb0. discriminate. - - admit. - - admit. (* ror *) - - admit. (* addressing *) - - admit. (* eval_condition *) - - admit. (* select *) - Admitted. - - Lemma eval_cond_correct : - forall cond (args : list Registers.reg) s1 c s' i rs args m b f asr asa, - translate_condition cond args s1 = OK c s' i -> - Op.eval_condition - cond - (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) - m = Some b -> - Verilog.expr_runp f asr asa c (boolToValue b). - Admitted. - - (** The proof of semantic preservation for the translation of instructions - is a simulation argument based on diagrams of the following form: -<< - match_states - code st rs ---------------- State m st assoc - || | - || | - || | - \/ v - code st rs' --------------- State m st assoc' - match_states ->> - where [tr_code c data control fin rtrn st] is assumed to hold. - - The precondition and postcondition is that that should hold is [match_assocmaps rs assoc]. - *) - - Definition transl_instr_prop (instr : RTL.instruction) : Prop := - forall m asr asa fin rtrn st stmt trans res, - tr_instr fin rtrn st (m.(HTL.mod_stk)) instr stmt trans -> - exists asr' asa', - HTL.step tge (HTL.State res m st asr asa) Events.E0 (HTL.State res m st asr' asa'). - - Opaque combine. - - Ltac tac0 := - match goal with - | [ |- context[Verilog.merge_arrs _ _] ] => unfold Verilog.merge_arrs - | [ |- context[Verilog.merge_arr] ] => unfold Verilog.merge_arr - | [ |- context[Verilog.merge_regs _ _] ] => unfold Verilog.merge_regs; crush; unfold_merge - | [ |- context[reg_stack_based_pointers] ] => unfold reg_stack_based_pointers; intros - | [ |- context[Verilog.arr_assocmap_set _ _ _ _] ] => unfold Verilog.arr_assocmap_set - - | [ |- context[HTL.empty_stack] ] => unfold HTL.empty_stack - - | [ |- context[_ # ?d <- _ ! ?d] ] => rewrite AssocMap.gss - | [ |- context[_ # ?d <- _ ! ?s] ] => rewrite AssocMap.gso - | [ |- context[(AssocMap.empty _) ! _] ] => rewrite AssocMap.gempty - - | [ |- context[array_get_error _ (combine Verilog.merge_cell (arr_repeat None _) _)] ] => - rewrite combine_lookup_first - - | [ |- state_st_wf _ _ ] => unfold state_st_wf; inversion 1 - | [ |- context[match_states _ _] ] => econstructor; auto - | [ |- match_arrs _ _ _ _ _ ] => econstructor; auto - | [ |- match_assocmaps _ _ _ # _ <- (posToValue _) ] => - apply regs_lessdef_add_greater; [> unfold Plt; lia | assumption] - - | [ H : ?asa ! ?r = Some _ |- Verilog.arr_assocmap_lookup ?asa ?r _ = Some _ ] => - unfold Verilog.arr_assocmap_lookup; setoid_rewrite H; f_equal - | [ |- context[(AssocMap.combine _ _ _) ! _] ] => - try (rewrite AssocMap.gcombine; [> | reflexivity]) - - | [ |- context[Registers.Regmap.get ?d (Registers.Regmap.set ?d _ _)] ] => - rewrite Registers.Regmap.gss - | [ |- context[Registers.Regmap.get ?s (Registers.Regmap.set ?d _ _)] ] => - destruct (Pos.eq_dec s d) as [EQ|EQ]; - [> rewrite EQ | rewrite Registers.Regmap.gso; auto] - - | [ H : opt_val_value_lessdef _ _ |- _ ] => invert H - | [ H : context[Z.of_nat (Z.to_nat _)] |- _ ] => rewrite Z2Nat.id in H; [> solve crush |] - | [ H : _ ! _ = Some _ |- _] => setoid_rewrite H - end. - - Ltac small_tac := repeat (crush; try array; try ptrofs); crush; auto. - Ltac big_tac := repeat (crush; try array; try ptrofs; try tac0); crush; auto. - - Lemma transl_inop_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : RTL.regset) (m : mem) (pc' : RTL.node), - (RTL.fn_code f) ! pc = Some (RTL.Inop pc') -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. - Proof. - intros s f sp pc rs m pc' H R1 MSTATE. - inv_state. - - unfold match_prog in TRANSL. - econstructor. - split. - apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - inv CONST; assumption. - inv CONST; assumption. - (* processing of state *) - econstructor. - crush. - econstructor. - econstructor. - econstructor. - - all: invert MARR; big_tac. - - inv CONST; constructor; simplify; rewrite AssocMap.gso; auto; lia. - - Unshelve. auto. - Qed. - Hint Resolve transl_inop_correct : htlproof. - - Lemma transl_iop_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (op : Op.operation) (args : list Registers.reg) - (res0 : Registers.reg) (pc' : RTL.node) (v : Values.val), - (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> - Op.eval_operation ge sp op (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some v -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.State s f sp pc' (Registers.Regmap.set res0 v rs) m) R2. - Proof. - intros s f sp pc rs m op args res0 pc' v H H0 R1 MSTATE. - inv_state. inv MARR. - exploit eval_correct; eauto. intros. inversion H1. inversion H2. - econstructor. split. - apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - inv CONST. assumption. - inv CONST. assumption. - econstructor; simpl; trivial. - constructor; trivial. - econstructor; simpl; eauto. - simpl. econstructor. econstructor. - apply H5. simplify. - - all: big_tac. - - assert (HPle: Ple res0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_def; eauto; simpl; auto). - - unfold Ple in HPle. lia. - apply regs_lessdef_add_match. assumption. - apply regs_lessdef_add_greater. unfold Plt; lia. assumption. - assert (HPle: Ple res0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_def; eauto; simpl; auto). - unfold Ple in HPle; lia. - eapply op_stack_based; eauto. - inv CONST. constructor; simplify. rewrite AssocMap.gso. rewrite AssocMap.gso. - assumption. lia. - assert (HPle: Ple res0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_def; eauto; simpl; auto). - unfold Ple in HPle. lia. - rewrite AssocMap.gso. rewrite AssocMap.gso. - assumption. lia. - assert (HPle: Ple res0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_def; eauto; simpl; auto). - unfold Ple in HPle. lia. - Unshelve. trivial. - Qed. - Hint Resolve transl_iop_correct : htlproof. - - Ltac tac := - repeat match goal with - | [ _ : error _ _ = OK _ _ _ |- _ ] => discriminate - | [ _ : context[if (?x && ?y) then _ else _] |- _ ] => - let EQ1 := fresh "EQ" in - let EQ2 := fresh "EQ" in - destruct x eqn:EQ1; destruct y eqn:EQ2; simpl in * - | [ _ : context[if ?x then _ else _] |- _ ] => - let EQ := fresh "EQ" in - destruct x eqn:EQ; simpl in * - | [ H : ret _ _ = _ |- _ ] => invert H - | [ _ : context[match ?x with | _ => _ end] |- _ ] => destruct x - end. - - Ltac inv_arr_access := - match goal with - | [ _ : translate_arr_access ?chunk ?addr ?args _ _ = OK ?c _ _ |- _] => - destruct c, chunk, addr, args; crush; tac; crush - end. - - Lemma transl_iload_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) - (addr : Op.addressing) (args : list Registers.reg) (dst : Registers.reg) - (pc' : RTL.node) (a v : Values.val), - (RTL.fn_code f) ! pc = Some (RTL.Iload chunk addr args dst pc') -> - Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> - Mem.loadv chunk m a = Some v -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.State s f sp pc' (Registers.Regmap.set dst v rs) m) R2. - Proof. - intros s f sp pc rs m chunk addr args dst pc' a v H H0 H1 R1 MSTATE. - inv_state. inv_arr_access. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. - - rewrite ARCHI in H1. crush. - subst. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - apply H6 in HPler0. - invert HPler0; try congruence. - rewrite EQr0 in H8. - invert H8. - clear H0. clear H6. - - unfold check_address_parameter_signed in *; - unfold check_address_parameter_unsigned in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. - - (** Modular preservation proof *) - (*assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Read bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - rewrite <- EXPR_OK. - - specialize (H7 (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4)))). - exploit H7; big_tac. - - (** RSBP preservation *) - unfold arr_stack_based_pointers in ASBP. - specialize (ASBP (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). - exploit ASBP; big_tac. - rewrite NORMALISE in H0. rewrite H1 in H0. assumption. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - pose proof (RSBP r1) as RSBPr1. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; - destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. - - rewrite ARCHI in H1. crush. - subst. - clear RSBPr1. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - pose proof (H0 r1). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - assert (HPler1 : Ple r1 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H6 in HPler0. - apply H8 in HPler1. - invert HPler0; invert HPler1; try congruence. - rewrite EQr0 in H9. - rewrite EQr1 in H11. - invert H9. invert H11. - clear H0. clear H6. clear H8. - - unfold check_address_parameter_signed in *; - unfold check_address_parameter_unsigned in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int - (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) - (Integers.Int.repr z0)))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush; try lia. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - apply IntExtra.add_mod; crush. - apply IntExtra.mul_mod2; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Read bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - rewrite <- EXPR_OK. - - specialize (H7 (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4)))). - exploit H7; big_tac. - - (** RSBP preservation *) - unfold arr_stack_based_pointers in ASBP. - specialize (ASBP (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). - exploit ASBP; big_tac. - rewrite NORMALISE in H0. rewrite H1 in H0. assumption. - - + invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - rewrite ARCHI in H0. crush. - - unfold check_address_parameter_unsigned in *; - unfold check_address_parameter_signed in *; crush. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - rewrite ZERO in H1. clear ZERO. - rewrite Integers.Ptrofs.add_zero_l in H1. - - remember i0 as OFFSET. - - (** Modular preservation proof *) - rename H0 into MOD_PRESERVE. - - (** Read bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - rewrite <- EXPR_OK. - - specialize (H7 (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4)))). - exploit H7; big_tac. - - (** RSBP preservation *) - unfold arr_stack_based_pointers in ASBP. - specialize (ASBP (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). - exploit ASBP; big_tac. - rewrite NORMALISE in H0. rewrite H1 in H0. assumption.*) - Admitted. - Hint Resolve transl_iload_correct : htlproof. - - Lemma transl_istore_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) - (addr : Op.addressing) (args : list Registers.reg) (src : Registers.reg) - (pc' : RTL.node) (a : Values.val) (m' : mem), - (RTL.fn_code f) ! pc = Some (RTL.Istore chunk addr args src pc') -> - Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> - Mem.storev chunk m a (Registers.Regmap.get src rs) = Some m' -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m') R2. - Proof. -(* intros s f sp pc rs m chunk addr args src pc' a m' H H0 H1 R1 MSTATES. - inv_state. inv_arr_access. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. - - rewrite ARCHI in H1. crush. - subst. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - apply H6 in HPler0. - invert HPler0; try congruence. - rewrite EQr0 in H8. - invert H8. - clear H0. clear H6. - - unfold check_address_parameter_unsigned in *; - unfold check_address_parameter_signed in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush; try lia. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Write bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET - assert (Z.to_nat - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.divu - OFFSET - (Integers.Ptrofs.repr 4))) - = - valueToNat x) - as EXPR_OK by admit - end. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - inversion MASSOC; revert HeqOFFSET; subst; clear MASSOC; intros HeqOFFSET. - - econstructor. - repeat split; crush. - unfold HTL.empty_stack. - crush. - unfold Verilog.merge_arrs. - - rewrite AssocMap.gcombine. - 2: { reflexivity. } - unfold Verilog.arr_assocmap_set. - rewrite AssocMap.gss. - unfold Verilog.merge_arr. - rewrite AssocMap.gss. - setoid_rewrite H5. - reflexivity. - - rewrite combine_length. - rewrite <- array_set_len. - unfold arr_repeat. crush. - apply list_repeat_len. - - rewrite <- array_set_len. - unfold arr_repeat. crush. - rewrite list_repeat_len. - rewrite H4. reflexivity. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. - - destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). - - erewrite Mem.load_store_same. - 2: { rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite e. - rewrite Integers.Ptrofs.unsigned_repr. - exact H1. - apply Integers.Ptrofs.unsigned_range_2. } - constructor. - erewrite combine_lookup_second. - simpl. - assert (Ple src (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; simpl; auto); - apply H0 in H13. - destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; constructor; invert H13; eauto. - - rewrite <- array_set_len. - unfold arr_repeat. crush. - rewrite list_repeat_len. auto. - - assert (4 * ptr / 4 = Integers.Ptrofs.unsigned OFFSET / 4) by (f_equal; assumption). - rewrite Z.mul_comm in H13. - rewrite Z_div_mult in H13; try lia. - replace 4 with (Integers.Ptrofs.unsigned (Integers.Ptrofs.repr 4)) in H13 by reflexivity. - rewrite <- PtrofsExtra.divu_unsigned in H13; unfold_constants; try lia. - rewrite H13. rewrite EXPR_OK. - rewrite array_get_error_set_bound. - reflexivity. - unfold arr_length, arr_repeat. simpl. - rewrite list_repeat_len. lia. - - erewrite Mem.load_store_other with (m1 := m). - 2: { exact H1. } - 2: { right. - rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite Integers.Ptrofs.unsigned_repr. - simpl. - destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. - right. - apply ZExtra.mod_0_bounds; try lia. - apply ZLib.Z_mod_mult'. - rewrite Z2Nat.id in H15; try lia. - apply Zmult_lt_compat_r with (p := 4) in H15; try lia. - rewrite ZLib.div_mul_undo in H15; try lia. - split; try lia. - apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. - } - - rewrite <- EXPR_OK. - rewrite PtrofsExtra.divu_unsigned; auto; try (unfold_constants; lia). - destruct (ptr ==Z Integers.Ptrofs.unsigned OFFSET / 4). - apply Z.mul_cancel_r with (p := 4) in e; try lia. - rewrite ZLib.div_mul_undo in e; try lia. - rewrite combine_lookup_first. - eapply H7; eauto. - - rewrite <- array_set_len. - unfold arr_repeat. crush. - rewrite list_repeat_len. auto. - rewrite array_gso. - unfold array_get_error. - unfold arr_repeat. - crush. - apply list_repeat_lookup. - lia. - unfold_constants. - intro. - apply Z2Nat.inj_iff in H13; try lia. - apply Z.div_pos; try lia. - apply Integers.Ptrofs.unsigned_range. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - unfold arr_stack_based_pointers. - intros. - destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). - - crush. - erewrite Mem.load_store_same. - 2: { rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite e. - rewrite Integers.Ptrofs.unsigned_repr. - exact H1. - apply Integers.Ptrofs.unsigned_range_2. } - crush. - destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; try constructor. - destruct (Archi.ptr64); try discriminate. - pose proof (RSBP src). rewrite EQ_SRC in H0. - assumption. - - simpl. - erewrite Mem.load_store_other with (m1 := m). - 2: { exact H1. } - 2: { right. - rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite Integers.Ptrofs.unsigned_repr. - simpl. - destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. - right. - apply ZExtra.mod_0_bounds; try lia. - apply ZLib.Z_mod_mult'. - invert H0. - apply Zmult_lt_compat_r with (p := 4) in H14; try lia. - rewrite ZLib.div_mul_undo in H14; try lia. - split; try lia. - apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. - } - apply ASBP; assumption. - - unfold stack_bounds in *. intros. - simpl. - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - erewrite Mem.load_store_other with (m1 := m). - 2: { exact H1. } - 2: { right. right. simpl. - rewrite ZERO. - rewrite Integers.Ptrofs.add_zero_l. - rewrite Integers.Ptrofs.unsigned_repr; crush; try lia. - apply ZExtra.mod_0_bounds; crush; try lia. } - crush. - exploit (BOUNDS ptr); try lia. intros. crush. - exploit (BOUNDS ptr v); try lia. intros. - invert H0. - match goal with | |- ?x = _ => destruct x eqn:EQ end; try reflexivity. - assert (Mem.valid_access m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) Writable). - { pose proof H1. eapply Mem.store_valid_access_2 in H0. - exact H0. eapply Mem.store_valid_access_3. eassumption. } - pose proof (Mem.valid_access_store m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) v). - apply X in H0. invert H0. congruence. - - + (** Preamble *) - invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - - unfold reg_stack_based_pointers in RSBP. - pose proof (RSBP r0) as RSBPr0. - pose proof (RSBP r1) as RSBPr1. - - destruct (Registers.Regmap.get r0 rs) eqn:EQr0; - destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. - - rewrite ARCHI in H1. crush. - subst. - clear RSBPr1. - - pose proof MASSOC as MASSOC'. - invert MASSOC'. - pose proof (H0 r0). - pose proof (H0 r1). - assert (HPler0 : Ple r0 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; crush; eauto). - assert (HPler1 : Ple r1 (RTL.max_reg_function f)) - by (eapply RTL.max_reg_function_use; eauto; simpl; auto). - apply H6 in HPler0. - apply H8 in HPler1. - invert HPler0; invert HPler1; try congruence. - rewrite EQr0 in H9. - rewrite EQr1 in H11. - invert H9. invert H11. - clear H0. clear H6. clear H8. - - unfold check_address_parameter_signed in *; - unfold check_address_parameter_unsigned in *; crush. - - remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) - (Integers.Ptrofs.of_int - (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) - (Integers.Int.repr z0)))) as OFFSET. - - (** Modular preservation proof *) - assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. - { rewrite HeqOFFSET. - apply PtrofsExtra.add_mod; crush; try lia. - rewrite Integers.Ptrofs.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - apply PtrofsExtra.of_int_mod. - apply IntExtra.add_mod; crush. - apply IntExtra.mul_mod2; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. - rewrite Integers.Int.unsigned_repr_eq. - rewrite <- Zmod_div_mod; crush. } - - (** Write bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. - assert (Mem.valid_access m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) Writable). - { pose proof H1. eapply Mem.store_valid_access_2 in H0. - exact H0. eapply Mem.store_valid_access_3. eassumption. } - pose proof (Mem.valid_access_store m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) v). - apply X in H0. invert H0. congruence. - - + invert MARR. crush. - - unfold Op.eval_addressing in H0. - destruct (Archi.ptr64) eqn:ARCHI; crush. - rewrite ARCHI in H0. crush. - - unfold check_address_parameter_unsigned in *; - unfold check_address_parameter_signed in *; crush. - - assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. - rewrite ZERO in H1. clear ZERO. - rewrite Integers.Ptrofs.add_zero_l in H1. - - remember i0 as OFFSET. - - (** Modular preservation proof *) - rename H0 into MOD_PRESERVE. - - (** Write bounds proof *) - assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. - { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. - assert (Mem.valid_access m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) Writable). - { pose proof H1. eapply Mem.store_valid_access_2 in H0. - exact H0. eapply Mem.store_valid_access_3. eassumption. } - pose proof (Mem.valid_access_store m AST.Mint32 sp' - (Integers.Ptrofs.unsigned - (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) - (Integers.Ptrofs.repr ptr))) v). - apply X in H0. invert H0. congruence.*) - Admitted. - Hint Resolve transl_istore_correct : htlproof. - - Lemma transl_icond_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (cond : Op.condition) (args : list Registers.reg) - (ifso ifnot : RTL.node) (b : bool) (pc' : RTL.node), - (RTL.fn_code f) ! pc = Some (RTL.Icond cond args ifso ifnot) -> - Op.eval_condition cond (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some b -> - pc' = (if b then ifso else ifnot) -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. - Proof. - intros s f sp pc rs m cond args ifso ifnot b pc' H H0 H1 R1 MSTATE. - inv_state. - - eexists. split. apply Smallstep.plus_one. - eapply HTL.step_module; eauto. - inv CONST; assumption. - inv CONST; assumption. -(* eapply Verilog.stmnt_runp_Vnonblock_reg with - (rhsval := if b then posToValue 32 ifso else posToValue 32 ifnot). - constructor. - - simpl. - destruct b. - eapply Verilog.erun_Vternary_true. - eapply eval_cond_correct; eauto. - constructor. - apply boolToValue_ValueToBool. - eapply Verilog.erun_Vternary_false. - eapply eval_cond_correct; eauto. - constructor. - apply boolToValue_ValueToBool. - constructor. - - big_tac. - - invert MARR. - destruct b; rewrite assumption_32bit; big_tac. - - Unshelve. - constructor. - Qed.*) - Admitted. - Hint Resolve transl_icond_correct : htlproof. - - Lemma transl_ijumptable_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) - (rs : Registers.Regmap.t Values.val) (m : mem) (arg : Registers.reg) (tbl : list RTL.node) - (n : Integers.Int.int) (pc' : RTL.node), - (RTL.fn_code f) ! pc = Some (RTL.Ijumptable arg tbl) -> - Registers.Regmap.get arg rs = Values.Vint n -> - list_nth_z tbl (Integers.Int.unsigned n) = Some pc' -> - forall R1 : HTL.state, - match_states (RTL.State s f sp pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. - Proof. - intros s f sp pc rs m arg tbl n pc' H H0 H1 R1 MSTATE. - Admitted. - Hint Resolve transl_ijumptable_correct : htlproof. - - Lemma transl_ireturn_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (stk : Values.block) - (pc : positive) (rs : RTL.regset) (m : mem) (or : option Registers.reg) - (m' : mem), - (RTL.fn_code f) ! pc = Some (RTL.Ireturn or) -> - Mem.free m stk 0 (RTL.fn_stacksize f) = Some m' -> - forall R1 : HTL.state, - match_states (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) pc rs m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.Returnstate s (Registers.regmap_optget or Values.Vundef rs) m') R2. - Proof. - intros s f stk pc rs m or m' H H0 R1 MSTATE. - inv_state. - - - econstructor. split. - eapply Smallstep.plus_two. - - eapply HTL.step_module; eauto. - inv CONST; assumption. - inv CONST; assumption. - constructor. - econstructor; simpl; trivial. - econstructor; simpl; trivial. - constructor. - econstructor; simpl; trivial. - constructor. - - constructor. constructor. - - unfold state_st_wf in WF; big_tac; eauto. - destruct wf as [HCTRL HDATA]. apply HCTRL. - apply AssocMapExt.elements_iff. eexists. - match goal with H: control ! pc = Some _ |- _ => apply H end. - - apply HTL.step_finish. - unfold Verilog.merge_regs. - unfold_merge; simpl. - rewrite AssocMap.gso. - apply AssocMap.gss. lia. - apply AssocMap.gss. - rewrite Events.E0_left. reflexivity. - - constructor; auto. - constructor. - - (* FIXME: Duplication *) - - econstructor. split. - eapply Smallstep.plus_two. - eapply HTL.step_module; eauto. - inv CONST; assumption. - inv CONST; assumption. - constructor. - econstructor; simpl; trivial. - econstructor; simpl; trivial. - constructor. constructor. constructor. - constructor. constructor. constructor. - - unfold state_st_wf in WF; big_tac; eauto. - - destruct wf as [HCTRL HDATA]. apply HCTRL. - apply AssocMapExt.elements_iff. eexists. - match goal with H: control ! pc = Some _ |- _ => apply H end. - - apply HTL.step_finish. - unfold Verilog.merge_regs. - unfold_merge. - rewrite AssocMap.gso. - apply AssocMap.gss. simpl; lia. - apply AssocMap.gss. - rewrite Events.E0_left. trivial. - - constructor; auto. - - simpl. inversion MASSOC. subst. - unfold find_assocmap, AssocMapExt.get_default. rewrite AssocMap.gso. - apply H1. eapply RTL.max_reg_function_use. eauto. simpl; tauto. - assert (HPle : Ple r (RTL.max_reg_function f)). - eapply RTL.max_reg_function_use. eassumption. simpl; auto. - apply ZExtra.Ple_not_eq. apply ZExtra.Ple_Plt_Succ. assumption. - - Unshelve. - all: constructor. - Qed. - Hint Resolve transl_ireturn_correct : htlproof. - - Lemma transl_callstate_correct: - forall (s : list RTL.stackframe) (f : RTL.function) (args : list Values.val) - (m : mem) (m' : Mem.mem') (stk : Values.block), - Mem.alloc m 0 (RTL.fn_stacksize f) = (m', stk) -> - forall R1 : HTL.state, - match_states (RTL.Callstate s (AST.Internal f) args m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states - (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) (RTL.fn_entrypoint f) - (RTL.init_regs args (RTL.fn_params f)) m') R2. - Proof. - intros s f args m m' stk H R1 MSTATE. - - inversion MSTATE; subst. inversion TF; subst. - econstructor. split. apply Smallstep.plus_one. - eapply HTL.step_call. crush. - - apply match_state with (sp' := stk); eauto. - - all: big_tac. - - apply regs_lessdef_add_greater. unfold Plt; lia. - apply regs_lessdef_add_greater. unfold Plt; lia. - apply regs_lessdef_add_greater. unfold Plt; lia. - apply init_reg_assoc_empty. - - constructor. - - destruct (Mem.load AST.Mint32 m' stk - (Integers.Ptrofs.unsigned (Integers.Ptrofs.add - Integers.Ptrofs.zero - (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. - pose proof Mem.load_alloc_same as LOAD_ALLOC. - pose proof H as ALLOC. - eapply LOAD_ALLOC in ALLOC. - 2: { exact LOAD. } - ptrofs. rewrite LOAD. - rewrite ALLOC. - repeat constructor. - - ptrofs. rewrite LOAD. - repeat constructor. - - unfold reg_stack_based_pointers. intros. - unfold RTL.init_regs; crush. - destruct (RTL.fn_params f); - rewrite Registers.Regmap.gi; constructor. - - unfold arr_stack_based_pointers. intros. - crush. - destruct (Mem.load AST.Mint32 m' stk - (Integers.Ptrofs.unsigned (Integers.Ptrofs.add - Integers.Ptrofs.zero - (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. - pose proof Mem.load_alloc_same as LOAD_ALLOC. - pose proof H as ALLOC. - eapply LOAD_ALLOC in ALLOC. - 2: { exact LOAD. } - rewrite ALLOC. - repeat constructor. - constructor. - - Transparent Mem.alloc. (* TODO: Since there are opaque there's probably a lemma. *) - Transparent Mem.load. - Transparent Mem.store. - unfold stack_bounds. - split. - - unfold Mem.alloc in H. - invert H. - crush. - unfold Mem.load. - intros. - match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. - invert v0. unfold Mem.range_perm in H4. - unfold Mem.perm in H4. crush. - unfold Mem.perm_order' in H4. - small_tac. - exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. - rewrite Maps.PMap.gss in H8. - match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. - crush. - apply proj_sumbool_true in H10. lia. - - unfold Mem.alloc in H. - invert H. - crush. - unfold Mem.store. - intros. - match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. - invert v0. unfold Mem.range_perm in H4. - unfold Mem.perm in H4. crush. - unfold Mem.perm_order' in H4. - small_tac. - exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. - rewrite Maps.PMap.gss in H8. - match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. - crush. - apply proj_sumbool_true in H10. lia. - constructor. simplify. rewrite AssocMap.gss. - simplify. rewrite AssocMap.gso. apply AssocMap.gss. simplify. lia. - Opaque Mem.alloc. - Opaque Mem.load. - Opaque Mem.store. - Qed. - Hint Resolve transl_callstate_correct : htlproof. - - Lemma transl_returnstate_correct: - forall (res0 : Registers.reg) (f : RTL.function) (sp : Values.val) (pc : RTL.node) - (rs : RTL.regset) (s : list RTL.stackframe) (vres : Values.val) (m : mem) - (R1 : HTL.state), - match_states (RTL.Returnstate (RTL.Stackframe res0 f sp pc rs :: s) vres m) R1 -> - exists R2 : HTL.state, - Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ - match_states (RTL.State s f sp pc (Registers.Regmap.set res0 vres rs) m) R2. - Proof. - intros res0 f sp pc rs s vres m R1 MSTATE. - inversion MSTATE. inversion MF. - Qed. - Hint Resolve transl_returnstate_correct : htlproof. - - Lemma option_inv : - forall A x y, - @Some A x = Some y -> x = y. - Proof. intros. inversion H. trivial. Qed. - - Lemma main_tprog_internal : - forall b, - Globalenvs.Genv.find_symbol tge tprog.(AST.prog_main) = Some b -> - exists f, Genv.find_funct_ptr (Genv.globalenv tprog) b = Some (AST.Internal f). - Proof. - intros. - destruct TRANSL. unfold main_is_internal in H1. - repeat (unfold_match H1). replace b with b0. - exploit function_ptr_translated; eauto. intros [tf [A B]]. - unfold transl_fundef, AST.transf_partial_fundef, Errors.bind in B. - unfold_match B. inv B. econstructor. apply A. - - apply option_inv. rewrite <- Heqo. rewrite <- H. - rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). - trivial. symmetry; eapply Linking.match_program_main; eauto. - Qed. - - Lemma transl_initial_states : - forall s1 : Smallstep.state (RTL.semantics prog), - Smallstep.initial_state (RTL.semantics prog) s1 -> - exists s2 : Smallstep.state (HTL.semantics tprog), - Smallstep.initial_state (HTL.semantics tprog) s2 /\ match_states s1 s2. - Proof. - induction 1. - destruct TRANSL. unfold main_is_internal in H4. - repeat (unfold_match H4). - assert (f = AST.Internal f1). apply option_inv. - rewrite <- Heqo0. rewrite <- H1. replace b with b0. - auto. apply option_inv. rewrite <- H0. rewrite <- Heqo. - trivial. - exploit function_ptr_translated; eauto. - intros [tf [A B]]. - unfold transl_fundef, Errors.bind in B. - unfold AST.transf_partial_fundef, Errors.bind in B. - repeat (unfold_match B). inversion B. subst. - exploit main_tprog_internal; eauto; intros. - rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). - apply Heqo. symmetry; eapply Linking.match_program_main; eauto. - inversion H5. - econstructor; split. econstructor. - apply (Genv.init_mem_transf_partial TRANSL'); eauto. - replace (AST.prog_main tprog) with (AST.prog_main prog). - rewrite symbols_preserved; eauto. - symmetry; eapply Linking.match_program_main; eauto. - apply H6. - - constructor. - apply transl_module_correct. - assert (Some (AST.Internal x) = Some (AST.Internal m)). - replace (AST.fundef HTL.module) with (HTL.fundef). - rewrite <- H6. setoid_rewrite <- A. trivial. - trivial. inv H7. assumption. - Qed. - Hint Resolve transl_initial_states : htlproof. - - Lemma transl_final_states : - forall (s1 : Smallstep.state (RTL.semantics prog)) - (s2 : Smallstep.state (HTL.semantics tprog)) - (r : Integers.Int.int), - match_states s1 s2 -> - Smallstep.final_state (RTL.semantics prog) s1 r -> - Smallstep.final_state (HTL.semantics tprog) s2 r. - Proof. - intros. inv H0. inv H. inv H4. invert MF. constructor. reflexivity. - Qed. - Hint Resolve transl_final_states : htlproof. - - Theorem transl_step_correct: - forall (S1 : RTL.state) t S2, - RTL.step ge S1 t S2 -> - forall (R1 : HTL.state), - match_states S1 R1 -> - exists R2, Smallstep.plus HTL.step tge R1 t R2 /\ match_states S2 R2. - Proof. - induction 1; eauto with htlproof; (intros; inv_state). - Qed. - Hint Resolve transl_step_correct : htlproof. +(* Lemma TRANSL' : *) +(* Linking.match_program (fun cu f tf => transl_fundef f = Errors.OK tf) eq prog tprog. *) +(* Proof. intros; apply match_prog_matches; assumption. Qed. *) + +(* Let ge : RTL.genv := Globalenvs.Genv.globalenv prog. *) +(* Let tge : HTL.genv := Globalenvs.Genv.globalenv tprog. *) + +(* Lemma symbols_preserved: *) +(* forall (s: AST.ident), Genv.find_symbol tge s = Genv.find_symbol ge s. *) +(* Proof. intros. eapply (Genv.find_symbol_match TRANSL'). Qed. *) + +(* Lemma function_ptr_translated: *) +(* forall (b: Values.block) (f: RTL.fundef), *) +(* Genv.find_funct_ptr ge b = Some f -> *) +(* exists tf, *) +(* Genv.find_funct_ptr tge b = Some tf /\ transl_fundef f = Errors.OK tf. *) +(* Proof. *) +(* intros. exploit (Genv.find_funct_ptr_match TRANSL'); eauto. *) +(* intros (cu & tf & P & Q & R); exists tf; auto. *) +(* Qed. *) + +(* Lemma functions_translated: *) +(* forall (v: Values.val) (f: RTL.fundef), *) +(* Genv.find_funct ge v = Some f -> *) +(* exists tf, *) +(* Genv.find_funct tge v = Some tf /\ transl_fundef f = Errors.OK tf. *) +(* Proof. *) +(* intros. exploit (Genv.find_funct_match TRANSL'); eauto. *) +(* intros (cu & tf & P & Q & R); exists tf; auto. *) +(* Qed. *) + +(* Lemma senv_preserved: *) +(* Senv.equiv (Genv.to_senv ge) (Genv.to_senv tge). *) +(* Proof *) +(* (Genv.senv_transf_partial TRANSL'). *) +(* Hint Resolve senv_preserved : htlproof. *) + +(* Lemma ptrofs_inj : *) +(* forall a b, *) +(* Ptrofs.unsigned a = Ptrofs.unsigned b -> a = b. *) +(* Proof. *) +(* intros. rewrite <- Ptrofs.repr_unsigned. symmetry. rewrite <- Ptrofs.repr_unsigned. *) +(* rewrite H. auto. *) +(* Qed. *) + +(* Lemma op_stack_based : *) +(* forall F V sp v m args rs op ge pc' res0 pc f e fin rtrn st stk, *) +(* tr_instr fin rtrn st stk (RTL.Iop op args res0 pc') *) +(* (Verilog.Vnonblock (Verilog.Vvar res0) e) *) +(* (state_goto st pc') -> *) +(* reg_stack_based_pointers sp rs -> *) +(* (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> *) +(* @Op.eval_operation F V ge (Values.Vptr sp Ptrofs.zero) op *) +(* (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some v -> *) +(* stack_based v sp. *) +(* Proof. *) +(* Ltac solve_no_ptr := *) +(* match goal with *) +(* | H: reg_stack_based_pointers ?sp ?rs |- stack_based (Registers.Regmap.get ?r ?rs) _ => *) +(* solve [apply H] *) +(* | H1: reg_stack_based_pointers ?sp ?rs, H2: Registers.Regmap.get _ _ = Values.Vptr ?b ?i *) +(* |- context[Values.Vptr ?b _] => *) +(* let H := fresh "H" in *) +(* assert (H: stack_based (Values.Vptr b i) sp) by (rewrite <- H2; apply H1); simplify; solve [auto] *) +(* | |- context[Registers.Regmap.get ?lr ?lrs] => *) +(* destruct (Registers.Regmap.get lr lrs) eqn:?; simplify; auto *) +(* | |- stack_based (?f _) _ => unfold f *) +(* | |- stack_based (?f _ _) _ => unfold f *) +(* | |- stack_based (?f _ _ _) _ => unfold f *) +(* | |- stack_based (?f _ _ _ _) _ => unfold f *) +(* | H: ?f _ _ = Some _ |- _ => *) +(* unfold f in H; repeat (unfold_match H); inv H *) +(* | H: ?f _ _ _ _ _ _ = Some _ |- _ => *) +(* unfold f in H; repeat (unfold_match H); inv H *) +(* | H: map (fun r : positive => Registers.Regmap.get r _) ?args = _ |- _ => *) +(* destruct args; inv H *) +(* | |- context[if ?c then _ else _] => destruct c; try discriminate *) +(* | H: match _ with _ => _ end = Some _ |- _ => repeat (unfold_match H) *) +(* | |- context[match ?g with _ => _ end] => destruct g; try discriminate *) +(* | |- _ => simplify; solve [auto] *) +(* end. *) +(* intros F V sp v m args rs op g pc' res0 pc f e fin rtrn st stk INSTR RSBP SEL EVAL. *) +(* inv INSTR. unfold translate_instr in H5. *) +(* unfold_match H5; repeat (unfold_match H5); repeat (simplify; solve_no_ptr). *) +(* Qed. *) + +(* Lemma int_inj : *) +(* forall x y, *) +(* Int.unsigned x = Int.unsigned y -> *) +(* x = y. *) +(* Proof. *) +(* intros. rewrite <- Int.repr_unsigned at 1. rewrite <- Int.repr_unsigned. *) +(* rewrite <- H. trivial. *) +(* Qed. *) + +(* Lemma eval_correct : *) +(* forall s sp op rs m v e asr asa f f' stk s' i pc res0 pc' args res ml st, *) +(* match_states (RTL.State stk f sp pc rs m) (HTL.State res ml st asr asa) -> *) +(* (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> *) +(* Op.eval_operation ge sp op *) +(* (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) m = Some v -> *) +(* translate_instr op args s = OK e s' i -> *) +(* exists v', Verilog.expr_runp f' asr asa e v' /\ val_value_lessdef v v'. *) +(* Proof. *) +(* Ltac eval_correct_tac := *) +(* match goal with *) +(* | |- context[valueToPtr] => unfold valueToPtr *) +(* | |- context[valueToInt] => unfold valueToInt *) +(* | |- context[bop] => unfold bop *) +(* | |- context[boplit] => unfold boplit *) +(* | |- val_value_lessdef Values.Vundef _ => solve [constructor] *) +(* | H : val_value_lessdef _ _ |- val_value_lessdef (Values.Vint _) _ => constructor; inv H *) +(* | |- val_value_lessdef (Values.Vint _) _ => constructor; auto *) +(* | H : context[RTL.max_reg_function ?f] *) +(* |- context[_ (Registers.Regmap.get ?r ?rs) (Registers.Regmap.get ?r0 ?rs)] => *) +(* let HPle1 := fresh "HPle" in *) +(* let HPle2 := fresh "HPle" in *) +(* assert (HPle1 : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* assert (HPle2 : Ple r0 (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* apply H in HPle1; apply H in HPle2; eexists; split; *) +(* [econstructor; eauto; constructor; trivial | inv HPle1; inv HPle2; try (constructor; auto)] *) +(* | H : context[RTL.max_reg_function ?f] *) +(* |- context[_ (Registers.Regmap.get ?r ?rs) _] => *) +(* let HPle1 := fresh "HPle" in *) +(* assert (HPle1 : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* apply H in HPle1; eexists; split; *) +(* [econstructor; eauto; constructor; trivial | inv HPle1; try (constructor; auto)] *) +(* | H : _ :: _ = _ :: _ |- _ => inv H *) +(* | |- context[match ?d with _ => _ end] => destruct d eqn:?; try discriminate *) +(* | |- Verilog.expr_runp _ _ _ _ _ => econstructor *) +(* | |- val_value_lessdef (?f _ _) _ => unfold f *) +(* | |- val_value_lessdef (?f _) _ => unfold f *) +(* | H : ?f (Registers.Regmap.get _ _) _ = Some _ |- _ => *) +(* unfold f in H; repeat (unfold_match H) *) +(* | H1 : Registers.Regmap.get ?r ?rs = Values.Vint _, H2 : val_value_lessdef (Registers.Regmap.get ?r ?rs) _ *) +(* |- _ => rewrite H1 in H2; inv H2 *) +(* | |- _ => eexists; split; try constructor; solve [eauto] *) +(* | H : context[RTL.max_reg_function ?f] |- context[_ (Verilog.Vvar ?r) (Verilog.Vvar ?r0)] => *) +(* let HPle1 := fresh "H" in *) +(* let HPle2 := fresh "H" in *) +(* assert (HPle1 : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* assert (HPle2 : Ple r0 (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* apply H in HPle1; apply H in HPle2; eexists; split; try constructor; eauto *) +(* | H : context[RTL.max_reg_function ?f] |- context[Verilog.Vvar ?r] => *) +(* let HPle := fresh "H" in *) +(* assert (HPle : Ple r (RTL.max_reg_function f)) by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* apply H in HPle; eexists; split; try constructor; eauto *) +(* | |- context[if ?c then _ else _] => destruct c eqn:?; try discriminate *) +(* end. *) +(* intros s sp op rs m v e asr asa f f' stk s' i pc pc' res0 args res ml st MSTATE INSTR EVAL TR_INSTR. *) +(* inv MSTATE. inv MASSOC. unfold translate_instr in TR_INSTR; repeat (unfold_match TR_INSTR); inv TR_INSTR; *) +(* unfold Op.eval_operation in EVAL; repeat (unfold_match EVAL); inv EVAL; *) +(* repeat (simplify; eval_correct_tac; unfold valueToInt in *) +(* - pose proof Integers.Ptrofs.agree32_sub as H2; unfold Integers.Ptrofs.agree32 in H2. *) +(* unfold Ptrofs.of_int. simpl. *) +(* apply ptrofs_inj. assert (Archi.ptr64 = false) by auto. eapply H2 in H3. *) +(* rewrite Ptrofs.unsigned_repr. apply H3. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* apply Int.unsigned_range_2. *) +(* auto. rewrite Ptrofs.unsigned_repr. replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* apply Int.unsigned_range_2. rewrite Ptrofs.unsigned_repr. auto. *) +(* replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* apply Int.unsigned_range_2. *) +(* - pose proof Integers.Ptrofs.agree32_sub as AGR; unfold Integers.Ptrofs.agree32 in AGR. *) +(* assert (ARCH: Archi.ptr64 = false) by auto. eapply AGR in ARCH. *) +(* apply int_inj. unfold Ptrofs.to_int. rewrite Int.unsigned_repr. *) +(* apply ARCH. Search Ptrofs.unsigned. pose proof Ptrofs.unsigned_range_2. *) +(* replace Ptrofs.max_unsigned with Int.max_unsigned; auto. *) +(* pose proof Ptrofs.agree32_of_int. unfold Ptrofs.agree32 in H2. *) +(* eapply H2 in ARCH. apply ARCH. *) +(* pose proof Ptrofs.agree32_of_int. unfold Ptrofs.agree32 in H2. *) +(* eapply H2 in ARCH. apply ARCH. *) +(* - admit. (* mulhs *) *) +(* - admit. (* mulhu *) *) +(* - rewrite H0 in Heqb. rewrite H1 in Heqb. discriminate. *) +(* - rewrite Heqb in Heqb0. discriminate. *) +(* - rewrite H0 in Heqb. rewrite H1 in Heqb. discriminate. *) +(* - rewrite Heqb in Heqb0. discriminate. *) +(* - admit. *) +(* - admit. (* ror *) *) +(* - admit. (* addressing *) *) +(* - admit. (* eval_condition *) *) +(* - admit. (* select *) *) +(* Admitted. *) + +(* Lemma eval_cond_correct : *) +(* forall cond (args : list Registers.reg) s1 c s' i rs args m b f asr asa, *) +(* translate_condition cond args s1 = OK c s' i -> *) +(* Op.eval_condition *) +(* cond *) +(* (List.map (fun r : BinNums.positive => Registers.Regmap.get r rs) args) *) +(* m = Some b -> *) +(* Verilog.expr_runp f asr asa c (boolToValue b). *) +(* Admitted. *) + +(* (** The proof of semantic preservation for the translation of instructions *) +(* is a simulation argument based on diagrams of the following form: *) +(* << *) +(* match_states *) +(* code st rs ---------------- State m st assoc *) +(* || | *) +(* || | *) +(* || | *) +(* \/ v *) +(* code st rs' --------------- State m st assoc' *) +(* match_states *) +(* >> *) +(* where [tr_code c data control fin rtrn st] is assumed to hold. *) + +(* The precondition and postcondition is that that should hold is [match_assocmaps rs assoc]. *) +(* *) *) + +(* Definition transl_instr_prop (instr : RTL.instruction) : Prop := *) +(* forall m asr asa fin rtrn st stmt trans res, *) +(* tr_instr fin rtrn st (m.(HTL.mod_stk)) instr stmt trans -> *) +(* exists asr' asa', *) +(* HTL.step tge (HTL.State res m st asr asa) Events.E0 (HTL.State res m st asr' asa'). *) + +(* Opaque combine. *) + +(* Ltac tac0 := *) +(* match goal with *) +(* | [ |- context[Verilog.merge_arrs _ _] ] => unfold Verilog.merge_arrs *) +(* | [ |- context[Verilog.merge_arr] ] => unfold Verilog.merge_arr *) +(* | [ |- context[Verilog.merge_regs _ _] ] => unfold Verilog.merge_regs; crush; unfold_merge *) +(* | [ |- context[reg_stack_based_pointers] ] => unfold reg_stack_based_pointers; intros *) +(* | [ |- context[Verilog.arr_assocmap_set _ _ _ _] ] => unfold Verilog.arr_assocmap_set *) + +(* | [ |- context[HTL.empty_stack] ] => unfold HTL.empty_stack *) + +(* | [ |- context[_ # ?d <- _ ! ?d] ] => rewrite AssocMap.gss *) +(* | [ |- context[_ # ?d <- _ ! ?s] ] => rewrite AssocMap.gso *) +(* | [ |- context[(AssocMap.empty _) ! _] ] => rewrite AssocMap.gempty *) + +(* | [ |- context[array_get_error _ (combine Verilog.merge_cell (arr_repeat None _) _)] ] => *) +(* rewrite combine_lookup_first *) + +(* | [ |- state_st_wf _ _ ] => unfold state_st_wf; inversion 1 *) +(* | [ |- context[match_states _ _] ] => econstructor; auto *) +(* | [ |- match_arrs _ _ _ _ _ ] => econstructor; auto *) +(* | [ |- match_assocmaps _ _ _ # _ <- (posToValue _) ] => *) +(* apply regs_lessdef_add_greater; [> unfold Plt; lia | assumption] *) + +(* | [ H : ?asa ! ?r = Some _ |- Verilog.arr_assocmap_lookup ?asa ?r _ = Some _ ] => *) +(* unfold Verilog.arr_assocmap_lookup; setoid_rewrite H; f_equal *) +(* | [ |- context[(AssocMap.combine _ _ _) ! _] ] => *) +(* try (rewrite AssocMap.gcombine; [> | reflexivity]) *) + +(* | [ |- context[Registers.Regmap.get ?d (Registers.Regmap.set ?d _ _)] ] => *) +(* rewrite Registers.Regmap.gss *) +(* | [ |- context[Registers.Regmap.get ?s (Registers.Regmap.set ?d _ _)] ] => *) +(* destruct (Pos.eq_dec s d) as [EQ|EQ]; *) +(* [> rewrite EQ | rewrite Registers.Regmap.gso; auto] *) + +(* | [ H : opt_val_value_lessdef _ _ |- _ ] => invert H *) +(* | [ H : context[Z.of_nat (Z.to_nat _)] |- _ ] => rewrite Z2Nat.id in H; [> solve crush |] *) +(* | [ H : _ ! _ = Some _ |- _] => setoid_rewrite H *) +(* end. *) + +(* Ltac small_tac := repeat (crush; try array; try ptrofs); crush; auto. *) +(* Ltac big_tac := repeat (crush; try array; try ptrofs; try tac0); crush; auto. *) + +(* Lemma transl_inop_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) +(* (rs : RTL.regset) (m : mem) (pc' : RTL.node), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Inop pc') -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f sp pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. *) +(* Proof. *) +(* intros s f sp pc rs m pc' H R1 MSTATE. *) +(* inv_state. *) + +(* unfold match_prog in TRANSL. *) +(* econstructor. *) +(* split. *) +(* apply Smallstep.plus_one. *) +(* eapply HTL.step_module; eauto. *) +(* inv CONST; assumption. *) +(* inv CONST; assumption. *) +(* (* processing of state *) *) +(* econstructor. *) +(* crush. *) +(* econstructor. *) +(* econstructor. *) +(* econstructor. *) + +(* all: invert MARR; big_tac. *) + +(* inv CONST; constructor; simplify; rewrite AssocMap.gso; auto; lia. *) + +(* Unshelve. auto. *) +(* Qed. *) +(* Hint Resolve transl_inop_correct : htlproof. *) + +(* Lemma transl_iop_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) +(* (rs : Registers.Regmap.t Values.val) (m : mem) (op : Op.operation) (args : list Registers.reg) *) +(* (res0 : Registers.reg) (pc' : RTL.node) (v : Values.val), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Iop op args res0 pc') -> *) +(* Op.eval_operation ge sp op (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some v -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f sp pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) +(* match_states (RTL.State s f sp pc' (Registers.Regmap.set res0 v rs) m) R2. *) +(* Proof. *) +(* intros s f sp pc rs m op args res0 pc' v H H0 R1 MSTATE. *) +(* inv_state. inv MARR. *) +(* exploit eval_correct; eauto. intros. inversion H1. inversion H2. *) +(* econstructor. split. *) +(* apply Smallstep.plus_one. *) +(* eapply HTL.step_module; eauto. *) +(* inv CONST. assumption. *) +(* inv CONST. assumption. *) +(* econstructor; simpl; trivial. *) +(* constructor; trivial. *) +(* econstructor; simpl; eauto. *) +(* simpl. econstructor. econstructor. *) +(* apply H5. simplify. *) + +(* all: big_tac. *) + +(* assert (HPle: Ple res0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_def; eauto; simpl; auto). *) + +(* unfold Ple in HPle. lia. *) +(* apply regs_lessdef_add_match. assumption. *) +(* apply regs_lessdef_add_greater. unfold Plt; lia. assumption. *) +(* assert (HPle: Ple res0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_def; eauto; simpl; auto). *) +(* unfold Ple in HPle; lia. *) +(* eapply op_stack_based; eauto. *) +(* inv CONST. constructor; simplify. rewrite AssocMap.gso. rewrite AssocMap.gso. *) +(* assumption. lia. *) +(* assert (HPle: Ple res0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_def; eauto; simpl; auto). *) +(* unfold Ple in HPle. lia. *) +(* rewrite AssocMap.gso. rewrite AssocMap.gso. *) +(* assumption. lia. *) +(* assert (HPle: Ple res0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_def; eauto; simpl; auto). *) +(* unfold Ple in HPle. lia. *) +(* Unshelve. trivial. *) +(* Qed. *) +(* Hint Resolve transl_iop_correct : htlproof. *) + +(* Ltac tac := *) +(* repeat match goal with *) +(* | [ _ : error _ _ = OK _ _ _ |- _ ] => discriminate *) +(* | [ _ : context[if (?x && ?y) then _ else _] |- _ ] => *) +(* let EQ1 := fresh "EQ" in *) +(* let EQ2 := fresh "EQ" in *) +(* destruct x eqn:EQ1; destruct y eqn:EQ2; simpl in * *) +(* | [ _ : context[if ?x then _ else _] |- _ ] => *) +(* let EQ := fresh "EQ" in *) +(* destruct x eqn:EQ; simpl in * *) +(* | [ H : ret _ _ = _ |- _ ] => invert H *) +(* | [ _ : context[match ?x with | _ => _ end] |- _ ] => destruct x *) +(* end. *) + +(* Ltac inv_arr_access := *) +(* match goal with *) +(* | [ _ : translate_arr_access ?chunk ?addr ?args _ _ = OK ?c _ _ |- _] => *) +(* destruct c, chunk, addr, args; crush; tac; crush *) +(* end. *) + +(* Lemma transl_iload_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) +(* (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) *) +(* (addr : Op.addressing) (args : list Registers.reg) (dst : Registers.reg) *) +(* (pc' : RTL.node) (a v : Values.val), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Iload chunk addr args dst pc') -> *) +(* Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> *) +(* Mem.loadv chunk m a = Some v -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f sp pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) +(* match_states (RTL.State s f sp pc' (Registers.Regmap.set dst v rs) m) R2. *) +(* Proof. *) +(* intros s f sp pc rs m chunk addr args dst pc' a v H H0 H1 R1 MSTATE. *) +(* inv_state. inv_arr_access. *) + +(* + (** Preamble *) *) +(* invert MARR. crush. *) + +(* unfold Op.eval_addressing in H0. *) +(* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + +(* unfold reg_stack_based_pointers in RSBP. *) +(* pose proof (RSBP r0) as RSBPr0. *) + +(* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. *) + +(* rewrite ARCHI in H1. crush. *) +(* subst. *) + +(* pose proof MASSOC as MASSOC'. *) +(* invert MASSOC'. *) +(* pose proof (H0 r0). *) +(* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) +(* apply H6 in HPler0. *) +(* invert HPler0; try congruence. *) +(* rewrite EQr0 in H8. *) +(* invert H8. *) +(* clear H0. clear H6. *) + +(* unfold check_address_parameter_signed in *; *) +(* unfold check_address_parameter_unsigned in *; crush. *) + +(* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) +(* (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. *) + +(* (** Modular preservation proof *) *) +(* (*assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) +(* { rewrite HeqOFFSET. *) +(* apply PtrofsExtra.add_mod; crush. *) +(* rewrite Integers.Ptrofs.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. *) +(* apply PtrofsExtra.of_int_mod. *) +(* rewrite Integers.Int.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. } *) + +(* (** Read bounds proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. *) +(* { destruct (Integers.Ptrofs.unsigned OFFSET *) +(* assert (Z.to_nat *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4))) *) +(* = *) +(* valueToNat x) *) +(* as EXPR_OK by admit *) +(* end. *) +(* rewrite <- EXPR_OK. *) + +(* specialize (H7 (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4)))). *) +(* exploit H7; big_tac. *) + +(* (** RSBP preservation *) *) +(* unfold arr_stack_based_pointers in ASBP. *) +(* specialize (ASBP (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). *) +(* exploit ASBP; big_tac. *) +(* rewrite NORMALISE in H0. rewrite H1 in H0. assumption. *) + +(* + (** Preamble *) *) +(* invert MARR. crush. *) + +(* unfold Op.eval_addressing in H0. *) +(* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + +(* unfold reg_stack_based_pointers in RSBP. *) +(* pose proof (RSBP r0) as RSBPr0. *) +(* pose proof (RSBP r1) as RSBPr1. *) + +(* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; *) +(* destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. *) + +(* rewrite ARCHI in H1. crush. *) +(* subst. *) +(* clear RSBPr1. *) + +(* pose proof MASSOC as MASSOC'. *) +(* invert MASSOC'. *) +(* pose proof (H0 r0). *) +(* pose proof (H0 r1). *) +(* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) +(* assert (HPler1 : Ple r1 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) +(* apply H6 in HPler0. *) +(* apply H8 in HPler1. *) +(* invert HPler0; invert HPler1; try congruence. *) +(* rewrite EQr0 in H9. *) +(* rewrite EQr1 in H11. *) +(* invert H9. invert H11. *) +(* clear H0. clear H6. clear H8. *) + +(* unfold check_address_parameter_signed in *; *) +(* unfold check_address_parameter_unsigned in *; crush. *) + +(* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) +(* (Integers.Ptrofs.of_int *) +(* (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) *) +(* (Integers.Int.repr z0)))) as OFFSET. *) + +(* (** Modular preservation proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) +(* { rewrite HeqOFFSET. *) +(* apply PtrofsExtra.add_mod; crush; try lia. *) +(* rewrite Integers.Ptrofs.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. *) +(* apply PtrofsExtra.of_int_mod. *) +(* apply IntExtra.add_mod; crush. *) +(* apply IntExtra.mul_mod2; crush. *) +(* rewrite Integers.Int.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. *) +(* rewrite Integers.Int.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. } *) + +(* (** Read bounds proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. *) +(* { destruct (Integers.Ptrofs.unsigned OFFSET *) +(* assert (Z.to_nat *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4))) *) +(* = *) +(* valueToNat x) *) +(* as EXPR_OK by admit *) +(* end. *) +(* rewrite <- EXPR_OK. *) + +(* specialize (H7 (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4)))). *) +(* exploit H7; big_tac. *) + +(* (** RSBP preservation *) *) +(* unfold arr_stack_based_pointers in ASBP. *) +(* specialize (ASBP (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). *) +(* exploit ASBP; big_tac. *) +(* rewrite NORMALISE in H0. rewrite H1 in H0. assumption. *) + +(* + invert MARR. crush. *) + +(* unfold Op.eval_addressing in H0. *) +(* destruct (Archi.ptr64) eqn:ARCHI; crush. *) +(* rewrite ARCHI in H0. crush. *) + +(* unfold check_address_parameter_unsigned in *; *) +(* unfold check_address_parameter_signed in *; crush. *) + +(* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) +(* rewrite ZERO in H1. clear ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l in H1. *) + +(* remember i0 as OFFSET. *) + +(* (** Modular preservation proof *) *) +(* rename H0 into MOD_PRESERVE. *) + +(* (** Read bounds proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as READ_BOUND_HIGH. *) +(* { destruct (Integers.Ptrofs.unsigned OFFSET *) +(* assert (Z.to_nat *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4))) *) +(* = *) +(* valueToNat x) *) +(* as EXPR_OK by admit *) +(* end. *) +(* rewrite <- EXPR_OK. *) + +(* specialize (H7 (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4)))). *) +(* exploit H7; big_tac. *) + +(* (** RSBP preservation *) *) +(* unfold arr_stack_based_pointers in ASBP. *) +(* specialize (ASBP (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu OFFSET (Integers.Ptrofs.repr 4)))). *) +(* exploit ASBP; big_tac. *) +(* rewrite NORMALISE in H0. rewrite H1 in H0. assumption.*) *) +(* Admitted. *) +(* Hint Resolve transl_iload_correct : htlproof. *) + +(* Lemma transl_istore_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) +(* (rs : Registers.Regmap.t Values.val) (m : mem) (chunk : AST.memory_chunk) *) +(* (addr : Op.addressing) (args : list Registers.reg) (src : Registers.reg) *) +(* (pc' : RTL.node) (a : Values.val) (m' : mem), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Istore chunk addr args src pc') -> *) +(* Op.eval_addressing ge sp addr (map (fun r : positive => Registers.Regmap.get r rs) args) = Some a -> *) +(* Mem.storev chunk m a (Registers.Regmap.get src rs) = Some m' -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f sp pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m') R2. *) +(* Proof. *) +(* (* intros s f sp pc rs m chunk addr args src pc' a m' H H0 H1 R1 MSTATES. *) +(* inv_state. inv_arr_access. *) + +(* + (** Preamble *) *) +(* invert MARR. crush. *) + +(* unfold Op.eval_addressing in H0. *) +(* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + +(* unfold reg_stack_based_pointers in RSBP. *) +(* pose proof (RSBP r0) as RSBPr0. *) + +(* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; crush. *) + +(* rewrite ARCHI in H1. crush. *) +(* subst. *) + +(* pose proof MASSOC as MASSOC'. *) +(* invert MASSOC'. *) +(* pose proof (H0 r0). *) +(* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) +(* apply H6 in HPler0. *) +(* invert HPler0; try congruence. *) +(* rewrite EQr0 in H8. *) +(* invert H8. *) +(* clear H0. clear H6. *) + +(* unfold check_address_parameter_unsigned in *; *) +(* unfold check_address_parameter_signed in *; crush. *) + +(* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) +(* (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. *) + +(* (** Modular preservation proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) +(* { rewrite HeqOFFSET. *) +(* apply PtrofsExtra.add_mod; crush; try lia. *) +(* rewrite Integers.Ptrofs.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. *) +(* apply PtrofsExtra.of_int_mod. *) +(* rewrite Integers.Int.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. } *) + +(* (** Write bounds proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. *) +(* { destruct (Integers.Ptrofs.unsigned OFFSET *) +(* assert (Z.to_nat *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.divu *) +(* OFFSET *) +(* (Integers.Ptrofs.repr 4))) *) +(* = *) +(* valueToNat x) *) +(* as EXPR_OK by admit *) +(* end. *) + +(* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) +(* inversion MASSOC; revert HeqOFFSET; subst; clear MASSOC; intros HeqOFFSET. *) + +(* econstructor. *) +(* repeat split; crush. *) +(* unfold HTL.empty_stack. *) +(* crush. *) +(* unfold Verilog.merge_arrs. *) + +(* rewrite AssocMap.gcombine. *) +(* 2: { reflexivity. } *) +(* unfold Verilog.arr_assocmap_set. *) +(* rewrite AssocMap.gss. *) +(* unfold Verilog.merge_arr. *) +(* rewrite AssocMap.gss. *) +(* setoid_rewrite H5. *) +(* reflexivity. *) + +(* rewrite combine_length. *) +(* rewrite <- array_set_len. *) +(* unfold arr_repeat. crush. *) +(* apply list_repeat_len. *) + +(* rewrite <- array_set_len. *) +(* unfold arr_repeat. crush. *) +(* rewrite list_repeat_len. *) +(* rewrite H4. reflexivity. *) + +(* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) +(* (Integers.Ptrofs.of_int (Integers.Int.repr z))) as OFFSET. *) + +(* destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). *) + +(* erewrite Mem.load_store_same. *) +(* 2: { rewrite ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l. *) +(* rewrite e. *) +(* rewrite Integers.Ptrofs.unsigned_repr. *) +(* exact H1. *) +(* apply Integers.Ptrofs.unsigned_range_2. } *) +(* constructor. *) +(* erewrite combine_lookup_second. *) +(* simpl. *) +(* assert (Ple src (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; simpl; auto); *) +(* apply H0 in H13. *) +(* destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; constructor; invert H13; eauto. *) + +(* rewrite <- array_set_len. *) +(* unfold arr_repeat. crush. *) +(* rewrite list_repeat_len. auto. *) + +(* assert (4 * ptr / 4 = Integers.Ptrofs.unsigned OFFSET / 4) by (f_equal; assumption). *) +(* rewrite Z.mul_comm in H13. *) +(* rewrite Z_div_mult in H13; try lia. *) +(* replace 4 with (Integers.Ptrofs.unsigned (Integers.Ptrofs.repr 4)) in H13 by reflexivity. *) +(* rewrite <- PtrofsExtra.divu_unsigned in H13; unfold_constants; try lia. *) +(* rewrite H13. rewrite EXPR_OK. *) +(* rewrite array_get_error_set_bound. *) +(* reflexivity. *) +(* unfold arr_length, arr_repeat. simpl. *) +(* rewrite list_repeat_len. lia. *) + +(* erewrite Mem.load_store_other with (m1 := m). *) +(* 2: { exact H1. } *) +(* 2: { right. *) +(* rewrite ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l. *) +(* rewrite Integers.Ptrofs.unsigned_repr. *) +(* simpl. *) +(* destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. *) +(* right. *) +(* apply ZExtra.mod_0_bounds; try lia. *) +(* apply ZLib.Z_mod_mult'. *) +(* rewrite Z2Nat.id in H15; try lia. *) +(* apply Zmult_lt_compat_r with (p := 4) in H15; try lia. *) +(* rewrite ZLib.div_mul_undo in H15; try lia. *) +(* split; try lia. *) +(* apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. *) +(* } *) + +(* rewrite <- EXPR_OK. *) +(* rewrite PtrofsExtra.divu_unsigned; auto; try (unfold_constants; lia). *) +(* destruct (ptr ==Z Integers.Ptrofs.unsigned OFFSET / 4). *) +(* apply Z.mul_cancel_r with (p := 4) in e; try lia. *) +(* rewrite ZLib.div_mul_undo in e; try lia. *) +(* rewrite combine_lookup_first. *) +(* eapply H7; eauto. *) + +(* rewrite <- array_set_len. *) +(* unfold arr_repeat. crush. *) +(* rewrite list_repeat_len. auto. *) +(* rewrite array_gso. *) +(* unfold array_get_error. *) +(* unfold arr_repeat. *) +(* crush. *) +(* apply list_repeat_lookup. *) +(* lia. *) +(* unfold_constants. *) +(* intro. *) +(* apply Z2Nat.inj_iff in H13; try lia. *) +(* apply Z.div_pos; try lia. *) +(* apply Integers.Ptrofs.unsigned_range. *) + +(* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) +(* unfold arr_stack_based_pointers. *) +(* intros. *) +(* destruct (4 * ptr ==Z Integers.Ptrofs.unsigned OFFSET). *) + +(* crush. *) +(* erewrite Mem.load_store_same. *) +(* 2: { rewrite ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l. *) +(* rewrite e. *) +(* rewrite Integers.Ptrofs.unsigned_repr. *) +(* exact H1. *) +(* apply Integers.Ptrofs.unsigned_range_2. } *) +(* crush. *) +(* destruct (Registers.Regmap.get src rs) eqn:EQ_SRC; try constructor. *) +(* destruct (Archi.ptr64); try discriminate. *) +(* pose proof (RSBP src). rewrite EQ_SRC in H0. *) +(* assumption. *) + +(* simpl. *) +(* erewrite Mem.load_store_other with (m1 := m). *) +(* 2: { exact H1. } *) +(* 2: { right. *) +(* rewrite ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l. *) +(* rewrite Integers.Ptrofs.unsigned_repr. *) +(* simpl. *) +(* destruct (Z_le_gt_dec (4 * ptr + 4) (Integers.Ptrofs.unsigned OFFSET)); eauto. *) +(* right. *) +(* apply ZExtra.mod_0_bounds; try lia. *) +(* apply ZLib.Z_mod_mult'. *) +(* invert H0. *) +(* apply Zmult_lt_compat_r with (p := 4) in H14; try lia. *) +(* rewrite ZLib.div_mul_undo in H14; try lia. *) +(* split; try lia. *) +(* apply Z.le_trans with (m := RTL.fn_stacksize f); crush; lia. *) +(* } *) +(* apply ASBP; assumption. *) + +(* unfold stack_bounds in *. intros. *) +(* simpl. *) +(* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) +(* erewrite Mem.load_store_other with (m1 := m). *) +(* 2: { exact H1. } *) +(* 2: { right. right. simpl. *) +(* rewrite ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l. *) +(* rewrite Integers.Ptrofs.unsigned_repr; crush; try lia. *) +(* apply ZExtra.mod_0_bounds; crush; try lia. } *) +(* crush. *) +(* exploit (BOUNDS ptr); try lia. intros. crush. *) +(* exploit (BOUNDS ptr v); try lia. intros. *) +(* invert H0. *) +(* match goal with | |- ?x = _ => destruct x eqn:EQ end; try reflexivity. *) +(* assert (Mem.valid_access m AST.Mint32 sp' *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) +(* (Integers.Ptrofs.repr ptr))) Writable). *) +(* { pose proof H1. eapply Mem.store_valid_access_2 in H0. *) +(* exact H0. eapply Mem.store_valid_access_3. eassumption. } *) +(* pose proof (Mem.valid_access_store m AST.Mint32 sp' *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) +(* (Integers.Ptrofs.repr ptr))) v). *) +(* apply X in H0. invert H0. congruence. *) + +(* + (** Preamble *) *) +(* invert MARR. crush. *) + +(* unfold Op.eval_addressing in H0. *) +(* destruct (Archi.ptr64) eqn:ARCHI; crush. *) + +(* unfold reg_stack_based_pointers in RSBP. *) +(* pose proof (RSBP r0) as RSBPr0. *) +(* pose proof (RSBP r1) as RSBPr1. *) + +(* destruct (Registers.Regmap.get r0 rs) eqn:EQr0; *) +(* destruct (Registers.Regmap.get r1 rs) eqn:EQr1; crush. *) + +(* rewrite ARCHI in H1. crush. *) +(* subst. *) +(* clear RSBPr1. *) + +(* pose proof MASSOC as MASSOC'. *) +(* invert MASSOC'. *) +(* pose proof (H0 r0). *) +(* pose proof (H0 r1). *) +(* assert (HPler0 : Ple r0 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; crush; eauto). *) +(* assert (HPler1 : Ple r1 (RTL.max_reg_function f)) *) +(* by (eapply RTL.max_reg_function_use; eauto; simpl; auto). *) +(* apply H6 in HPler0. *) +(* apply H8 in HPler1. *) +(* invert HPler0; invert HPler1; try congruence. *) +(* rewrite EQr0 in H9. *) +(* rewrite EQr1 in H11. *) +(* invert H9. invert H11. *) +(* clear H0. clear H6. clear H8. *) + +(* unfold check_address_parameter_signed in *; *) +(* unfold check_address_parameter_unsigned in *; crush. *) + +(* remember (Integers.Ptrofs.add (Integers.Ptrofs.repr (uvalueToZ asr # r0)) *) +(* (Integers.Ptrofs.of_int *) +(* (Integers.Int.add (Integers.Int.mul (valueToInt asr # r1) (Integers.Int.repr z)) *) +(* (Integers.Int.repr z0)))) as OFFSET. *) + +(* (** Modular preservation proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET mod 4 = 0) as MOD_PRESERVE. *) +(* { rewrite HeqOFFSET. *) +(* apply PtrofsExtra.add_mod; crush; try lia. *) +(* rewrite Integers.Ptrofs.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. *) +(* apply PtrofsExtra.of_int_mod. *) +(* apply IntExtra.add_mod; crush. *) +(* apply IntExtra.mul_mod2; crush. *) +(* rewrite Integers.Int.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. *) +(* rewrite Integers.Int.unsigned_repr_eq. *) +(* rewrite <- Zmod_div_mod; crush. } *) + +(* (** Write bounds proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. *) +(* { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. *) +(* assert (Mem.valid_access m AST.Mint32 sp' *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) +(* (Integers.Ptrofs.repr ptr))) Writable). *) +(* { pose proof H1. eapply Mem.store_valid_access_2 in H0. *) +(* exact H0. eapply Mem.store_valid_access_3. eassumption. } *) +(* pose proof (Mem.valid_access_store m AST.Mint32 sp' *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) +(* (Integers.Ptrofs.repr ptr))) v). *) +(* apply X in H0. invert H0. congruence. *) + +(* + invert MARR. crush. *) + +(* unfold Op.eval_addressing in H0. *) +(* destruct (Archi.ptr64) eqn:ARCHI; crush. *) +(* rewrite ARCHI in H0. crush. *) + +(* unfold check_address_parameter_unsigned in *; *) +(* unfold check_address_parameter_signed in *; crush. *) + +(* assert (Integers.Ptrofs.repr 0 = Integers.Ptrofs.zero) as ZERO by reflexivity. *) +(* rewrite ZERO in H1. clear ZERO. *) +(* rewrite Integers.Ptrofs.add_zero_l in H1. *) + +(* remember i0 as OFFSET. *) + +(* (** Modular preservation proof *) *) +(* rename H0 into MOD_PRESERVE. *) + +(* (** Write bounds proof *) *) +(* assert (Integers.Ptrofs.unsigned OFFSET < f.(RTL.fn_stacksize)) as WRITE_BOUND_HIGH. *) +(* { destruct (Integers.Ptrofs.unsigned OFFSET destruct x eqn:EQ end; try reflexivity. *) +(* assert (Mem.valid_access m AST.Mint32 sp' *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) +(* (Integers.Ptrofs.repr ptr))) Writable). *) +(* { pose proof H1. eapply Mem.store_valid_access_2 in H0. *) +(* exact H0. eapply Mem.store_valid_access_3. eassumption. } *) +(* pose proof (Mem.valid_access_store m AST.Mint32 sp' *) +(* (Integers.Ptrofs.unsigned *) +(* (Integers.Ptrofs.add (Integers.Ptrofs.repr 0) *) +(* (Integers.Ptrofs.repr ptr))) v). *) +(* apply X in H0. invert H0. congruence.*) *) +(* Admitted. *) +(* Hint Resolve transl_istore_correct : htlproof. *) + +(* Lemma transl_icond_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) +(* (rs : Registers.Regmap.t Values.val) (m : mem) (cond : Op.condition) (args : list Registers.reg) *) +(* (ifso ifnot : RTL.node) (b : bool) (pc' : RTL.node), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Icond cond args ifso ifnot) -> *) +(* Op.eval_condition cond (map (fun r : positive => Registers.Regmap.get r rs) args) m = Some b -> *) +(* pc' = (if b then ifso else ifnot) -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f sp pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. *) +(* Proof. *) +(* intros s f sp pc rs m cond args ifso ifnot b pc' H H0 H1 R1 MSTATE. *) +(* inv_state. *) + +(* eexists. split. apply Smallstep.plus_one. *) +(* eapply HTL.step_module; eauto. *) +(* inv CONST; assumption. *) +(* inv CONST; assumption. *) +(* (* eapply Verilog.stmnt_runp_Vnonblock_reg with *) +(* (rhsval := if b then posToValue 32 ifso else posToValue 32 ifnot). *) +(* constructor. *) + +(* simpl. *) +(* destruct b. *) +(* eapply Verilog.erun_Vternary_true. *) +(* eapply eval_cond_correct; eauto. *) +(* constructor. *) +(* apply boolToValue_ValueToBool. *) +(* eapply Verilog.erun_Vternary_false. *) +(* eapply eval_cond_correct; eauto. *) +(* constructor. *) +(* apply boolToValue_ValueToBool. *) +(* constructor. *) + +(* big_tac. *) + +(* invert MARR. *) +(* destruct b; rewrite assumption_32bit; big_tac. *) + +(* Unshelve. *) +(* constructor. *) +(* Qed.*) *) +(* Admitted. *) +(* Hint Resolve transl_icond_correct : htlproof. *) + +(* Lemma transl_ijumptable_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (sp : Values.val) (pc : positive) *) +(* (rs : Registers.Regmap.t Values.val) (m : mem) (arg : Registers.reg) (tbl : list RTL.node) *) +(* (n : Integers.Int.int) (pc' : RTL.node), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Ijumptable arg tbl) -> *) +(* Registers.Regmap.get arg rs = Values.Vint n -> *) +(* list_nth_z tbl (Integers.Int.unsigned n) = Some pc' -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f sp pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ match_states (RTL.State s f sp pc' rs m) R2. *) +(* Proof. *) +(* intros s f sp pc rs m arg tbl n pc' H H0 H1 R1 MSTATE. *) +(* Admitted. *) +(* Hint Resolve transl_ijumptable_correct : htlproof. *) + +(* Lemma transl_ireturn_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (stk : Values.block) *) +(* (pc : positive) (rs : RTL.regset) (m : mem) (or : option Registers.reg) *) +(* (m' : mem), *) +(* (RTL.fn_code f) ! pc = Some (RTL.Ireturn or) -> *) +(* Mem.free m stk 0 (RTL.fn_stacksize f) = Some m' -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) pc rs m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) +(* match_states (RTL.Returnstate s (Registers.regmap_optget or Values.Vundef rs) m') R2. *) +(* Proof. *) +(* intros s f stk pc rs m or m' H H0 R1 MSTATE. *) +(* inv_state. *) + +(* - econstructor. split. *) +(* eapply Smallstep.plus_two. *) + +(* eapply HTL.step_module; eauto. *) +(* inv CONST; assumption. *) +(* inv CONST; assumption. *) +(* constructor. *) +(* econstructor; simpl; trivial. *) +(* econstructor; simpl; trivial. *) +(* constructor. *) +(* econstructor; simpl; trivial. *) +(* constructor. *) + +(* constructor. constructor. *) + +(* unfold state_st_wf in WF; big_tac; eauto. *) +(* destruct wf as [HCTRL HDATA]. apply HCTRL. *) +(* apply AssocMapExt.elements_iff. eexists. *) +(* match goal with H: control ! pc = Some _ |- _ => apply H end. *) + +(* apply HTL.step_finish. *) +(* unfold Verilog.merge_regs. *) +(* unfold_merge; simpl. *) +(* rewrite AssocMap.gso. *) +(* apply AssocMap.gss. lia. *) +(* apply AssocMap.gss. *) +(* rewrite Events.E0_left. reflexivity. *) + +(* constructor; auto. *) +(* constructor. *) + +(* (* FIXME: Duplication *) *) +(* - econstructor. split. *) +(* eapply Smallstep.plus_two. *) +(* eapply HTL.step_module; eauto. *) +(* inv CONST; assumption. *) +(* inv CONST; assumption. *) +(* constructor. *) +(* econstructor; simpl; trivial. *) +(* econstructor; simpl; trivial. *) +(* constructor. constructor. constructor. *) +(* constructor. constructor. constructor. *) + +(* unfold state_st_wf in WF; big_tac; eauto. *) + +(* destruct wf as [HCTRL HDATA]. apply HCTRL. *) +(* apply AssocMapExt.elements_iff. eexists. *) +(* match goal with H: control ! pc = Some _ |- _ => apply H end. *) + +(* apply HTL.step_finish. *) +(* unfold Verilog.merge_regs. *) +(* unfold_merge. *) +(* rewrite AssocMap.gso. *) +(* apply AssocMap.gss. simpl; lia. *) +(* apply AssocMap.gss. *) +(* rewrite Events.E0_left. trivial. *) + +(* constructor; auto. *) + +(* simpl. inversion MASSOC. subst. *) +(* unfold find_assocmap, AssocMapExt.get_default. rewrite AssocMap.gso. *) +(* apply H1. eapply RTL.max_reg_function_use. eauto. simpl; tauto. *) +(* assert (HPle : Ple r (RTL.max_reg_function f)). *) +(* eapply RTL.max_reg_function_use. eassumption. simpl; auto. *) +(* apply ZExtra.Ple_not_eq. apply ZExtra.Ple_Plt_Succ. assumption. *) + +(* Unshelve. *) +(* all: constructor. *) +(* Qed. *) +(* Hint Resolve transl_ireturn_correct : htlproof. *) + +(* Lemma transl_callstate_correct: *) +(* forall (s : list RTL.stackframe) (f : RTL.function) (args : list Values.val) *) +(* (m : mem) (m' : Mem.mem') (stk : Values.block), *) +(* Mem.alloc m 0 (RTL.fn_stacksize f) = (m', stk) -> *) +(* forall R1 : HTL.state, *) +(* match_states (RTL.Callstate s (AST.Internal f) args m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) +(* match_states *) +(* (RTL.State s f (Values.Vptr stk Integers.Ptrofs.zero) (RTL.fn_entrypoint f) *) +(* (RTL.init_regs args (RTL.fn_params f)) m') R2. *) +(* Proof. *) +(* intros s f args m m' stk H R1 MSTATE. *) + +(* inversion MSTATE; subst. inversion TF; subst. *) +(* econstructor. split. apply Smallstep.plus_one. *) +(* eapply HTL.step_call. crush. *) + +(* apply match_state with (sp' := stk); eauto. *) + +(* all: big_tac. *) + +(* apply regs_lessdef_add_greater. unfold Plt; lia. *) +(* apply regs_lessdef_add_greater. unfold Plt; lia. *) +(* apply regs_lessdef_add_greater. unfold Plt; lia. *) +(* apply init_reg_assoc_empty. *) + +(* constructor. *) + +(* destruct (Mem.load AST.Mint32 m' stk *) +(* (Integers.Ptrofs.unsigned (Integers.Ptrofs.add *) +(* Integers.Ptrofs.zero *) +(* (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. *) +(* pose proof Mem.load_alloc_same as LOAD_ALLOC. *) +(* pose proof H as ALLOC. *) +(* eapply LOAD_ALLOC in ALLOC. *) +(* 2: { exact LOAD. } *) +(* ptrofs. rewrite LOAD. *) +(* rewrite ALLOC. *) +(* repeat constructor. *) + +(* ptrofs. rewrite LOAD. *) +(* repeat constructor. *) + +(* unfold reg_stack_based_pointers. intros. *) +(* unfold RTL.init_regs; crush. *) +(* destruct (RTL.fn_params f); *) +(* rewrite Registers.Regmap.gi; constructor. *) + +(* unfold arr_stack_based_pointers. intros. *) +(* crush. *) +(* destruct (Mem.load AST.Mint32 m' stk *) +(* (Integers.Ptrofs.unsigned (Integers.Ptrofs.add *) +(* Integers.Ptrofs.zero *) +(* (Integers.Ptrofs.repr (4 * ptr))))) eqn:LOAD. *) +(* pose proof Mem.load_alloc_same as LOAD_ALLOC. *) +(* pose proof H as ALLOC. *) +(* eapply LOAD_ALLOC in ALLOC. *) +(* 2: { exact LOAD. } *) +(* rewrite ALLOC. *) +(* repeat constructor. *) +(* constructor. *) + +(* Transparent Mem.alloc. (* TODO: Since there are opaque there's probably a lemma. *) *) +(* Transparent Mem.load. *) +(* Transparent Mem.store. *) +(* unfold stack_bounds. *) +(* split. *) + +(* unfold Mem.alloc in H. *) +(* invert H. *) +(* crush. *) +(* unfold Mem.load. *) +(* intros. *) +(* match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. *) +(* invert v0. unfold Mem.range_perm in H4. *) +(* unfold Mem.perm in H4. crush. *) +(* unfold Mem.perm_order' in H4. *) +(* small_tac. *) +(* exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. *) +(* rewrite Maps.PMap.gss in H8. *) +(* match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. *) +(* crush. *) +(* apply proj_sumbool_true in H10. lia. *) + +(* unfold Mem.alloc in H. *) +(* invert H. *) +(* crush. *) +(* unfold Mem.store. *) +(* intros. *) +(* match goal with | |- context[if ?x then _ else _] => destruct x end; try congruence. *) +(* invert v0. unfold Mem.range_perm in H4. *) +(* unfold Mem.perm in H4. crush. *) +(* unfold Mem.perm_order' in H4. *) +(* small_tac. *) +(* exploit (H4 ptr). rewrite Integers.Ptrofs.unsigned_repr; small_tac. intros. *) +(* rewrite Maps.PMap.gss in H8. *) +(* match goal with | H8 : context[if ?x then _ else _] |- _ => destruct x eqn:EQ end; try contradiction. *) +(* crush. *) +(* apply proj_sumbool_true in H10. lia. *) +(* constructor. simplify. rewrite AssocMap.gss. *) +(* simplify. rewrite AssocMap.gso. apply AssocMap.gss. simplify. lia. *) +(* Opaque Mem.alloc. *) +(* Opaque Mem.load. *) +(* Opaque Mem.store. *) +(* Qed. *) +(* Hint Resolve transl_callstate_correct : htlproof. *) + +(* Lemma transl_returnstate_correct: *) +(* forall (res0 : Registers.reg) (f : RTL.function) (sp : Values.val) (pc : RTL.node) *) +(* (rs : RTL.regset) (s : list RTL.stackframe) (vres : Values.val) (m : mem) *) +(* (R1 : HTL.state), *) +(* match_states (RTL.Returnstate (RTL.Stackframe res0 f sp pc rs :: s) vres m) R1 -> *) +(* exists R2 : HTL.state, *) +(* Smallstep.plus HTL.step tge R1 Events.E0 R2 /\ *) +(* match_states (RTL.State s f sp pc (Registers.Regmap.set res0 vres rs) m) R2. *) +(* Proof. *) +(* intros res0 f sp pc rs s vres m R1 MSTATE. *) +(* inversion MSTATE. inversion MF. *) +(* Qed. *) +(* Hint Resolve transl_returnstate_correct : htlproof. *) + +(* Lemma option_inv : *) +(* forall A x y, *) +(* @Some A x = Some y -> x = y. *) +(* Proof. intros. inversion H. trivial. Qed. *) + +(* Lemma main_tprog_internal : *) +(* forall b, *) +(* Globalenvs.Genv.find_symbol tge tprog.(AST.prog_main) = Some b -> *) +(* exists f, Genv.find_funct_ptr (Genv.globalenv tprog) b = Some (AST.Internal f). *) +(* Proof. *) +(* intros. *) +(* destruct TRANSL. unfold main_is_internal in H1. *) +(* repeat (unfold_match H1). replace b with b0. *) +(* exploit function_ptr_translated; eauto. intros [tf [A B]]. *) +(* unfold transl_fundef, AST.transf_partial_fundef, Errors.bind in B. *) +(* unfold_match B. inv B. econstructor. apply A. *) + +(* apply option_inv. rewrite <- Heqo. rewrite <- H. *) +(* rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). *) +(* trivial. symmetry; eapply Linking.match_program_main; eauto. *) +(* Qed. *) + +(* Lemma transl_initial_states : *) +(* forall s1 : Smallstep.state (RTL.semantics prog), *) +(* Smallstep.initial_state (RTL.semantics prog) s1 -> *) +(* exists s2 : Smallstep.state (HTL.semantics tprog), *) +(* Smallstep.initial_state (HTL.semantics tprog) s2 /\ match_states s1 s2. *) +(* Proof. *) +(* induction 1. *) +(* destruct TRANSL. unfold main_is_internal in H4. *) +(* repeat (unfold_match H4). *) +(* assert (f = AST.Internal f1). apply option_inv. *) +(* rewrite <- Heqo0. rewrite <- H1. replace b with b0. *) +(* auto. apply option_inv. rewrite <- H0. rewrite <- Heqo. *) +(* trivial. *) +(* exploit function_ptr_translated; eauto. *) +(* intros [tf [A B]]. *) +(* unfold transl_fundef, Errors.bind in B. *) +(* unfold AST.transf_partial_fundef, Errors.bind in B. *) +(* repeat (unfold_match B). inversion B. subst. *) +(* exploit main_tprog_internal; eauto; intros. *) +(* rewrite symbols_preserved. replace (AST.prog_main tprog) with (AST.prog_main prog). *) +(* apply Heqo. symmetry; eapply Linking.match_program_main; eauto. *) +(* inversion H5. *) +(* econstructor; split. econstructor. *) +(* apply (Genv.init_mem_transf_partial TRANSL'); eauto. *) +(* replace (AST.prog_main tprog) with (AST.prog_main prog). *) +(* rewrite symbols_preserved; eauto. *) +(* symmetry; eapply Linking.match_program_main; eauto. *) +(* apply H6. *) + +(* constructor. *) +(* apply transl_module_correct. *) +(* assert (Some (AST.Internal x) = Some (AST.Internal m)). *) +(* replace (AST.fundef HTL.module) with (HTL.fundef). *) +(* rewrite <- H6. setoid_rewrite <- A. trivial. *) +(* trivial. inv H7. assumption. *) +(* Qed. *) +(* Hint Resolve transl_initial_states : htlproof. *) + +(* Lemma transl_final_states : *) +(* forall (s1 : Smallstep.state (RTL.semantics prog)) *) +(* (s2 : Smallstep.state (HTL.semantics tprog)) *) +(* (r : Integers.Int.int), *) +(* match_states s1 s2 -> *) +(* Smallstep.final_state (RTL.semantics prog) s1 r -> *) +(* Smallstep.final_state (HTL.semantics tprog) s2 r. *) +(* Proof. *) +(* intros. inv H0. inv H. inv H4. invert MF. constructor. reflexivity. *) +(* Qed. *) +(* Hint Resolve transl_final_states : htlproof. *) + +(* Theorem transl_step_correct: *) +(* forall (S1 : RTL.state) t S2, *) +(* RTL.step ge S1 t S2 -> *) +(* forall (R1 : HTL.state), *) +(* match_states S1 R1 -> *) +(* exists R2, Smallstep.plus HTL.step tge R1 t R2 /\ match_states S2 R2. *) +(* Proof. *) +(* induction 1; eauto with htlproof; (intros; inv_state). *) +(* Qed. *) +(* Hint Resolve transl_step_correct : htlproof. *) Theorem transf_program_correct: Smallstep.forward_simulation (RTL.semantics prog) (HTL.semantics tprog). Proof. - eapply Smallstep.forward_simulation_plus; eauto with htlproof. - apply senv_preserved. - Qed. + (* eapply Smallstep.forward_simulation_plus; eauto with htlproof. *) + (* apply senv_preserved. *) + (* Qed. *) + Admitted. End CORRECTNESS. -- cgit From b141f1e5b58aaabd091f30d2371e43712fbaef38 Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Tue, 7 Jul 2020 15:32:13 +0100 Subject: remove const prop --- src/Compiler.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler.v b/src/Compiler.v index 513b5fa..546ba87 100644 --- a/src/Compiler.v +++ b/src/Compiler.v @@ -80,7 +80,7 @@ Definition transf_backend (r : RTL.program) : res Verilog.program := @@ Tailcall.transf_program @@@ Inlining.transf_program @@ Renumber.transf_program - @@ Constprop.transf_program + (* @@ Constprop.transf_program *) @@ Renumber.transf_program @@@ CSE.transf_program @@@ Deadcode.transf_program -- cgit From 65ac86da554770ba0e3a24d187037c6a72a8725b Mon Sep 17 00:00:00 2001 From: Nadesh Ramanathan Date: Tue, 7 Jul 2020 15:33:25 +0100 Subject: added counter in testbench --- src/verilog/PrintVerilog.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/verilog/PrintVerilog.ml b/src/verilog/PrintVerilog.ml index 5265c97..f8d597a 100644 --- a/src/verilog/PrintVerilog.ml +++ b/src/verilog/PrintVerilog.ml @@ -169,9 +169,12 @@ let testbench = "module testbench; always #5 clk = ~clk; + reg [31:0] count; + initial count = 0; always @(posedge clk) begin + count <= count + 1; if (finish == 1) begin - $display(\"finished: %d\", return_val); + $display(\"finished: %d cycles %d\", return_val, count); $finish; end end -- cgit