File:  [Qemu by Fabrice Bellard] / qemu / tests / cris / check_lz.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 18:35:27 2018 UTC (8 years, 1 month ago) by root
Branches: qemu, MAIN
CVS tags: qemu1001, qemu1000, qemu0151, qemu0150, qemu0141, qemu0140, HEAD
qemu 0.14.0

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "sys.h"

static inline int cris_lz(int x)
{
	int r;
	asm ("lz\t%1, %0\n" : "=r" (r) : "r" (x));
	return r;
}

void check_lz(void)
{
	int i;

	if (cris_lz(0) != 32)
		err();
	if (cris_lz(1) != 31)
		err();
	if (cris_lz(2) != 30)
		err();
	if (cris_lz(4) != 29)
		err();
	if (cris_lz(8) != 28)
		err();

	/* try all positions with a single bit.  */
	for (i = 1; i < 32; i++) {
		if (cris_lz(1 << (i-1)) != (32 - i))
			err();
	}

	/* try all positions with all bits.  */
	for (i = 1; i < 32; i++) {
		/* split up this computation to clarify it.  */
		uint32_t val;
		val = (unsigned int)-1 >> (32 - i);
		if (cris_lz(val) != (32 - i))
			err();
	}
}

int main(void)
{
	check_lz();
	pass();
	exit(0);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.