History

lib/armeabi.c: fix zero from/to double conversion

tccgen.c: - allow cross-compiling 0.0L (cross-compile tcc with tcc) tccelf.c: - use alignment of TLS section for PT_TLS tccpp.c: - support long double constants on systems that do not support long doubles (i.e. mark them (VT_DOUBLE | VT_LONG)) tccdefs.h: #define __has_feature() for android remove _unaligned (why define a msvc extension under !_WIN32)

grischka committed 3 years ago

Commit 19ef0241 parent 86f3d8e5 files · +38 −27Browse files

Unified · Split

5 files
  1. include/tccdefs.h +2 −7
  2. lib/armeabi.c +8 −1
  3. tccelf.c +2 −1
  4. tccgen.c +11 −4
  5. tccpp.c +15 −14
include/tccdefs.h+2−7
@@ -18,7 +18,7 @@ · 17 unmodified lines
1818
1919 #if __SIZEOF_POINTER__ == 4
2020 /* 32bit systems. */
21−#if defined TARGETOS_OpenBSD
21+#if defined __OpenBSD__
2222 #define __SIZE_TYPE__ unsigned long
2323 #define __PTRDIFF_TYPE__ long
2424 #else
@@ -68,12 +68,6 @@ · 43 unmodified lines
6868 #define __WINT_TYPE__ int
6969 #endif
7070
71−#if !defined _WIN32
72− /* extension to generate different code on old cpu's (>20y ago) */
73− #define _unaligned
74− #define __unaligned
75−#endif
76−
7771 #if __STDC_VERSION__ >= 201112L
7872 # define __STDC_NO_ATOMICS__ 1
7973 # define __STDC_NO_COMPLEX__ 1
@@ -135,6 +129,7 @@ · 55 unmodified lines
135129 #define BIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD
136130 #define __PRETTY_FUNCTION__ __FUNCTION__
137131 #define __has_builtin(x) 0
132+ #define __has_feature(x) 0
138133 #define _Nonnull
139134 #define _Nullable
140135
lib/armeabi.c+8−1
@@ -137,6 +137,11 @@ void __aeabi_ ## name(double_unsigned_struct val) \ · 136 unmodified lines
137137 int exp, high_shift, sign; \
138138 double_unsigned_struct ret; \
139139 \
140+ if ((val.high & ~0x80000000) == 0 && val.low == 0) { \
141+ ret.low = ret.high = 0; \
142+ goto _ret_; \
143+ } \
144+ \
140145 /* compute sign */ \
141146 sign = val.high >> 31; \
142147 \
@@ -190,6 +195,7 @@ void __aeabi_ ## name(double_unsigned_struct val) \ · 47 unmodified lines
190195 ret.low++; \
191196 } \
192197 \
198+_ret_: \
193199 double_unsigned_struct_return(ret); \
194200 }
195201
@@ -313,7 +319,7 @@ void __aeabi_ ## name(unsigned long long v) \ · 117 unmodified lines
313319 } \
314320 } else { \
315321 ret.high = ret.low = 0; \
316− double_unsigned_struct_return(ret); \
322+ goto _ret_; \
317323 } \
318324 } \
319325 \
@@ -323,6 +329,7 @@ void __aeabi_ ## name(unsigned long long v) \ · 3 unmodified lines
323329 /* fill sign bit */ \
324330 ret.high |= sign << 31; \
325331 \
332+_ret_: \
326333 double_unsigned_struct_return(ret); \
327334 }
328335
tccelf.c+2−1
@@ -2277,8 +2277,9 @@ static int layout_sections(TCCState *s1, int *sec_order, struct dyn_inf *d) · 2276 unmodified lines
22772277 ph->p_flags |= PF_X;
22782278 if (f & SHF_TLS) {
22792279 ph->p_type = PT_TLS;
2280− ph->p_align = 4;
2280+ ph->p_align = align + 1;
22812281 }
2282+
22822283 ph->p_offset = file_offset;
22832284 ph->p_vaddr = addr;
22842285 if (n == 0) {
tccgen.c+11−4
@@ -3147,7 +3147,10 @@ error: · 3146 unmodified lines
31473147
31483148 c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
31493149 #if !defined TCC_IS_NATIVE && !defined TCC_IS_NATIVE_387
3150− c &= (dbt != VT_LDOUBLE) | !!nocode_wanted;
3150+ /* don't try to convert to ldouble when cross-compiling
3151+ (except when it's '0' which is needed for arm:gen_negf()) */
3152+ if (dbt_bt == VT_LDOUBLE && !nocode_wanted && (sf || vtop->c.i != 0))
3153+ c = 0;
31513154 #endif
31523155 if (c) {
31533156 /* constant case: we can do it now */
@@ -5449,7 +5452,11 @@ ST_FUNC void unary(void) · 2295 unmodified lines
54495452 t = VT_DOUBLE;
54505453 goto push_tokc;
54515454 case TOK_CLDOUBLE:
5455+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
5456+ t = VT_DOUBLE | VT_LONG;
5457+#else
54525458 t = VT_LDOUBLE;
5459+#endif
54535460 goto push_tokc;
54545461 case TOK_CLONG:
54555462 t = (LONG_SIZE == 8 ? VT_LLONG : VT_INT) | VT_LONG;
@@ -7662,8 +7669,6 @@ static void init_putv(init_params *p, CType *type, unsigned long c) · 2206 unmodified lines
76627669 else if (sizeof (long double) == sizeof (double))
76637670 __asm__("fldl %1\nfstpt %0\n" : "=m" (*ptr) : "m" (vtop->c.ld));
76647671 #endif
7665− else if (vtop->c.ld == 0.0)
7666− ;
76677672 else
76687673 #endif
76697674 /* For other platforms it should work natively, but may not work
@@ -7671,7 +7676,9 @@ static void init_putv(init_params *p, CType *type, unsigned long c) · 1 unmodified line
76717676 if (sizeof(long double) == LDOUBLE_SIZE)
76727677 memcpy(ptr, &vtop->c.ld, LDOUBLE_SIZE);
76737678 else if (sizeof(double) == LDOUBLE_SIZE)
7674− memcpy(ptr, &vtop->c.ld, LDOUBLE_SIZE);
7679+ *(double*)ptr = (double)vtop->c.ld;
7680+ else if (0 == memcmp(ptr, &vtop->c.ld, LDOUBLE_SIZE))
7681+ ; /* nothing to do for 0.0 */
76757682 #ifndef TCC_CROSS_TEST
76767683 else
76777684 tcc_error("can't cross compile long double constants");
tccpp.c+15−14
@@ -1002,7 +1002,11 @@ static inline int tok_size(const int *p) · 1001 unmodified lines
10021002 case TOK_CULLONG:
10031003 return 1 + 2;
10041004 case TOK_CLDOUBLE:
1005+#ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
1006+ return 1 + 8 / 4;
1007+#else
10051008 return 1 + LDOUBLE_SIZE / 4;
1009+#endif
10061010 default:
10071011 return 1 + 0;
10081012 }
@@ -1143,25 +1147,24 @@ static void tok_str_add2(TokenString *s, int t, CValue *cv) · 134 unmodified lines
11431147 #if LONG_SIZE == 8
11441148 case TOK_CLONG:
11451149 case TOK_CULONG:
1146−#endif
1147−#if LDOUBLE_SIZE == 8
1148− case TOK_CLDOUBLE:
11491150 #endif
11501151 str[len++] = cv->tab[0];
11511152 str[len++] = cv->tab[1];
11521153 break;
1153−#if LDOUBLE_SIZE == 12
11541154 case TOK_CLDOUBLE:
1155+#if LDOUBLE_SIZE == 8 || defined TCC_USING_DOUBLE_FOR_LDOUBLE
1156+ str[len++] = cv->tab[0];
1157+ str[len++] = cv->tab[1];
1158+#elif LDOUBLE_SIZE == 12
11551159 str[len++] = cv->tab[0];
11561160 str[len++] = cv->tab[1];
11571161 str[len++] = cv->tab[2];
11581162 #elif LDOUBLE_SIZE == 16
1159− case TOK_CLDOUBLE:
11601163 str[len++] = cv->tab[0];
11611164 str[len++] = cv->tab[1];
11621165 str[len++] = cv->tab[2];
11631166 str[len++] = cv->tab[3];
1164−#elif LDOUBLE_SIZE != 8
1167+#else
11651168 #error add long double size support
11661169 #endif
11671170 break;
@@ -1229,12 +1232,12 @@ static inline void tok_get(int *t, const int **pp, CValue *cv) · 61 unmodified lines
12291232 n = 2;
12301233 goto copy;
12311234 case TOK_CLDOUBLE:
1232−#if LDOUBLE_SIZE == 16
1233− n = 4;
1235+#if LDOUBLE_SIZE == 8 || defined TCC_USING_DOUBLE_FOR_LDOUBLE
1236+ n = 2;
12341237 #elif LDOUBLE_SIZE == 12
12351238 n = 3;
1236−#elif LDOUBLE_SIZE == 8
1237− n = 2;
1239+#elif LDOUBLE_SIZE == 16
1240+ n = 4;
12381241 #else
12391242 # error add long double size support
12401243 #endif
@@ -2334,11 +2337,10 @@ static void parse_number(const char *p) · 1093 unmodified lines
23342337 tokc.f = (float)d;
23352338 } else if (t == 'L') {
23362339 ch = *p++;
2340+ tok = TOK_CLDOUBLE;
23372341 #ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
2338− tok = TOK_CDOUBLE;
23392342 tokc.d = d;
23402343 #else
2341− tok = TOK_CLDOUBLE;
23422344 /* XXX: not large enough */
23432345 tokc.ld = (long double)d;
23442346 #endif
@@ -2390,11 +2392,10 @@ static void parse_number(const char *p) · 45 unmodified lines
23902392 tokc.f = strtof(token_buf, NULL);
23912393 } else if (t == 'L') {
23922394 ch = *p++;
2395+ tok = TOK_CLDOUBLE;
23932396 #ifdef TCC_USING_DOUBLE_FOR_LDOUBLE
2394− tok = TOK_CDOUBLE;
23952397 tokc.d = strtod(token_buf, NULL);
23962398 #else
2397− tok = TOK_CLDOUBLE;
23982399 tokc.ld = strtold(token_buf, NULL);
23992400 #endif
24002401 } else {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t