File: bcj_test.c

package info (click to toggle)
luatex 0.70.1.20120524-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 242,132 kB
  • sloc: ansic: 890,140; cpp: 469,298; perl: 73,299; sh: 46,668; makefile: 16,604; python: 8,427; lisp: 6,684; xml: 3,926; lex: 3,784; java: 3,569; pascal: 3,569; yacc: 2,461; exp: 2,031; ruby: 1,375; objc: 1,362; tcl: 631; sed: 522; asm: 435; csh: 46; awk: 30
file content (65 lines) | stat: -rw-r--r-- 1,280 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
///////////////////////////////////////////////////////////////////////////////
//
/// \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.
//
//  Author:     Lasse Collin
//
//  This file has been put into the public domain.
//  You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////

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;
}