From ffe451afe78d2802227e2b4891bcd6017022514a Mon Sep 17 00:00:00 2001 From: de4dot Date: Sat, 23 Feb 2019 12:15:10 +0100 Subject: [PATCH] Add IcedFeatures.Initialize() --- Iced/Intel/IcedFeatures.cs | 19 +++++++++++++++++++ README.md | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Iced/Intel/IcedFeatures.cs b/Iced/Intel/IcedFeatures.cs index 7e014a7f3..f66e3db3f 100644 --- a/Iced/Intel/IcedFeatures.cs +++ b/Iced/Intel/IcedFeatures.cs @@ -21,6 +21,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +using System.Runtime.CompilerServices; + namespace Iced.Intel { /// /// Gets the available features @@ -129,5 +131,22 @@ namespace Iced.Intel { #endif } } + + /// + /// Initializes some static constructors related to the decoder and instruction info. If those + /// static constructors are initialized, the jitter generates faster code since it doesn't have + /// to add runtime checks to see if those static constructors must be called. + /// + /// This method should be called before using the decoder and instruction info classes and + /// should *not* be called from the same method as any code that uses the decoder / instruction + /// info classes. Eg. call this method from Main() and decode instructions / get instruction info + /// in a method called by Main(). + /// + public static void Initialize() { +#if (!NO_DECODER32 || !NO_DECODER64) && !NO_DECODER + // The decoder already initializes this stuff, but when it's called, it's a little bit too late. + RuntimeHelpers.RunClassConstructor(typeof(Decoder).TypeHandle); +#endif + } } } diff --git a/README.md b/README.md index cad51a608..f7dcea6be 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Decoder: - `ByteArrayCodeReader` - `InstructionList` - `ConstantOffsets` +- `IcedFeatures.Initialize()` Formatters: @@ -73,6 +74,7 @@ namespace Iced.Examples { const int HEXBYTES_COLUMN_BYTE_LENGTH = 10; static void Main(string[] args) { + IcedFeatures.Initialize(); DecoderFormatterExample(); EncoderExample(); CreateInstructionsExample();