History

i386: use __fixdfdi instead of __tcc_cvt_ftol

Variants __fixsfdi/__fixxfdi are not needed for now because the value is converted to double always. Also: - remove __tcc_fpinit for unix as it seems redundant by the __setfpucw call in the startup code - avoid reference to s->runtime_main in cross compilers - configure: fix --with-libgcc help - tcctok.h: cleanup

grischka committed 12 years ago

Commit 4ad186c1 parent 8efaa716 files · +84 −80Browse files

Unified · Split

6 files
  1. configure +1 −1
  2. i386-gen.c +12 −16
  3. lib/libtcc1.c +21 −18
  4. tccelf.c +2 −2
  5. tccpe.c +2 −0
  6. tcctok.h +46 −43
configure+1−1
@@ -273,7 +273,7 @@ Advanced options (experts only): · 272 unmodified lines
273273 --strip-binaries strip symbol tables from resulting binaries
274274 --disable-static make libtcc.so instead of libtcc.a
275275 --disable-rpath disable use of -rpath with the above
276− --with-libgcc use libgcc_s.so.1 instead of libtcc.a in dynamic link
276+ --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
277277 --enable-mingw32 build windows version on linux with mingw32
278278 --enable-cygwin build windows version on windows with cygwin
279279 --enable-cross build cross compilers
i386-gen.c+12−16
@@ -581,14 +581,6 @@ ST_FUNC void gfunc_prolog(CType *func_type) · 580 unmodified lines
581581 func_bound_offset = lbounds_section->data_offset;
582582 }
583583 #endif
584−
585−#ifndef CONFIG_USE_LIBGCC
586−#ifndef TCC_TARGET_PE
587− if (0 == strcmp(funcname, "main"))
588− gen_static_call(TOK___tcc_fpinit);
589−#endif
590−#endif
591−
592584 }
593585
594586 /* generate function epilog */
@@ -988,16 +980,20 @@ ST_FUNC void gen_cvt_itof(int t) · 393 unmodified lines
988980 }
989981
990982 /* convert fp to int 't' type */
991−/* XXX: handle long long case */
992983 ST_FUNC void gen_cvt_ftoi(int t)
993984 {
994− gv(RC_FLOAT);
995− save_reg(TREG_EAX);
996− save_reg(TREG_EDX);
997− gen_static_call(TOK___tcc_cvt_ftol);
998− vtop->r = TREG_EAX; /* mark reg as used */
999− if (t == VT_LLONG)
1000− vtop->r2 = TREG_EDX;
985+ int bt = vtop->type.t & VT_BTYPE;
986+ if (bt == VT_FLOAT)
987+ vpush_global_sym(&func_old_type, TOK___fixsfdi);
988+ else if (bt == VT_LDOUBLE)
989+ vpush_global_sym(&func_old_type, TOK___fixxfdi);
990+ else
991+ vpush_global_sym(&func_old_type, TOK___fixdfdi);
992+ vswap();
993+ gfunc_call(1);
994+ vpushi(0);
995+ vtop->r = REG_IRET;
996+ vtop->r2 = REG_LRET;
1001997 }
1002998
1003999 /* convert from one floating point type to another */
lib/libtcc1.c+21−18
@@ -478,24 +478,6 @@ long long __ashldi3(long long a, int b) · 477 unmodified lines
478478 #endif
479479 }
480480
481−#ifndef _WIN32
482−void __tcc_fpinit(void)
483−{
484− unsigned c = 0x137F;
485− __asm__ __volatile__ ("fldcw %0" : : "m" (c));
486−}
487−#endif
488−long long __tcc_cvt_ftol(long double x)
489−{
490− unsigned c0, c1;
491− long long ret;
492− __asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
493− c1 = c0 | 0x0C00;
494− __asm__ __volatile__ ("fldcw %0" : : "m" (c1));
495− __asm__ __volatile__ ("fistpll %0" : "=m" (ret));
496− __asm__ __volatile__ ("fldcw %0" : : "m" (c0));
497− return ret;
498−}
499481 #endif /* !__x86_64__ */
500482
501483 /* XXX: fix tcc's code generator to do this instead */
@@ -616,6 +598,27 @@ unsigned long long __fixunsxfdi (long double a1) · 114 unmodified lines
616598 return 0;
617599 }
618600
601+long long __fixsfdi (float a1)
602+{
603+ long long ret; int s;
604+ ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
605+ return s ? ret : -ret;
606+}
607+
608+long long __fixdfdi (double a1)
609+{
610+ long long ret; int s;
611+ ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
612+ return s ? ret : -ret;
613+}
614+
615+long long __fixxfdi (long double a1)
616+{
617+ long long ret; int s;
618+ ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
619+ return s ? ret : -ret;
620+}
621+
619622 #if defined(__x86_64__) && !defined(_WIN64)
620623
621624 #ifndef __TINYC__
tccelf.c+2−2
@@ -178,11 +178,11 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name) · 177 unmodified lines
178178 return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0);
179179 }
180180
181−#ifdef TCC_IS_NATIVE
181+#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
182182 /* return elf symbol value or error */
183183 ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name)
184184 {
185− return (void*)get_elf_sym_addr(s, name, 1);
185+ return (void*)(uintptr_t)get_elf_sym_addr(s, name, 1);
186186 }
187187 #endif
188188
tccpe.c+2−0
@@ -1800,7 +1800,9 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) · 1799 unmodified lines
18001800
18011801 if (TCC_OUTPUT_MEMORY == s1->output_type) {
18021802 pe_type = PE_RUN;
1803+#ifdef TCC_IS_NATIVE
18031804 s1->runtime_main = start_symbol;
1805+#endif
18041806 } else {
18051807 pe->start_addr = (DWORD)tcc_get_symbol_err(s1, start_symbol);
18061808 }
tcctok.h+46−43
@@ -143,23 +143,34 @@ · 142 unmodified lines
143143 #endif
144144
145145 /* builtin functions or variables */
146−#ifdef TCC_ARM_EABI
147− DEF(TOK_memcpy, "__aeabi_memcpy")
148− DEF(TOK_memcpy4, "__aeabi_memcpy4")
149− DEF(TOK_memcpy8, "__aeabi_memcpy8")
150− DEF(TOK_memset, "__aeabi_memset")
151− DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
152− DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
153−#else
146+#ifndef TCC_ARM_EABI
154147 DEF(TOK_memcpy, "memcpy")
155148 DEF(TOK_memset, "memset")
156149 DEF(TOK___divdi3, "__divdi3")
157150 DEF(TOK___moddi3, "__moddi3")
158151 DEF(TOK___udivdi3, "__udivdi3")
159152 DEF(TOK___umoddi3, "__umoddi3")
153+ DEF(TOK___ashrdi3, "__ashrdi3")
154+ DEF(TOK___lshrdi3, "__lshrdi3")
155+ DEF(TOK___ashldi3, "__ashldi3")
156+ DEF(TOK___floatundisf, "__floatundisf")
157+ DEF(TOK___floatundidf, "__floatundidf")
158+# ifndef TCC_ARM_VFP
159+ DEF(TOK___floatundixf, "__floatundixf")
160+ DEF(TOK___fixunsxfdi, "__fixunsxfdi")
161+# endif
162+ DEF(TOK___fixunssfdi, "__fixunssfdi")
163+ DEF(TOK___fixunsdfdi, "__fixunsdfdi")
160164 #endif
161−#if defined(TCC_TARGET_ARM)
162−#ifdef TCC_ARM_EABI
165+
166+#if defined TCC_TARGET_ARM
167+# ifdef TCC_ARM_EABI
168+ DEF(TOK_memcpy, "__aeabi_memcpy")
169+ DEF(TOK_memcpy4, "__aeabi_memcpy4")
170+ DEF(TOK_memcpy8, "__aeabi_memcpy8")
171+ DEF(TOK_memset, "__aeabi_memset")
172+ DEF(TOK___aeabi_ldivmod, "__aeabi_ldivmod")
173+ DEF(TOK___aeabi_uldivmod, "__aeabi_uldivmod")
163174 DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
164175 DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
165176 DEF(TOK___divsi3, "__aeabi_idiv")
@@ -168,24 +179,33 @@ · 2 unmodified lines
168179 DEF(TOK___floatdidf, "__aeabi_l2d")
169180 DEF(TOK___fixsfdi, "__aeabi_f2lz")
170181 DEF(TOK___fixdfdi, "__aeabi_d2lz")
171−#else
182+ DEF(TOK___ashrdi3, "__aeabi_lasr")
183+ DEF(TOK___lshrdi3, "__aeabi_llsr")
184+ DEF(TOK___ashldi3, "__aeabi_llsl")
185+ DEF(TOK___floatundisf, "__aeabi_ul2f")
186+ DEF(TOK___floatundidf, "__aeabi_ul2d")
187+ DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
188+ DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
189+# else
172190 DEF(TOK___modsi3, "__modsi3")
173191 DEF(TOK___umodsi3, "__umodsi3")
174192 DEF(TOK___divsi3, "__divsi3")
175193 DEF(TOK___udivsi3, "__udivsi3")
176194 DEF(TOK___floatdisf, "__floatdisf")
177195 DEF(TOK___floatdidf, "__floatdidf")
178−#ifndef TCC_ARM_VFP
196+# ifndef TCC_ARM_VFP
179197 DEF(TOK___floatdixf, "__floatdixf")
180198 DEF(TOK___fixunssfsi, "__fixunssfsi")
181199 DEF(TOK___fixunsdfsi, "__fixunsdfsi")
182200 DEF(TOK___fixunsxfsi, "__fixunsxfsi")
183201 DEF(TOK___fixxfdi, "__fixxfdi")
184−#endif
202+# endif
185203 DEF(TOK___fixsfdi, "__fixsfdi")
186204 DEF(TOK___fixdfdi, "__fixdfdi")
205+# endif
187206 #endif
188−#elif defined(TCC_TARGET_C67)
207+
208+#if defined TCC_TARGET_C67
189209 DEF(TOK__divi, "_divi")
190210 DEF(TOK__divu, "_divu")
191211 DEF(TOK__divf, "_divf")
@@ -193,32 +213,18 @@ · 1 unmodified line
193213 DEF(TOK__remi, "_remi")
194214 DEF(TOK__remu, "_remu")
195215 #endif
196−#ifdef TCC_TARGET_I386
197− DEF(TOK___tcc_fpinit, "__tcc_fpinit")
198− DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")
199−#endif
200−#ifdef TCC_ARM_EABI
201− DEF(TOK___ashrdi3, "__aeabi_lasr")
202− DEF(TOK___lshrdi3, "__aeabi_llsr")
203− DEF(TOK___ashldi3, "__aeabi_llsl")
204− DEF(TOK___floatundisf, "__aeabi_ul2f")
205− DEF(TOK___floatundidf, "__aeabi_ul2d")
206− DEF(TOK___fixunssfdi, "__aeabi_f2ulz")
207− DEF(TOK___fixunsdfdi, "__aeabi_d2ulz")
208−#else
209− DEF(TOK___ashrdi3, "__ashrdi3")
210− DEF(TOK___lshrdi3, "__lshrdi3")
211− DEF(TOK___ashldi3, "__ashldi3")
212− DEF(TOK___floatundisf, "__floatundisf")
213− DEF(TOK___floatundidf, "__floatundidf")
214−#ifndef TCC_ARM_VFP
215− DEF(TOK___floatundixf, "__floatundixf")
216− DEF(TOK___fixunsxfdi, "__fixunsxfdi")
216+
217+#if defined TCC_TARGET_I386
218+ DEF(TOK___fixsfdi, "__fixsfdi")
219+ DEF(TOK___fixdfdi, "__fixdfdi")
220+ DEF(TOK___fixxfdi, "__fixxfdi")
217221 #endif
218− DEF(TOK___fixunssfdi, "__fixunssfdi")
219− DEF(TOK___fixunsdfdi, "__fixunsdfdi")
222+
223+#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
224+ DEF(TOK_alloca, "alloca")
220225 #endif
221−#ifdef TCC_TARGET_PE
226+
227+#if defined TCC_TARGET_PE
222228 DEF(TOK___chkstk, "__chkstk")
223229 #endif
224230
@@ -233,20 +239,17 @@ · 8 unmodified lines
233239 DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
234240 DEF(TOK___bound_local_new, "__bound_local_new")
235241 DEF(TOK___bound_local_delete, "__bound_local_delete")
236−#ifdef TCC_TARGET_PE
242+# ifdef TCC_TARGET_PE
237243 DEF(TOK_malloc, "malloc")
238244 DEF(TOK_free, "free")
239245 DEF(TOK_realloc, "realloc")
240246 DEF(TOK_memalign, "memalign")
241247 DEF(TOK_calloc, "calloc")
242−#endif
248+# endif
243249 DEF(TOK_memmove, "memmove")
244250 DEF(TOK_strlen, "strlen")
245251 DEF(TOK_strcpy, "strcpy")
246252 #endif
247−#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
248− DEF(TOK_alloca, "alloca")
249−#endif
250253
251254 /* Tiny Assembler */
252255 DEF_ASM(byte)

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