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

📄 mathtesc.c

📁 arm ads1.2 with crack.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * ask the user for two numbers and pass these through to each of the
 * macro instantiations in turn printing the output back
 *
 * Inputs
 * ------
 *   option
 *   - reserved for future use
 * Return Values
 * ------ ------
 *     TRUE	 - bit testing completed correctly
 *     FALSE - some error occurred
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static Boolean MathsTest( unsigned int option )
{
	double			number1 ;
	double			number2 ;
	unsigned int	uiN1 ;
	signed int		siN1 ;
	unsigned int	uiN2 ;
	signed int		siN2 ;
	unsigned short	usN1 ;
	signed short	ssN1 ;
	unsigned short	usN2 ;
	signed short	ssN2 ;
	double			uiMultiplied ;
	double			siMultiplied ;
	unsigned int	uiDivided ;
	signed int		siDivided ;
	unsigned short	usDiv16 ;
	signed short	ssDiv16 ;
	double			ufDivided ;
	double			sfDivided ;
	u32				arg1[ 4 ] ;
	u32				arg2[ 4 ] ;
	
	if( option > MATHS_OPTIONS ) {
		fprintf( stderr, "[MathsTest] Error in arguments, aborting.\n\n" ) ;
		/* function name given since intended as internal error for programmer */
		return FALSE ;
	}

	for( siN1 = 0 ; siN1 < 4 ; siN1 += 1 ) {
		/* reset arguments */
		arg1[ siN1 ] = 0 ;
		arg2[ siN1 ] = 0 ;
	}

	printf( "Please enter two values for Maths Macros testing.\n\n" ) ;
	
	printf( "The first number corresponds to the numerator during division and\n" ) ;
	printf( "the value passed to the square root, cube root, cosine and sine functions.\n\n" ) ;
	
	printf( "Some routines may not return the expected values during testing if the values\n" ) ;
	printf( "given for testing do not obey the rules governing values passed to the functions.\n\n" ) ;
	
	printf( "Enter the first number: " ) ;
	number1 = ReadDouble( ) ;

	if( number1 < 0 ) {
		uiN1 = 0xFFFFFFFFu + ( signed int )number1 + 1 ;
		usN1 = ( unsigned short )( 0xFFFFu + number1 + 1 ) ;
	}
	else {
		uiN1 = ( unsigned int )number1 ;
		usN1 = ( unsigned short )number1 ;
	}
	siN1 = ( signed int )number1 ;
	ssN1 = ( signed short )number1 ;
	
	printf( "Enter the second number: " ) ;
	number2 = ReadDouble( ) ;

	if( number2 < 0 ) {
		uiN2 = 0xFFFFFFFFu + ( signed int )number2 + 1 ;
		usN2 = ( unsigned short )( 0xFFFFu + number2 + 1 ) ;
	}
	else {
		uiN2 = ( unsigned int )number2 ;
		usN2 = ( unsigned short )number2 ;
	}
	siN2 = ( signed int )number2 ;
	ssN2 = ( signed short )number2 ;
	
	printf( "For testing all the routines except the cosine and sine functions, the numbers used\n" ) ;
	printf( "are the integer parts of the any floating point numbers given, whilst the fractional\n" ) ;
	printf( "part is maintained for testing the cosine and sine functions.\n\n" ) ;
	
	printf( "Values given are '%d' & '%d'\n\n", siN1, siN2 ) ;
	
	printf( "Note that the cosine and sine tests are calculated based on a fixed point precision,\n" ) ;
	printf( "which is set as 14 using the actual decimal values '%lf' & '%lf'\n\n", number1, number2 ) ;
	
	if( number2 == 0 ) {
		printf( "The division routines will not be tested since the second number is 0.\n\n" ) ;
	}
	
	printf( "Starting test...\n\n" ) ;
	
	uiMultiplied = ( double )uiN1*( double )uiN2 ;
	siMultiplied = ( double )siN1*( double )siN2 ;
	if( number2 != 0 ) {
		usDiv16 = ( unsigned short )( ( uiN1 )/( unsigned int )( usN2 ) ) ;
		ssDiv16 = ( signed short )( ( siN1 )/( signed int )( ssN2 ) ) ;
		uiDivided = ( unsigned int )( ( uiN1 )/( uiN2 ) ) ;
		ufDivided = ( double )( uiN1 )/( double )( uiN2 ) ;
		siDivided = ( signed int )( ( siN1 )/( siN2 ) ) ;
		sfDivided = ( double )( siN1 )/( double )( siN2 ) ;
	}
	else {
		usDiv16 = 0 ;
		ssDiv16 = 0 ;
		ufDivided = 0 ;
		uiDivided = 0 ;
		sfDivided = 0 ;
		siDivided = 0 ;
	}
	
	RUNMATHS( ADDABS, io_standard2, siN1, siN2, arg1, arg2, siN1+abs( siN2 ), 1 ) ;
	RUNMATHS( SIGNSAT, io_standard2, siN1, siN2, arg1, arg2, SignedSaturation( siN1, siN2 ), 1 ) ;		

	RUNMATHS( UMUL_32x32_64, io_32x32_64, uiN1, uiN2, arg1, arg2, uiMultiplied, 0 ) ;
	RUNMATHS( SMUL_32x32_64, io_32x32_64, siN1, siN2, arg1, arg2, siMultiplied, 1 ) ;
	RUNMATHS( MUL_64x64_64, io_64x64_64, siN1, siN2, arg1, arg2, siMultiplied, 1 ) ;
	RUNMATHS( UMUL_64x64_128, io_64x64_128, uiN1, uiN2, arg1, arg2, uiMultiplied, 0 ) ;
	
	RUNMATHS( SMUL_64x64_128, io_64x64_128, siN1, siN2, arg1, arg2, siMultiplied, 1 ) ;
	
	if( number2 != 0 ) {
		RUNMATHS( UDIV_32d16_16r16, io_32d32_32r32, uiN1, usN2, arg1, arg2, usDiv16, 0 ) ;
		RUNMATHS( SDIV_32d16_16r16, io_32d32_32r32, siN1, ssN2, arg1, arg2, ssDiv16, 1 ) ;
		RUNMATHS( UDIV_32d32_32r32, io_32d32_32r32, uiN1, uiN2, arg1, arg2, uiDivided, 0 ) ;
		RUNMATHS( SDIV_32d32_32r32, io_32d32_32r32, siN1, siN2, arg1, arg2, siDivided, 1 ) ;
		RUNMATHS( UDIV_64d32_32r32, io_64d32_32r32, uiN1, uiN2, arg1, arg2, uiDivided, 0 ) ;
		RUNMATHS( SDIV_64d32_32r32, io_64d32_32r32, siN1, siN2, arg1, arg2, siDivided, 1 ) ;
		RUNMATHS( UDIV_64d64_64r64, io_64d64_64r64, uiN1, uiN2, arg1, arg2, uiDivided, 0 ) ;
		RUNMATHS( SDIV_64d64_64r64, io_64d64_64r64, siN1, siN2, arg1, arg2, siDivided, 1 ) ;
	}
	
	RUNMATHS( SQR_32_16r17, io_s32_32r32, uiN1, uiN2, arg1, arg2, ( int )sqrt( uiN1 ), 0 ) ;
	RUNMATHS( CBR_32_11, io_c32_32, uiN1, uiN2, arg1, arg2, ( int )( floor( pow( uiN1, 1.0/3.0 ) + 0.5 ) ), 0 ) ;
	
	if( number2 != 0 ) {
		RUNMATHS( UDIVF_32d32_32, io_32d32_f32, uiN1, uiN2, arg1, arg2, ufDivided, 0 ) ;
		RUNMATHS( SDIVF_32d32_32, io_32d32_f32, siN1, siN2, arg1, arg2, sfDivided, 1 ) ;
	}
	
	RUNMATHS( ARMCOS, io_csf32_f32, number1, number2, arg1, arg2, cos( number1 ), 1 ) ;
	RUNMATHS( ARMSIN, io_csf32_f32, number1, number2, arg1, arg2, sin( number1 ), 1 ) ;
	
	printf( "Test completed.\n\n" ) ;
	
	return TRUE ;
}

/**** Menu **************************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * print the menu of options to the screen (defined in standard way for NextTask 
 * function and will be called by NextTask)
 *
 * Inputs
 * ------
 *   numberOptions
 *   - the number of menu options that should be printed
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static void Menu( unsigned int numberOptions )
{
	if( numberOptions == MATHS_OPTIONS ) {
		printf( " 1. Test mathematics routines.\n" ) ;
	}
	else {
		fprintf( stderr, "[Menu] Error in arguments, aborting.\n\n" ) ;
		/* function name given since intended as internal error for programmer */
	}
}

/**** RetrieveOutput ****************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * extract each 32 bits from the given argument and print the value either the
 * value as a positive result or negative result according to the value of a parameter
 * given and whether the top most bit of the result is set
 *
 * Inputs
 * ------
 *   arg
 *   - array of unsigned integers making up the x*32-bit value
 *   size
 *   - total number of bits in argument = x*32bit value
 *   q
 *   - position of decimal point for fixed point operations (0 for integers)
 *   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 RetrieveOutput( u32 *arg, int size, int q, int sign )
{
	double	factor32 = ( double )65536 * 65536 ;	/* 2^16 x 2^16 = 2^32, 32-bit factor */
	u32		intNumber ;
	double	nans = 0 ;
	double	pans = 0 ;
	int		archSize = 0 ;
	int		isNegative = 0 ;
	int		notTested = 1 ;
  
	if( size == 0 ) {
  		return ;
	}

	while( archSize < size ) {
    	intNumber = *arg++ ;	/* read first 32-bit part from argument array */
    
    	nans += ( double )( ( int )( ~intNumber ) ) ;	/* NOT int number for negative result */
    	pans += ( double )intNumber ;
    	archSize += 32 ;
    	nans /= factor32 ;
    	pans /= factor32 ;
  	}		
  
	printf( " result   = " ) ;

	while( size > 0 ) {
    	arg -= 1 ;
    	printf( "0x%08x ", *arg ) ;
    	if( sign && notTested ) {
    		isNegative = *arg & 0x80000000 ;
    		notTested = 0 ;
    	}
    	size -= 32 ;
    	nans = nans * factor32 ;
    	pans = pans * factor32 ;
  	}

	factor32 = ( double )( ( int )( 1 << q ) ) ;	/* shift decimal point accordingly */
	nans = -1-nans ;	/* i.e. NOT( nans ) */
	nans /= factor32 ;
	pans /= factor32 ;
	if( sign && isNegative ) {
		printf( "i.e. %g\n", nans ) ;
	}
	else {
		printf( "i.e. %g\n", pans ) ;
	}
}

/**** SignedSaturation **************************************************************
 *
 * Version & Date
 * -------   ----
 * 1.0.0, 30/06/1998
 *
 * Description
 * -----------
 * given two signed numbers, add them together saturating the result
 *
 * Inputs
 * ------
 *   value1, value2
 *   - the two signed numbers to add together
 * Return Values
 * ------ ------
 *     int        - the result of the addition
 *     0x80000000 - if the actual result overflows the negative range
 *     0x7FFFFFFF - if the actual result overflows the positive range
 *
 * History (with dates)
 * -------  ---- -----
 * 1.0.0, 30/06/1998    first release
 *
 ************************************************************************************/
static int SignedSaturation( int value1, int value2 )
{
	int	result ;
	
	result = value1 + value2 ;
	if( ( value1 > 0 ) && ( value2 > 0 ) ) {
		if( result < 0 ) {
			result = 0x7FFFFFFF ;
		}
	}
	else if( ( value1 < 0 ) && ( value2 < 0 ) ) {
		if( result > 0 ) {
			result = 0x80000000 ;
		}
	}
	
	return result ;
}

⌨️ 快捷键说明

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