⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fptest.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
static char     fpasccsid[] = " @(#)fptest.c 1.1 7/30/92 Copyright Sun Microsystems";/* * fptest.c:  main() routine, etc. used by fputest and mc68881 */#include <sys/types.h>#include <stdio.h>#include <sys/file.h>#include <signal.h>#ifdef SVR4#include <sys/fcntl.h>#include <siginfo.h>#include <ucontext.h>#endif SVR4#include <math.h>#include <errno.h>#include <sys/mman.h>#include <kvm.h>#include <nlist.h>#include <setjmp.h>#include "fp.h"#include <sys/time.h>#include <sys/wait.h>#include "sdrtns.h"#define pi			3.141592654#define FP_EXCEPTION_ERROR      3#define COMPUTATION_ERROR       4#define SPMATH_ERROR		5#define SYSTEST_ERROR		6#define PROBE_EEPROM_ERROR	7#define DPMATH_ERROR		10#define NO_COMPARE_FILES	69#define TIMES   		10000#define SLEEP_MOD 		1000#define ANSWER_SB  		1.6364567280#define MARGIN      		.0000000010#define SPMARGIN		.0000001#define DPMARGIN		.000000000000001#define fp_absent		0#define fp_enabled		1#define	CTOB(x)			(((u_long)(x)) * pagesize)#define BTOC(x)			(((u_long)(x)) / pagesize)#define PADDR(page, addr)	(CTOB(page) + ((u_long)addr & (pagesize-1)))int             simulate_error = 0;char            perror_msg_buffer[30];char           *perror_msg = perror_msg_buffer;int		pass = 0;int		errors = 0;char		msg_buffer[MESSAGE_SIZE];char		*msg = msg_buffer;char		device_fpname[20];char		*device = device_fpname;char            sysdiag_directory[50];char           *SD = sysdiag_directory;extern int      errno;#ifdef FPUextern int      fpu_sysdiag();#ifdef SVR4extern void     sigfpe_handler(int, siginfo_t *, ucontext_t *);struct sigaction newfpu, oldfpu;#else SVR4extern int      sigsegv_handler();extern int      sigfpe_handler();#endif SVR4#endif#ifdef sun4#ifdef SVR4struct nlist nl[] = {        {"fpu_exists", 0, 0, 0, 0, 0 },        { "" },};#else SVR4struct nlist    nl[] = {			{"_fpu_exists"},			"",};#endif SVR4/* *      returns '0' if there is fpu *      else '1' if there is no fpu *      else print message and exit */check_fpu(){    kvm_t           *mem;    int             value;    char 	    *vmunix, *getenv();    vmunix = getenv("KERNELNAME");    if (( mem = kvm_open(vmunix, NULL, NULL, O_RDONLY, NULL)) == NULL)	send_message(-PROBE_DEV_ERROR, ERROR, "kvm_open failed.");    if (kvm_nlist(mem, nl) == -1)	send_message(-PROBE_DEV_ERROR, ERROR, "kvm_nlist failed.");    if (kvm_read(mem, nl[0].n_value, &value, sizeof(int)) != sizeof(int))	send_message(-PROBE_DEV_ERROR, ERROR, "kvm_read failed.");    kvm_close(mem);    if ( value == 1 )    	return(0);    else	return(1);}#endif					       /* end of sun4 */static int      dummy(){return FALSE;}main(argc, argv)    int             argc;    char           *argv[];{    register float  x, y, z;    register int    i, j;    int             fpa = FALSE;    int             spmath(), dpmath();    u_long         *fpa_pointer;    int             type;    char           *fp;    int             probe881(), probe;    char            temp;    test_init(argc, argv, dummy, dummy, (char *)NULL);    test_name = TEST_NAME;	/* has to be here to overwrite default argv[0]*/    if (getenv("SD_LOG_DIRECTORY"))	exec_by_sundiag = TRUE;    if (getenv("SD_LOAD_TEST"))	if (strcmp(getenv("SD_LOAD_TEST"), "yes") == 0)	    quick_test = TRUE;    sprintf(perror_msg, " perror says");#ifdef sun3    if (minitfp_()) {	send_message(0, VERBOSE,"An MC68881 is installed.");	strcpy(device, "MC68881");    } else {	send_message(0, VERBOSE, "No 68881 is installed."); 	strcpy(device, "softfp");    }#else#ifdef sun4    if (check_fpu() == 0) {	strcpy(device, "fpu");	device_name = device;  /* need device name for verbose message */	send_message(0, VERBOSE,"An FPU is installed.");    }#else    strcpy(device, "softfp");#endif#endif    device_name = device; 	/* Got the device name here. */#ifdef FPU#ifdef SVR4        newfpu.sa_handler = sigfpe_handler;        sigemptyset(&newfpu.sa_mask);        newfpu.sa_flags = SA_SIGINFO;        if(sigaction(SIGFPE, &newfpu, &oldfpu)) {                perror("sigaction SIGFPE");                exit();        }#else SVR4        signal(SIGFPE, sigfpe_handler);#endif SVR4#endif    while (pass == 0) {	pass++;#ifdef FPU	if (fpu_sysdiag() == (-1)) {	    errors++;	    send_message(-SYSTEST_ERROR, FATAL, "Failed systest for FPU.");	}	send_message(0, VERBOSE, "Passed Systest for FPU.");#endif#ifdef MCNSOFT	if (spmath())	    send_message(-SPMATH_ERROR, ERROR, 		"Failed single precision FPA math test.");	send_message(0, VERBOSE, 		"Passed single precision FPA math test using the %s.",			Device);	if (dpmath())	    send_message(-DPMATH_ERROR, ERROR,		"Failed double precision FPA math test.");	send_message(0, VERBOSE, 		"Passed double precision FPA math test using the %s.",			Device);	x = 1.4567;	y = 1.1234;	if (quick_test)	    j = 1;	else	    j = TIMES;	    send_message(0, VERBOSE,		"Starting multiple multiplications.");	for (i = 0; i < j; ++i) {	    z = x * y;	    send_message(0, DEBUG,		"Result: was (%2.10f), expected (%2.10f), Diff (%2.10e)", 			z, ANSWER_SB, z - ANSWER_SB);	    if (z < (ANSWER_SB - MARGIN) || z > (ANSWER_SB + MARGIN)) {		errors++;		send_message(-COMPUTATION_ERROR, ERROR, 	"Multiplication failed, result was (%2.10f), expected (%2.10f).",			z, ANSWER_SB);	    }	    if (i % SLEEP_MOD == 0)		send_message(0, DEBUG, "i = %d", i);	    if (!debug && !quick_test && (i % SLEEP_MOD) == 0)		sleep(3);	}	if (quick_test)	    break;	send_message(0, VERBOSE, "%s passed.",Device);#endif					       /* endif for def of MC68881 */    }/* end of while */    test_end();}/* end of main */spmath(){    float           a, b, ans;    int             spfpa;    a = 1.2345;    b = 0.9876;    /* Basic tests of the following arithmetic operations: +, -, *, and /   */    send_message(0, VERBOSE, "Starting SPMATH routine on %s.", 		Device);    for (spfpa = 1; spfpa < 100; ++spfpa) {	if (spfpa % 10 == 0)	    send_message(0, DEBUG, "%s: spfpa= %d", Device, spfpa);	ans = a + b;	ans = a + b;	if (ans != 2.2221000) {	    if (ans < (2.2221000 - SPMARGIN) || ans > (2.2221000 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a + b\nExpected: 2.2221000    	Actual: %1.7f", ans);		return (1);	    }	}	ans = (a - b);	if (ans != 0.2469000) {	    if (ans < (0.2469000 - SPMARGIN) || ans > (0.2469000 + SPMARGIN)) {		send_message(0, ERROR, "Error   a - b\nExpected: 0.2469000    	Actual: %1.7f", ans);		return (1);	    }	}	ans = a * b;	if (ans != 1.2191923) {	    if (ans < (1.2191923 - SPMARGIN) || ans > (1.2191923 + SPMARGIN)) {		send_message(0, ERROR, "Error   a * b\nExpected: 1.2191922    	Actual: %1.7f", ans);		return (1);	    }	}	ans = a / b;	if (ans != 1.2500000) {	    if (ans < (1.2500000 - SPMARGIN) || ans > (1.2500000 + SPMARGIN)) {		send_message(0, ERROR, "Error   a / b\nExpected: 1.2500000	Actual: %1.7f", ans);		return (1);	    }	}	ans = a + (a - b);	if (ans != 1.4814000) {	    if (ans < (1.4814000 - SPMARGIN) || ans > (1.4814000 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a + (a + b)\nExpected: 1.4814000 	Actual: %1.7f", ans);		return (1);	    }	}	ans = a - (a + b);	if (ans != -(0.9876000)) {	    if (ans < (-(0.9876000) - SPMARGIN) ||					ans > (-(0.9876000) + SPMARGIN)) {		send_message(0, ERROR, "Error:  a - (a + b)\nExpected: -0.9876000 	Actual: %1.7f", ans);		return (1);	    }	}	ans = a + (a * b);	if (ans != 2.4536924) {	    if (ans < (2.4536924 - SPMARGIN) || ans > (2.4536924 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a + (a * b)\nExpected: 2.4536924  	Actual: %1.7f", ans);		return (1);	    }	}	ans = a - (a * b);	if (ans != 0.0153078) {	    if (ans < (0.0153078 - SPMARGIN) || ans > (0.0153078 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a - (a * b)\nExpected: 0.0153078    	Actual: %1.7f", ans);		return (1);	    }	}	ans = a + (a / b);	if (ans != 2.4845002) {	    if (ans < (2.4845002 - SPMARGIN) || ans > (2.4845002 + SPMARGIN)) {		send_message(0, ERROR, "a + (a / b)\nExpected: 2.4845002   	 Actual: %1.7f", ans);		return (1);	    }	}	ans = a - (a / b);	if (ans != -(0.0155000)) {	    if (ans < (-(0.0155000) - SPMARGIN) ||					ans > (-(0.0155000) + SPMARGIN)) {		send_message(0, ERROR, "Error:  a - (a / b)\nExpected: -0.0155000   	 Actual: %1.7f", ans);		return (1);	    }	}	ans = a * (a + b);	if (ans != 2.7431827) {	    if (ans < (2.7431827 - SPMARGIN) || ans > (2.7431827 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a * (a + b)\nExpected: 2.7431825   	 Actual: %1.7f", ans);		return (1);	    }	}	ans = a * (a - b);	if (ans != 0.3047981) {	    if (ans < (0.3047981 - SPMARGIN) || ans > (0.3047981 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a * ( a - b)\nExpected: 0.3047980   	 Actual: %1.7f", ans);		return (1);	    }	}	ans = a / (a + b);	if (ans != 0.5555556) {	    if (ans < (0.5555556 - SPMARGIN) || ans > (0.5555556 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a / ( a - b)\nExpected: 0.5555550      Actual: %1.7f", ans);		return (1);	    }	}	ans = a / (a - b);	if (ans != 4.9999995) {	    if (ans < (4.9999995 - SPMARGIN) || ans > (4.9999995 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a / ( a - b)\nExpected: 5.0000000   	 Actual: %1.7f", ans);		return (1);	    }	}	ans = a * (a / b);	if (ans != 1.5431250) {	    if (ans < (1.5431250 - SPMARGIN) || ans > (1.5431250 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a * ( a / b)\nExpected: 1.5431250   	 Actual: %1.7f)", ans);		return (1);	    }	}	ans = a / (a * b);	if (ans != 1.0125557) {	    if (ans < (1.0125557 - SPMARGIN) || ans > (1.0125557 + SPMARGIN)) {		send_message(0, ERROR, "Error:  a / ( a * b)\nExpected: 1.0125557	 Actual: %1.7f)", ans);		return (1);	    }	}	if (quick_test)	    break;	if (!quick_test && (spfpa % 25) == 0)	    sleep(1);    }					       /* end of for loop */    return (0);}dpmath(){    double          x, result;#ifdef SVR4    double	    a, b, ans;#else SVR4    long float      a, b, ans;#endif SVR4    int             dpfpa;    a = 1.2345;    b = 0.9876;    /* Basic tests of the following arithmetic operations: +, -, *, and /   */    send_message(0, VERBOSE, "Starting DPMATH routine on %s.", Device);    for (dpfpa = 1; dpfpa < 100; ++dpfpa) {	if (dpfpa % 10 == 0)	    send_message(0, DEBUG, "%s: dpfpa= %d", Device, dpfpa);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -