Пример #1
0
int testconvert(int i)
{
    float f = h2f(i);
    int i2 = f2h(f);
    if (i != i2) {
	printf("error: 0x%x -> %g -> 0x%x\n", i, f, i2);
	return 1;
    }
    return 0;
}
Пример #2
0
void printall()
{
    for (int i = 0; i < 65536; i++) {
	float f = h2f(i);
	printf("0x%x -> %g 0x%x\n", i, f, floatToBits(f));
    }
    for (int e = -10; e < 10; e++) {
	double f = pow(10.0, e);
	int i = f2h(f);
	printf("%g -> 0x%x ->%g\n", f, i, h2f(i));
    }
}
Пример #3
0
int overflowtest(float f)
{
    uint32_t fi = floatToBits(f);
    int i = f2h(f);
    int e = 0x7c00 | ((fi>>16)&0x8000);
    if (i != e) {
	printf("error: %g->0x%x->%g, expected 0x%x->%sinf\n",
	       f, i, h2f(i), e, (e&0x8000) ? "-" : "");
	return 1;
    }
    return 0;
}
Пример #4
0
int excheck(uint32_t val)
{
    float f = bitsToFloat(val);
    int i = f2h(f);
    float f2 = h2f(i);
    if (memcmp(&f, &f2, 4)) {
	printf("error: %g(0x%0x)->0x%x->%g(0x%0x)\n", 
	       f, floatToBits(f), i, f2, floatToBits(f2));
	return 1;
    }
    return 0;
}
Пример #5
0
void f2htimingtest()
{
    int total = 0;
    float f[65536];
    for (int i = 0; i < 65536; i++) {
	f[i] = h2f(i);
	if (!isfinite(f[i])) f[i] = 1;
    }
    for (int j = 0; j < 30*1024; j++) {
	for (int i = 1024; i < 31740; i++) total += f2h(f[i]);
    }
    printf("%d\n", total);
}
Пример #6
0
int testround(float val)
{
    int i = f2h(val);
    float f = fabs(h2f(i)-val);
    float f1 = fabs(h2f(i-1)-val);
    float f2 = fabs(h2f(i+1)-val);
    if (f1 < f) {
	printf("error: %g->0x%x->%g, expected ->0x%x->%g\n",
	       val, i, h2f(i), i-1, h2f(i-1));
	return 1;
    }
    if (f2 < f) {
	printf("error: %g->0x%x->%g, expected ->0x%x->%g\n",
	       val, i, h2f(i), i+1, h2f(i+1));
	return 1;
    }
    return 0;
}
Пример #7
0
/*
 * Return the value of a property of the FDT root node.
 *
 * @name	name of the property
 * @return	value of the property
 */
static char *get_property(const u16 *property)
{
	struct fdt_header *header = (struct fdt_header *)fdt;
	const fdt32_t *pos;
	const char *strings;

	if (!header)
		return NULL;

	if (f2h(header->magic) != FDT_MAGIC) {
		printf("Wrong magic\n");
		return NULL;
	}

	pos = (fdt32_t *)(fdt + f2h(header->off_dt_struct));
	strings = fdt + f2h(header->off_dt_strings);

	for (;;) {
		switch (f2h(pos[0])) {
		case FDT_BEGIN_NODE: {
			char *c = (char *)&pos[1];
			size_t i;

			for (i = 0; c[i]; ++i)
				;
			pos = &pos[2 + (i >> 2)];
			break;
		}
		case FDT_PROP: {
			struct fdt_property *prop = (struct fdt_property *)pos;
			const char *label = &strings[f2h(prop->nameoff)];
			efi_status_t ret;

			/* Check if this is the property to be returned */
			if (!efi_st_strcmp_16_8(property, label)) {
				char *str;
				efi_uintn_t len = f2h(prop->len);

				if (!len)
					return NULL;
				/*
				 * The string might not be 0 terminated.
				 * It is safer to make a copy.
				 */
				ret = boottime->allocate_pool(
					EFI_LOADER_DATA, len + 1,
					(void **)&str);
				if (ret != EFI_SUCCESS) {
					efi_st_printf("AllocatePool failed\n");
					return NULL;
				}
				boottime->copy_mem(str, &pos[3], len);
				str[len] = 0;

				return str;
			}

			pos = &pos[3 + ((f2h(prop->len) + 3) >> 2)];
			break;
		}
		case FDT_NOP:
			pos = &pos[1];
			break;
		default:
			return NULL;
		}
	}
}