Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: partial SSE scalar op support #92

Merged
merged 3 commits into from
Aug 9, 2021
Merged

feat: partial SSE scalar op support #92

merged 3 commits into from
Aug 9, 2021

Conversation

pnwamk
Copy link
Contributor

@pnwamk pnwamk commented Jul 30, 2021

No description provided.

@pnwamk
Copy link
Contributor Author

pnwamk commented Jul 30, 2021

C code used to sanity check SSE-related assembly call in LLVM:

#include <stdio.h>

// clang -S -emit-llvm sse_ops.c

int main()
{
  float x1 = 3.0;
  float y1 = 0.14159;
  float res1;

  asm ( "addss %2,%1" : "=x,x" (res1) : "x,x" (x1), "x,m" (y1) );
  printf("addss: x = %f, y = %f, res = %f\n", x1, y1, res1);
  asm ( "subss %2,%1" : "=x,x" (res1) : "x,x" (x1), "x,m" (y1) );
  printf("subss: x = %f, y = %f, res = %f\n", x1, y1, res1);
  asm ( "mulss %2,%1" : "=x,x" (res1) : "x,x" (x1), "x,m" (y1) );
  printf("mulss: x = %f, y = %f, res = %f\n", x1, y1, res1);
  asm ( "divss %2,%1" : "=x,x" (res1) : "x,x" (x1), "x,m" (y1) );
  printf("divss: x = %f, y = %f, res = %f\n", x1, y1, res1);
  asm ( "minss %2,%1" : "=x,x" (res1) : "x,x" (x1), "x,m" (y1) );
  printf("minss: x = %f, y = %f, res = %f\n", x1, y1, res1);
  asm ( "maxss %2,%1" : "=x,x" (res1) : "x,x" (x1), "x,m" (y1) );
  printf("maxss: x = %f, y = %f, res = %f\n", x1, y1, res1);

  double x2 = 3.0;
  double y2 = 0.14159;
  double res2;

  asm ( "addsd %2,%1" : "=x,x" (res2) : "x,x" (x2), "x,m" (y2) );
  printf("addsd: x = %f, y = %f, res = %f\n", x2, y2, res2);
  asm ( "subsd %2,%1" : "=x,x" (res2) : "x,x" (x2), "x,m" (y2) );
  printf("subsd: x = %f, y = %f, res = %f\n", x2, y2, res2);
  asm ( "mulsd %2,%1" : "=x,x" (res2) : "x,x" (x2), "x,m" (y2) );
  printf("mulsd: x = %f, y = %f, res = %f\n", x2, y2, res2);
  asm ( "divsd %2,%1" : "=x,x" (res2) : "x,x" (x2), "x,m" (y2) );
  printf("divsd: x = %f, y = %f, res = %f\n", x2, y2, res2);
  asm ( "minsd %2,%1" : "=x,x" (res2) : "x,x" (x2), "x,m" (y2) );
  printf("minsd: x = %f, y = %f, res = %f\n", x2, y2, res2);
  asm ( "maxsd %2,%1" : "=x,x" (res2) : "x,x" (x2), "x,m" (y2) );
  printf("maxsd: x = %f, y = %f, res = %f\n", x2, y2, res2);

  return 0;
}

@pnwamk
Copy link
Contributor Author

pnwamk commented Jul 30, 2021

These changes make a small increase in the number of functions successfully recovered:

diff -U1 old-reopt-explore-stats.txt new-reopt-explore-stats.txt 
--- old-stats.txt	2021-07-30 13:13:17.000000000 -0700
+++ new-stats.txt	2021-07-30 13:13:33.000000000 -0700
@@ -28,6 +28,6 @@
 Recovery:
-  Succeeded: 21,819 (72%)
-  Failed: 8,402 (28%)
-    Unsupported function value: 2,336 (8%)
-    Unimplemented LLVM backend feature: 4,990 (17%)
+  Succeeded: 21,842 (72%)
+  Failed: 8,379 (28%)
+    Unsupported function value: 2,396 (8%)
+    Unimplemented LLVM backend feature: 4,907 (16%)
     Stack offset escape: 83 (0%)
Click to see full stats before and after.

Full reopt-explore stats w/o PR changes:

reopt analyzed 394 binaries:
Generated LLVM bitcode for 394 out of 394 binaries.
Initialization:
  Code segment: 42,933,178 bytes
  Initial entry points: 79776
  Warnings: 0
Discovery:
  Bytes discovered: 23,025,164 (54%)
  Succeeded: 64,494 (81%)
  Failed: 15,500 (19%)
    Unhandled instruction: 425 (1%)
    Unidentified control flow: 15,075 (19%)
Argument Analysis:
  Succeeded: 40,429 (63%)
  Failed: 24,065 (37%)
  Header Warnings: 0
  DWARF Warnings: 0
  Code Warnings: 38,681
Invariant Inference:
  Succeeded: 30,221 (75%)
  Failed: 10,208 (25%)
    Symbolic call stack height: 1 (0%)
    Unresolved stack read: 13 (0%)
    Indirect call target: 526 (1%)
    Call target not function entry point: 41 (0%)
    Unresolved call target arguments: 9,614 (24%)
    Could not resolve varargs args: 13 (0%)
Recovery:
  Succeeded: 21,819 (72%)
  Failed: 8,402 (28%)
    Unsupported function value: 2,336 (8%)
    Unimplemented LLVM backend feature: 4,990 (17%)
    Stack offset escape: 83 (0%)
    Stack read overlapping offset: 1 (0%)
    Unresolved return value: 8 (0%)
    Missing variable value: 984 (3%)

Full reopt-explore stats w/ PR changes:

reopt analyzed 394 binaries:
Generated LLVM bitcode for 394 out of 394 binaries.
Initialization:
  Code segment: 42,933,178 bytes
  Initial entry points: 79776
  Warnings: 0
Discovery:
  Bytes discovered: 23,025,164 (54%)
  Succeeded: 64,494 (81%)
  Failed: 15,500 (19%)
    Unhandled instruction: 425 (1%)
    Unidentified control flow: 15,075 (19%)
Argument Analysis:
  Succeeded: 40,429 (63%)
  Failed: 24,065 (37%)
  Header Warnings: 0
  DWARF Warnings: 0
  Code Warnings: 38,681
Invariant Inference:
  Succeeded: 30,221 (75%)
  Failed: 10,208 (25%)
    Symbolic call stack height: 1 (0%)
    Unresolved stack read: 13 (0%)
    Indirect call target: 526 (1%)
    Call target not function entry point: 41 (0%)
    Unresolved call target arguments: 9,614 (24%)
    Could not resolve varargs args: 13 (0%)
Recovery:
  Succeeded: 21,842 (72%)
  Failed: 8,379 (28%)
    Unsupported function value: 2,396 (8%)
    Unimplemented LLVM backend feature: 4,907 (16%)
    Stack offset escape: 83 (0%)
    Stack read overlapping offset: 1 (0%)
    Unresolved return value: 8 (0%)
    Missing variable value: 984 (3%)

@pnwamk pnwamk force-pushed the feat/sse-scalar-ops branch from 374d048 to 1f7f40d Compare August 6, 2021 22:06
@pnwamk
Copy link
Contributor Author

pnwamk commented Aug 6, 2021

C code for extracting LLVM for ucomisx instructions:

#include <stdio.h>

// clang -S -emit-llvm ucomsx.c

int main()
{
  float x1 = 2.0;
  float y1 = 1.0;
  short res1;
  short cf = 0; // bit 0
  short pf = 0; // bit 2
  short zf = 0; // bit 6

  asm ( "ucomiss %1,%2\n\t"
        "pushfw\n\t"
        "popw %0\n\t"
        : "=r,r" (res1)
        : "x,x" (x1), "x,M" (y1) );
  // cf = (res1 & 0b1) ? 1 : 0;
  // pf = (res1 & 0b100) ? 1 : 0;
  // zf = (res1 & 0b1000000) ? 1 : 0;

  // printf("ucomiss: x = %f, y = %f, zf,pf,cf =%i,%i,%i\n",
  //         x1, y1, zf, pf, cf);

  double x2 = 3.0;
  double y2 = 1.0;
  short res2;

  asm ( "ucomisd %1,%2\n\t"
        "pushfw\n\t"
        "popw %0\n\t"
        : "=r,r" (res2)
        : "x,x" (x2), "x,N" (y2) );
  // cf = (res2 & 0b1) ? 1 : 0;
  // pf = (res2 & 0b100) ? 1 : 0;
  // zf = (res2 & 0b1000000) ? 1 : 0;

  // printf("ucomiss: x = %f, y = %f, zf,pf,cf =%i,%i,%i\n",
  //         x1, y1, zf, pf, cf);

  return 0;
}

@pnwamk
Copy link
Contributor Author

pnwamk commented Aug 9, 2021

Metric changes with latest improvements:

$ diff -U1 pre_additions.txt post_additions.txt 
--- pre_additions.txt	2021-08-09 12:18:49.000000000 -0700
+++ post_additions.txt	2021-08-09 12:18:18.000000000 -0700
@@ -28,6 +28,6 @@
 Recovery:
-  Succeeded: 21,819 (72%)
-  Failed: 8,402 (28%)
-    Unsupported function value: 2,336 (8%)
-    Unimplemented LLVM backend feature: 4,990 (17%)
+  Succeeded: 21,868 (72%)
+  Failed: 8,353 (28%)
+    Unsupported function value: 2,396 (8%)
+    Unimplemented LLVM backend feature: 4,881 (16%)
     Stack offset escape: 83 (0%)

@pnwamk pnwamk merged commit befc3e8 into main Aug 9, 2021
@pnwamk pnwamk deleted the feat/sse-scalar-ops branch August 9, 2021 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant