diff --git a/src/StgSharp.Native/sn-src/mk.fma.x86.c b/src/StgSharp.Native/sn-src/mk.fma.x86.c index 57040a79..66c31228 100644 --- a/src/StgSharp.Native/sn-src/mk.fma.x86.c +++ b/src/StgSharp.Native/sn-src/mk.fma.x86.c @@ -12,7 +12,6 @@ #define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i) - SN_MK_PROC_DECL_STD(float, sse, , fma) { __mk_param_std(LEFT_RIGHT_ANS, float); @@ -125,7 +124,7 @@ SN_MK_PROC_DECL_STD(float, avx, _fma, fma) register __m256 a1 = _mm256_load_ps((float *)&a_base->y[1]); register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]); register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]); - + SN_MK_FMA_F32_AVX2_CYCLE(0); SN_MK_FMA_F32_AVX2_CYCLE(1); SN_MK_FMA_F32_AVX2_CYCLE(2); diff --git a/src/StgSharp.RegularAnalysis/Abstraction/SequenceEmitter.cs b/src/StgSharp.RegularAnalysis/Abstraction/SequenceEmitter.cs index 2bcca18b..ffce674e 100644 --- a/src/StgSharp.RegularAnalysis/Abstraction/SequenceEmitter.cs +++ b/src/StgSharp.RegularAnalysis/Abstraction/SequenceEmitter.cs @@ -38,6 +38,20 @@ namespace StgSharp.RegularAnalysis.Abstraction emitter.Append(string.IsNullOrEmpty(line) ? string.Empty : line); } + public static SequenceEmitter AppendLine( + this SequenceEmitter emitter, + params string[] lines + ) + { + if (lines is null || lines.Length == 0) { + return emitter; + } + foreach (string line in lines) { + emitter = emitter.AppendLine(line); + } + return emitter; + } + public static SequenceEmitter AppendLine( this SequenceEmitter emitter, string line, diff --git a/src/StgSharp.RegularAnalysis/Text/TextRegexSourceGen.GenClass.SingleIR.cs b/src/StgSharp.RegularAnalysis/Text/TextRegexSourceGen.GenClass.SingleIR.cs index 25fb9c57..14ca3d24 100644 --- a/src/StgSharp.RegularAnalysis/Text/TextRegexSourceGen.GenClass.SingleIR.cs +++ b/src/StgSharp.RegularAnalysis/Text/TextRegexSourceGen.GenClass.SingleIR.cs @@ -76,6 +76,24 @@ namespace StgSharp.RegularAnalysis.Text #region code + private static int TryGeneratePack( + int outer_level, + ReadOnlySpan ir_span, + SourceGenContext sc, + in SequenceEmitter code, + in List> local_func + ) + { + if (ir_span[0] is not RegexPackIR pack) { + return -1; + } + string group_name = pack.GroupName; + string begin = sc.GroupBegin(group_name); + string end = sc.GroupEnd(group_name); + _ = code.AppendLine(begin).AppendLine(end); + return 1; + } + private static int TryGenerateCountSet( int outer_level, ReadOnlySpan ir_span, @@ -87,10 +105,18 @@ namespace StgSharp.RegularAnalysis.Text if (ir_span[0] is not RegexCountSetIR count_set) { return -1; } + + bool is_greedy = count_set.IsGreedy; + int min = count_set.Min; + int max = count_set.Max; + int leave = is_greedy ? max : min; + string counter = sc.RequireNewCounter(); string set_source = count_set.CharSet; RegexCharSet[] set_arr = FigureCharSetType(set_source, out bool accept); - _ = code.AppendLine(accept ? @$"if(" : @$"if(!("); + _ = code.AppendLine($@"for(; {counter}<{leave}; {counter}++)") + .AppendLine("{") + .AppendLine(accept ? @$"if(" : @$"if(!("); string _case_code; RegexCharSet set; for (int i = 1; i < set_arr.Length - 1; i++) @@ -101,10 +127,21 @@ namespace StgSharp.RegularAnalysis.Text } set = set_arr[^1]; _case_code = GenLine(set, sc, ")"); - _ = code.AppendLine(_case_code) - .AppendLine("{") - .AppendLine("-------------------------------------")// TODO case success - .AppendLine("}"); + _ = code.AppendLine(_case_code, // + "{", // in case match + "}", // + "else", // + "{", // + "break;", // in case miss match + "}", // + "}", // end of for + @$"if({counter}>{min})", // match here + "{", // in case count reaches min count request + "}", // + "else", // + "{", // in case count does not reach min count request + "}", // + string.Empty); //endof count return 1; } @@ -128,18 +165,17 @@ namespace StgSharp.RegularAnalysis.Text string counter = sc.RequireNewCounter(); // TODO cannot check real count outside the cycle - _ = code.AppendLine($@"int {counter} = 0;") - .AppendLine(@$"for(; {counter}<{leave}; {counter}++)") - .AppendLine("{") - .AppendLine(@$"if({sc.InputSpan}[{sc.Position}..].StartWith({literal}))") - .AppendLine("{") - .AppendLine(@$"{sc.Position}+={seq.Length};") - .AppendLine("}") - .AppendLine("}") - .AppendLine() - .AppendLine(@$"if({counter}>{min})") // TODO match here - - .AppendLine($@"else"); // TODO fail here + _ = code.AppendLine($@"int {counter} = 0;", // + @$"for(; {counter}<{leave}; {counter}++)", // + "{", // + @$"if({sc.InputSpan}[{sc.Position}..].StartWith({literal}))", // + "{", // + @$"{sc.Position}+={seq.Length};", // + "}", // + "}", // + @$"if({counter}>{min})", // TODO match here + $@"else", // + "}"); // TODO fail here return 1; } @@ -181,6 +217,16 @@ namespace StgSharp.RegularAnalysis.Text _ = code.AppendLine(accept ? @$"if(" : @$"if(!("); string _case_code; RegexCharSet set; + /* + * in loop: + * for( is cas1 1 || + * is case 2 || + * ..... + * is case last) + * { + * success here + * } + */ for (int i = 1; i < set_arr.Length - 1; i++) { set = set_arr[i];