Doc: Rename Doxygen HTML doc directory name liblzma => api.
[xz/debian.git] / tests / bcj_test.c
blob05de38a28a35b24c650da4c10103bab45fdbe413
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file bcj_test.c
4 /// \brief Source code of compress_prepared_bcj_*
5 ///
6 /// This is a simple program that should make the compiler to generate
7 /// PC-relative branches, jumps, and calls. The compiled files can then
8 /// be used to test the branch conversion filters. Note that this program
9 /// itself does nothing useful.
10 ///
11 /// Compiling: gcc -std=c99 -fPIC -c bcj_test.c
12 /// Don't optimize or strip.
14 // Author: Lasse Collin
16 // This file has been put into the public domain.
17 // You can do whatever you want with this file.
19 ///////////////////////////////////////////////////////////////////////////////
21 extern int jump(int a, int b);
24 extern int
25 call(int a, int b)
27 if (a < b)
28 a = jump(a, b);
30 return a;
34 extern int
35 jump(int a, int b)
37 // The loop generates conditional jump backwards.
38 while (1) {
39 if (a < b) {
40 a *= 2;
41 a += 3 * b;
42 break;
43 } else {
44 // Put enough code here to prevent JMP SHORT on x86.
45 a += b;
46 a /= 2;
47 b += b % 5;
48 a -= b / 3;
49 b = 2 * b + a - 1;
50 a *= b + a + 1;
51 b += a - 1;
52 a += b * 2 - a / 5;
56 return a;
60 int
61 main(int argc, char **argv)
63 int a = call(argc, argc + 1);
64 return a == 0;