~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to src/experimental/allow_loopvars_from_memsetcpy_inasm.diff

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
commit a61ef3dbbaf7333ad67fca29c0aad5bcc99b653a
 
2
Author: Alon Zakai <alonzakai@gmail.com>
 
3
Date:   Wed Mar 6 18:18:03 2013 -0800
 
4
 
 
5
    handle new vars in asm code, such as the loop vars from memset/memcpy loops
 
6
 
 
7
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
 
8
index f2dc516..65059e8 100644
 
9
--- a/tools/js-optimizer.js
 
10
+++ b/tools/js-optimizer.js
 
11
@@ -1321,7 +1321,7 @@ function normalizeAsm(func) {
 
12
       var name = v[0];
 
13
       var value = v[1];
 
14
       if (!(name in data.vars)) {
 
15
-        assert(value[0] == 'num' || (value[0] == 'unary-prefix' && value[2][0] == 'num')); // must be valid coercion no-op
 
16
+        if (!(value[0] == 'num' || (value[0] == 'unary-prefix' && value[2][0] == 'num'))) break outer; // must be valid coercion no-op
 
17
         data.vars[name] = detectAsmCoercion(value);
 
18
         v.length = 1; // make an un-assigning var
 
19
       } else {
 
20
@@ -1331,6 +1331,7 @@ function normalizeAsm(func) {
 
21
     i++;
 
22
   }
 
23
   // finally, look for other var definitions and collect them
 
24
+  var extra = [];
 
25
   while (i < stats.length) {
 
26
     traverse(stats[i], function(node, type) {
 
27
       if (type == 'var') {
 
28
@@ -1340,6 +1341,7 @@ function normalizeAsm(func) {
 
29
           var value = v[1];
 
30
           if (!(name in data.vars)) {
 
31
             data.vars[name] = detectAsmCoercion(value);
 
32
+            extra.push(['var', [[name]]]); // add a 'var' for normal JS
 
33
           }
 
34
         }
 
35
         unVarify(node[1], node);
 
36
@@ -1353,6 +1355,7 @@ function normalizeAsm(func) {
 
37
     });
 
38
     i++;
 
39
   }
 
40
+  if (extra.length > 0) stats.splice.apply(stats, [0, 0].concat(extra));
 
41
   //printErr('normalized \n\n' + astToSrc(func) + '\n\nwith: ' + JSON.stringify(data));
 
42
   return data;
 
43
 }
 
44
diff --git a/tools/test-js-optimizer-asm-regs-output.js b/tools/test-js-optimizer-asm-regs-output.js
 
45
index 99bccd2..f84b8d5 100644
 
46
--- a/tools/test-js-optimizer-asm-regs-output.js
 
47
+++ b/tools/test-js-optimizer-asm-regs-output.js
 
48
@@ -9,6 +9,18 @@ function asm(d1, i2) {
 
49
   d4 = d1 * 5;
 
50
   return d4;
 
51
 }
 
52
+function asm2(d1, i2) {
 
53
+  d1 = +d1;
 
54
+  i2 = i2 | 0;
 
55
+  var i3 = 0, d4 = +0;
 
56
+  i3 = i2;
 
57
+  i2 = d1 + i3 | 0;
 
58
+  d1 = d(Math_max(10, Math_min(5, f())));
 
59
+  i3 = i2 + 2 | 0;
 
60
+  print(i3);
 
61
+  d4 = d1 * 5;
 
62
+  return d4;
 
63
+}
 
64
 function _doit(i1, i2, i3) {
 
65
   i1 = i1 | 0;
 
66
   i2 = i2 | 0;
 
67
diff --git a/tools/test-js-optimizer-asm-regs.js b/tools/test-js-optimizer-asm-regs.js
 
68
index 0afced2..fbaa7c4 100644
 
69
--- a/tools/test-js-optimizer-asm-regs.js
 
70
+++ b/tools/test-js-optimizer-asm-regs.js
 
71
@@ -10,6 +10,19 @@ function asm(x, y) {
 
72
   double2 = double1*5;
 
73
   return double2;
 
74
 }
 
75
+function asm2(x, y) {
 
76
+  x = +x;
 
77
+  y = y | 0;
 
78
+  var int1 = 0, int2 = 0; // do not mix the types!
 
79
+  var double1 = +0, double2 = +0;
 
80
+  var tempy = y;
 
81
+  int1 = (x+tempy)|0;
 
82
+  double1 = d(Math.max(10, Math_min(5, f())));
 
83
+  int2 = (int1+2)|0;
 
84
+  print(int2);
 
85
+  double2 = double1*5;
 
86
+  return double2;
 
87
+}
 
88
 function _doit($x, $y$0, $y$1) {
 
89
   $x = $x | 0;
 
90
   $y$0 = $y$0 | 0;
 
91
@@ -41,5 +54,5 @@ function retf() {
 
92
   }
 
93
   // missing final return, need it as a float
 
94
 }
 
95
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "_doit", "rett", "ret2t", "retf"]
 
96
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "asm2", "_doit", "rett", "ret2t", "retf"]
 
97