Commit graph

13480 commits

Author SHA1 Message Date
Christoph Oelckers
6727301330 - moved all code related to function calls into the helper class so that all future work on the calling convention is in one place only. 2019-04-15 15:52:12 +02:00
Christoph Oelckers
a900390683 - moved all handling for the simple calls into EmitterArray to have it in one place only.
The main case of FxVmFunctionCall is not done yet, though.
2019-04-15 15:52:11 +02:00
Christoph Oelckers
054640ce41 - removed OP_TAIL.
The amount of support code for this minor optimization was quite large and this stood in the way of streamlining the VM's calling convention, so it was preferable to remove it before moving on.
2019-04-15 15:52:10 +02:00
Magnus Norddahl
33bef2183e - fix compile errors 2019-04-15 15:52:08 +02:00
Christoph Oelckers
ab689c0984 - fixed TArray's Append methods.
I mistakenly assumed that Grow would incease the array's reserved space.
2019-04-15 15:52:07 +02:00
Christoph Oelckers
e9a5f094c9 - changed OP_PARAM handling so that all registers remain allocated until the call instruction and reordered instruction emission so that the param instructions all directly precede the call instruction. 2019-04-15 15:48:37 +02:00
Christoph Oelckers
9380ccb922 - completed the Dehacked fix.
I missed some arguments that were specified but set to 'not given'.
2019-04-15 15:48:35 +02:00
Christoph Oelckers
f10c927850 - fixed: The Dehacked function wrappers now need full parameter lists. 2019-04-15 15:48:32 +02:00
Magnus Norddahl
783adc7be1 - disabled code that shows how a thunk function and native setup would look like 2019-04-15 15:48:31 +02:00
Christoph Oelckers
03001991f1 - fixed IJMP code generation for the JIT compiler.
With a proper count value available this can be done properly. The only relevant targets are the jumps immediately succeeding the IJMP instructions, nothing else.
2019-04-15 15:48:30 +02:00
Christoph Oelckers
f557c77602 - do not use instructions from too recent instruction set extensions.
andn is part of BMI1 which was introduced in 2012, which is far too recent to be used unchecked.
2019-04-15 15:48:29 +02:00
Christoph Oelckers
9456c877d4 - deconstruct A_Jump with multiple labels into A_Jump(chance, RandomPick(label1, label2, label3,...)) to remove this ugly special case from the VM calling convention.
This also adds the number of available choices to OP_IJMP.
2019-04-15 15:48:27 +02:00
Magnus Norddahl
44b89bba96 - inline ReadBarrier, GetClass and GetClassMeta 2019-04-15 15:48:25 +02:00
Christoph Oelckers
05fd4d8b62 - fixed RNG setup in FxRandom. 2019-04-15 15:48:24 +02:00
Christoph Oelckers
9d126954d1 - removed the default parameter handling from all native script functions because it is no longer needed.
# Conflicts:
#	src/p_actionfunctions.cpp

# Conflicts:
#	src/hwrenderer/postprocessing/hw_postprocessshader.cpp
#	src/v_2ddrawer.cpp
2019-04-15 14:59:00 +02:00
Christoph Oelckers
6d8cf38cef - fixed FxFRandom setup which used a path in FxRandom that is no longer supported. 2019-04-15 14:37:46 +02:00
Magnus Norddahl
075a666c75 - stop using lambda functions for CreateCall because MSVC lambas use a different calling convention and "converts" them to the right one by generating a thunk function 2019-04-15 14:37:44 +02:00
Magnus Norddahl
51900d5d98 - removed the SetupSimpleFrameMissingArgs logic as the number of args are now guaranteed 2019-04-15 14:37:43 +02:00
Magnus Norddahl
66a970059b - add warning text when falling back to the VM 2019-04-15 14:37:41 +02:00
Christoph Oelckers
7d2c4a05e2 - removed the unused 'no arguments' cases from the BuiltinRandom functions and split off BuiltinRandom2 into its own function.
This removes the last non-vararg cases where a native VM function checks 'numparam'. As of this commit all function calls will pass the complete list of arguments.
2019-04-15 14:37:40 +02:00
Magnus Norddahl
ac01af3ef0 - make functions using too many registers (more than 200) fall back to the VM 2019-04-15 14:37:38 +02:00
Christoph Oelckers
a0b4f5ad68 - always pass complete argument lists in the VM. 2019-04-15 14:37:37 +02:00
Christoph Oelckers
44eee13aa7 - build full argument lists for action function calls.
This uses one static global array to avoid frequent reallocations.
2019-04-15 14:37:35 +02:00
Christoph Oelckers
a371a8456a - implemented VMCallWithDefaults and used it for all calls with variable arguments.
This isn't used for the 3 action function calls because it requires an array allocation which would be a bit too costly for something as frequently called as action functions.
They will need a different approach.
2019-04-15 14:37:34 +02:00
Christoph Oelckers
29d7e11937 - fixed last commit. 2019-04-15 14:37:31 +02:00
Christoph Oelckers
28461de6ec - marked all places where an incomplete parameter list may be passed to the VM by a native call by redirecting VMCall to an intermediate VMCallWithDefaults. This function must later fill in the missing arguments from the default. 2019-04-15 14:37:30 +02:00
Christoph Oelckers
7fe33d336c Avoid using argument count for any kind of decision making in native VM functions.
This allows retaining the functionality, even if for the JIT compiler's benefit all default arguments are pushed onto the stack instead of reading them from the defaults array.

# Conflicts:
#	src/r_data/r_sections.h
2019-04-15 14:37:28 +02:00
Magnus Norddahl
2dd03270b2 - remove unused argument 2019-04-15 14:37:26 +02:00
Magnus Norddahl
fd955249fd - avoid calling VMFillParams for simple stack frames
- split Setup into more functions
2019-04-15 14:37:24 +02:00
Magnus Norddahl
5181106264 - add dword store to memset code 2019-04-15 14:37:23 +02:00
Magnus Norddahl
43cfedbd23 - disable jit in 32-bit builds 2019-04-15 14:37:21 +02:00
Magnus Norddahl
18258c6cd5 - fix wrong offsets 2019-04-15 14:37:20 +02:00
Magnus Norddahl
c9a20d56d1 - generate a memset for the allocated stack memory because that's what the VM does
(this really shouldn't be done by the VM either - the compiler backend should clear its registers if it wants them to be zero!)
2019-04-15 14:37:19 +02:00
Magnus Norddahl
8fd2bd1d51 - fix operand size mismatch error 2019-04-15 14:37:17 +02:00
Chronos Ouroboros
104f49e589 Fix the code for MODF_RK in the JIT compiler. 2019-04-15 14:37:16 +02:00
Chronos Ouroboros
c8e56f4dda Fixed the Vector2/3 != operator. 2019-04-15 14:37:14 +02:00
Chronos Ouroboros
c3c100bf9f Added support for CMP_APPROX to EQV_R and moved the code to a template. 2019-04-15 14:37:13 +02:00
Magnus Norddahl
b4db05a7ff - modify exception checks to jump ahead if the exception is to be thrown as it limits static misprediction 2019-04-15 14:37:11 +02:00
Magnus Norddahl
3504f48bfa - fix a typo 2019-04-15 14:37:10 +02:00
Magnus Norddahl
3f952e94cd - fix the throw messages 2019-04-15 14:37:09 +02:00
Christoph Oelckers
74d02811c7 - fixed vector math instructions to use the same order of operations as the VM. 2019-04-15 14:37:07 +02:00
Magnus Norddahl
64387abcce - add vm_jit cvar to control JIT compilation 2019-04-15 14:37:05 +02:00
Magnus Norddahl
87744b22ab - update JIT PARAM handling to match the VM instruction change 2019-04-15 14:37:04 +02:00
Magnus Norddahl
43a6fc7227 - RUNTIME_FUNCTION only exists in 64-bit Windows 2019-04-15 14:37:02 +02:00
Magnus Norddahl
a54dbec73a - fix wrong shift direction 2019-04-15 14:37:01 +02:00
Magnus Norddahl
bd1f529574 - build enough of the unwind opcodes for visual studio's debugger to produce the correct call stack 2019-04-15 14:36:59 +02:00
Magnus Norddahl
ea8725f03b - construct our own runtime as the one provided by asmjit is too primitive 2019-04-15 14:36:58 +02:00
Magnus Norddahl
89bf3f0455 - add more names to asmjit objects 2019-04-15 14:36:56 +02:00
Magnus Norddahl
7e9e823674 - remove the frameX registers as they were just constant offsets to vmframe that could be merged into other constant offsets 2019-04-15 14:36:55 +02:00
Magnus Norddahl
475510c8ea - give the remaining virtual registers names 2019-04-15 14:36:53 +02:00
Magnus Norddahl
68c05a424b - give temp registers names and reuse the FString object for formatting names 2019-04-15 14:36:52 +02:00
Magnus Norddahl
d48738437b - skip RESULT opcodes when outputting assembly 2019-04-15 14:36:51 +02:00
Magnus Norddahl
77850c1ec5 - clean up assembly output slightly by only generating labels for the opcodes jumped to 2019-04-15 14:36:49 +02:00
Magnus Norddahl
316010378d - fix CASTB opcode implementation 2019-04-15 14:36:48 +02:00
Magnus Norddahl
2c89d1e694 - fix missing convert from float to double in LSP and LSP_R opcodes
- fix missing convert from double to float in SSP and SSP_R opcodes
2019-04-15 14:36:46 +02:00
Magnus Norddahl
9b9113d0c4 - fix debug build compile error 2019-04-15 14:36:44 +02:00
Magnus Norddahl
7230974c1e - remove the need to do any VARF_Native runtime checks by making native functions use the same calling convention as the script version 2019-04-15 14:36:43 +02:00
Magnus Norddahl
ae6c7e541c - do script calls directly from asmjit without using a lambda wrapper
- do VARF_Native check at compile time when possible
2019-04-15 14:36:41 +02:00
Magnus Norddahl
37dfbba232 - add -dumpjit command line parameter that dumps the JIT log for all functions to dumpjit.txt
# Conflicts:
#	src/scripting/backend/vmbuilder.cpp
2019-04-15 14:36:39 +02:00
Magnus Norddahl
a60ac7b47d - fix return warning 2019-04-15 14:33:49 +02:00
Magnus Norddahl
e7f0b7a0bd - switch to using setjmp/longjmp for exception handling 2019-04-15 14:33:47 +02:00
Magnus Norddahl
b24ec1f9cc - add disabled code that attempts to load registers directly from function arguments 2019-04-15 14:33:46 +02:00
Magnus Norddahl
04ba3ede16 - add missing include statement 2019-04-15 14:33:44 +02:00
Magnus Norddahl
6db9b1394c - allocate VMFrame on the stack for simple functions with no strings 2019-04-15 14:33:43 +02:00
Magnus Norddahl
84d2de34f0 - remove argument not used anymore 2019-04-15 14:33:41 +02:00
Magnus Norddahl
f0c059678b - move VM creation into the jitted function. this will allow the jit compiler to skip vm frame creation when possible 2019-04-15 14:33:39 +02:00
Magnus Norddahl
baaed0920a - create ScriptCall function pointer on VMScriptFunction 2019-04-15 14:33:37 +02:00
Magnus Norddahl
03689cf004 - modify the VM calling convention so that the callee sets up its own VM frame 2019-04-15 14:33:35 +02:00
Magnus Norddahl
992c097ad1 - fix wrong registers getting saved when passing parameters by reference 2019-04-15 14:33:34 +02:00
Magnus Norddahl
19ae43be17 - removed CanJit as all opcodes are now implemented
- fix some store bugs
2019-04-15 14:33:32 +02:00
Magnus Norddahl
b3aeb37189 - fix 32 bit compile errors 2019-04-15 14:33:31 +02:00
Magnus Norddahl
e2dcca611c - catch and rethrow c++ exceptions 2019-04-15 14:33:29 +02:00
Magnus Norddahl
22e60d74ad - reuse temp virtual registers 2019-04-15 14:33:28 +02:00
Magnus Norddahl
80cda43370 - workaround bug in asmjit's register allocator for calls where the return register is already allocated in a physical register needed by one of the call arguments 2019-04-15 14:33:26 +02:00
Magnus Norddahl
bb3d0021d6 - switch ToMemAddress to imm_ptr where allowed 2019-04-15 14:33:25 +02:00
Magnus Norddahl
f90019561d - switch from ASMJIT_ARCH_X64 to ASMJIT_ARCH_64BIT when checking if we need to use 64-bit pointers 2019-04-15 14:33:23 +02:00
Magnus Norddahl
e0f0511d29 - create a very basic OP_IJMP implementation 2019-04-15 14:33:22 +02:00
Magnus Norddahl
812a4290b1 - create CreateCall helper to get rid of a lot of the cc.call boilerplate 2019-04-15 14:33:20 +02:00
Magnus Norddahl
ff6317d6f4 - implement OP_TAIL and OP_TAIL_K 2019-04-15 14:33:19 +02:00
Magnus Norddahl
be6637dd17 - use the ParamOpcodes array for finding the OP_PARAM's used by a call 2019-04-15 14:33:17 +02:00
Magnus Norddahl
f1f2dca792 - implement string version of OP_CAST 2019-04-15 14:33:16 +02:00
Magnus Norddahl
0cf5f3704b - implement string part of OP_CASTB 2019-04-15 14:33:14 +02:00
Magnus Norddahl
097de74510 - implement OP_LFP 2019-04-15 14:33:13 +02:00
Magnus Norddahl
7f996b5334 - read the parameters and registers directly off the stack 2019-04-15 14:33:11 +02:00
Jonathan Russell
ff421eda63 - changed a bunch of manual address additions in string opcodes to leas 2019-04-15 14:33:10 +02:00
Magnus Norddahl
b6521467f3 - more load fixes 2019-04-15 14:33:08 +02:00
Magnus Norddahl
e28389ad12 - fix truncated load addresses due to a bug in asmjit
- change ToMemAddress to use uint64_t
2019-04-15 14:33:06 +02:00
Magnus Norddahl
db0c516693 - avoid certain x86::ptr overloads as the last argument is not always an offset 2019-04-15 14:33:05 +02:00
Jonathan Russell
0da351bfea - fixed typo in last commit 2019-04-15 14:33:03 +02:00
Jonathan Russell
2dd2344e80 - implemented SS_R, LCS_R, and LKS_R 2019-04-15 14:33:02 +02:00
Magnus Norddahl
fb7df75011 - fix bug in LKF_R 2019-04-15 14:33:00 +02:00
Magnus Norddahl
d74cc3e49e - fixed OP_VTBL bug 2019-04-15 14:32:59 +02:00
Magnus Norddahl
e93d9570dc - fix crash in OP_RET handling 2019-04-15 14:32:57 +02:00
Magnus Norddahl
378e58731a - simplify some code 2019-04-15 14:32:56 +02:00
Jonathan Russell
b342dbc8db - added string PARAM and RET 2019-04-15 14:32:54 +02:00
Magnus Norddahl
608f49a4a8 - fix clang errors and warnings 2019-04-15 14:32:53 +02:00
Jonathan Russell
06780bf228 - added OP_MOVES, OP_CONCAT, OP_LENS, OP_CMPS 2019-04-15 14:32:52 +02:00
Magnus Norddahl
a4b3536caf - fix opcodes not being listed in jit debug assembly 2019-04-15 14:32:50 +02:00
Magnus Norddahl
c328f9c85c - move EmitRESULT to jit_call 2019-04-15 14:32:49 +02:00
Magnus Norddahl
ff8d21b2ec - minor cleanups in header file 2019-04-15 14:32:47 +02:00
Magnus Norddahl
9d970a1acb - split JitCompiler into multiple files 2019-04-15 14:32:46 +02:00
Jonathan Russell
8905701df7 - added strings and a few string opcodes 2019-04-15 14:32:44 +02:00
Magnus Norddahl
f3ca96373a - fix CALL_K and disable CALL 2019-04-15 14:32:43 +02:00
Magnus Norddahl
56fe7af9d3 - implement OP_CALL and OP_CALL_K 2019-04-15 14:32:41 +02:00
Magnus Norddahl
60ee2c91a4 - fix misc integer opcodes and remove mov statements when they have no effect 2019-04-15 14:32:40 +02:00
Jonathan Russell
279e97fcc9 - changed the way EmitComparisonOpcode works to get rid of the temporary register that was used previously 2019-04-15 14:32:38 +02:00
Magnus Norddahl
c248fad17f - implement PARAM and PARAMI 2019-04-15 14:32:37 +02:00
Magnus Norddahl
53b11dd0d8 - fix missing zero extend 2019-04-15 14:32:36 +02:00
Magnus Norddahl
29f6258d33 - fix that the code for META and CLSS was swapped 2019-04-15 14:32:34 +02:00
Magnus Norddahl
c2669d3a03 - some jump fixes 2019-04-15 14:32:33 +02:00
Magnus Norddahl
f7dd6a1313 - fix jump direction in EmitComparisonOpcode 2019-04-15 14:32:31 +02:00
Jonathan Russell
9530a2e43c - more spelling mistakes... 2019-04-15 14:32:29 +02:00
Jonathan Russell
a770b3af16 - fix minor spelling error 2019-04-15 14:32:28 +02:00
Jonathan Russell
821c336c5e - add vector comparison opcodes 2019-04-15 14:32:26 +02:00
Magnus Norddahl
14d6aa8cac - remove some macros and add functions checking if a register needs to be copied 2019-04-15 14:32:25 +02:00
Magnus Norddahl
35a8162022 - implemented LBIT, SBIT, VTBL, SCOPE, NEW, NEW_K, THROW, EQA_R and EQA_K 2019-04-15 14:32:23 +02:00
Magnus Norddahl
4cab630871 - implement emitter functions for LKP_R, META, CLSS, LO, LO_R, LP, LP_R, SO, SO_R, SP, SP_R
- add emit code for throwing exceptions on null pointers
2019-04-15 14:32:22 +02:00
Magnus Norddahl
2efaa7846d - improve jit debug output slightly 2019-04-15 14:32:20 +02:00
Magnus Norddahl
f0dbc8414a - fix offsetting bug when loading address registers 2019-04-15 14:32:19 +02:00
Magnus Norddahl
db78d02d79 - fix swapped operands in EmitSUBF_KR 2019-04-15 14:32:17 +02:00
Magnus Norddahl
ede8c6d86b - implement MODF_RR, MODF_RK and MODF_KR 2019-04-15 14:32:16 +02:00
Magnus Norddahl
708362b31f - fix mul using wrong instruction 2019-04-15 14:32:14 +02:00
Magnus Norddahl
c46a4d4483 - implement BOUND opcodes and add logging the resulting assembly code if asmjit throws an exception 2019-04-15 14:32:13 +02:00
Magnus Norddahl
c2938926a7 - implement a few more opcodes and fix some bugs 2019-04-15 14:32:11 +02:00
Magnus Norddahl
9427e22d7c - implemented pow, min, max 2019-04-15 14:32:10 +02:00
Magnus Norddahl
f4181be6b8 - implement ATAN2 and FLOP 2019-04-15 14:32:08 +02:00
Magnus Norddahl
77fe376eca - implement DYNCAST*, TEST, TESTN and JMP opcodes 2019-04-15 14:32:07 +02:00
Magnus Norddahl
9474a2554d - convert JitCompile's switch into a class to enable easier code reuse 2019-04-15 14:32:05 +02:00
Magnus Norddahl
9889d2fbb6 - fix clang compile error 2019-04-15 14:32:03 +02:00
Magnus Norddahl
976a7fab3a - implement throwing by storing exception information in a struct, then return from the jitted function and throw from c++ 2019-04-15 14:32:02 +02:00
Jonathan Russell
45bc0d266e - removed the ability to use printf-like formatting in emitAbortExceptionCall, it barely worked 2019-04-15 14:32:00 +02:00
Jonathan Russell
197b20af5d - add first draft of abort exceptions 2019-04-15 14:31:58 +02:00
Magnus Norddahl
c65b7076eb - call play sqrt when calculating lengths 2019-04-15 14:31:57 +02:00
Magnus Norddahl
50d0049460 - fix 8 and 16 bit store 2019-04-15 14:31:55 +02:00
Magnus Norddahl
76c08bf725 - destroy the jit runtime when all script functions are destroyed 2019-04-15 14:31:54 +02:00
Magnus Norddahl
4820c32794 - disable all unimplemented opcodes in the switch to ensure 'Unknown VM opcode' fatal error is generated if CanJit has a bug 2019-04-15 14:31:52 +02:00
Magnus Norddahl
e9914f38af Fix compile errors on macOS 2019-04-15 14:31:51 +02:00
Jonathan Russell
601c492cf2 - added remaining int arithmetic opcodes (and fixed float loading offset issue) 2019-04-15 14:31:49 +02:00
Jonathan Russell
e771064657 - forgot to turn off debug switch in last commit 2019-04-15 14:31:47 +02:00
Jonathan Russell
4228891da2 - made absMaskInt const 2019-04-15 14:31:46 +02:00
Jonathan Russell
8306815292 - implemented CMP_APPROX for OP_EQF_*, making ~== work for doubles 2019-04-15 14:31:44 +02:00
Chronos Ouroboros
e07af1428c Updated CanJit's supported opcodes list. 2019-04-15 14:31:43 +02:00
Chronos Ouroboros
63cda1c13d Pointer addition opcodes must leave NULL pointers as they are. 2019-04-15 14:31:41 +02:00
Chronos Ouroboros
3c8aa9f641 Changed binary int ops to use a temporary register, fixed some opcodes.
For some reason, binary ops might reuse one of the input registers as the output register.
This is a problem for very obvious reasons.
2019-04-15 14:31:39 +02:00
Jonathan Russell
62ece01c0a - made CMP_CHECK checking compile time 2019-04-15 14:31:37 +02:00
Jonathan Russell
f897f2bfd3 - added exact floating point comparison opcodes 2019-04-15 14:31:36 +02:00
Jonathan Russell
5846357268 - implemented all integer comparison operators 2019-04-15 14:31:34 +02:00
Jonathan Russell
166ce87a86 - adds OP_EQ_R, the first instruction using jumps 2019-04-15 14:31:33 +02:00
Magnus Norddahl
5c3ef8ac15 - add misc float opcodes 2019-04-15 14:31:31 +02:00
Jonathan Russell
b242ffdbbe - added most vector maths opcodes 2019-04-15 14:31:29 +02:00