Sha256: 6984161ceebc2f94ba41047b85ddd083f64266f354d79f128c57882378aadb61

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
laag-xz-5.2.4.0 vendor/git.tukaani.org/xz/tests/bcj_test.c