Skip to content

Commit

Permalink
save x87 state
Browse files Browse the repository at this point in the history
  • Loading branch information
clamchowder committed Aug 8, 2024
1 parent f9c658a commit 2e91113
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
1 change: 1 addition & 0 deletions AsmGen/UarchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void GenerateTestBlock(StringBuilder sb, IUarchTest.ISA isa)
sb.AppendLine("#endif");
sb.AppendLine(" gettimeofday(&endTv, &endTz);");
sb.AppendLine(" time_diff_ms = 1000 * (endTv.tv_sec - startTv.tv_sec) + ((endTv.tv_usec - startTv.tv_usec) / 1000);");
//sb.AppendLine(" fprintf(stderr, \"%lu ms elapsed, %lu iter\\n\", time_diff_ms, structIterations);");
if (DivideTimeByCount)
sb.AppendLine(" latency = 1e6 * (float)time_diff_ms / (float)(iterations);");
else
Expand Down
39 changes: 3 additions & 36 deletions AsmGen/UarchTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,6 @@ public static void GenerateVsExternLines(StringBuilder sb, UarchTest test)
sb.AppendLine("extern \"C\" uint64_t " + test.Prefix + counts[i] + $"({test.FunctionDefinitionParameters});");
}

public static void GenerateTestBlock(StringBuilder sb, UarchTest test)
{
sb.AppendLine(" if (argc > 1 && strncmp(test_name, \"" + test.Prefix + "\", " + test.Prefix.Length + ") == 0) {");
sb.AppendLine(" printf(\"" + test.Description + ":\\n\");");

int[] counts = test.Counts;
for (int i = 0; i < counts.Length; i++)
{
// use more iterations (iterations = structIterations * 100) and divide iteration count by tested-thing count
// for certain tests like call stack depth
if (test.DivideTimeByCount)
{
sb.AppendLine(" tmp = structIterations;");
sb.AppendLine(" structIterations = iterations / " + counts[i] + ";");
}

sb.AppendLine(" gettimeofday(&startTv, &startTz);");
sb.AppendLine(" " + test.Prefix + counts[i] + $"({test.GetFunctionCallParameters});");
sb.AppendLine(" gettimeofday(&endTv, &endTz);");
sb.AppendLine(" time_diff_ms = 1000 * (endTv.tv_sec - startTv.tv_sec) + ((endTv.tv_usec - startTv.tv_usec) / 1000);");
if (test.DivideTimeByCount)
sb.AppendLine(" latency = 1e6 * (float)time_diff_ms / (float)(iterations);");
else
sb.AppendLine(" latency = 1e6 * (float)time_diff_ms / (float)(structIterations);");
sb.AppendLine(" printf(\"" + counts[i] + ",%f\\n\", latency);\n");

if (test.DivideTimeByCount)
{
sb.AppendLine(" structIterations = tmp;");
}
}

sb.AppendLine(" }\n");
}

/// <summary>
/// Generates test functions in assembly, with filler instructions between two divs
/// Args are put into rcx, rdx, r8 (in that order) to match Windows calling convention
Expand Down Expand Up @@ -324,7 +289,8 @@ public static void GenerateX86AsmDivStructureTestFuncs(StringBuilder sb, int[] c
string initInstrs = null,
string postLoadInstrs1 = null,
string postLoadInstrs2 = null,
bool lfence = true)
bool lfence = true,
string cleanupInstrs = null)
{
for (int i = 0; i < counts.Length; i++)
{
Expand Down Expand Up @@ -383,6 +349,7 @@ public static void GenerateX86AsmDivStructureTestFuncs(StringBuilder sb, int[] c

sb.AppendLine(" dec %rcx");
sb.AppendLine(" jne " + funcName + "start");
if (cleanupInstrs != null) sb.AppendLine(cleanupInstrs);
sb.AppendLine(" pop %rdx");
sb.AppendLine(" pop %rcx");
sb.AppendLine(" pop %r8");
Expand Down
9 changes: 7 additions & 2 deletions AsmGen/tests/MmxRfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,24 @@ public override void GenerateAsm(StringBuilder sb, IUarchTest.ISA isa)

public void GenerateX86GccAsm(StringBuilder sb)
{
string initInstrs = " movq (%rdx), %mm0\n" +
string initInstrs =
" fsave (%r8)\n" +
" movq (%rdx), %mm0\n" +
" movq 8(%rdx), %mm1\n" +
" movq 16(%rdx), %mm2\n" +
" movq 24(%rdx), %mm3\n" +
" movq 32(%rdx), %mm4\n";

string cleanupInstrs = " frstor (%r8)";

string[] unrolledAdds = new string[4];
unrolledAdds[0] = " paddw %mm0, %mm1";
unrolledAdds[1] = " paddw %mm0, %mm2";
unrolledAdds[2] = " paddw %mm0, %mm3";
unrolledAdds[3] = " paddw %mm0, %mm4";

UarchTestHelpers.GenerateX86AsmStructureTestFuncs(sb, this.Counts, this.Prefix, unrolledAdds, unrolledAdds, initInstrs: initInstrs);
UarchTestHelpers.GenerateX86AsmStructureTestFuncs(
sb, this.Counts, this.Prefix, unrolledAdds, unrolledAdds, initInstrs: initInstrs, cleanupInstrs: cleanupInstrs);
}
}
}

0 comments on commit 2e91113

Please sign in to comment.