forked from Github_Repos/cvw
Update sample SoftFloat programs
This commit is contained in:
parent
860eca356e
commit
896fc0be0e
3
tests/fp/sample/compile.sh
Executable file
3
tests/fp/sample/compile.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
gcc -c -I. -I../../source/include -O2 -o $1.o $1.c
|
||||||
|
gcc -I -I. -I../../source/include -o $1 $1.o softfloat.a
|
52
tests/fp/sample/div.c
Normal file
52
tests/fp/sample/div.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "softfloat.h"
|
||||||
|
#include "softfloat_types.h"
|
||||||
|
|
||||||
|
int float_rounding_mode = 0;
|
||||||
|
|
||||||
|
union dp {
|
||||||
|
unsigned short x[4];
|
||||||
|
double y;
|
||||||
|
} X;
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
uint8_t rounding_mode;
|
||||||
|
uint8_t exceptions;
|
||||||
|
|
||||||
|
uint64_t n, d, result;
|
||||||
|
float64_t d_n, d_d, d_result;
|
||||||
|
|
||||||
|
n = 0x3feffffffefffff6;
|
||||||
|
d = 0xffeffffffffffffe;
|
||||||
|
//n = 0x00000000400001ff;
|
||||||
|
//d = 0x3ffffdfffffffbfe;
|
||||||
|
|
||||||
|
d_n.v = n;
|
||||||
|
d_d.v = d;
|
||||||
|
|
||||||
|
softfloat_roundingMode = rounding_mode;
|
||||||
|
softfloat_exceptionFlags = 0;
|
||||||
|
softfloat_detectTininess = softfloat_tininess_beforeRounding;
|
||||||
|
|
||||||
|
d_result = f64_div(d_n, d_d);
|
||||||
|
|
||||||
|
//result = d_result.v;
|
||||||
|
//exceptions = softfloat_exceptionFlags & 0x1f;
|
||||||
|
|
||||||
|
X.x[3] = (d_result.v & 0xffff000000000000) >> 48;
|
||||||
|
X.x[2] = (d_result.v & 0x0000ffff00000000) >> 32;
|
||||||
|
X.x[1] = (d_result.v & 0x00000000ffff0000) >> 16;
|
||||||
|
X.x[0] = (d_result.v & 0x000000000000ffff);
|
||||||
|
|
||||||
|
printf("Number = %.4x\n", X.x[3]);
|
||||||
|
printf("Number = %.4x\n", X.x[2]);
|
||||||
|
printf("Number = %.4x\n", X.x[1]);
|
||||||
|
printf("Number = %.4x\n", X.x[0]);
|
||||||
|
printf("Number = %1.25lg\n", X.y);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
47
tests/fp/sample/fma.c
Normal file
47
tests/fp/sample/fma.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "softfloat.h"
|
||||||
|
#include "softfloat_types.h"
|
||||||
|
|
||||||
|
int float_rounding_mode = 0;
|
||||||
|
|
||||||
|
union sp {
|
||||||
|
unsigned short x[2];
|
||||||
|
float y;
|
||||||
|
} X;
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
uint8_t rounding_mode;
|
||||||
|
uint8_t exceptions;
|
||||||
|
|
||||||
|
uint32_t multiplier, multiplicand, addend, result;
|
||||||
|
float32_t f_multiplier, f_multiplicand, f_addend, f_result;
|
||||||
|
|
||||||
|
multiplier = 0xbf800000;
|
||||||
|
multiplicand = 0xbf800000;
|
||||||
|
addend = 0xffaaaaaa;
|
||||||
|
|
||||||
|
f_multiplier.v = multiplier;
|
||||||
|
f_multiplicand.v = multiplicand;
|
||||||
|
f_addend.v = addend;
|
||||||
|
|
||||||
|
softfloat_roundingMode = rounding_mode;
|
||||||
|
softfloat_exceptionFlags = 0;
|
||||||
|
softfloat_detectTininess = softfloat_tininess_beforeRounding;
|
||||||
|
|
||||||
|
f_result = f32_mulAdd(f_multiplier, f_multiplicand, f_addend);
|
||||||
|
|
||||||
|
result = f_result.v;
|
||||||
|
exceptions = softfloat_exceptionFlags & 0x1f;
|
||||||
|
|
||||||
|
printf("%x\n", f_result.v);
|
||||||
|
|
||||||
|
// Print out SP number
|
||||||
|
X.x[1] = (f_result.v & 0xffff0000) >> 16;
|
||||||
|
X.x[0] = (f_result.v & 0x0000ffff);
|
||||||
|
printf("Number = %f\n", X.y);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user