@@ -35,7 +35,6 @@ private void GenerateCode()
35
35
GenerateProcessStateField ( ) ;
36
36
GenerateRegisterIndex ( ) ;
37
37
}
38
-
39
38
40
39
private void GenerateMnemonicEnum ( )
41
40
{
@@ -557,7 +556,8 @@ Action<CodeWriter, EncodingSymbolSelector, EncodingBitValue> writeSelector
557
556
}
558
557
else
559
558
{
560
- w . WriteLine ( $ "return TryDecodeFromBitValues(bitValue, { extract . SelectorIndex } , { string . Join ( "," , parameters . Select ( x => $ "out { x . ParameterName } ") ) } );") ;
559
+ WriteSelectorCode ( w , extract . Selector ! , parameters , writeSelector ) ;
560
+ //w.WriteLine($"return TryDecodeFromBitValues(bitValue, {extract.SelectorIndex}, {string.Join(",", parameters.Select(x => $"out {x.ParameterName}"))});");
561
561
}
562
562
}
563
563
else
@@ -602,122 +602,127 @@ Action<CodeWriter, EncodingSymbolSelector, EncodingBitValue> writeSelector
602
602
// return false;
603
603
// }
604
604
605
- if ( map . SelectorList . Count > 0 )
605
+ //if (map.SelectorList.Count > 0)
606
+ //{
607
+ // w.WriteLine();
608
+ // // We inline aggressively because the selectorIndex is a constant passed as it seems that the vast majority of selectorIndex are unique to an extract.
609
+ // w.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]");
610
+ // w.WriteLine($"public static bool TryDecodeFromBitValues(uint bitValue, byte selectorIndex, {parameterSignature})");
611
+ // w.OpenBraceBlock();
612
+ // {
613
+ // w.WriteLine("switch (selectorIndex)");
614
+ // w.OpenBraceBlock();
615
+ // {
616
+ // foreach (var selector in map.SelectorList)
617
+ // {
618
+ // w.WriteLine($"case {selector.Index}:");
619
+ // w.OpenBraceBlock();
620
+ // WriteSelectorCode(w, selector, parameters, writeSelector);
621
+
622
+ // w.CloseBraceBlock();
623
+ // }
624
+ // }
625
+ // w.CloseBraceBlock();
626
+ // w.WriteLine();
627
+ // foreach (var parameter in parameters)
628
+ // {
629
+ // w.WriteLine($"{parameter.ParameterName} = default;");
630
+ // }
631
+
632
+ // w.WriteLine("return false;");
633
+ // }
634
+ // w.CloseBraceBlock();
635
+ //}
636
+ }
637
+ w . CloseBraceBlock ( ) ;
638
+ }
639
+
640
+ private void WriteSelectorCode ( CodeWriter w , EncodingSymbolSelector selector , List < ( string ParameterType , string ParameterName ) > parameters , Action < CodeWriter , EncodingSymbolSelector , EncodingBitValue > writeSelector )
641
+ {
642
+ w . WriteLine ( ExtractBitRangeString ( selector . BitRanges , "bitValue" , "bitsToTest" ) ) ;
643
+
644
+ if ( selector . Kind == EncodingSymbolSelectorKind . Regular )
645
+ {
646
+ w . WriteLine ( $ "switch (bitsToTest)") ;
647
+ w . OpenBraceBlock ( ) ;
606
648
{
607
- w . WriteLine ( ) ;
608
- // We inline aggressively because the selectorIndex is a constant passed as it seems that the vast majority of selectorIndex are unique to an extract.
609
- w . WriteLine ( "[MethodImpl(MethodImplOptions.AggressiveInlining)]" ) ;
610
- w . WriteLine ( $ "public static bool TryDecodeFromBitValues(uint bitValue, byte selectorIndex, { parameterSignature } )") ;
611
- w . OpenBraceBlock ( ) ;
649
+ foreach ( var bitValue in selector . BitValues )
612
650
{
613
- w . WriteLine ( "switch (selectorIndex) ") ;
651
+ w . WriteLine ( $ "case { bitValue . BitSelectorValue } : ") ;
614
652
w . OpenBraceBlock ( ) ;
653
+ if ( bitValue . Kind == EncodingBitValueKind . BitExtract )
615
654
{
616
- foreach ( var selector in map . SelectorList )
655
+ var bitRanges = bitValue . BitItems . Select ( x => x . Range ) . ToList ( ) ;
656
+ var bitValueExtractString = ExtractBitRangeString ( bitRanges , "bitValue" , "extractedValue" ) ;
657
+ Debug . Assert ( parameters . Count == 1 ) ;
658
+ w . WriteLine ( bitValueExtractString ) ;
659
+
660
+ if ( bitValue . Addend != 0 )
617
661
{
618
- w . WriteLine ( $ "case { selector . Index } :") ;
619
- w . OpenBraceBlock ( ) ;
620
- w . WriteLine ( ExtractBitRangeString ( selector . BitRanges , "bitValue" , "bitsToTest" ) ) ;
662
+ w . WriteLine ( bitValue . HasNegativeExtract
663
+ ? $ "{ parameters [ 0 ] . ParameterName } = { bitValue . Addend } - ({ parameters [ 0 ] . ParameterType } )extractedValue;"
664
+ : $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue - { bitValue . Addend } ;") ;
665
+ }
666
+ else
667
+ {
668
+ w . WriteLine ( $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue;") ;
669
+ }
670
+ }
671
+ else
672
+ {
673
+ writeSelector ( w , selector , bitValue ) ;
674
+ }
675
+ w . WriteLine ( "return true;" ) ;
676
+ w . CloseBraceBlock ( ) ;
677
+ }
678
+ }
679
+ w . CloseBraceBlock ( ) ;
680
+ w . WriteLine ( "break;" ) ;
681
+ }
682
+ else
683
+ {
684
+ Debug . Assert ( selector . Kind == EncodingSymbolSelectorKind . Masked ) ;
621
685
622
- if ( selector . Kind == EncodingSymbolSelectorKind . Regular )
623
- {
624
- w . WriteLine ( $ "switch (bitsToTest)") ;
625
- w . OpenBraceBlock ( ) ;
626
- {
627
- foreach ( var bitValue in selector . BitValues )
628
- {
629
- w . WriteLine ( $ "case { bitValue . BitSelectorValue } :") ;
630
- w . OpenBraceBlock ( ) ;
631
- if ( bitValue . Kind == EncodingBitValueKind . BitExtract )
632
- {
633
- var bitRanges = bitValue . BitItems . Select ( x => x . Range ) . ToList ( ) ;
634
- var bitValueExtractString = ExtractBitRangeString ( bitRanges , "bitValue" , "extractedValue" ) ;
635
- Debug . Assert ( parameters . Count == 1 ) ;
636
- w . WriteLine ( bitValueExtractString ) ;
637
-
638
- if ( bitValue . Addend != 0 )
639
- {
640
- w . WriteLine ( bitValue . HasNegativeExtract
641
- ? $ "{ parameters [ 0 ] . ParameterName } = { bitValue . Addend } - ({ parameters [ 0 ] . ParameterType } )extractedValue;"
642
- : $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue - { bitValue . Addend } ;") ;
643
- }
644
- else
645
- {
646
- w . WriteLine ( $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue;") ;
647
- }
648
- }
649
- else
650
- {
651
- writeSelector ( w , selector , bitValue ) ;
652
- }
653
- w . WriteLine ( "return true;" ) ;
654
- w . CloseBraceBlock ( ) ;
655
- }
656
- }
657
- w . CloseBraceBlock ( ) ;
658
- w . WriteLine ( "break;" ) ;
659
- }
660
- else
661
- {
662
- Debug . Assert ( selector . Kind == EncodingSymbolSelectorKind . Masked ) ;
663
-
664
- // Order from the highest number of bits sets to the lowest number
665
- // If the mask is 0, it means that all bits are sets
666
- var bitValues = selector . BitValues . OrderByDescending ( x => BitOperations . PopCount ( x . BitSelectorMask == 0 ? uint . MaxValue : x . BitSelectorMask ) ) . ToList ( ) ;
667
-
668
- foreach ( var bitValue in bitValues )
669
- {
670
- w . WriteLine ( bitValue . BitSelectorMask == 0
671
- ? $ "if (bitsToTest == { bitValue . BitSelectorValue } )"
672
- : $ "if ((bitsToTest & 0x{ bitValue . BitSelectorMask : x} ) == { bitValue . BitSelectorValue } )"
673
- ) ;
674
- w . OpenBraceBlock ( ) ;
675
- {
676
- if ( bitValue . Kind == EncodingBitValueKind . BitExtract )
677
- {
678
- var bitRanges = bitValue . BitItems . Select ( x => x . Range ) . ToList ( ) ;
679
- var bitValueExtractString = ExtractBitRangeString ( bitRanges , "bitValue" , "extractedValue" ) ;
680
- Debug . Assert ( parameters . Count == 1 ) ;
681
- w . WriteLine ( bitValueExtractString ) ;
682
- if ( bitValue . Addend != 0 )
683
- {
684
- w . WriteLine ( bitValue . HasNegativeExtract
685
- ? $ "{ parameters [ 0 ] . ParameterName } = { bitValue . Addend } - ({ parameters [ 0 ] . ParameterType } )extractedValue;"
686
- : $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue - { bitValue . Addend } ;") ;
687
- }
688
- else
689
- {
690
- w . WriteLine ( $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue;") ;
691
- }
692
- }
693
- else
694
- {
695
- writeSelector ( w , selector , bitValue ) ;
696
- }
697
- w . WriteLine ( "return true;" ) ;
698
- }
699
- w . CloseBraceBlock ( ) ;
700
- }
701
-
702
- w . WriteLine ( "break;" ) ;
703
- }
686
+ // Order from the highest number of bits sets to the lowest number
687
+ // If the mask is 0, it means that all bits are sets
688
+ var bitValues = selector . BitValues . OrderByDescending ( x => BitOperations . PopCount ( x . BitSelectorMask == 0 ? uint . MaxValue : x . BitSelectorMask ) ) . ToList ( ) ;
704
689
705
- w . CloseBraceBlock ( ) ;
690
+ foreach ( var bitValue in bitValues )
691
+ {
692
+ w . WriteLine ( bitValue . BitSelectorMask == 0
693
+ ? $ "if (bitsToTest == { bitValue . BitSelectorValue } )"
694
+ : $ "if ((bitsToTest & 0x{ bitValue . BitSelectorMask : x} ) == { bitValue . BitSelectorValue } )"
695
+ ) ;
696
+ w . OpenBraceBlock ( ) ;
697
+ {
698
+ if ( bitValue . Kind == EncodingBitValueKind . BitExtract )
699
+ {
700
+ var bitRanges = bitValue . BitItems . Select ( x => x . Range ) . ToList ( ) ;
701
+ var bitValueExtractString = ExtractBitRangeString ( bitRanges , "bitValue" , "extractedValue" ) ;
702
+ Debug . Assert ( parameters . Count == 1 ) ;
703
+ w . WriteLine ( bitValueExtractString ) ;
704
+ if ( bitValue . Addend != 0 )
705
+ {
706
+ w . WriteLine ( bitValue . HasNegativeExtract
707
+ ? $ "{ parameters [ 0 ] . ParameterName } = { bitValue . Addend } - ({ parameters [ 0 ] . ParameterType } )extractedValue;"
708
+ : $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue - { bitValue . Addend } ;") ;
709
+ }
710
+ else
711
+ {
712
+ w . WriteLine ( $ "{ parameters [ 0 ] . ParameterName } = ({ parameters [ 0 ] . ParameterType } )extractedValue;") ;
706
713
}
707
714
}
708
- w . CloseBraceBlock ( ) ;
709
- w . WriteLine ( ) ;
710
- foreach ( var parameter in parameters )
715
+ else
711
716
{
712
- w . WriteLine ( $ " { parameter . ParameterName } = default;" ) ;
717
+ writeSelector ( w , selector , bitValue ) ;
713
718
}
714
-
715
- w . WriteLine ( "return false;" ) ;
719
+ w . WriteLine ( "return true;" ) ;
716
720
}
717
721
w . CloseBraceBlock ( ) ;
718
722
}
723
+
724
+ w . WriteLine ( "break;" ) ;
719
725
}
720
- w . CloseBraceBlock ( ) ;
721
726
}
722
727
723
728
private string ExtractBitRangeString ( List < BitRange > bitRanges , string inputValue , string outputValue )
0 commit comments