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
273 --strip-binaries strip symbol tables from resulting binaries273 --strip-binaries strip symbol tables from resulting binaries
274 --disable-static make libtcc.so instead of libtcc.a274 --disable-static make libtcc.so instead of libtcc.a
275 --disable-rpath disable use of -rpath with the above275 --disable-rpath disable use of -rpath with the above
276 --with-libgcc use libgcc_s.so.1 instead of libtcc.a in dynamic link276 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
277 --enable-mingw32 build windows version on linux with mingw32277 --enable-mingw32 build windows version on linux with mingw32
278 --enable-cygwin build windows version on windows with cygwin278 --enable-cygwin build windows version on windows with cygwin
279 --enable-cross build cross compilers279 --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
581 func_bound_offset = lbounds_section->data_offset;581 func_bound_offset = lbounds_section->data_offset;
582 }582 }
583#endif583#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
592}584}
593 585
594/* generate function epilog */586/* generate function epilog */
@@ -988,16 +980,20 @@ ST_FUNC void gen_cvt_itof(int t) · 393 unmodified lines
988}980}
989 981
990/* convert fp to int 't' type */982/* convert fp to int 't' type */
991/* XXX: handle long long case */
992ST_FUNC void gen_cvt_ftoi(int t)983ST_FUNC void gen_cvt_ftoi(int t)
993{984{
994 gv(RC_FLOAT);985 int bt = vtop->type.t & VT_BTYPE;
995 save_reg(TREG_EAX);986 if (bt == VT_FLOAT)
996 save_reg(TREG_EDX);987 vpush_global_sym(&func_old_type, TOK___fixsfdi);
997 gen_static_call(TOK___tcc_cvt_ftol);988 else if (bt == VT_LDOUBLE)
998 vtop->r = TREG_EAX; /* mark reg as used */989 vpush_global_sym(&func_old_type, TOK___fixxfdi);
999 if (t == VT_LLONG)990 else
1000 vtop->r2 = TREG_EDX;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;
1001}997}
1002 998
1003/* convert from one floating point type to another */999/* 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
478#endif478#endif
479}479}
480 480
481#ifndef _WIN32
482void __tcc_fpinit(void)
483{
484 unsigned c = 0x137F;
485 __asm__ __volatile__ ("fldcw %0" : : "m" (c));
486}
487#endif
488long 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}
499#endif /* !__x86_64__ */481#endif /* !__x86_64__ */
500 482
501/* XXX: fix tcc's code generator to do this instead */483/* XXX: fix tcc's code generator to do this instead */
@@ -616,6 +598,27 @@ unsigned long long __fixunsxfdi (long double a1) · 114 unmodified lines
616 return 0;598 return 0;
617}599}
618 600
601long 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
608long 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
615long 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
619#if defined(__x86_64__) && !defined(_WIN64)622#if defined(__x86_64__) && !defined(_WIN64)
620 623
621#ifndef __TINYC__624#ifndef __TINYC__
tccelf.c+2−2
@@ -178,11 +178,11 @@ LIBTCCAPI void *tcc_get_symbol(TCCState *s, const char *name) · 177 unmodified lines
178 return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0);178 return (void*)(uintptr_t)get_elf_sym_addr(s, name, 0);
179}179}
180 180
181#ifdef TCC_IS_NATIVE181#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
182/* return elf symbol value or error */182/* return elf symbol value or error */
183ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name)183ST_FUNC void* tcc_get_symbol_err(TCCState *s, const char *name)
184{184{
185 return (void*)get_elf_sym_addr(s, name, 1);185 return (void*)(uintptr_t)get_elf_sym_addr(s, name, 1);
186}186}
187#endif187#endif
188 188
tccpe.c+2−0
@@ -1800,7 +1800,9 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) · 1799 unmodified lines
1800 1800
1801 if (TCC_OUTPUT_MEMORY == s1->output_type) {1801 if (TCC_OUTPUT_MEMORY == s1->output_type) {
1802 pe_type = PE_RUN;1802 pe_type = PE_RUN;
1803#ifdef TCC_IS_NATIVE
1803 s1->runtime_main = start_symbol;1804 s1->runtime_main = start_symbol;
1805#endif
1804 } else {1806 } else {
1805 pe->start_addr = (DWORD)tcc_get_symbol_err(s1, start_symbol);1807 pe->start_addr = (DWORD)tcc_get_symbol_err(s1, start_symbol);
1806 }1808 }
tcctok.h+46−43
@@ -143,23 +143,34 @@ · 142 unmodified lines
143#endif143#endif
144 144
145/* builtin functions or variables */145/* builtin functions or variables */
146#ifdef TCC_ARM_EABI146#ifndef 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
154 DEF(TOK_memcpy, "memcpy")147 DEF(TOK_memcpy, "memcpy")
155 DEF(TOK_memset, "memset")148 DEF(TOK_memset, "memset")
156 DEF(TOK___divdi3, "__divdi3")149 DEF(TOK___divdi3, "__divdi3")
157 DEF(TOK___moddi3, "__moddi3")150 DEF(TOK___moddi3, "__moddi3")
158 DEF(TOK___udivdi3, "__udivdi3")151 DEF(TOK___udivdi3, "__udivdi3")
159 DEF(TOK___umoddi3, "__umoddi3")152 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")
160#endif164#endif
161#if defined(TCC_TARGET_ARM)165
162#ifdef TCC_ARM_EABI166#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")
163 DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")174 DEF(TOK___aeabi_idivmod, "__aeabi_idivmod")
164 DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")175 DEF(TOK___aeabi_uidivmod, "__aeabi_uidivmod")
165 DEF(TOK___divsi3, "__aeabi_idiv")176 DEF(TOK___divsi3, "__aeabi_idiv")
@@ -168,24 +179,33 @@ · 2 unmodified lines
168 DEF(TOK___floatdidf, "__aeabi_l2d")179 DEF(TOK___floatdidf, "__aeabi_l2d")
169 DEF(TOK___fixsfdi, "__aeabi_f2lz")180 DEF(TOK___fixsfdi, "__aeabi_f2lz")
170 DEF(TOK___fixdfdi, "__aeabi_d2lz")181 DEF(TOK___fixdfdi, "__aeabi_d2lz")
171#else182 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
172 DEF(TOK___modsi3, "__modsi3")190 DEF(TOK___modsi3, "__modsi3")
173 DEF(TOK___umodsi3, "__umodsi3")191 DEF(TOK___umodsi3, "__umodsi3")
174 DEF(TOK___divsi3, "__divsi3")192 DEF(TOK___divsi3, "__divsi3")
175 DEF(TOK___udivsi3, "__udivsi3")193 DEF(TOK___udivsi3, "__udivsi3")
176 DEF(TOK___floatdisf, "__floatdisf")194 DEF(TOK___floatdisf, "__floatdisf")
177 DEF(TOK___floatdidf, "__floatdidf")195 DEF(TOK___floatdidf, "__floatdidf")
178#ifndef TCC_ARM_VFP196# ifndef TCC_ARM_VFP
179 DEF(TOK___floatdixf, "__floatdixf")197 DEF(TOK___floatdixf, "__floatdixf")
180 DEF(TOK___fixunssfsi, "__fixunssfsi")198 DEF(TOK___fixunssfsi, "__fixunssfsi")
181 DEF(TOK___fixunsdfsi, "__fixunsdfsi")199 DEF(TOK___fixunsdfsi, "__fixunsdfsi")
182 DEF(TOK___fixunsxfsi, "__fixunsxfsi")200 DEF(TOK___fixunsxfsi, "__fixunsxfsi")
183 DEF(TOK___fixxfdi, "__fixxfdi")201 DEF(TOK___fixxfdi, "__fixxfdi")
184#endif202# endif
185 DEF(TOK___fixsfdi, "__fixsfdi")203 DEF(TOK___fixsfdi, "__fixsfdi")
186 DEF(TOK___fixdfdi, "__fixdfdi")204 DEF(TOK___fixdfdi, "__fixdfdi")
205# endif
187#endif206#endif
188#elif defined(TCC_TARGET_C67)207
208#if defined TCC_TARGET_C67
189 DEF(TOK__divi, "_divi")209 DEF(TOK__divi, "_divi")
190 DEF(TOK__divu, "_divu")210 DEF(TOK__divu, "_divu")
191 DEF(TOK__divf, "_divf")211 DEF(TOK__divf, "_divf")
@@ -193,32 +213,18 @@ · 1 unmodified line
193 DEF(TOK__remi, "_remi")213 DEF(TOK__remi, "_remi")
194 DEF(TOK__remu, "_remu")214 DEF(TOK__remu, "_remu")
195#endif215#endif
196#ifdef TCC_TARGET_I386216
197 DEF(TOK___tcc_fpinit, "__tcc_fpinit")217#if defined TCC_TARGET_I386
198 DEF(TOK___tcc_cvt_ftol, "__tcc_cvt_ftol")218 DEF(TOK___fixsfdi, "__fixsfdi")
199#endif219 DEF(TOK___fixdfdi, "__fixdfdi")
200#ifdef TCC_ARM_EABI220 DEF(TOK___fixxfdi, "__fixxfdi")
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")
217#endif221#endif
218 DEF(TOK___fixunssfdi, "__fixunssfdi")222
219 DEF(TOK___fixunsdfdi, "__fixunsdfdi")223#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
224 DEF(TOK_alloca, "alloca")
220#endif225#endif
221#ifdef TCC_TARGET_PE226
227#if defined TCC_TARGET_PE
222 DEF(TOK___chkstk, "__chkstk")228 DEF(TOK___chkstk, "__chkstk")
223#endif229#endif
224 230
@@ -233,20 +239,17 @@ · 8 unmodified lines
233 DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")239 DEF(TOK___bound_ptr_indir16, "__bound_ptr_indir16")
234 DEF(TOK___bound_local_new, "__bound_local_new")240 DEF(TOK___bound_local_new, "__bound_local_new")
235 DEF(TOK___bound_local_delete, "__bound_local_delete")241 DEF(TOK___bound_local_delete, "__bound_local_delete")
236#ifdef TCC_TARGET_PE242# ifdef TCC_TARGET_PE
237 DEF(TOK_malloc, "malloc")243 DEF(TOK_malloc, "malloc")
238 DEF(TOK_free, "free")244 DEF(TOK_free, "free")
239 DEF(TOK_realloc, "realloc")245 DEF(TOK_realloc, "realloc")
240 DEF(TOK_memalign, "memalign")246 DEF(TOK_memalign, "memalign")
241 DEF(TOK_calloc, "calloc")247 DEF(TOK_calloc, "calloc")
242#endif248# endif
243 DEF(TOK_memmove, "memmove")249 DEF(TOK_memmove, "memmove")
244 DEF(TOK_strlen, "strlen")250 DEF(TOK_strlen, "strlen")
245 DEF(TOK_strcpy, "strcpy")251 DEF(TOK_strcpy, "strcpy")
246#endif252#endif
247#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
248 DEF(TOK_alloca, "alloca")
249#endif
250 253
251/* Tiny Assembler */254/* Tiny Assembler */
252 DEF_ASM(byte)255 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