add single ir generator methods
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i)
|
#define _FMA_SELECT(i) _MM_SHUFFLE(i, i, i, i)
|
||||||
|
|
||||||
|
|
||||||
SN_MK_PROC_DECL_STD(float, sse, , fma)
|
SN_MK_PROC_DECL_STD(float, sse, , fma)
|
||||||
{
|
{
|
||||||
__mk_param_std(LEFT_RIGHT_ANS, float);
|
__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 a1 = _mm256_load_ps((float *)&a_base->y[1]);
|
||||||
register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]);
|
register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]);
|
||||||
register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]);
|
register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]);
|
||||||
|
|
||||||
SN_MK_FMA_F32_AVX2_CYCLE(0);
|
SN_MK_FMA_F32_AVX2_CYCLE(0);
|
||||||
SN_MK_FMA_F32_AVX2_CYCLE(1);
|
SN_MK_FMA_F32_AVX2_CYCLE(1);
|
||||||
SN_MK_FMA_F32_AVX2_CYCLE(2);
|
SN_MK_FMA_F32_AVX2_CYCLE(2);
|
||||||
|
|||||||
@@ -38,6 +38,20 @@ namespace StgSharp.RegularAnalysis.Abstraction
|
|||||||
emitter.Append(string.IsNullOrEmpty(line) ? string.Empty : line);
|
emitter.Append(string.IsNullOrEmpty(line) ? string.Empty : line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SequenceEmitter<string> AppendLine(
|
||||||
|
this SequenceEmitter<string> 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<string> AppendLine(
|
public static SequenceEmitter<string> AppendLine(
|
||||||
this SequenceEmitter<string> emitter,
|
this SequenceEmitter<string> emitter,
|
||||||
string line,
|
string line,
|
||||||
|
|||||||
@@ -76,6 +76,24 @@ namespace StgSharp.RegularAnalysis.Text
|
|||||||
|
|
||||||
#region code
|
#region code
|
||||||
|
|
||||||
|
private static int TryGeneratePack(
|
||||||
|
int outer_level,
|
||||||
|
ReadOnlySpan<RegexIR> ir_span,
|
||||||
|
SourceGenContext sc,
|
||||||
|
in SequenceEmitter<string> code,
|
||||||
|
in List<SequenceEmitter<string>> 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(
|
private static int TryGenerateCountSet(
|
||||||
int outer_level,
|
int outer_level,
|
||||||
ReadOnlySpan<RegexIR> ir_span,
|
ReadOnlySpan<RegexIR> ir_span,
|
||||||
@@ -87,10 +105,18 @@ namespace StgSharp.RegularAnalysis.Text
|
|||||||
if (ir_span[0] is not RegexCountSetIR count_set) {
|
if (ir_span[0] is not RegexCountSetIR count_set) {
|
||||||
return -1;
|
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;
|
string set_source = count_set.CharSet;
|
||||||
RegexCharSet[] set_arr = FigureCharSetType(set_source, out bool accept);
|
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;
|
string _case_code;
|
||||||
RegexCharSet set;
|
RegexCharSet set;
|
||||||
for (int i = 1; i < set_arr.Length - 1; i++)
|
for (int i = 1; i < set_arr.Length - 1; i++)
|
||||||
@@ -101,10 +127,21 @@ namespace StgSharp.RegularAnalysis.Text
|
|||||||
}
|
}
|
||||||
set = set_arr[^1];
|
set = set_arr[^1];
|
||||||
_case_code = GenLine(set, sc, ")");
|
_case_code = GenLine(set, sc, ")");
|
||||||
_ = code.AppendLine(_case_code)
|
_ = code.AppendLine(_case_code, //
|
||||||
.AppendLine("{")
|
"{", // in case match
|
||||||
.AppendLine("-------------------------------------")// TODO case success
|
"}", //
|
||||||
.AppendLine("}");
|
"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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,18 +165,17 @@ namespace StgSharp.RegularAnalysis.Text
|
|||||||
string counter = sc.RequireNewCounter();
|
string counter = sc.RequireNewCounter();
|
||||||
|
|
||||||
// TODO cannot check real count outside the cycle
|
// TODO cannot check real count outside the cycle
|
||||||
_ = code.AppendLine($@"int {counter} = 0;")
|
_ = code.AppendLine($@"int {counter} = 0;", //
|
||||||
.AppendLine(@$"for(; {counter}<{leave}; {counter}++)")
|
@$"for(; {counter}<{leave}; {counter}++)", //
|
||||||
.AppendLine("{")
|
"{", //
|
||||||
.AppendLine(@$"if({sc.InputSpan}[{sc.Position}..].StartWith({literal}))")
|
@$"if({sc.InputSpan}[{sc.Position}..].StartWith({literal}))", //
|
||||||
.AppendLine("{")
|
"{", //
|
||||||
.AppendLine(@$"{sc.Position}+={seq.Length};")
|
@$"{sc.Position}+={seq.Length};", //
|
||||||
.AppendLine("}")
|
"}", //
|
||||||
.AppendLine("}")
|
"}", //
|
||||||
.AppendLine()
|
@$"if({counter}>{min})", // TODO match here
|
||||||
.AppendLine(@$"if({counter}>{min})") // TODO match here
|
$@"else", //
|
||||||
|
"}"); // TODO fail here
|
||||||
.AppendLine($@"else"); // TODO fail here
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +217,16 @@ namespace StgSharp.RegularAnalysis.Text
|
|||||||
_ = code.AppendLine(accept ? @$"if(" : @$"if(!(");
|
_ = code.AppendLine(accept ? @$"if(" : @$"if(!(");
|
||||||
string _case_code;
|
string _case_code;
|
||||||
RegexCharSet set;
|
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++)
|
for (int i = 1; i < set_arr.Length - 1; i++)
|
||||||
{
|
{
|
||||||
set = set_arr[i];
|
set = set_arr[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user