From dc0adb533dc15a007e9ca2dc0533ef6a61f13393 Mon Sep 17 00:00:00 2001 From: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com> Date: Mon, 22 Feb 2021 03:23:48 +0100 Subject: PPTC & Pool Enhancements. (#1968) * PPTC & Pool Enhancements. * Avoid buffer allocations in CodeGenContext.GetCode(). Avoid stream allocations in PTC.PtcInfo. Refactoring/nits. * Use XXHash128, for Ptc.Load & Ptc.Save, x10 faster than Md5. * Why not a nice Span. * Added a simple PtcFormatter library for deserialization/serialization, which does not require reflection, in use at PtcJumpTable and PtcProfiler; improves maintainability and simplicity/readability of affected code. * Nits. * Revert #1987. * Revert "Revert #1987." This reverts commit 998be765cf7f7da5ff0c1c08de704c9012b0f49c. --- ARMeilleure/CodeGen/X86/CodeGenContext.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'ARMeilleure/CodeGen/X86/CodeGenContext.cs') diff --git a/ARMeilleure/CodeGen/X86/CodeGenContext.cs b/ARMeilleure/CodeGen/X86/CodeGenContext.cs index da147cca..fa726f2f 100644 --- a/ARMeilleure/CodeGen/X86/CodeGenContext.cs +++ b/ARMeilleure/CodeGen/X86/CodeGenContext.cs @@ -2,6 +2,7 @@ using ARMeilleure.CodeGen.RegisterAllocators; using ARMeilleure.Common; using ARMeilleure.IntermediateRepresentation; using ARMeilleure.Translation.PTC; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -301,15 +302,13 @@ namespace ARMeilleure.CodeGen.X86 { Assembler assembler = new Assembler(codeStream, _ptcInfo); - byte[] buffer; - for (int index = 0; index < _jumps.Count; index++) { Jump jump = _jumps[index]; - buffer = new byte[jump.JumpPosition - _stream.Position]; + Span buffer = new byte[jump.JumpPosition - _stream.Position]; - _stream.Read(buffer, 0, buffer.Length); + _stream.Read(buffer); _stream.Seek(_ptcDisabled ? ReservedBytesForJump : jump.InstSize, SeekOrigin.Current); codeStream.Write(buffer); @@ -324,13 +323,7 @@ namespace ARMeilleure.CodeGen.X86 } } - buffer = new byte[_stream.Length - _stream.Position]; - - _stream.Read(buffer, 0, buffer.Length); - - codeStream.Write(buffer); - - _ptcInfo?.WriteCode(codeStream); + _stream.CopyTo(codeStream); return codeStream.ToArray(); } -- cgit v1.2.3