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

📄 mathtesc.c

📁 arm ads1.2 with crack.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Mathematics C test harness
 * Copyright (C) ARM Limited 1998-1999. All rights reserved.
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include "mathtesc.h"
#include "mathtess.h"

#include "custredc.h"
#include "definesc.h"
#include "fileutlc.h"
#include "optionsc.h"

#define	MATHS_OPTIONS	1

typedef struct	IOType	IOType ;
typedef			IOType	*IOTypePtr ;

struct IOType {
	int	arg1size ;	/* size in bits of argument */
	int arg1q ;		/* position of floating point for fixed point operations */
	int arg2size ;
	int arg2q ;
	int out1size ;
	int out1q ;
	int out2size ;
	int out2q ;
} ;
/* define the IO structure used for testing */

static IOType	io_standard2	= { 32,  0, 32,  0,  32,  0,  0,  0 } ;
/* two 32-bit inputs, one 32-bit result - standard type */
static IOType	io_32x32_64		= { 32,  0, 32,  0,  64,  0,  0,  0 } ;
/* two 32-bit inputs, one 64-bit result */
static IOType	io_64x64_64		= { 64,  0, 64,  0,  64,  0,  0,  0 } ;
/* two 64-bit inputs, one 64-bit result */
static IOType	io_64x64_128	= { 64,  0, 64,  0, 128,  0,  0,  0 } ;
/* two 64-bit inputs, one 128-bit result */
static IOType	io_32d32_32r32	= { 32,  0, 32,  0,  32,  0, 32,  0 } ;
/* two 32-bit inputs, one 32-bit quotient & one 32-bit remainder result */
static IOType	io_64d32_32r32	= { 64,  0, 32,  0,  32,  0, 32,  0 } ;
/* one 64-bit, one 32-bit input, one 32-bit quotient & one 32-bit remainder */
static IOType	io_64d64_64r64	= { 64,  0, 64,  0,  64,  0, 64,  0 } ;
/* two 64-bit inputs, one 64-bit quotient & one 64-bit remainder */
static IOType	io_s32_32r32	= { 32,  0,  0,  0,  32,  0, 32,  0 } ;
/* one 32-bit input, one 32-bit quotient & one 32-bit remainder */
static IOType	io_c32_32		= { 32,  0,  0,  0,  32,  0,  0,  0 } ;
/* one 32-bit input, one 32-bit output */
static IOType	io_32d32_f32	= { 32,  0, 32,  0,  32, 16,  0,  0 } ;
/* two 32-bit inputs, one 32-bit quotient with 16-bit fixed decimal point */
static IOType	io_csf32_f32	= { 32, 14,  0,  0,  32, 14,  0,  0 } ;
/* one 32-bit input with 14-bit fixed decimal point, one 32-bit output with 14-bit fixed decimal point */

static Boolean MathsTest( unsigned int option ) ;
static void Menu( unsigned int numberOptions ) ;
static void RetrieveOutput( u32 *buff, int size, int q, int sign ) ;
static int SignedSaturation( int value1, int value2 ) ;

/**** RUNMATHS **********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * macro to call each of the maths macros in turn after initialising the argument list,
 * passing the created arguments, retrieving the outputs and printing the results back
 *
 * Inputs
 * ------
 *   MATHSNAME
 *   - the name of the maths macro to call (case sensitive = actual macro name)
 *   IOTYPE
 *   - the IOType structure for the macro call to make up arguments
 *   NUMBER1, NUMBER2
 *   - the numbers to be broken into 32bit parts and passed to macros
 *   ARG1, ARG2
 *   - initialised arrays of unsigned integers to hold the x*32-bit values for each
 *     number respectively and post macro call the results of the macro
 *   ACTUALRESULT
 *   - an integer containing the expected result generated by some other method
 *   SIGN
 *   - 1 : print back the negative output result if top bit of output is set
 *     0 : print back the positive output result
 * Outputs
 * -------
 *   ARG1, ARG2
 *   - arrays of 32bit chunks that contain the output results in x*32bit format
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
#define PRERUN( NAME ) { \
	printf( "Testing function %s\n", #NAME ) ; \
}

#define POSTRUN( CRESULT ) { \
	printf( "\n C result = %g\n\n", ( double )CRESULT ) ; \
}

#define RUNMATHS( MATHSNAME, IO_TYPE, NUMBER1, NUMBER2, ARG1, ARG2, CRESULT, SIGN ) { \
	PRERUN( MATHSNAME ) ; \
	InitInputs( &IO_TYPE, NUMBER1, NUMBER2, ARG1, ARG2 ) ; \
	init_##MATHSNAME( ARG1, ARG2 ) ; \
	GetOutputs( &IO_TYPE, ARG1, ARG2, SIGN ) ; \
	POSTRUN( CRESULT ) ; \
}

/**** GetOutputs ********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * break down the given arguments into 32 bit chunks and print the values either the
 * value as a positive result or (possible) negative result if signed result according
 * to value in given parameter and whether the top most bit of the result is set
 *
 * Inputs
 * ------
 *   ioTypePtr
 *   - a pointer to an IOType that contains the information about data for the
 *     two arguments given
 *   arg1
 *   - pointer to array of u32's that holds the first output result
 *   arg2
 *   - pointer to array of u32's that holds the second output result
 *   actualResult
 *   - the expected result obtained from some other means (such as C based routines)
 *   sign
 *   - 1 : print back the negative output result if top bit of output is set
 *     0 : print back the positive output result
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static void GetOutputs( IOTypePtr ioTypePtr, u32 *arg1, u32 *arg2, int sign )
{
	RetrieveOutput( arg1, ioTypePtr->out1size, ioTypePtr->out1q, sign ) ;
	RetrieveOutput( arg2, ioTypePtr->out2size, ioTypePtr->out2q, sign ) ;
}

/**** InitArg ***********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * extract each 32 bits from the given number and place them into the array given
 * and print the current 32-bits out to the screen
 *
 * Inputs
 * ------
 *   arg
 *   - an initialised array of unsigned integers to hold the x*32-bit value
 *   number
 *   - the value to add split over 32-bit chunks and add to arg as given by user
 *   size
 *   - total number of bits that are to be in argument = x*32bit value (ensures
 *     that negative values are correctly sign extended over whole bit range)
 *   q
 *   - position of decimal point for fixed point operations (0 for integers)
 * Outputs
 * -------
 *   arg
 *   - an array of 32bit chunks that contains the number in x*32bit format
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static void InitArg( u32 *arg, double number, int size, int q )
{
	int		archSize = 32 ;	/* 32-bit integer architecture (default) */
	double	factor32 = ( double ) 65536 * 65536 ;	/* 2^16 x 2^16 = 2^32, 32-bit factor */
	u32		eor = 0 ;	/* exclusive OR to enable use of +ve algorithm for -ve values */
	u32		intNumber ;
  
	if( size == 0 ) {
		*arg = 0 ;
  		return ;
	}
	
	number *= ( double )( ( int )( 1 << q ) ) ; /* shift decimal point accordingly */

	if( number < 0 ) {
		number = -1-number ; /* ie NOT(number) to use postive algorithm */
    	eor = 0xffffffff ;	/* set up exclusive OR to convert back */
	}
			
	while( archSize < size ) {
    	archSize += 32 ;
    	number = number / factor32 ;	/* reduce given number by 32-bits */
    	arg += 1 ;	/* increment the argument array, since lowest sig bit first */
  	}

	printf( " argument = " );
					   
	while( archSize > 0 ) {
    	intNumber = ( u32 )number ;	/* discard the fractional part of number */
    	number = number - ( double )intNumber ;	/* get the fractional part of number */
    	number = number * factor32 ;	/* shift fractional part into next 32-bit range */
    	intNumber = intNumber ^ eor ;	/* exclusive OR int number to count for -ve case */
    	*arg-- = intNumber ;	/* add adjusted int number into 32-bit argument array */
    	printf( "0x%08x ", intNumber ) ;
    	archSize -= 32 ;
	}

	printf("\n");
}

/**** InitInputs ********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * extract each 32 bits from the given numbers and place them into their respective
 * array given and print the current 32-bits out to the screen
 *
 * Inputs
 * ------
 *   ioTypePtr
 *   - a pointer to an IOType that contains information about the arguments to be
 *     constructed
 *   number1, number2
 *   - the numbers to be broken into 32bit chunks and added to given arrays
 *   arg1, arg2
 *   - initialised arrays of unsigned integers to hold the x*32-bit values for each
 *     number respectively
 * Outputs
 * -------
 *   arg1, arg2
 *   - arrays of 32bit chunks that contain the numbers in x*32bit format
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static void InitInputs( IOTypePtr ioTypePtr, double number1, double number2, u32 *arg1, u32 *arg2 )
{
	InitArg( arg1, number1, ioTypePtr->arg1size, ioTypePtr->arg1q ) ;
	InitArg( arg2, number2, ioTypePtr->arg2size, ioTypePtr->arg2q ) ;
}

/**** math_main *********************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * initialise the application then loop whilst the user is still working
 *
 * Return Values
 * ------ ------
 *     0 - application terminated correctly
 *     1 - some error occurred
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
int math_main( int argc, char **argv )
{
	unsigned int	option ;
	char			newStdIn[ ] = "stdin" ;
	char			newStdOut[ ] = "stdout" ;
	char			newStdErr[ ] = "stderr" ;
	unsigned int	stdio = 0 ;
	
	if( ChangeStdIO( &argc, &argv, newStdIn, stdin ) == STDINID ) {
		stdio |= ( 1 << STDINID ) ;
	}
	if( ChangeStdIO( &argc, &argv, newStdOut, stdout ) == STDOUTID ) {
		stdio |= ( 1 << STDOUTID ) ;
	}
	if( ChangeStdIO( &argc, &argv, newStdErr, stderr ) == STDERRID ) {
		stdio |= ( 1 << STDERRID ) ;
	}
	
	while( 1 ) {
		if( ( option = NextTask( MATHS_OPTIONS, &Menu ) ) == 0 ) {
			break ;
		}
		
		MathsTest( option ) ;
	}
	
	/* redirection based on trying to open files that don't exist do using defaults */
	if( stdio & ( 1 << STDINID ) ) {
		ResetStdIO( stdin ) ;
	}
	if( stdio & ( 1 << STDOUTID ) ) {
		ResetStdIO( stdout ) ;
	}
	if( stdio & ( 1 << STDERRID ) ) {
		ResetStdIO( stderr ) ;
	}
		
	return 0 ;
}

/**** MathsTest *********************************************************************

⌨️ 快捷键说明

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