1 // SPDX-License-Identifier: GPL-2.0
11 #include <sys/types.h>
12 #include <sys/select.h>
17 unsigned long long res64 = -1;
18 unsigned int res32 = -1;
19 unsigned short res16 = -1;
25 feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
35 if (res16 != 1 || res32 != 1 || res64 != 1) {
36 printf("[BAD]\tfisttp 1\n");
39 ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
41 printf("[BAD]\tfisttp 1: wrong exception state\n");
45 feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
55 if (res16 != 3 || res32 != 3 || res64 != 3) {
56 printf("[BAD]\tfisttp pi\n");
59 ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
60 if (ex != FE_INEXACT) {
61 printf("[BAD]\tfisttp pi: wrong exception state\n");
65 feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
78 if (res16 != 0xfffd || res32 != 0xfffffffd || res64 != 0xfffffffffffffffdULL) {
79 printf("[BAD]\tfisttp -pi\n");
82 ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
83 if (ex != FE_INEXACT) {
84 printf("[BAD]\tfisttp -pi: wrong exception state\n");
88 feclearexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
98 /* Test truncation to zero (round-to-nearest would give 1 here) */
99 if (res16 != 0 || res32 != 0 || res64 != 0) {
100 printf("[BAD]\tfisttp ln2\n");
103 ex = fetestexcept(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW);
104 if (ex != FE_INEXACT) {
105 printf("[BAD]\tfisttp ln2: wrong exception state\n");
112 void sighandler(int sig)
114 printf("[FAIL]\tGot signal %d, exiting\n", sig);
118 int main(int argc, char **argv, char **envp)
122 /* SIGILL triggers on 32-bit kernels w/o fisttp emulation
123 * when run with "no387 nofxsr". Other signals are caught
126 signal(SIGILL, sighandler);
127 signal(SIGFPE, sighandler);
128 signal(SIGSEGV, sighandler);
130 printf("[RUN]\tTesting fisttp instructions\n");
133 printf("[OK]\tfisttp\n");
135 printf("[FAIL]\tfisttp errors: %d\n", err);