1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00
xz-archive/tests/bcj_test.c
Lasse Collin 975d8fd72a Recreated the BCJ test files for x86 and SPARC. The old files
were linked with crt*.o, which are copyrighted, and thus the
old test files were not in the public domain as a whole. They
are freely distributable though, but it is better to be careful
and avoid including any copyrighted pieces in the test files.
The new files are just compiled and assembled object files,
and thus don't contain any copyrighted code.
2009-02-06 09:13:15 +02:00

66 lines
1.4 KiB
C

///////////////////////////////////////////////////////////////////////////////
//
/// \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 -c 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;
}