lltest.c 2.47 KB
#include <rmon.h>
#include "corefunc.h"

static long long fll ( long long );
static long fi ( long);
static long long f2 (long long, long long *, long long);

static long long fll ( long long a)
{
	if (a > 3)
		return a;
	else if (a == 0)
		return 1;
	else
		return a*a;
}

static long fi ( long a) 
{ 
	return a+1; 
}

static long long f2 (long long a, long long *p, long long b)
{
	return a+b+ *p;
}

lltest()
{
	int numFailures = 0;
	long long a, b;
	unsigned long long c, d;
	int i, j;
	long long arr[4];
	long long arri[2] = {0x100001000LL, 3};
	struct rec {
		int one;
		long long two;
	} vrec;

	/* lladdsub */

	a = 0x10000000aLL;
	b = a;
	b++;
	d = b - 1;
	numFailures += check_equal(a, d);
	c = a + b;
	numFailures += check_equal(c, 0x200000015LLU);
	a--;	/* 0x100000009 */
	d = c - a;
	b = -a;
	numFailures += check_equal(d, 0x10000000cLL);
	numFailures += check_equal(b, 0xfffffffefffffff7LL);

	/* llcmp */
	a = 2;
	b = 5LL;
	c = a > -2;
	numFailures += check_equal(c, 1);
	i = a > 0x100000002LL;
	numFailures += check_equal(i, 0);
	i = (a > -2 ? 2 : 3);
	numFailures += check_equal(i, 2);
	i = (a > 0x100000002LL ? 2 : 3);
	numFailures += check_equal(i, 3);

	/* llmisc */

	numFailures += check_equal(sizeof(long long), 8);
	numFailures += check_equal(__builtin_alignof(long long), 8);
	c = 4;

	arr[0] = arri[1];
	arr[3] = arr[0];
	a = arr[3];
	numFailures += check_equal(a, 3);
	arr[a] >>= 1;
	numFailures += check_equal(arr[a], 1);
	vrec.one = 1;
	a--;
	vrec.two = a;
	numFailures += check_equal(vrec.two, 2LL);
	c ^= 1;
	/* c == 5 */
	c = ~c & (c | 2);
	numFailures += check_equal(c, 2);
	c = (long long) 3.0;
	numFailures += check_equal(c, 3);
	switch (c) {
	case 0:
		osSyncPrintf("switch fail\n");
		numFailures++;
		break;

	case 3LL:
		break;
	default:
		osSyncPrintf("switch fail\n");
		numFailures++;
		break;
	}

	/* llmuldiv */

	a = 2;
	b = 5LL;
	b *= a;
	numFailures += check_equal(b, 10);
	c = b / 3;
	numFailures += check_equal(c, 3);
	c = 1 << (long long)((a < 3 ? 1 : 3)*4%3+1); 
	numFailures += check_equal(c, 4LLU);
	b = a*4%3+1;
	numFailures += check_equal(b, 3);
	b >>= 1;
	numFailures += check_equal(b, 1);

	/* llpars() */

	i = 1;
	a = 0;
	a = i;
	a = fll(a);
	numFailures += check_equal(a, 1);
	i = a;
	i = fll(i);
	a = fll(a+i);
	numFailures += check_equal(a, 4);
	a = fll(0);
	numFailures += check_equal(a, 1);
	a = fll(4);
	numFailures += check_equal(a, 4);
	a = fi(a);
	numFailures += check_equal(a, 5);
	a = f2(-1, &a, 2);
	numFailures += check_equal(a, 6);
	 return(numFailures);
}