Commit graph

76 commits

Author SHA1 Message Date
gdkchan
9878fc2d3c
Implement inline memory load/store exclusive and ordered (#1413)
* Implement inline memory load/store exclusive

* Fix missing REX prefix on 8-bits CMPXCHG

* Increment PTC version due to bugfix

* Remove redundant memory checks

* Address PR feedback

* Increment PPTC version
2020-07-30 11:29:28 -03:00
gdkchan
57bb0abda3
Print guest stack trace on invalid memory access (#1407)
* Print guest stack trace on invalid memory access

* Improve XML docs
2020-07-30 23:16:41 +10:00
Ficture Seven
b3c051bbec
Use movd,movq for i32/64 VectorExtract %x, 0x0 (#1439)
* Use movd,movq for i32/64 VectorExtract %x, 0x0

* Increment PPTC interval version

* Use else-if instead

- Address gdkchan's feedback.
- Clean up Debug.Assert calls

* Inline `count` expression into Debug.Assert

Apparently the CoreCLR JIT will not eliminate this. :(
2020-07-30 15:52:26 +10:00
gdkchan
2678bf0010
PPTC version increment (#1427) 2020-07-25 20:01:57 +02:00
gdkchan
80d4199fb3
Refactor NativeContext (#1410)
* Refactor NativeContext

* Fix bugs

* Use correct counts

* Check index using register count constants
2020-07-24 16:13:14 -03:00
Valentin PONS
3af2ce74ec
Implements some 32-bit instructions (VBIC, VTST, VSRA) (#1192)
* Added some 32 bits instructions:

* VBIC
* VTST
* VSRA

* Incremented the PTC

* Add tests and fix implementation

* Fixed VBIC immediate opcode mapping

* Hey hey!

* Nit.

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
Co-authored-by: LDj3SNuD <dvitiello@gmail.com>
Co-authored-by: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com>
2020-07-19 15:11:58 -03:00
LDj3SNuD
56a61a5758
CPU: A32: Fix Vabs_V & Vneg_V (S8, S16, S32 & F32); add Tests. (#1394)
* Fix Vabs_V & Vneg_V (S8, S16, S32 & F32); add Tests.

* Update Ptc.cs
2020-07-17 10:57:49 -03:00
LDj3SNuD
88619d71b8
CPU: A32: Add Vadd & Vsub Wide (S/U_8/16/32) Inst.s with Test. (#1390) 2020-07-17 14:21:40 +10:00
Ficture Seven
863b0c8dcb
Fix Decode exception condition (#1377) 2020-07-15 17:48:16 +10:00
LDj3SNuD
a804db6eed
Add Fmax/minv_V & S/Ushl_S Inst.s with Tests. Fix Maxps/d & Minps/d d… (#1335)
* Add Fmax/minv_V & S/Ushl_S Inst.s with Tests. Fix Maxps/d & Minps/d double zero sign handling. Allows better handling of NaNs.

* Optimized EmitSse2VectorIsNaNOpF() for multiple uses per opF.
2020-07-13 21:08:47 +10:00
riperiperi
d7044b10a2
Add SSE4.2 Path for CRC32, add A32 variant, add tests for non-castagnoli variants. (#1328)
* Add CRC32 A32 instructions.

* Fix CRC32 instructions.

* Add CRC intrinsic and fast path.

Loop is currently unrolled, will look into adding temp vars after tests are added.

* Begin work on Crc tests

* Fix SSE4.2 path for CRC32C, finialize tests.

* Remove unused IR path.

* Fix spacing between prefix checks.

* This should be Src.

* PTC Version

* OpCodeTable Order

* Integer check improvement. Value and Crc can be either 32 or 64 size.

* This wasn't necessary...

* If size is 3, value type must be I64.

* Fix same src+dest handling for non crc intrinsics.

* Pre-fix (ha) issue with vex encodings
2020-07-13 20:48:14 +10:00
Ficture Seven
30d4f752f4
Fix Node Uses/Assignments (#1376)
* Fix Node Uses/Assignments

* Bump PPTC Version Number

Co-authored-by: jduncanator <1518948+jduncanator@users.noreply.github.com>
2020-07-13 20:20:07 +10:00
Ficture Seven
b5127131c5
Fix folding of ConvertI64ToI32 imm64 (#1383)
* Fix folding of ConvertI64ToI32 imm64

* Increment PTC internal version

* Clean up
2020-07-13 19:10:33 +10:00
gdkchan
38b26cf424
Mask shift constants on x86 backend (#1382)
* Mask shift constants on x86 backendd

* Version bump
2020-07-11 15:52:38 +10:00
Ficture Seven
0195d0938d
Fold ZeroExtend8/16/32 imm32/64 (#1358)
* Fold ZeroExtend8/16/32 imm32/64

* Increment PTC version
2020-07-11 11:00:41 +10:00
Ficture Seven
7639bb2e86
Fold ConvertI64ToI32 imm64 (#1359)
* Fold ConvertI64ToI32 imm64

* Increment PTC version

* Bump PPTC InternalVersion

Co-authored-by: jduncanator <1518948+jduncanator@users.noreply.github.com>
2020-07-11 10:35:38 +10:00
LDj3SNuD
c050994995
Fix PPTC on Windows 7. (#1369)
* Fix PPTC on Windows 7.

* Address gdkchan comment.
2020-07-09 10:45:24 +10:00
riperiperi
9a49f8aec9
Fix VMVN (immediate), Add VPMIN, VPMAX, VMVN (register) (#1303)
* Add Vmvn (register), tests for both Vmvn variants.

* Add Vpmin, Vpmax, improve Non-FastFp accuracy for Vpadd

* Rebase on top of PTC.

* Add Nopcode

* Increment PTC version.

* Fix nits.
2020-06-24 10:43:44 +10:00
Thog
05c63f3061
Increment PTC version (#1311)
Fix issues caused by 2421186d97
2020-06-18 13:41:00 +02:00
Ficture Seven
2421186d97
Generalize tail continues (#1298)
* Generalize tail continues

* Fix DecodeBasicBlock

`Next` and `Branch` would be null, which is not the state expected by
the branch instructions. They end up branching or falling into a block
which is never populated by the `Translator`. This causes an assert to
be fired when building the CFG.

* Clean up Decode overloads

* Do not synchronize when branching into exit block

If we're branching into an exit block, that exit block will tail
continue into another translation which already has a synchronization.

* Remove A32 predicate tail continue

If `block` is not an exit block then the `block.Next` must exist (as
per the last instruction of `block`).

* Throw if decoded 0 blocks

Address gdkchan's feedback

* Rebuild block list instead of setting to null

Address gdkchan's feedback
2020-06-18 13:37:21 +10:00
LDj3SNuD
5e724cf24e
Add Profiled Persistent Translation Cache. (#769)
* Delete DelegateTypes.cs

* Delete DelegateCache.cs

* Add files via upload

* Update Horizon.cs

* Update Program.cs

* Update MainWindow.cs

* Update Aot.cs

* Update RelocEntry.cs

* Update Translator.cs

* Update MemoryManager.cs

* Update InstEmitMemoryHelper.cs

* Update Delegates.cs

* Nit.

* Nit.

* Nit.

* 10 fewer MSIL bytes for us

* Add comment. Nits.

* Update Translator.cs

* Update Aot.cs

* Nits.

* Opt..

* Opt..

* Opt..

* Opt..

* Allow to change compression level.

* Update MemoryManager.cs

* Update Translator.cs

* Manage corner cases during the save phase. Nits.

* Update Aot.cs

* Translator response tweak for Aot disabled. Nit.

* Nit.

* Nits.

* Create DelegateHelpers.cs

* Update Delegates.cs

* Nit.

* Nit.

* Nits.

* Fix due to #784.

* Fixes due to #757 & #841.

* Fix due to #846.

* Fix due to #847.

* Use MethodInfo for managed method calls.

Use IR methods instead of managed methods about Max/Min (S/U).
Follow-ups & Nits.

* Add missing exception messages.

Reintroduce slow path for Fmov_Vi.
Implement slow path for Fmov_Si.

* Switch to the new folder structure.

Nits.

* Impl. index-based relocation information. Impl. cache file version field.

* Nit.

* Address gdkchan comments.

Mainly:
- fixed cache file corruption issue on exit; - exposed a way to disable AOT on the GUI.

* Address AcK77 comment.

* Address Thealexbarney, jduncanator & emmauss comments.

Header magic, CpuId (FI) & Aot -> Ptc.

* Adaptation to the new application reloading system.

Improvements to the call system of managed methods.
Follow-ups.
Nits.

* Get the same boot times as on master when PTC is disabled.

* Profiled Aot.

* A32 support (#897).

* #975 support (1 of 2).

* #975 support (2 of 2).

* Rebase fix & nits.

* Some fixes and nits (still one bug left).

* One fix & nits.

* Tests fix (by gdk) & nits.

* Support translations not only in high quality and rejit.

Nits.

* Added possibility to skip translations and continue execution, using `ESC` key.

* Update SettingsWindow.cs

* Update GLRenderer.cs

* Update Ptc.cs

* Disabled Profiled PTC by default as requested in the past by gdk.

* Fix rejit bug. Increased number of parallel translations. Add stack unwinding stuffs support (1 of 2).

Nits.

* Add stack unwinding stuffs support (2 of 2). Tuned number of parallel translations.

* Restored the ability to assemble jumps with 8-bit offset when Profiled PTC is disabled or during profiling.

Modifications due to rebase.
Nits.

* Limited profiling of the functions to be translated to the addresses belonging to the range of static objects only.

* Nits.

* Nits.

* Update Delegates.cs

* Nit.

* Update InstEmitSimdArithmetic.cs

* Address riperiperi comments.

* Fixed the issue of unjustifiably longer boot times at the second boot than at the first boot, measured at the same time or reference point and with the same number of translated functions.

* Implemented a simple redundant load/save mechanism.

Halved the value of Decoder.MaxInstsPerFunction more appropriate for the current performance of the Translator.
Replaced by Logger.PrintError to Logger.PrintDebug in TexturePool.cs about the supposed invalid texture format to avoid the spawn of the log.
Nits.

* Nit.

Improved Logger.PrintError in TexturePool.cs to avoid log spawn.
Added missing code for FZ handling (in output) for fp max/min instructions (slow paths).

* Add configuration migration for PTC

Co-authored-by: Thog <me@thog.eu>
2020-06-16 20:28:02 +02:00
riperiperi
fa286d3535
VABS takes one input register, not two. (#1300) 2020-06-14 10:32:21 +10:00
merry
f8cd072b62
Faster crc32 implementation (#1294)
* Add Pclmulqdq intrinsic

* Implement crc32 in terms of pclmulqdq

* Address PR comments
2020-06-05 20:58:27 +10:00
LDj3SNuD
83d94b21d0
Add FMaxNmV & FMinNmV Inst.s with Test. (#1279)
Successful unit testing on Windows (debug and release mode).
2020-05-27 18:51:59 +02:00
mageven
6416bc1938
Implement CNTVCT_EL0 (#1268)
* Implement CNTVCT_EL0

* Fix comment
2020-05-23 12:15:59 +02:00
LDj3SNuD
3b70a28087
Unwinding Follow-up. Fix a bug in JitUnwindWindows where ... (#1238)
... in case of "Vector" unwind codes the remaining unwind codes could be corrupted.
Nits.
2020-05-15 13:46:35 +02:00
Thog
378259a40a
Surface Flinger: Implement GetBufferHistory (#1232)
* Surface Flinger: Implement GetBufferHistory

Also fix some bugs on the Surface Flinger implementation

* Address Ac_K's comment
2020-05-15 03:30:08 +02:00
Ficture Seven
430a48338b
Fix RET Xn translation (#1242) 2020-05-14 14:50:35 +10:00
gdkchan
96c7988671
Remove CpuId IR instruction (#1227) 2020-05-13 15:30:21 +10:00
Ficture Seven
4b79b78b8c
Fix tailcall case in EmitterContext (#1235) 2020-05-11 10:04:52 +10:00
mageven
492bb6ee5f
Suppress CS0169 CS0649 warns from HID structs (#1222)
Also fix typo in a pragma restore in Logger
2020-05-10 16:02:41 +02:00
Ac_K
4c54f36c38
Upgrade projects to C#8 (#1193)
Some parts of our code needs C# 8 who isn't set as default in Visual Studio. To fix this we have to set the C# version correctly in the csproj files and then we are be able to build the project using Visual Studio.
2020-05-04 12:14:48 +10:00
Ficture Seven
180ad8605d
Improve IRDumper (#1135)
* Improve IRDumper

* Make Symbols.Add(ulong, ulong, ulong, string) thread safe

* Use a StringBuilder for MemoryOperand

* Add #if M_DEBUG guards

* Fix JMP_TABLE typo

* Fix using in Symbols

* Use Conditional("M_DEBUG") instead

Address gdkchan's feedback

* Use a struct instead of 4-tuple

Address gdkchan's feedback

* Place symbols in comments instead

Address gdkchan's feedback

* Use StringBuilder throughout

* Handle offsetted symbols

* Fix naming convention of Builder

* Avoid ArgumentException

* Remove unnecessary using

* Use switch expression instead

* Turn into a class

* Clean up

* Remove unnecessary using
2020-05-04 12:06:22 +10:00
gdkchan
f77694e4f7
Implement a new physical memory manager and replace DeviceMemory (#856)
* Implement a new physical memory manager and replace DeviceMemory

* Proper generic constraints

* Fix debug build

* Add memory tests

* New CPU memory manager and general code cleanup

* Remove host memory management from CPU project, use Ryujinx.Memory instead

* Fix tests

* Document exceptions on MemoryBlock

* Fix leak on unix memory allocation

* Proper disposal of some objects on tests

* Fix JitCache not being set as initialized

* GetRef without checks for 8-bits and 16-bits CAS

* Add MemoryBlock destructor

* Throw in separate method to improve codegen

* Address PR feedback

* QueryModified improvements

* Fix memory write tracking not marking all pages as modified in some cases

* Simplify MarkRegionAsModified

* Remove XML doc for ghost param

* Add back optimization to avoid useless buffer updates

* Add Ryujinx.Cpu project, move MemoryManager there and remove MemoryBlockWrapper

* Some nits

* Do not perform address translation when size is 0

* Address PR feedback and format NativeInterface class

* Remove ghost parameter description

* Update Ryujinx.Cpu to .NET Core 3.1

* Address PR feedback

* Fix build

* Return a well defined value for GetPhysicalAddress with invalid VA, and do not return unmapped ranges as modified

* Typo
2020-05-04 08:54:50 +10:00
Ficture Seven
71dbb38b9a
Do not compute dominance information when not in SSA (#1176) 2020-05-01 23:15:55 +02:00
gdkchan
fe5bb439f1
Do temp constant copy for CompareAndSwap, other improvements to PreAllocator (#1126)
* Do temp constant copy for CompareAndSwap, other improvements to PreAllocator

* Nit
2020-04-25 23:00:54 +10:00
Michael Kuklinski
c46edfab85
Update .NET Core to 3.1, and update NuGet Packages (#1121)
* Updated all NuGet packages to latest, and updated the framework from .NET Core 3.0 to 3.1.

* Updating appveyor settings for 3.1

Updating appveyor to use the netcoreapp3.1 path instead of 3.0.

* Removing unneeded NuGet package System.Runtime.CompilerServices.Unsafe.

* Removing unused NuGet package SharpFontCore.

* Removing unused NuGet package TimeZoneConverter.Posix

* Cleaning up by adding newline to a csproj.

* Simplfying a NuGet conditional include, and adding a warning disable for an annoying NuGet package.

* I'm not sure if .travis.yml is still used, but I'm updating its 'dotnet' version to the correct SDK.

* Making the runtime version into its own environment variable so it's a bit easier to change in the future.

* Removing OpenTK.NetStandard reference from Ryujinx.Common

* Fixing indentation in Common.csproj

* Updating the README to specify .NET Core 3.1.

* Reverting the update of the GTKSharp package so it doesn't block the PR.
2020-04-22 14:13:41 +10:00
Cristallix
4738113f29
Suppress warnings from fields never used or never assigned (CS0169 and CS0649) (#919)
* chore : disable unwanted warnings and minor code cleanup

* chore : remove more warnings

* fix : reorder struct correctly

* fix : restore _isKernel and remove useless comment

* fix : copy/paste error

* fix : restore CallMethod call

* fix : whitespace

* chore : clean using

* feat : remove warnings

* fix : simplify warning removal on struct

* fix : revert fields deletion and code clean up

* fix : re-add RE value

* fix : typo
2020-04-21 07:59:59 +10:00
Ficture Seven
ca8745fc8e
Avoid temporaries when pre-allocating Store %x, imm8/16/32 (#1123) 2020-04-20 22:40:13 +10:00
Ficture Seven
e4ee61d6c3
Improve V128 (#1097)
* Improve V128

* Use LayoutKind.Sequential instead

* Add As<T>, Get<T> & Set<T>

* Fix CpuTest

* Rename Get<T> & Set<T> to Extract<T> & Insert<T>

* Add XML documentation

* Nit
2020-04-17 08:19:20 +10:00
Ficture Seven
496db602ff
Optimize %x ^ %x = 0 (#1094)
* JIT: Optimize %x ^ %x = 0

* Address feedback

* Fix typo
2020-04-09 09:36:19 +10:00
riperiperi
e99e6d0ad1
Use the jump table for HighCq tail continues. (#1088)
* Use the jump table for tail continues.

This path is always reached when a function larger than our current length limit (currently 5000) is compiled.

* Use Call Flag rather than 1L
2020-04-04 19:05:11 +11:00
riperiperi
f695a215ad
Add Fast Paths for Crypto instructions (A32/A64) (#1026)
* Add Fast Paths for Crypto instructions (A32/A64)

* Replace additional XOR with passing in const zero.
2020-03-25 17:20:29 +11:00
LDj3SNuD
1de16f7653
Add Fcvtas_S/V & Fcvtau_S/V. (#1018) 2020-03-24 22:53:49 +01:00
Chenj168
31b94f4641
Move the MakeOp to OpCodeTable class, for reduce the use of ConcurrentDictionary (#996) 2020-03-20 15:15:37 +11:00
Chenj168
561d64e5bf
Modify TranslatedFunction.GetPointer () to optimize performance (#995)
* add local var to reduce calling Marshal.GetFunctionPointerForDelegate

* modify code style
2020-03-20 09:11:20 +11:00
riperiperi
8226997bc7
CodeGen Optimisations (LSRA and Translator) (#978)
* Start of JIT garbage collection improvements

- thread static pool for Operand, MemoryOperand, Operation
- Operands and Operations are always to be constructed via their static
helper classes, so they can be pooled.
- removing LinkedList from Node for sources/destinations (replaced with
List<>s for now, but probably could do arrays since size is bounded)
- removing params constructors from Node
- LinkedList<> to List<> with Clear() for Operand assignments/uses
- ThreadStaticPool is very simple and basically just exists for the
purpose of our specific translation allocation problem. Right now it
will stay at the worst case allocation count for that thread (so far) -
the pool can never shrink.

- Still some cases of Operand[] that haven't been removed yet. Will need
to evaluate them (eg. is there a reasonable max number of params for
Calls?)

* ConcurrentStack instead of ConcurrentQueue for Rejit

* Optimize some parts of LSRA

- BitMap now operates on 64-bit int rather than 32-bit
- BitMap is now pooled in a ThreadStatic pool (within lrsa)
- BitMap now is now its own iterator. Marginally speeds up iterating
through the bits.
- A few cases where enumerators were generated have been converted to
forms that generate less garbage.
- New data structure for sorting _usePositions in LiveIntervals. Much
faster split, NextUseAfter, initial insertion. Random insertion is
slightly slower.
- That last one is WIP since you need to insert the values backwards. It
would be ideal if it just flipped it for you, uncomplicating things on
the caller side.

* Use a static pool of thread static pools. (yes.)

Prevents each execution thread creating its own lowCq pool and making me cry.

* Move constant value to top, change naming convention.

* Fix iteration of memory operands.

* Increase max thread count.

* Address Feedback
2020-03-18 22:44:32 +11:00
riperiperi
dd433c1296
Implement AESMC, AESIMC, AESE, AESD and VEOR AArch32 instructions (#982)
* Add VEOR and AES instructions.

* Add tests for crypto instructions.

* Update ValueSource name.
2020-03-14 10:29:58 +11:00
riperiperi
d904706fc0
Use a Jump Table for direct and indirect calls/jumps, removing transitions to managed (#975)
* Implement Jump Table for Native Calls

NOTE: this slows down rejit considerably! Not recommended to be used
without codegen optimisation or AOT.

- Does not work on Linux
- A32 needs an additional commit.

* A32 Support

(WIP)

* Actually write Direct Call pointers to the table

That would help.

* Direct Calls: Rather than returning to the translator, attempt to keep within the native stack frame.

A return to the translator can still happen, but only by exceptionally
bubbling up to it.

Also:
- Always translate lowCq as a function. Faster interop with the direct
jumps, and this will be useful in future if we want to do speculative
translation.
- Tail Call Detection: after the decoding stage, detect if we do a tail
call, and avoid translating into it. Detected if a jump is made to an
address outwith the contiguous sequence of blocks surrounding the entry
point. The goal is to reduce code touched by jit and rejit.

* A32 Support

* Use smaller max function size for lowCq, fix exceptional returns

When a return has an unexpected value and there is no code block
following this one, we now return the value rather than continuing.

* CompareAndSwap (buggy)

* Ensure CompareAndSwap does not get optimized away.

* Use CompareAndSwap to make the dynamic table thread safe.

* Tail call for linux, throw on too many arguments.

* Combine CompareAndSwap 128 and 32/64.

They emit different IR instructions since their PreAllocator behaviour
is different, but now they just have one function on EmitterContext.

* Fix issues separating from optimisations.

* Use a stub to find and execute missing functions.

This allows us to skip doing many runtime comparisons and branches, and reduces the amount of code we need to emit significantly.

For the indirect call table, this stub also does the work of moving in the highCq address to the table when one is found.

* Make Jump Tables and Jit Cache dynmically resize

Reserve virtual memory, commit as needed.

* Move TailCallRemover to its own class.

* Multithreaded Translation (based on heuristic)

A poor one, at that. Need to get core count for a better one, which
means a lot of OS specific garbage.

* Better priority management for background threads.

* Bound core limit a bit more

Past a certain point the load is not paralellizable and starts stealing from the main thread. Likely due to GC, memory, heap allocation thread contention. Reduce by one core til optimisations come to improve the situation.

* Fix memory management on linux.

* Temporary solution to some sync problems.

This will make sure threads exit correctly, most of the time. There is a potential race where setting the sync counter to 0 does nothing (counter stays at what it was before, thread could take too long to exit), but we need to find a better way to do this anyways. Synchronization frequency has been tightened as we never enter blockwise segments of code. Essentially this means, check every x functions or loop iterations, before lowcq blocks existed and were worth just as much. Ideally it should be done in a better way, since functions can be anywhere from 1 to 5000 instructions. (maybe based on host timer, or an interrupt flag from a scheduler thread)

* Address feedback minus CompareAndSwap change.

* Use default ReservedRegion granularity.

* Merge CompareAndSwap with its V128 variant.

* We already got the source, no need to do it again.

* Make sure all background translation threads exit.

* Fix CompareAndSwap128

Detection criteria was a bit scuffed.

* Address Comments.
2020-03-12 14:20:55 +11:00
gdkchan
c26f3774bd
Implement VMULL, VMLSL, VRSHR, VQRSHRN, VQRSHRUN AArch32 instructions + other fixes (#977)
* Implement VMULL, VMLSL, VQRSHRN, VQRSHRUN AArch32 instructions plus other fixes

* Re-align opcode table

* Re-enable undefined, use subclasses to fix checks

* Add test and fix VRSHR instruction

* PR feedback
2020-03-11 11:49:27 +11:00