aboutsummaryrefslogtreecommitdiff
path: root/i386-gen.c
Commit message (Collapse)AuthorAgeFilesLines
* unsorted adjustmentsgrischka2017-07-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - configure * use aarch64 instead of arm64 - Makefile * rename the custom include file to "config-extra.mak" * Also avoid "rm -r /*" if $(tccdir) is empty - pp/Makefile * fix .expect generation with gcc - tcc.h * cleanup #defines for _MSC_VER - tccgen.c: * fix const-propagation for &,| * fix anonymous named struct (ms-extension) and enable -fms-extension by default - i386-gen.c * clear VT_DEFSIGN - x86_64-gen.c/win64: * fix passing structs in registers * fix alloca (need to keep "func_scratch" below each alloca area on stack) (This allows to compile a working gnu-make on win64) - tccpp.c * alternative approach to 37999a4fbf3487b363fd0c2f9b7ab622401b202a This is to avoid some slowdown with ## token pasting. * get_tok_str() : return <eof> for TOK_EOF * -funsigned-char: apply to "string" literals as well - tccpe/tools.c: -impdef: support both 32 and 64 bit dlls anyway
* configure: --config-musl/-uClibc switch & misc cleanupsgrischka2017-05-131-0/+3
| | | | | | | | | | | | | | | - configure: - add --config-uClibc,-musl switch and suggest to use it if uClibc/musl is detected - make warning options magic clang compatible - simplify (use $confvars instead of individual options) - Revert "Remove some unused-parameter lint" 7443db0d5f841b81a55e918bf8c228dd20f9ddb2 rather use -Wno-unused-parameter (or just not -Wextra) - #ifdef functions that are unused on some targets - tccgen.c: use PTR_SIZE==8 instead of (X86_64 || ARM64) - tccpe.c: fix some warnings - integrate dummy arm-asm better
* Spelling fixes in C comments onlyLarry Doolittle2017-05-071-2/+2
|
* fixes & cleanupsgrischka2017-02-131-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - tccgen.c/tcc.h: allow function declaration after use: int f() { return g(); } int g() { return 1; } may be a warning but not an error see also 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 - tccgen.c: redundant code related to inline functions removed (functions used anywhere have sym->c set automatically) - tccgen.c: make 32bit llop non-equal test portable (probably not on C67) - dynarray_add: change prototype to possibly avoid aliasing problems or at least warnings - lib/alloca*.S: ".section .note.GNU-stack,"",%progbits" removed (has no effect) - tccpe: set SizeOfCode field (for correct upx decompression) - libtcc.c: fixed alternative -run invocation tcc "-run -lxxx ..." file.c (meant to load the library after file). Also supported now: tcc files ... options ... -run @ arguments ...
* tccgen: factor out gfunc_returngrischka2017-02-081-10/+11
| | | | | | | Also: - on windows i386 and x86-64, structures of size <= 8 are NOT returned in registers if size is not one of 1,2,4,8. - cleanup: put all tv-push/pop/swap/rot into one place
* Revert "partial revert of the commit 4ad186c5ef61"grischka2017-02-051-10/+0
| | | | | | | | | | | | | | | | | | There seems nothing wrong. With int t1 = 176401255; float f = 0.25; int t2 = t1 * f; // 176401255 * 0.25 = 44100313.75 according to the arithmetic conversion rules, the number 176401255 needs to be converted to float, and the compiler can choose either the nearest higher or nearest lower representable number "in an implementation-defined manner". Which may be 176401248 or 176401264. So as result both 44100312 and 44100313 are correct. This reverts commit 664c19ad5ef16f3463087a33ecfe5d5ac24f81ec.
* i386-gen: fix USE_EBXgrischka2016-12-191-5/+10
| | | | | | | | | | | | | Restore ebx from *ebp because alloca might change esp. Also disable USE_EBX for upcoming release. Actually the benefit is less than one would expect, it appears that tcc can't do much with more than 3 registers except with extensive use of long longs where the disassembly looks much prettier (and shorter also). Also: tccgen/expr_cond() : fix wrong gv/save_regs order
* tccgen: nocode_wanted alternativelygrischka2016-12-181-18/+15
| | | | | | | | | | | | | | | tccgen.c: remove any 'nocode_wanted' checks, except in - greloca(), disables output elf symbols and relocs - get_reg(), will return just the first suitable reg) - save_regs(), will do nothing Some minor adjustments were made where nocode_wanted is set. xxx-gen.c: disable code output directly where it happens in functions: - g(), output disabled - gjmp(), will do nothing - gtst(), dto.
* i386: Fix various testsuite issuesMichael Matz2016-12-151-8/+21
| | | | | | | | | on 32bit long long support was sometimes broken. This fixes code-gen for long long values in switches, disables a x86-64 specific testcase and avoid an undefined shift amount. It comments out a bitfield test involving long long bitfields > 32 bit; with GCC layout they can straddle multiple words and code generation isn't prepared for this.
* x86-64: relocation addend is 64bitMichael Matz2016-12-151-2/+2
| | | | | | | | Some routines were using the wrong type (int) in passing addends, truncating it. This matters when bit 31 isn't set and the high 32 bits are set: the truncation would make it unsigned where in reality it's signed (happen e.g. on the x86-64 with it's load address at top-2GB).
* Fix relocs_info declaration in tcc.hThomas Preud'homme2016-12-051-15/+0
| | | | | | | | | C standard specifies that array should be declared with a non null size or with * for standard array. Declaration of relocs_info in tcc.h was not respecting this rule. This commit add a R_NUM macro that maps to the R_<ARCH>_NUM macros and declare relocs_info using it. This commit also moves all linker-related macros from <arch>-gen.c files to <arch>-link.c ones.
* Make build_got_entries more target independentThomas Preud'homme2016-12-031-0/+1
| | | | | Factor most of common logic between targets in build_got_entries by defining target specific info into structures in the backends.
* i386 + bcheck: fix __bound_local_newPavlas, Zdenek2016-11-091-6/+8
| | | | | | | | | | | | With -b, this produces garbage. Code to call __bound_local_new is put at wrong place, overwriting the regparam setup code. Fix copied from x86_64-gen.c. void __attribute__((regparm(3))) fun(int unused) { char local[1]; }
* i386-gen: use EBX as 4th registergrischka2016-10-191-4/+13
| | | | | May be enabled/disabled by changing this line: #define USE_EBX 1
* lib/libtcc1.c: cleanupgrischka2016-10-191-16/+3
| | | | | | | - remove #include dependencies from libtcc1.c for easier cross compilation - clear_cache only on ARM - error-message for mprotect failure
* i386: do not 'lexpand' into registers necessarilygrischka2016-10-161-2/+2
| | | | | | | | | | | | | | Previously, long longs were 'lexpand'ed into two registers always. Now, it expands - constants into two constants (lo-part, hi-part) - variables into two lvalues with offset+4 for the hi-part. This makes long long operations look a bit nicer. Also: don't apply i386 'inc/dec' optimization if carry generation is wanted.
* tccgen: arm/i386: save_reg_upstackgrischka2016-10-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tccgen.c:gv() when loading long long from lvalue, before was saving all registers which caused problems in the arm function call register parameter preparation, as with void foo(long long y, int x); int main(void) { unsigned int *xx[1], x; unsigned long long *yy[1], y; foo(**yy, **xx); return 0; } Now only the modified register is saved if necessary, as in this case where it is used to store the result of the post-inc: long long *p, v, **pp; v = 1; p = &v; p[0]++; printf("another long long spill test : %lld\n", *p); i386-gen.c : - found a similar problem with TOK_UMULL caused by the vstack juggle in tccgen:gen_opl() (bug seen only when using EBX as 4th register)
* gtst_addr(): short conditional jumps (i386, x86_64)Pavlas, Zdenek2016-09-301-0/+13
|
* short_call_convention patch from tcc bugzillaseyko2016-05-151-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | BUGZILLA: interfacing with other compilers extend the return value to the whole register if necessary. visual studio and gcc do not always set the whole eax register when assigning the return value of a function. We've encountered wrong execution results on i386 platforms with an application that uses both code compiled with TCC and code compiled with other compilers (namely: Visual Studio on Windows, and GCC on Linux). When calling a function that returns an integer value shorter than 32 bits, TCC reads the return value from the whole EAX register, although the code generated by the other compilers can only sets AL for 8 bit values or AX for 16 bits values, and the rest of EAX can be anything. We worked around this with the attached patch on i386 for the version 0.9.26, but we did not look at other platforms to find if there are similar issues.
* allow to compile tcc by pccseyko2016-04-151-1/+1
| | | | | * pcc have only __linux__ macro (and no __linux) * pcc don't have __clear_cache proc
* Fix assignment to/from volatile typesMichael Matz2016-03-261-0/+3
| | | | | | | | | Code like this was broken: char volatile vi = i; See testcase, happens in ideosyncratic legacy code sprinkling volatile all over.
* Bug fix for commit 553242c18a2387fb896df66eb9b5a502f0e87ff0.Edmund Grimley Evans2015-11-201-5/+7
| | | | | | In gtst, vtop->c.i is not usually zero, but it is when compiling: int f(void) { return 1 && 1 ? 1 : 1; }
* Replace pointer casts with calls to (read|write)(16|32|64)le.Edmund Grimley Evans2015-11-191-15/+10
| | | | | This stops UBSan from giving runtime misaligned address errors and might eventually allow building on a non-little-endian host.
* Merge the integer members of union CValue into "uint64_t i".Edmund Grimley Evans2015-11-171-11/+13
|
* Revert "fix-mixed-struct (patch by Pip Cet)"gus knight2015-07-291-14/+5
| | | | This reverts commit 4e04f67c94c97b4f28a4d73759a0ad38fb3a10f7. Requested by grischka.
* Revert all of my changes to directories & codingstyle.gus knight2015-07-291-0/+1144
|
* Reorganize the source tree.gus knight2015-07-271-1144/+0
| | | | | | | | | | * Documentation is now in "docs". * Source code is now in "src". * Misc. fixes here and there so that everything still works. I think I got everything in this commit, but I only tested this on Linux (Make) and Windows (CMake), so I might've messed something up on other platforms...
* Trim trailing spaces everywhere.gus knight2015-07-271-12/+12
|
* fix-mixed-struct (patch by Pip Cet)seyko2015-05-141-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Jsut for testing. It works for me (don't break anything) Small fixes for x86_64-gen.c in "tccpp: fix issues, add tests" are dropped in flavor of this patch. Pip Cet: Okay, here's a first patch that fixes the problem (but I've found another bug, yet unfixed, in the process), though it's not particularly pretty code (I tried hard to keep the changes to the minimum necessary). If we decide to actually get rid of VT_QLONG and VT_QFLOAT (please, can we?), there are some further simplifications in tccgen.c that might offset some of the cost of this patch. The idea is that an integer is no longer enough to describe how an argument is stored in registers. There are a number of possibilities (none, integer register, two integer registers, float register, two float registers, integer register plus float register, float register plus integer register), and instead of enumerating them I've introduced a RegArgs type that stores the offsets for each of our registers (for the other architectures, it's simply an int specifying the number of registers). If someone strongly prefers an enum, we could do that instead, but I believe this is a place where keeping things general is worth it, because this way it should be doable to add SSE or AVX support. There is one line in the patch that looks suspicious: } else { addr = (addr + align - 1) & -align; param_addr = addr; addr += size; - sse_param_index += reg_count; } break; However, this actually fixes one half of a bug we have when calling a function with eight double arguments "interrupted" by a two-double structure after the seventh double argument: f(double,double,double,double,double,double,double,struct { double x,y; },double); In this case, the last argument should be passed in %xmm7. This patch fixes the problem in gfunc_prolog, but not the corresponding problem in gfunc_call, which I'll try tackling next.
* tccpp: fix issues, add testsgrischka2015-05-091-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fix some macro expansion issues * add some pp tests in tests/pp * improved tcc -E output for better diff'ability * remove -dD feature (quirky code, exotic feature, didn't work well) Based partially on ideas / researches from PipCet Some issues remain with VA_ARGS macros (if used in a rather tricky way). Also, to keep it simple, the pp doesn't automtically add any extra spaces to separate tokens which otherwise would form wrong tokens if re-read from tcc -E output (such as '+' '=') GCC does that, other compilers don't. * cleanups - #line 01 "file" / # 01 "file" processing - #pragma comment(lib,"foo") - tcc -E: forward some pragmas to output (pack, comment(lib)) - fix macro parameter list parsing mess from a3fc54345949535524d01319e1ca6378b7c2c201 a715d7143d9d17da17e67fec6af1c01409a71a31 (some coffee might help, next time ;) - introduce TOK_PPSTR - to have character constants as written in the file (similar to TOK_PPNUM) - allow '\' appear in macros - new functions begin/end_macro to: - fix switching macro levels during expansion - allow unget_tok to unget more than one tok - slight speedup by using bitflags in isidnum_table Also: - x86_64.c : fix decl after statements - i386-gen,c : fix a vstack leak with VLA on windows - configure/Makefile : build on windows (MSYS) was broken - tcc_warning: fflush stderr to keep output order (win32)
* a lot simpler VLA codeseyko2015-05-041-4/+0
| | | | | | | | Author: Philip <pipcet@gmail.com> Our VLA code can be made a lot simpler (simple enough for even me to understand it) by giving up on the optimization idea, which is very tempting. There's a patch to do that attached, feel free to test and commit it if you like. (It passes all the tests, at least
* make a bound checking more compatible with Windows 64seyko2015-03-261-7/+7
| | | | | | On Linux 32: sizeof(long)=32 == sizeof(void *)=32 on Linux 64: sizeof(long)=64 == sizeof(void *)=64 on Windows 64: sizeof(long)=32 != sizeof(void *)=64
* Fix stack overwrite on structure returnMichael Matz2015-03-091-1/+2
| | | | | | | | | The common code to move a returned structure packed into registers into memory on the caller side didn't take the register size into account when allocating local storage, so sometimes that lead to stack overwrites (e.g. in 73_arm64.c), on x86_64. This fixes it by generally making gfunc_sret also return the register size.
* partial revert of the commit 4ad186c5ef61seyko2015-03-041-0/+23
| | | | | | | | | | | | | | | A test program: /* result of the new version inroduced in 4ad186c5ef61: t2a = 44100312 */ #include<stdio.h> int main() { int t1 = 176401255; float f = 0.25f; int t2a = (int)(t1 * f); // must be 44100313 int t2b = (int)(t1 * (float)0.25f); printf("t2a=%d t2b=%d \n",t2a,t2b); return 0; }
* A partial reverse for commit eda2c756edc4dca004ba217d5bf361235dd9de1fseyko2015-03-031-1/+1
| | | | | | | | | | | | | | | Author: Thomas Preud'homme <robotux@celest.fr> Date: Tue Dec 31 23:51:20 2013 +0800 Move logic for if (int value) to tccgen.c Move the logic to do a test of an integer value (ex if (0)) out of arch-specific code to tccgen.c to avoid code duplication. This also fixes test of long long value which was only testing the bottom half of such values on 32 bits architectures. I don't understand why if () in gtst(i) was removed. This patch allows to compile a linux kernel v.2.4.26 W/o this patch a tcc simply crashes.
* be stricter with aliasinggrischka2014-01-071-2/+2
| | | | | | | | | | | | | | Refactoring (no logical changes): - use memcpy in tccgen.c:ieee_finite(double d) - use union to store attribute flags in Sym Makefile: "CFLAGS+=-fno-strict-aliasing" basically not necessary anymore but I left it for now because gcc sometimes behaves unexpectedly without. Also: - configure: back to mode 100755 - tcc.h: remove unused variables tdata/tbss_section - x86_64-gen.c: adjust gfunc_sret for prototype
* i386: use __fixdfdi instead of __tcc_cvt_ftolgrischka2014-01-061-16/+12
| | | | | | | | | | | | 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
* Fix struct ret in variadic fct with ARM hardfloatThomas Preud'homme2014-01-061-1/+2
| | | | | | | | | | | | | The procedure calling standard for ARM architecture mandate the use of the base standard for variadic function. Therefore, hgen float aggregate must be returned via stack when greater than 4 bytes and via core registers else in case of variadic function. This patch improve gfunc_sret() to take into account whether the function is variadic or not and make use of gfunc_sret() return value to determine whether to pass a structure via stack in gfunc_prolog(). It also take advantage of knowing if a function is variadic or not move float result value from VFP register to core register in gfunc_epilog().
* Don't call __tcc_fpinit if using libgccThomas Preud'homme2014-01-061-0/+2
|
* Move logic for if (int value) to tccgen.cThomas Preud'homme2014-01-041-18/+1
| | | | | | | Move the logic to do a test of an integer value (ex if (0)) out of arch-specific code to tccgen.c to avoid code duplication. This also fixes test of long long value which was only testing the bottom half of such values on 32 bits architectures.
* Report error on NaN comparisonThomas Preud'homme2014-01-031-1/+4
| | | | | | | | Use comisd / fcompp for float comparison (except TOK_EQ and TOK_NE) instead of ucomisd / fucompp to detect NaN comparison. Thanks Vincent Lefèvre for the bug report and for also giving the solution.
* Fix "Add support for struct > 4B returned via registers"grischka2013-12-161-1/+1
| | | | | | | | | | | - avoid assumption "ret_align == register_size" which is false for non-arm targets - rename symbol "sret" to more descriptive "ret_nregs" This fixes commit dcec8673f21da86ae3dcf1ca3e9498127715b795 Also: - remove multiple definitions in win32/include/math.h
* Add support for struct > 4B returned via registersThomas Preud'homme2013-11-221-4/+5
| | | | | | | | On ARM with hardfloat calling convention, structure containing 4 fields or less of the same float type are returned via float registers. This means that a structure can be returned in up to 4 double registers in a structure is composed of 4 doubles. This commit adds support for return of structures in several registers.
* i386-gen: preserve fp control word in gen_cvt_ftoigrischka2013-08-281-63/+28
| | | | | | | | | | | | | | | | | | | | | | | - Use runtime function for conversion - Also initialize fp with tcc -run on windows This fixes a bug where double x = 1.0; double y = 1.0000000000000001; double z = x < y ? 0 : sqrt (x*x - y*y); caused a bad sqrt because rounding precision for the x < y comparison was different to the one used within the sqrt function. This also fixes a bug where printf("%d, %d", (int)pow(10, 2), (int)pow(10, 2)); would print 100, 99 Unrelated: win32: document relative include & lib lookup win32: normalize_slashes: do not mirror silly gcc behavior This reverts part of commit 8a81f9e1036637e21a47e14fb56bf64133546890 winapi: add missing WINAPI decl. for some functions
* Add support for load/store of _Bool valueThomas Preud'homme2013-06-141-1/+1
| | | | | Add support for loading _Bool value in i386, x86_64 and arm as well as support for storing _Bool value on arm.
* avoid "decl after statement" pleasegrischka2013-04-301-2/+5
| | | | for compiling tcc with msc
* Improved variable length array support.James Lyon2013-04-271-0/+39
| | | | | | | | | | | | | | | VLA storage is now freed when it goes out of scope. This makes it possible to use a VLA inside a loop without consuming an unlimited amount of memory. Combining VLAs with alloca() should work as in GCC - when a VLA is freed, memory allocated by alloca() after the VLA was created is also freed. There are some exceptions to this rule when using goto: if a VLA is in scope at the goto, jumping to a label will reset the stack pointer to where it was immediately after the last VLA was created prior to the label, or to what it was before the first VLA was created if the label is outside the scope of any VLA. This means that in some cases combining alloca() and VLAs will free alloca() memory where GCC would not.
* Fixed i386 calling convention issue and CMake build on i386.James Lyon2013-04-261-0/+8
| | | | | The i386 calling convention expects the callee to pop 1 word of the stack when performing a struct ret.
* Tests in abitest.c now work on Win32.James Lyon2013-04-181-8/+27
| | | | | | | I expect that Linux-x86 is probably fine. All other architectures except ARM are definitely broken since I haven't yet implemented gfunc_sret for these, although replicating the current behaviour should be straightforward.
* add version number to manpageUrs Janssen2013-02-171-1/+1
| | | | | | | avoid c++/c99 style comments in preprocessor directives avoid leadings whitespaces in preprocessor directives mention implemented variable length arrays in documentation fixed ambiguous option in texi2html call (Austin English)