@@ -1735,7 +1735,6 @@ private static (string Default, string? IndexRegisterW) GetMemoryOperandType(Mem
1735
1735
case Arm64MemoryEncodingKind . BaseRegisterAndFixedImmediateOptional :
1736
1736
case Arm64MemoryEncodingKind . BaseRegisterAndImmediateOptional :
1737
1737
return ( "Arm64ImmediateMemoryAccessor" , null ) ;
1738
- break ;
1739
1738
case Arm64MemoryEncodingKind . BaseRegisterAndIndexXmAndLslAmount :
1740
1739
return ( "Arm64RegisterXExtendMemoryAccessor" , null ) ;
1741
1740
case Arm64MemoryEncodingKind . BaseRegisterAndIndexWmOrXmAndExtend :
@@ -1791,7 +1790,6 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
1791
1790
string ? baseType ;
1792
1791
1793
1792
var operandName = GetNormalizedOperandName ( register . Name ) ;
1794
-
1795
1793
List < WriteEncodingDelegate > encodings = new ( ) ;
1796
1794
1797
1795
var testArguments = new List < RegisterTestArgument > ( ) ;
@@ -1891,9 +1889,7 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
1891
1889
operandVariationX . TestArguments . Add ( new RegisterTestArgument ( "X" , 31 ) ) ;
1892
1890
}
1893
1891
1894
- var encodingX = GetRegisterIndexEncoding ( instruction , register , operandVariationX ) ;
1895
- Debug . Assert ( encodingX is not null ) ;
1896
- operandVariationX . WriteEncodings . Add ( encodingX ) ;
1892
+ AddRegisterIndexEncoding ( instruction , register , operandVariationX ) ;
1897
1893
1898
1894
var operandVariationW = new OperandVariation ( )
1899
1895
{
@@ -1909,9 +1905,7 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
1909
1905
}
1910
1906
operandVariationW . AcceptedBitValues . AddRange ( xOrWSelector . BitValues . Where ( x => x . Text == "W" ) ) ;
1911
1907
1912
- var encodingW = GetRegisterIndexEncoding ( instruction , register , operandVariationW ) ;
1913
- Debug . Assert ( encodingW is not null ) ;
1914
- operandVariationW . WriteEncodings . Add ( encodingW ) ;
1908
+ AddRegisterIndexEncoding ( instruction , register , operandVariationW ) ;
1915
1909
1916
1910
operandVariations . Add ( operandVariationX ) ;
1917
1911
operandVariations . Add ( operandVariationW ) ;
@@ -2045,12 +2039,7 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
2045
2039
operandVariation . AcceptedBitValues . Add ( bitValue ) ;
2046
2040
operandVariation . TestArguments . AddRange ( testArguments ) ;
2047
2041
2048
- var indexEncoding = GetRegisterIndexEncoding ( instruction , register , operandVariation ) ;
2049
- if ( indexEncoding != null )
2050
- {
2051
- operandVariation . WriteEncodings . Add ( indexEncoding ) ;
2052
- }
2053
-
2042
+ AddRegisterIndexEncoding ( instruction , register , operandVariation ) ;
2054
2043
GenerateEncodingForExtract ( instruction , register . IndexerExtract , operandVariation , "ElementIndex" , "element indexer" ) ;
2055
2044
operandVariations . Add ( operandVariation ) ;
2056
2045
}
@@ -2106,12 +2095,7 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
2106
2095
break ;
2107
2096
}
2108
2097
2109
- var indexEncoding = GetRegisterIndexEncoding ( instruction , register , operandVariation ) ;
2110
- if ( indexEncoding is not null )
2111
- {
2112
- operandVariation . WriteEncodings . Add ( indexEncoding ! ) ;
2113
- }
2114
-
2098
+ AddRegisterIndexEncoding ( instruction , register , operandVariation ) ;
2115
2099
GenerateEncodingForExtract ( instruction , register . IndexerExtract , operandVariation , "ElementIndex" , "element indexer" ) ;
2116
2100
operandVariations . Add ( operandVariation ) ;
2117
2101
}
@@ -2174,11 +2158,8 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
2174
2158
opVar . TestArguments . AddRange ( testArguments ) ;
2175
2159
}
2176
2160
2177
- var directIndexEncoding = GetRegisterIndexEncoding ( instruction , register , opVar ) ;
2178
- if ( directIndexEncoding is not null )
2179
- {
2180
- encodings . Add ( directIndexEncoding ) ;
2181
- }
2161
+ opVar . WriteEncodings . AddRange ( encodings ) ;
2162
+ AddRegisterIndexEncoding ( instruction , register , opVar ) ;
2182
2163
2183
2164
switch ( instruction . Id )
2184
2165
{
@@ -2204,7 +2185,6 @@ private static void GetRegisterOperandVariation(int operandIndex, Instruction in
2204
2185
//break;
2205
2186
}
2206
2187
2207
- opVar . WriteEncodings . AddRange ( encodings ) ;
2208
2188
GenerateEncodingForExtract ( instruction , register . IndexerExtract , opVar , "ElementIndex" , "element indexer" ) ;
2209
2189
operandVariations . Add ( opVar ) ;
2210
2190
}
@@ -2393,52 +2373,69 @@ private static void GenerateSwitchCaseFromValue(string valuePath, List<(int Valu
2393
2373
return null ;
2394
2374
}
2395
2375
2396
- private static WriteEncodingDelegate ? GetRegisterIndexEncoding ( Instruction instruction , RegisterOperandDescriptor register , OperandVariation operandVariation )
2376
+ private static void AddRegisterIndexEncoding ( Instruction instruction , RegisterOperandDescriptor register , OperandVariation operandVariation )
2397
2377
{
2378
+ var operandVar = operandVariation . OperandName ;
2379
+
2380
+ if ( register . IsOptional )
2381
+ {
2382
+ var regName = instruction . Id == "RET_64r_branch_reg" ? "X30" : "XZR" ;
2383
+ operandVariation . WriteEncodings . Add ( ( w , variable , variation , operand , index ) => w . WriteLine ( $ "{ operandVar } = ({ operandVar } .Kind == Arm64RegisterKind.Invalid) ? Arm64RegisterX.{ regName } : { operandVar } ;") ) ;
2384
+ }
2385
+
2398
2386
switch ( register . RegisterIndexEncodingKind )
2399
2387
{
2400
2388
case Arm64RegisterIndexEncodingKind . Std5 :
2401
2389
{
2402
2390
if ( register . LowBitIndexEncoding == 0 )
2403
2391
{
2404
- return ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint){ op . OperandName } .Index;") ;
2392
+ operandVariation . WriteEncodings . Add ( ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint){ operandVar } .Index;") ) ;
2405
2393
}
2406
2394
else
2407
2395
{
2408
- return ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint){ op . OperandName } .Index << { register . LowBitIndexEncoding } ;") ;
2396
+ operandVariation . WriteEncodings . Add ( ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint){ operandVar } .Index << { register . LowBitIndexEncoding } ;") ) ;
2409
2397
}
2398
+
2399
+ break ;
2410
2400
}
2411
2401
case Arm64RegisterIndexEncodingKind . Std4 :
2412
2402
{
2413
2403
if ( register . LowBitIndexEncoding == 0 )
2414
2404
{
2415
- return ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint)({ op . OperandName } .Index & 0xF);") ; // 4 bits so we mask by security
2405
+ operandVariation . WriteEncodings . Add ( ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint)({ operandVar } .Index & 0xF);") ) ; // 4 bits so we mask by security
2416
2406
}
2417
2407
else
2418
2408
{
2419
- return ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint)({ op . OperandName } .Index & 0xF) << { register . LowBitIndexEncoding } ;") ;
2409
+ operandVariation . WriteEncodings . Add ( ( w , variable , instr , op , opIndex ) => w . WriteLine ( $ "{ variable } |= (uint)({ operandVar } .Index & 0xF) << { register . LowBitIndexEncoding } ;") ) ;
2420
2410
}
2411
+
2412
+ break ;
2421
2413
}
2422
2414
case Arm64RegisterIndexEncodingKind . Std5Plus1 :
2423
- return ( w , variable , instr , op , opIndex ) =>
2424
- {
2425
- var previousOp = instr . Operands [ opIndex - 1 ] ;
2426
- w . WriteLine ( $ "if ({ op . OperandName } .Index != (({ previousOp . OperandName } .Index + 1) & 0x1F)) throw new { nameof ( ArgumentOutOfRangeException ) } (nameof({ op . OperandName } ), $\" Invalid Register. Index `{{{op.OperandName}.Index}}` must be + 1 from operand { previousOp . OperandName } with index `{{{previousOp.OperandName}.Index}}`\" );") ;
2427
- } ;
2415
+ operandVariation . WriteEncodings . Add (
2416
+ ( w , variable , instr , op , opIndex ) =>
2417
+ {
2418
+ var previousOp = instr . Operands [ opIndex - 1 ] ;
2419
+ w . WriteLine (
2420
+ $ "if ({ operandVar } .Index != (({ previousOp . OperandName } .Index + 1) & 0x1F)) throw new { nameof ( ArgumentOutOfRangeException ) } (nameof({ operandVar } ), $\" Invalid Register. Index `{{{operandVar}.Index}}` must be + 1 from operand { previousOp . OperandName } with index `{{{previousOp.OperandName}.Index}}`\" );") ;
2421
+ }
2422
+ ) ;
2423
+ break ;
2428
2424
case Arm64RegisterIndexEncodingKind . BitMapExtract :
2429
2425
GenerateEncodingForExtract ( instruction , register . RegisterIndexExtract , operandVariation , "Index" , "register index" ) ;
2430
2426
break ;
2431
2427
case Arm64RegisterIndexEncodingKind . Fixed :
2432
- return ( w , variable , instr , op , opIndex ) =>
2433
- {
2434
- w . WriteLine ( $ "if ({ operandVariation . OperandName } .Index != { register . FixedRegisterIndex } ) throw new { nameof ( ArgumentOutOfRangeException ) } (nameof({ op . OperandName } ), $\" Invalid Register. Expecting the fixed index { register . FixedRegisterIndex } instead of {{{operandVariation.OperandName}}}\" );") ;
2435
- } ;
2428
+ operandVariation . WriteEncodings . Add ( ( w , variable , instr , op , opIndex ) =>
2429
+ {
2430
+ w . WriteLine (
2431
+ $ "if ({ operandVariation . OperandName } .Index != { register . FixedRegisterIndex } ) throw new { nameof ( ArgumentOutOfRangeException ) } (nameof({ operandVar } ), $\" Invalid Register. Expecting the fixed index { register . FixedRegisterIndex } instead of {{{operandVariation.OperandName}}}\" );") ;
2432
+ }
2433
+ ) ;
2434
+ break ;
2436
2435
default :
2437
2436
Debug . Assert ( false , "register" , $ "RegisterIndexEncodingKind `{ register . RegisterIndexEncodingKind } ` is not supported") ;
2438
2437
break ;
2439
2438
}
2440
-
2441
- return null ;
2442
2439
}
2443
2440
2444
2441
private static string GetNormalizedOperandName ( string name )
0 commit comments