tools/testing/selftests/x86/test_FISTTP.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/x86/test_FISTTP.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/x86/test_FISTTP.c
Extension
.c
Size
3124 bytes
Lines
139
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0
#undef _GNU_SOURCE
#define _GNU_SOURCE 1
#undef __USE_GNU
#define __USE_GNU 1
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <fenv.h>

unsigned long long res64 = -1;
unsigned int res32 = -1;
unsigned short res16 = -1;

int test(void)
{
	int ex;

	feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	asm volatile ("\n"
	"	fld1""\n"
	"	fisttps	res16""\n"
	"	fld1""\n"
	"	fisttpl	res32""\n"
	"	fld1""\n"
	"	fisttpll res64""\n"
	: : : "memory"
	);
	if (res16 != 1 || res32 != 1 || res64 != 1) {
		printf("[BAD]\tfisttp 1\n");
		return 1;
	}
	ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	if (ex != 0) {
		printf("[BAD]\tfisttp 1: wrong exception state\n");
		return 1;
	}

	feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	asm volatile ("\n"
	"	fldpi""\n"
	"	fisttps	res16""\n"
	"	fldpi""\n"
	"	fisttpl	res32""\n"
	"	fldpi""\n"
	"	fisttpll res64""\n"
	: : : "memory"
	);
	if (res16 != 3 || res32 != 3 || res64 != 3) {
		printf("[BAD]\tfisttp pi\n");
		return 1;
	}
	ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	if (ex != FE_INEXACT) {
		printf("[BAD]\tfisttp pi: wrong exception state\n");
		return 1;
	}

	feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	asm volatile ("\n"
	"	fldpi""\n"
	"	fchs""\n"
	"	fisttps	res16""\n"
	"	fldpi""\n"
	"	fchs""\n"
	"	fisttpl	res32""\n"
	"	fldpi""\n"
	"	fchs""\n"
	"	fisttpll res64""\n"
	: : : "memory"
	);
	if (res16 != 0xfffd || res32 != 0xfffffffd || res64 != 0xfffffffffffffffdULL) {
		printf("[BAD]\tfisttp -pi\n");
		return 1;
	}
	ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	if (ex != FE_INEXACT) {
		printf("[BAD]\tfisttp -pi: wrong exception state\n");
		return 1;
	}

	feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
	asm volatile ("\n"
	"	fldln2""\n"

Annotation

Implementation Notes