File tree Expand file tree Collapse file tree 1 file changed +41
-10
lines changed Expand file tree Collapse file tree 1 file changed +41
-10
lines changed Original file line number Diff line number Diff line change 1
1
#include <stdint.h>
2
- #include <math.h>
3
-
4
- // these 2 functions seem to actually work... no idea why
5
- // replacing with libgcc does not work (probably due to wrong calling conventions)
6
- double __aeabi_f2d (float x ) {
7
- // TODO
8
- return 0.0 ;
2
+ typedef float float_t ;
3
+ typedef union {
4
+ float f ;
5
+ struct {
6
+ uint64_t m : 23 ;
7
+ uint64_t e : 8 ;
8
+ uint64_t s : 1 ;
9
+ };
10
+ } float_s_t ;
11
+
12
+ typedef union {
13
+ double d ;
14
+ struct {
15
+ uint64_t m : 52 ;
16
+ uint64_t e : 11 ;
17
+ uint64_t s : 1 ;
18
+ };
19
+ } double_s_t ;
20
+
21
+ double __attribute__((pcs ("aapcs" ))) __aeabi_f2d (float x ) {
22
+ float_s_t fx = {0 };
23
+ double_s_t dx = {0 };
24
+
25
+ fx .f = x ;
26
+ dx .s = (fx .s );
27
+ dx .e = (fx .e - 127 + 1023 ) & 0x7FF ;
28
+ dx .m = fx .m ;
29
+ dx .m <<=(52 - 23 ); // left justify
30
+ return dx .d ;
9
31
}
10
32
11
- float __aeabi_d2f (double x ) {
12
- // TODO
13
- return 0.0 ;
33
+ float __attribute__((pcs ("aapcs" ))) __aeabi_d2f (double x ) {
34
+ float_s_t fx = {0 };
35
+ double_s_t dx = {0 };
36
+
37
+ dx .d = x ;
38
+ fx .s = (dx .s );
39
+ fx .e = (dx .e - 1023 + 127 ) & 0xFF ;
40
+ fx .m = (dx .m >>(52 - 23 )); // right justify
41
+ return fx .f ;
14
42
}
43
+ double __aeabi_dmul (double x , double y ) {
44
+ return 0.0 ;
15
45
46
+ }
16
47
/*
17
48
double sqrt(double x) {
18
49
// TODO
You can’t perform that action at this time.
0 commit comments