diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-01-18 00:50:29 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-01-18 00:50:29 +0200 |
commit | c9cba976913e55ff9aac8a8133cc94416c7c1c9c (patch) | |
tree | d1ec057fb8231c1c87151b29be5ad3b7f1689a96 /tests/bcj_test.c | |
parent | Subblock decoder: Don't exit the main loop in decode_buffer() (diff) | |
download | xz-c9cba976913e55ff9aac8a8133cc94416c7c1c9c.tar.xz |
Added test_compress.sh and bunch of files needed by it.
This new set of tests compress and decompress several
test files with many different compression options.
This set of tests will be extended later.
Diffstat (limited to 'tests/bcj_test.c')
-rw-r--r-- | tests/bcj_test.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/bcj_test.c b/tests/bcj_test.c new file mode 100644 index 00000000..d64c5a79 --- /dev/null +++ b/tests/bcj_test.c @@ -0,0 +1,66 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file bcj_test.c +/// \brief Source code of compress_prepared_bcj_* +/// +/// This is a simple program that should make the compiler to generate +/// PC-relative branches, jumps, and calls. The compiled files can then +/// be used to test the branch conversion filters. Note that this program +/// itself does nothing useful. +/// +/// Compiling: gcc -std=c99 -fPIC bcj_test.c +/// Don't optimize or strip. +// +// This code has been put into the public domain. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// +/////////////////////////////////////////////////////////////////////////////// + +extern int jump(int a, int b); + + +extern int +call(int a, int b) +{ + if (a < b) + a = jump(a, b); + + return a; +} + + +extern int +jump(int a, int b) +{ + // The loop generates conditional jump backwards. + while (1) { + if (a < b) { + a *= 2; + a += 3 * b; + break; + } else { + // Put enough code here to prevent JMP SHORT on x86. + a += b; + a /= 2; + b += b % 5; + a -= b / 3; + b = 2 * b + a - 1; + a *= b + a + 1; + b += a - 1; + a += b * 2 - a / 5; + } + } + + return a; +} + + +int +main(int argc, char **argv) +{ + int a = call(argc, argc + 1); + return a == 0; +} |