Skip to content

Commit e43e27c

Browse files
committed
Merge pull request #356 from iabdalkader/d2f
Implement __aeabi_f2d and __aeabi_d2f
2 parents 196990b + 5b6008d commit e43e27c

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

stm/math.c

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
11
#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;
931
}
1032

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;
1442
}
43+
double __aeabi_dmul(double x , double y) {
44+
return 0.0;
1545

46+
}
1647
/*
1748
double sqrt(double x) {
1849
// TODO

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy