SharpDisasm.Tests/OpTableGeneration.cs
/// <summary>
/// Add an instruction definition containing an avx cpuid bit, but 
/// declared in its legacy SSE form. The function splits the definition to create two new
/// definitions, one for SSE and one promoted to an AVX form.
/// </summary>
/// <param name="insnDef"></param>
/// <param name="opcexts"></param>
Add an instruction definition containing an avx cpuid bit, but
declared in its legacy SSE form. The function splits the definition to create two new
definitions, one for SSE and one promoted to an AVX form.
Add an instruction definition containing an avx cpuid bit but declared in its legacy SSE form . The function splits the definition to create two new definitions one for SSE and one promoted to an AVX form .
private void AddSSE2AVXInsn(UdInsnDef insnDef, Dictionary<string, string> opcexts)
            {
                var sseMnemonic = insnDef.Mnemonic;
                var sseOpcodes = insnDef.Opcodes.ToArray();
                var sseOpcexts = new Dictionary<string, string>();
                foreach (var kv in opcexts)
                {
                    if (!kv.Key.StartsWith("/vex"))
                        sseOpcexts.Add(kv.Key, kv.Value);
                }
                var sseOperands = (from opr in insnDef.Operands
                                   where opr != "H" && opr != "L"
                                   select opr).ToArray();
                var ssePrefixes = (from pfx in insnDef.Prefixes
                                   where !pfx.StartsWith("vex")
                                   select pfx).ToArray();
                var sseCpuid = (from cpu in insnDef.CpuIds
                                where !cpu.StartsWith("avx")
                                select cpu).ToArray();
                AddInsn(new UdInsnDef(sseMnemonic, ssePrefixes, sseOpcodes, sseOperands, sseCpuid), sseOpcexts);
                var vexMnemonic = "v" + insnDef.Mnemonic;
                var vexPrefixes = insnDef.Prefixes.ToArray();
                var vexopcodes = new string[] { "c4" };
                var vexopcexts = new Dictionary<string, string>();
                foreach (var kv in opcexts)
                {
                    if (!kv.Key.StartsWith("/sse"))
                        vexopcexts[kv.Key] = kv.Value;
                }
                vexopcexts["/vex"] = opcexts["/sse"] + "_" + "0f";
                if (insnDef.Opcodes.Count > 1 && (insnDef.Opcodes[1] == "38" || insnDef.Opcodes[1] == "3a"))
                {
                    vexopcexts["/vex"] += insnDef.Opcodes[1];
                    vexopcodes = vexopcodes.Concat(insnDef.Opcodes.Skip(2).ToArray()).ToArray();
                }
                else
                {
                    vexopcodes = vexopcodes.Concat(insnDef.Opcodes.Skip(1).ToArray()).ToArray();
                }
                var vexoperands = new List<String>();
                foreach (var o in insnDef.Operands)
                {
                    var opr = o;
                    if (new string[] { "V", "W", "H", "U" }.Contains(opr))
                        opr = opr + "x";
                    vexoperands.Add(opr);
                }
                var vexcpuid = (from cpu in insnDef.CpuIds
                                where !cpu.StartsWith("sse")
                                select cpu).ToArray();
                AddInsn(new UdInsnDef(vexMnemonic, vexPrefixes, vexopcodes, vexoperands.ToArray(), vexcpuid), vexopcexts);
            }
private void AddSSE2AVXInsn ( UdInsnDef insnDef , Dictionary < string , string > opcexts ) { var sseMnemonic = insnDef . Mnemonic ; var sseOpcodes = insnDef . Opcodes . ToArray ( ) ; var sseOpcexts = new Dictionary < string , string > ( ) ; foreach ( var kv in opcexts ) { if ( ! kv . Key . StartsWith ( " " ) ) sseOpcexts . Add ( kv . Key , kv . Value ) ; } var sseOperands = ( from opr in insnDef . Operands where opr != " " && opr != " " select opr ) . ToArray ( ) ; var ssePrefixes = ( from pfx in insnDef . Prefixes where ! pfx . StartsWith ( " " ) select pfx ) . ToArray ( ) ; var sseCpuid = ( from cpu in insnDef . CpuIds where ! cpu . StartsWith ( " " ) select cpu ) . ToArray ( ) ; AddInsn ( new UdInsnDef ( sseMnemonic , ssePrefixes , sseOpcodes , sseOperands , sseCpuid ) , sseOpcexts ) ; var vexMnemonic = " " + insnDef . Mnemonic ; var vexPrefixes = insnDef . Prefixes . ToArray ( ) ; var vexopcodes = new string [ ] { " " } ; var vexopcexts = new Dictionary < string , string > ( ) ; foreach ( var kv in opcexts ) { if ( ! kv . Key . StartsWith ( " " ) ) vexopcexts [ kv . Key ] = kv . Value ; } vexopcexts [ " " ] = opcexts [ " " ] + " " + " " ; if ( insnDef . Opcodes . Count > 1 && ( insnDef . Opcodes [ 1 ] == " " || insnDef . Opcodes [ 1 ] == " " ) ) { vexopcexts [ " " ] += insnDef . Opcodes [ 1 ] ; vexopcodes = vexopcodes . Concat ( insnDef . Opcodes . Skip ( 2 ) . ToArray ( ) ) . ToArray ( ) ; } else { vexopcodes = vexopcodes . Concat ( insnDef . Opcodes . Skip ( 1 ) . ToArray ( ) ) . ToArray ( ) ; } var vexoperands = new List < String > ( ) ; foreach ( var o in insnDef . Operands ) { var opr = o ; if ( new string [ ] { " " , " " , " " , " " } . Contains ( opr ) ) opr = opr + " " ; vexoperands . Add ( opr ) ; } var vexcpuid = ( from cpu in insnDef . CpuIds where ! cpu . StartsWith ( " " ) select cpu ) . ToArray ( ) ; AddInsn ( new UdInsnDef ( vexMnemonic , vexPrefixes , vexopcodes , vexoperands . ToArray ( ) , vexcpuid ) , vexopcexts ) ; }
Add an instruction definition containing an avx cpuid bit, but
declared in its legacy SSE form.
Add an instruction definition containing an avx cpuid bit but declared in its legacy SSE form .
// SSE // Remove vex opcode extensions // strip out avx operands, preserving relative ordering // of remaining operands // strip out avx prefixes // strip out avx bits from cpuid // AVX // make the operand size explicit: x
insnDef
UdInsnDef
None
opcexts
Dictionary<string, string>
None