forked from Github_Repos/cvw
		
	fma16_testgen.c test cases
This commit is contained in:
		
							parent
							
								
									64d4cad288
								
							
						
					
					
						commit
						c8f2dce026
					
				| @ -11,6 +11,7 @@ typedef union sp { | |||||||
| // lists of tests, terminated with 0x8000
 | // lists of tests, terminated with 0x8000
 | ||||||
| uint16_t easyExponents[] = {15, 0x8000}; | uint16_t easyExponents[] = {15, 0x8000}; | ||||||
| uint16_t medExponents[] = {1, 14, 15, 16, 20, 30, 0x8000}; | uint16_t medExponents[] = {1, 14, 15, 16, 20, 30, 0x8000}; | ||||||
|  | uint16_t allExponents[] = {1, 15, 16, 30, 31, 0x8000}; | ||||||
| uint16_t easyFracts[] = {0, 0x200, 0x8000}; // 1.0 and 1.1
 | uint16_t easyFracts[] = {0, 0x200, 0x8000}; // 1.0 and 1.1
 | ||||||
| uint16_t medFracts[] = {0, 0x200, 0x001, 0x3FF, 0x8000};  | uint16_t medFracts[] = {0, 0x200, 0x001, 0x3FF, 0x8000};  | ||||||
| uint16_t zeros[] = {0x0000, 0x8000}; | uint16_t zeros[] = {0x0000, 0x8000}; | ||||||
| @ -107,8 +108,8 @@ void genMulTests(uint16_t *e, uint16_t *f, int sgn, char *testName, char *desc, | |||||||
|     fclose(fptr); |     fclose(fptr); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void genAddTests(uint16_t *e, uint16_t *f, int sgn, char *testName, char *desc) { | void genAddTests(uint16_t *e, uint16_t *f, int sgn, char *testName, char *desc, int zeroAllowed, int infAllowed, int nanAllowed) { | ||||||
|     int i, j, numCases; |     int i, j, k, numCases; | ||||||
|     float16_t x, y, z; |     float16_t x, y, z; | ||||||
|     float16_t cases[100000]; |     float16_t cases[100000]; | ||||||
|     FILE *fptr; |     FILE *fptr; | ||||||
| @ -122,7 +123,72 @@ void genAddTests(uint16_t *e, uint16_t *f, int sgn, char *testName, char *desc) | |||||||
|         x.v = cases[i].v; |         x.v = cases[i].v; | ||||||
|         for (j=0; j<numCases; j++) { |         for (j=0; j<numCases; j++) { | ||||||
|             z.v = cases[j].v; |             z.v = cases[j].v; | ||||||
|             //genCase(fptr, x, y, z, 0, 1, 0, 0);
 |             for (k=0; k<=sgn; k++) { | ||||||
|  |                 z.v ^= (k<<15); | ||||||
|  |                 genCase(fptr, x, y, z, 0, 1, 0, 0, zeroAllowed, infAllowed, nanAllowed); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     fclose(fptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | void genFMATests(uint16_t *e, uint16_t *f, int sgn, char *testName, char *desc, int zeroAllowed, int infAllowed, int nanAllowed) { | ||||||
|  |     int i, j, k, l, numCases; | ||||||
|  |     float16_t x, y, z; | ||||||
|  |     float16_t cases[100000]; | ||||||
|  |     FILE *fptr; | ||||||
|  |     char fn[80]; | ||||||
|  |   | ||||||
|  |     sprintf(fn, "work/%s.tv", testName); | ||||||
|  |     fptr = fopen(fn, "w"); | ||||||
|  |     prepTests(e, f, testName, desc, cases, fptr, &numCases); | ||||||
|  |     for (i=0; i < numCases; i++) { | ||||||
|  |         x.v = cases[i].v; | ||||||
|  |         for (j=0; j<numCases; j++) { | ||||||
|  |             y.v = cases[j].v; | ||||||
|  |             for (k=0; k<numCases; k++) { | ||||||
|  |                 z.v = cases[k].v; | ||||||
|  |                 for (l=0; l<=sgn; l++) { | ||||||
|  |                     z.v ^= (l<<15); | ||||||
|  |                     genCase(fptr, x, y, z, 1, 1, 0, 0, zeroAllowed, infAllowed, nanAllowed); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     fclose(fptr); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void genSpecialTests(uint16_t *e, uint16_t *f, int sgn, char *testName, char *desc, int zeroAllowed, int infAllowed, int nanAllowed) { | ||||||
|  |     int i, j, k, sx, sy, sz, numCases; | ||||||
|  |     float16_t x, y, z; | ||||||
|  |     float16_t cases[100000]; | ||||||
|  |     FILE *fptr; | ||||||
|  |     char fn[80]; | ||||||
|  |   | ||||||
|  |     sprintf(fn, "work/%s.tv", testName); | ||||||
|  |     fptr = fopen(fn, "w"); | ||||||
|  |     prepTests(e, f, testName, desc, cases, fptr, &numCases); | ||||||
|  |     cases[numCases].v = 0x0000; // add +0 case
 | ||||||
|  |     cases[numCases+1].v = 0x8000; // add -0 case
 | ||||||
|  |     numCases += 2;  | ||||||
|  |     for (i=0; i < numCases; i++) { | ||||||
|  |         x.v = cases[i].v; | ||||||
|  |         for (j=0; j<numCases; j++) { | ||||||
|  |             y.v = cases[j].v; | ||||||
|  |             for (k=0; k<numCases; k++) { | ||||||
|  |                 z.v = cases[k].v; | ||||||
|  |                 for (sx=0; sx<=sgn; sx++) { | ||||||
|  |                     x.v ^= (sx<<15); | ||||||
|  |                     for (sy=0; sy<=sgn; sy++) { | ||||||
|  |                         y.v ^= (sy<<15); | ||||||
|  |                         for (sz=0; sz<=sgn; sz++) { | ||||||
|  |                             z.v ^= (sz<<15); | ||||||
|  |                             genCase(fptr, x, y, z, 1, 1, 0, 0, zeroAllowed, infAllowed, nanAllowed); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     fclose(fptr); |     fclose(fptr); | ||||||
| @ -138,5 +204,26 @@ int main() | |||||||
|     genMulTests(medExponents, medFracts, 0, "fmul_1", "// Multiply with various exponents and unsigned fractions, RZ", 0, 0, 0); |     genMulTests(medExponents, medFracts, 0, "fmul_1", "// Multiply with various exponents and unsigned fractions, RZ", 0, 0, 0); | ||||||
|     genMulTests(medExponents, medFracts, 1, "fmul_2", "// Multiply with various exponents and signed fractions, RZ", 0, 0, 0); |     genMulTests(medExponents, medFracts, 1, "fmul_2", "// Multiply with various exponents and signed fractions, RZ", 0, 0, 0); | ||||||
| 
 | 
 | ||||||
|  |     // Test cases: addition
 | ||||||
|  |     genAddTests(easyExponents, easyFracts, 0, "fadd_0", "// Add with exponent of 0, significand of 1.0 and 1.1, RZ", 0, 0, 0); | ||||||
|  |     genAddTests(medExponents, medFracts, 0, "fadd_1", "// Add with various exponents and unsigned fractions, RZ", 0, 0, 0); | ||||||
|  |     genAddTests(medExponents, medFracts, 1, "fadd_2", "// Add with various exponents and signed fractions, RZ", 0, 0, 0); | ||||||
|  | 
 | ||||||
|  |     // Test cases: FMA
 | ||||||
|  |     genFMATests(easyExponents, easyFracts, 0, "fma_0", "// FMA with exponent of 0, significand of 1.0 and 1.1, RZ", 0, 0, 0); | ||||||
|  |     genFMATests(medExponents, medFracts, 0, "fma_1", "// FMA with various exponents and unsigned fractions, RZ", 0, 0, 0); | ||||||
|  |     genFMATests(medExponents, medFracts, 1, "fma_2", "// FMA with various exponents and signed fractions, RZ", 0, 0, 0); | ||||||
|  | 
 | ||||||
|  |     // Test cases: Zero, Infinity, NaN
 | ||||||
|  |     genSpecialTests(allExponents, medFracts, 1, "fma_special_rz", "// FMA with special cases, RZ", 1, 1, 1); | ||||||
|  |   | ||||||
|  |     // Full test cases with other rounding modes
 | ||||||
|  |     softfloat_roundingMode = softfloat_round_near_even;  | ||||||
|  |     genSpecialTests(allExponents, medFracts, 1, "fma_special_rne", "// FMA with special cases, RNE", 1, 1, 1); | ||||||
|  |     softfloat_roundingMode = softfloat_round_min;  | ||||||
|  |     genSpecialTests(allExponents, medFracts, 1, "fma_special_rm", "// FMA with special cases, RM", 1, 1, 1); | ||||||
|  |     softfloat_roundingMode = softfloat_round_max;  | ||||||
|  |     genSpecialTests(allExponents, medFracts, 1, "fma_special_rp", "// FMA with special cases, RP", 1, 1, 1); | ||||||
|  |    | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user