Home | History | Annotate | Download | only in compiler
      1 // Copyright 2014 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Flags: --allow-natives-syntax --use-osr
      6 
      7 var counter = 111;
      8 
      9 function gen(w) {  // defeat compiler cache.
     10  var num = counter++;
     11   var Z = [ "", "", "", ];
     12   Z[w] = "%OptimizeOsr()";
     13   var src =
     14     "function f" + num + "(a,b,c) {" +
     15     "  var x = 0;" +
     16     "  var y = 0;" +
     17     "  var z = 0;" +
     18     "  while (a > 0) { " + Z[0] + "; x += 19; a--; }" +
     19     "  while (b > 0) { " + Z[1] + "; y += 23; b--; }" +
     20     "  while (c > 0) { " + Z[2] + "; z += 29; c--; }" +
     21     "  return x + y + z;" +
     22     "} f" + num;
     23   return eval(src);
     24 }
     25 
     26 function check(x,a,b,c) {
     27   for (var i = 0; i < 3; i++) {
     28     var f = gen(i);
     29     assertEquals(x, f(a, b, c));
     30   }
     31 }
     32 
     33 check(213, 3,3,3);
     34 check(365, 4,5,6);
     35 check(6948, 99,98,97);
     36