/* Copyright (C) 2018 de4dot@gmail.com This file is part of Iced. Iced is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Iced is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Iced. If not, see . */ using System; using System.Diagnostics; namespace Iced.Intel { /// /// Size of a memory reference /// public enum MemorySize { /// /// Unknown size or the instruction doesn't reference the memory (eg. lea) /// Unknown, /// /// Memory location contains a /// UInt8, /// /// Memory location contains a /// UInt16, /// /// Memory location contains a /// UInt32, /// /// Memory location contains a 52-bit unsigned integer /// UInt52, /// /// Memory location contains a /// UInt64, /// /// Memory location contains a uint128 /// UInt128, /// /// Memory location contains a uint256 /// UInt256, /// /// Memory location contains a uint512 /// UInt512, /// /// Memory location contains a /// Int8, /// /// Memory location contains a /// Int16, /// /// Memory location contains a /// Int32, /// /// Memory location contains a /// Int64, /// /// Memory location contains a int128 /// Int128, /// /// Memory location contains a int256 /// Int256, /// /// Memory location contains a int512 /// Int512, /// /// Memory location contains a seg:ptr pair, (offset) + (segment/selector) /// SegPtr16, /// /// Memory location contains a seg:ptr pair, (offset) + (segment/selector) /// SegPtr32, /// /// Memory location contains a seg:ptr pair, (offset) + (segment/selector) /// SegPtr64, /// /// Memory location contains a 16-bit offset (jmp/call word ptr [mem]) /// WordOffset, /// /// Memory location contains a 32-bit offset (jmp/call dword ptr [mem]) /// DwordOffset, /// /// Memory location contains a 64-bit offset (jmp/call qword ptr [mem]) /// QwordOffset, /// /// Memory location contains two s (16-bit bound) /// Bound16_WordWord, /// /// Memory location contains two s (32-bit bound) /// Bound32_DwordDword, /// /// 32-bit bndmov, 2 x uint32 /// Bnd32, /// /// 64-bit bndmov, 2 x uint64 /// Bnd64, /// /// Memory location contains a 16-bit limit and a 24-bit address (eg. lgdtw) /// Fword5, /// /// Memory location contains a 16-bit limit and a 32-bit address (eg. lgdtd) /// Fword6, /// /// Memory location contains a 16-bit limit and a 64-bit address (eg. lgdtq) /// Fword10, /// /// Memory location contains an 16-bit floating point value /// Float16, /// /// Memory location contains a /// Float32, /// /// Memory location contains a /// Float64, /// /// Memory location contains an 80-bit floating point value /// Float80, /// /// Memory location contains a float128 /// Float128, /// /// Memory location contains a 14-byte FPU environment (16-bit fldenv/fstenv) /// FpuEnv14, /// /// Memory location contains a 28-byte FPU environment (32/64-bit fldenv/fstenv) /// FpuEnv28, /// /// Memory location contains a 94-byte FPU environment (16-bit fsave/frstor) /// FpuState94, /// /// Memory location contains a 108-byte FPU environment (32/64-bit fsave/frstor) /// FpuState108, /// /// Memory location contains 512-bytes of fxsave/fxrstor data /// Fxsave_512Byte, /// /// Memory location contains 512-bytes of fxsave64/fxrstor64 data /// Fxsave64_512Byte, /// /// 32-bit XSAVE area /// Xsave, /// /// 64-bit XSAVE area /// Xsave64, /// /// Memory location contains a 10-byte bcd value (fbld/fbstp) /// Bcd, /// /// 16 bit location: 2 x uint8 /// Packed16_UInt8, /// /// 16 bit location: 2 x int8 /// Packed16_Int8, /// /// 32 bit location: 4 x uint8 /// Packed32_UInt8, /// /// 32 bit location: 4 x int8 /// Packed32_Int8, /// /// 32 bit location: 2 x uint16 /// Packed32_UInt16, /// /// 32 bit location: 2 x int16 /// Packed32_Int16, /// /// 64-bit location: 8 x uint8 /// Packed64_UInt8, /// /// 64-bit location: 8 x int8 /// Packed64_Int8, /// /// 64-bit location: 4 x uint16 /// Packed64_UInt16, /// /// 64-bit location: 4 x int16 /// Packed64_Int16, /// /// 64-bit location: 2 x uint32 /// Packed64_UInt32, /// /// 64-bit location: 2 x int32 /// Packed64_Int32, /// /// 64-bit location: 4 x float16 /// Packed64_Float16, /// /// 64-bit location: 2 x float32 /// Packed64_Float32, /// /// 128 bit location: 16 x uint8 /// Packed128_UInt8, /// /// 128 bit location: 16 x int8 /// Packed128_Int8, /// /// 128 bit location: 8 x uint16 /// Packed128_UInt16, /// /// 128 bit location: 8 x int16 /// Packed128_Int16, /// /// 128 bit location: 4 x uint32 /// Packed128_UInt32, /// /// 128 bit location: 4 x int32 /// Packed128_Int32, /// /// 128 bit location: 2 x uint52 /// Packed128_UInt52, /// /// 128 bit location: 2 x uint64 /// Packed128_UInt64, /// /// 128 bit location: 2 x int64 /// Packed128_Int64, /// /// 128 bit location: 8 x float16 /// Packed128_Float16, /// /// 128 bit location: 4 x float32 /// Packed128_Float32, /// /// 128 bit location: 2 x float64 /// Packed128_Float64, /// /// 256 bit location: 32 x uint8 /// Packed256_UInt8, /// /// 256 bit location: 32 x int8 /// Packed256_Int8, /// /// 256 bit location: 16 x uint16 /// Packed256_UInt16, /// /// 256 bit location: 16 x int16 /// Packed256_Int16, /// /// 256 bit location: 8 x uint32 /// Packed256_UInt32, /// /// 256 bit location: 8 x int32 /// Packed256_Int32, /// /// 256 bit location: 4 x uint52 /// Packed256_UInt52, /// /// 256 bit location: 4 x uint64 /// Packed256_UInt64, /// /// 256 bit location: 4 x int64 /// Packed256_Int64, /// /// 256 bit location: 2 x uint128 /// Packed256_UInt128, /// /// 256 bit location: 2 x int128 /// Packed256_Int128, /// /// 256 bit location: 16 x float16 /// Packed256_Float16, /// /// 256 bit location: 8 x float32 /// Packed256_Float32, /// /// 256 bit location: 4 x float64 /// Packed256_Float64, /// /// 256 bit location: 2 x float128 /// Packed256_Float128, /// /// 512 bit location: 64 x uint8 /// Packed512_UInt8, /// /// 512 bit location: 64 x int8 /// Packed512_Int8, /// /// 512 bit location: 32 x uint16 /// Packed512_UInt16, /// /// 512 bit location: 32 x int16 /// Packed512_Int16, /// /// 512 bit location: 16 x uint32 /// Packed512_UInt32, /// /// 512 bit location: 16 x int32 /// Packed512_Int32, /// /// 512 bit location: 8 x uint52 /// Packed512_UInt52, /// /// 512 bit location: 8 x uint64 /// Packed512_UInt64, /// /// 512 bit location: 8 x int64 /// Packed512_Int64, /// /// 256 bit location: 4 x uint128 /// Packed512_UInt128, /// /// 512 bit location: 16 x float32 /// Packed512_Float32, /// /// 512 bit location: 8 x float64 /// Packed512_Float64, /// /// Broadcast uint32 to 64 bits /// Broadcast64_UInt32, /// /// Broadcast int32 to 64 bits /// Broadcast64_Int32, /// /// Broadcast float32 to 64 bits /// Broadcast64_Float32, /// /// Broadcast uint32 to 128 bits /// Broadcast128_UInt32, /// /// Broadcast int32 to 128 bits /// Broadcast128_Int32, /// /// Broadcast uint52 to 128 bits /// Broadcast128_UInt52, /// /// Broadcast uint64 to 128 bits /// Broadcast128_UInt64, /// /// Broadcast int64 to 128 bits /// Broadcast128_Int64, /// /// Broadcast float32 to 128 bits /// Broadcast128_Float32, /// /// Broadcast float64 to 128 bits /// Broadcast128_Float64, /// /// Broadcast uint32 to 256 bits /// Broadcast256_UInt32, /// /// Broadcast int32 to 256 bits /// Broadcast256_Int32, /// /// Broadcast uint52 to 256 bits /// Broadcast256_UInt52, /// /// Broadcast uint64 to 256 bits /// Broadcast256_UInt64, /// /// Broadcast int64 to 256 bits /// Broadcast256_Int64, /// /// Broadcast float32 to 256 bits /// Broadcast256_Float32, /// /// Broadcast float64 to 256 bits /// Broadcast256_Float64, /// /// Broadcast uint32 to 512 bits /// Broadcast512_UInt32, /// /// Broadcast int32 to 512 bits /// Broadcast512_Int32, /// /// Broadcast uint52 to 512 bits /// Broadcast512_UInt52, /// /// Broadcast uint64 to 512 bits /// Broadcast512_UInt64, /// /// Broadcast int64 to 512 bits /// Broadcast512_Int64, /// /// Broadcast float32 to 512 bits /// Broadcast512_Float32, /// /// Broadcast float64 to 512 bits /// Broadcast512_Float64, } #if !NO_INSTR_INFO /// /// extension methods /// public static class MemorySizeExtensions { internal static readonly MemorySizeInfo[] MemorySizeInfos = new MemorySizeInfo[DecoderConstants.NumberOfMemorySizes] { new MemorySizeInfo(MemorySize.Unknown, 0, 0, MemorySize.Unknown, false, false), new MemorySizeInfo(MemorySize.UInt8, 1, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.UInt16, 2, 2, MemorySize.UInt16, false, false), new MemorySizeInfo(MemorySize.UInt32, 4, 4, MemorySize.UInt32, false, false), new MemorySizeInfo(MemorySize.UInt52, 8, 8, MemorySize.UInt52, false, false), new MemorySizeInfo(MemorySize.UInt64, 8, 8, MemorySize.UInt64, false, false), new MemorySizeInfo(MemorySize.UInt128, 16, 16, MemorySize.UInt128, false, false), new MemorySizeInfo(MemorySize.UInt256, 32, 32, MemorySize.UInt256, false, false), new MemorySizeInfo(MemorySize.UInt512, 64, 64, MemorySize.UInt512, false, false), new MemorySizeInfo(MemorySize.Int8, 1, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Int16, 2, 2, MemorySize.Int16, true, false), new MemorySizeInfo(MemorySize.Int32, 4, 4, MemorySize.Int32, true, false), new MemorySizeInfo(MemorySize.Int64, 8, 8, MemorySize.Int64, true, false), new MemorySizeInfo(MemorySize.Int128, 16, 16, MemorySize.Int128, true, false), new MemorySizeInfo(MemorySize.Int256, 32, 32, MemorySize.Int256, true, false), new MemorySizeInfo(MemorySize.Int512, 64, 64, MemorySize.Int512, true, false), new MemorySizeInfo(MemorySize.SegPtr16, 4, 4, MemorySize.SegPtr16, false, false), new MemorySizeInfo(MemorySize.SegPtr32, 6, 6, MemorySize.SegPtr32, false, false), new MemorySizeInfo(MemorySize.SegPtr64, 10, 10, MemorySize.SegPtr64, false, false), new MemorySizeInfo(MemorySize.WordOffset, 2, 2, MemorySize.WordOffset, false, false), new MemorySizeInfo(MemorySize.DwordOffset, 4, 4, MemorySize.DwordOffset, false, false), new MemorySizeInfo(MemorySize.QwordOffset, 8, 8, MemorySize.QwordOffset, false, false), new MemorySizeInfo(MemorySize.Bound16_WordWord, 4, 4, MemorySize.Bound16_WordWord, false, false), new MemorySizeInfo(MemorySize.Bound32_DwordDword, 8, 8, MemorySize.Bound32_DwordDword, false, false), new MemorySizeInfo(MemorySize.Bnd32, 8, 8, MemorySize.Bnd32, false, false), new MemorySizeInfo(MemorySize.Bnd64, 16, 16, MemorySize.Bnd64, false, false), new MemorySizeInfo(MemorySize.Fword5, 5, 5, MemorySize.Fword5, false, false), new MemorySizeInfo(MemorySize.Fword6, 6, 6, MemorySize.Fword6, false, false), new MemorySizeInfo(MemorySize.Fword10, 10, 10, MemorySize.Fword10, false, false), new MemorySizeInfo(MemorySize.Float16, 2, 2, MemorySize.Float16, true, false), new MemorySizeInfo(MemorySize.Float32, 4, 4, MemorySize.Float32, true, false), new MemorySizeInfo(MemorySize.Float64, 8, 8, MemorySize.Float64, true, false), new MemorySizeInfo(MemorySize.Float80, 10, 10, MemorySize.Float80, true, false), new MemorySizeInfo(MemorySize.Float128, 16, 16, MemorySize.Float128, true, false), new MemorySizeInfo(MemorySize.FpuEnv14, 14, 14, MemorySize.FpuEnv14, false, false), new MemorySizeInfo(MemorySize.FpuEnv28, 28, 28, MemorySize.FpuEnv28, false, false), new MemorySizeInfo(MemorySize.FpuState94, 94, 94, MemorySize.FpuState94, false, false), new MemorySizeInfo(MemorySize.FpuState108, 108, 108, MemorySize.FpuState108, false, false), new MemorySizeInfo(MemorySize.Fxsave_512Byte, 512, 512, MemorySize.Fxsave_512Byte, false, false), new MemorySizeInfo(MemorySize.Fxsave64_512Byte, 512, 512, MemorySize.Fxsave64_512Byte, false, false), new MemorySizeInfo(MemorySize.Xsave, 0, 0, MemorySize.Xsave, false, false), new MemorySizeInfo(MemorySize.Xsave64, 0, 0, MemorySize.Xsave64, false, false), new MemorySizeInfo(MemorySize.Bcd, 10, 10, MemorySize.Bcd, true, false), new MemorySizeInfo(MemorySize.Packed16_UInt8, 2, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.Packed16_Int8, 2, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Packed32_UInt8, 4, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.Packed32_Int8, 4, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Packed32_UInt16, 4, 2, MemorySize.UInt16, false, false), new MemorySizeInfo(MemorySize.Packed32_Int16, 4, 2, MemorySize.Int16, true, false), new MemorySizeInfo(MemorySize.Packed64_UInt8, 8, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.Packed64_Int8, 8, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Packed64_UInt16, 8, 2, MemorySize.UInt16, false, false), new MemorySizeInfo(MemorySize.Packed64_Int16, 8, 2, MemorySize.Int16, true, false), new MemorySizeInfo(MemorySize.Packed64_UInt32, 8, 4, MemorySize.UInt32, false, false), new MemorySizeInfo(MemorySize.Packed64_Int32, 8, 4, MemorySize.Int32, true, false), new MemorySizeInfo(MemorySize.Packed64_Float16, 8, 2, MemorySize.Float16, true, false), new MemorySizeInfo(MemorySize.Packed64_Float32, 8, 4, MemorySize.Float32, true, false), new MemorySizeInfo(MemorySize.Packed128_UInt8, 16, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.Packed128_Int8, 16, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Packed128_UInt16, 16, 2, MemorySize.UInt16, false, false), new MemorySizeInfo(MemorySize.Packed128_Int16, 16, 2, MemorySize.Int16, true, false), new MemorySizeInfo(MemorySize.Packed128_UInt32, 16, 4, MemorySize.UInt32, false, false), new MemorySizeInfo(MemorySize.Packed128_Int32, 16, 4, MemorySize.Int32, true, false), new MemorySizeInfo(MemorySize.Packed128_UInt52, 16, 8, MemorySize.UInt52, false, false), new MemorySizeInfo(MemorySize.Packed128_UInt64, 16, 8, MemorySize.UInt64, false, false), new MemorySizeInfo(MemorySize.Packed128_Int64, 16, 8, MemorySize.Int64, true, false), new MemorySizeInfo(MemorySize.Packed128_Float16, 16, 2, MemorySize.Float16, true, false), new MemorySizeInfo(MemorySize.Packed128_Float32, 16, 4, MemorySize.Float32, true, false), new MemorySizeInfo(MemorySize.Packed128_Float64, 16, 8, MemorySize.Float64, true, false), new MemorySizeInfo(MemorySize.Packed256_UInt8, 32, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.Packed256_Int8, 32, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Packed256_UInt16, 32, 2, MemorySize.UInt16, false, false), new MemorySizeInfo(MemorySize.Packed256_Int16, 32, 2, MemorySize.Int16, true, false), new MemorySizeInfo(MemorySize.Packed256_UInt32, 32, 4, MemorySize.UInt32, false, false), new MemorySizeInfo(MemorySize.Packed256_Int32, 32, 4, MemorySize.Int32, true, false), new MemorySizeInfo(MemorySize.Packed256_UInt52, 32, 8, MemorySize.UInt52, false, false), new MemorySizeInfo(MemorySize.Packed256_UInt64, 32, 8, MemorySize.UInt64, false, false), new MemorySizeInfo(MemorySize.Packed256_Int64, 32, 8, MemorySize.Int64, true, false), new MemorySizeInfo(MemorySize.Packed256_UInt128, 32, 16, MemorySize.UInt128, false, false), new MemorySizeInfo(MemorySize.Packed256_Int128, 32, 16, MemorySize.Int128, true, false), new MemorySizeInfo(MemorySize.Packed256_Float16, 32, 2, MemorySize.Float16, true, false), new MemorySizeInfo(MemorySize.Packed256_Float32, 32, 4, MemorySize.Float32, true, false), new MemorySizeInfo(MemorySize.Packed256_Float64, 32, 8, MemorySize.Float64, true, false), new MemorySizeInfo(MemorySize.Packed256_Float128, 32, 16, MemorySize.Float128, true, false), new MemorySizeInfo(MemorySize.Packed512_UInt8, 64, 1, MemorySize.UInt8, false, false), new MemorySizeInfo(MemorySize.Packed512_Int8, 64, 1, MemorySize.Int8, true, false), new MemorySizeInfo(MemorySize.Packed512_UInt16, 64, 2, MemorySize.UInt16, false, false), new MemorySizeInfo(MemorySize.Packed512_Int16, 64, 2, MemorySize.Int16, true, false), new MemorySizeInfo(MemorySize.Packed512_UInt32, 64, 4, MemorySize.UInt32, false, false), new MemorySizeInfo(MemorySize.Packed512_Int32, 64, 4, MemorySize.Int32, true, false), new MemorySizeInfo(MemorySize.Packed512_UInt52, 64, 8, MemorySize.UInt52, false, false), new MemorySizeInfo(MemorySize.Packed512_UInt64, 64, 8, MemorySize.UInt64, false, false), new MemorySizeInfo(MemorySize.Packed512_Int64, 64, 8, MemorySize.Int64, true, false), new MemorySizeInfo(MemorySize.Packed512_UInt128, 64, 16, MemorySize.UInt128, false, false), new MemorySizeInfo(MemorySize.Packed512_Float32, 64, 4, MemorySize.Float32, true, false), new MemorySizeInfo(MemorySize.Packed512_Float64, 64, 8, MemorySize.Float64, true, false), new MemorySizeInfo(MemorySize.Broadcast64_UInt32, 8, 4, MemorySize.UInt32, false, true), new MemorySizeInfo(MemorySize.Broadcast64_Int32, 8, 4, MemorySize.Int32, true, true), new MemorySizeInfo(MemorySize.Broadcast64_Float32, 8, 4, MemorySize.Float32, true, true), new MemorySizeInfo(MemorySize.Broadcast128_UInt32, 16, 4, MemorySize.UInt32, false, true), new MemorySizeInfo(MemorySize.Broadcast128_Int32, 16, 4, MemorySize.Int32, true, true), new MemorySizeInfo(MemorySize.Broadcast128_UInt52, 16, 8, MemorySize.UInt52, false, true), new MemorySizeInfo(MemorySize.Broadcast128_UInt64, 16, 8, MemorySize.UInt64, false, true), new MemorySizeInfo(MemorySize.Broadcast128_Int64, 16, 8, MemorySize.Int64, true, true), new MemorySizeInfo(MemorySize.Broadcast128_Float32, 16, 4, MemorySize.Float32, true, true), new MemorySizeInfo(MemorySize.Broadcast128_Float64, 16, 8, MemorySize.Float64, true, true), new MemorySizeInfo(MemorySize.Broadcast256_UInt32, 32, 4, MemorySize.UInt32, false, true), new MemorySizeInfo(MemorySize.Broadcast256_Int32, 32, 4, MemorySize.Int32, true, true), new MemorySizeInfo(MemorySize.Broadcast256_UInt52, 32, 8, MemorySize.UInt52, false, true), new MemorySizeInfo(MemorySize.Broadcast256_UInt64, 32, 8, MemorySize.UInt64, false, true), new MemorySizeInfo(MemorySize.Broadcast256_Int64, 32, 8, MemorySize.Int64, true, true), new MemorySizeInfo(MemorySize.Broadcast256_Float32, 32, 4, MemorySize.Float32, true, true), new MemorySizeInfo(MemorySize.Broadcast256_Float64, 32, 8, MemorySize.Float64, true, true), new MemorySizeInfo(MemorySize.Broadcast512_UInt32, 64, 4, MemorySize.UInt32, false, true), new MemorySizeInfo(MemorySize.Broadcast512_Int32, 64, 4, MemorySize.Int32, true, true), new MemorySizeInfo(MemorySize.Broadcast512_UInt52, 64, 8, MemorySize.UInt52, false, true), new MemorySizeInfo(MemorySize.Broadcast512_UInt64, 64, 8, MemorySize.UInt64, false, true), new MemorySizeInfo(MemorySize.Broadcast512_Int64, 64, 8, MemorySize.Int64, true, true), new MemorySizeInfo(MemorySize.Broadcast512_Float32, 64, 4, MemorySize.Float32, true, true), new MemorySizeInfo(MemorySize.Broadcast512_Float64, 64, 8, MemorySize.Float64, true, true), }; /// /// Gets the memory size info /// /// Memory size /// public static MemorySizeInfo GetInfo(this MemorySize memorySize) { var infos = MemorySizeInfos; if ((uint)memorySize >= (uint)infos.Length) ThrowArgumentOutOfRangeException(nameof(memorySize)); return infos[(int)memorySize]; } static void ThrowArgumentOutOfRangeException(string paramName) => throw new ArgumentOutOfRangeException(paramName); /// /// Gets the size in bytes of the memory location or 0 if it's not accessed by the instruction or unknown or variable sized /// /// Memory size /// public static int GetSize(this MemorySize memorySize) => memorySize.GetInfo().Size; /// /// Gets the size in bytes of the packed element. If it's not a packed data type, it's equal to . /// /// Memory size /// public static int GetElementSize(this MemorySize memorySize) => memorySize.GetInfo().ElementSize; /// /// Gets the element type if it's packed data or if it's not packed data /// /// Memory size /// public static MemorySize GetElementType(this MemorySize memorySize) => memorySize.GetInfo().ElementType; /// /// true if it's signed data (signed integer or a floating point value) /// /// Memory size /// public static bool IsSigned(this MemorySize memorySize) => memorySize.GetInfo().IsSigned; /// /// Checks if is a broadcast memory type /// /// Memory size /// public static bool IsBroadcast(this MemorySize memorySize) => memorySize >= FirstBroadcastMemorySize; const MemorySize FirstBroadcastMemorySize = MemorySize.Broadcast64_UInt32; /// /// true if this is a packed data type, eg. /// /// Memory size /// public static bool IsPacked(this MemorySize memorySize) => memorySize.GetInfo().IsPacked; /// /// Gets the number of elements in the packed data type or 1 if it's not packed data () /// /// Memory size /// public static int GetElementCount(this MemorySize memorySize) => memorySize.GetInfo().ElementCount; } /// /// information /// public readonly struct MemorySizeInfo { // 8 bytes in size readonly ushort size; readonly ushort elementSize; readonly byte memorySize; readonly byte elementType; // Use flags if more booleans are needed readonly bool isSigned; readonly bool isBroadcast; /// /// Gets the value /// public MemorySize MemorySize => (MemorySize)memorySize; /// /// Size in bytes of the memory location or 0 if it's not accessed or unknown /// public int Size => size; /// /// Size in bytes of the packed element. If it's not a packed data type, it's equal to . /// public int ElementSize => elementSize; /// /// Element type if it's packed data or the type itself if it's not packed data /// public MemorySize ElementType => (MemorySize)elementType; /// /// true if it's signed data (signed integer or a floating point value) /// public bool IsSigned => isSigned; /// /// true if it's a broadcast memory type /// public bool IsBroadcast => isBroadcast; /// /// true if this is a packed data type, eg. . See also /// public bool IsPacked => elementSize < size; /// /// Gets the number of elements in the packed data type or 1 if it's not packed data () /// public int ElementCount => elementSize == size ? 1 : size / elementSize;// ElementSize can be 0 so we don't divide by it if es == s /// /// Constructor /// /// Memory size value /// Size of location /// Size of the packed element, or if it's not packed data /// Element type if it's packed data or /// true if signed data /// true if broadcast public MemorySizeInfo(MemorySize memorySize, int size, int elementSize, MemorySize elementType, bool isSigned, bool isBroadcast) { if (size < 0) throw new ArgumentOutOfRangeException(nameof(size)); if (elementSize < 0) throw new ArgumentOutOfRangeException(nameof(elementSize)); if (elementSize > size) throw new ArgumentOutOfRangeException(nameof(elementSize)); Debug.Assert(DecoderConstants.NumberOfMemorySizes <= byte.MaxValue + 1); this.memorySize = (byte)memorySize; Debug.Assert(size <= ushort.MaxValue); this.size = (ushort)size; Debug.Assert(elementSize <= ushort.MaxValue); this.elementSize = (ushort)elementSize; Debug.Assert(DecoderConstants.NumberOfMemorySizes <= byte.MaxValue + 1); this.elementType = (byte)elementType; this.isSigned = isSigned; this.isBroadcast = isBroadcast; } } #endif }