18e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// Copyright 2013 the V8 project authors. All rights reserved.
28e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// Redistribution and use in source and binary forms, with or without
38e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// modification, are permitted provided that the following conditions are
48e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// met:
58e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//
68e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//     * Redistributions of source code must retain the above copyright
78e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//       notice, this list of conditions and the following disclaimer.
88e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//     * Redistributions in binary form must reproduce the above
98e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//       copyright notice, this list of conditions and the following
108e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//       disclaimer in the documentation and/or other materials provided
118e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//       with the distribution.
128e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//     * Neither the name of Google Inc. nor the names of its
138e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//       contributors may be used to endorse or promote products derived
148e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//       from this software without specific prior written permission.
158e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org//
168e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
198e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
208e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
218e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
228e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
238e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
248e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
268e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org
288e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org// Flags: --allow-natives-syntax
298e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org
308e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgfunction div(g) {
318e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org  return (g/-1) ^ 1
328e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org}
338e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org
348e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgvar kMinInt = 1 << 31;
358e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgvar expected_MinInt = div(kMinInt);
368e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgvar expected_minus_zero = div(0);
378e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org%OptimizeFunctionOnNextCall(div);
388e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgassertEquals(expected_MinInt, div(kMinInt));
398e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgassertEquals(expected_minus_zero , div(0));
408e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org
418e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgfunction mul(g) {
428e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org  return (g * -1) ^ 1
438e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org}
448e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org
458e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgexpected_MinInt = mul(kMinInt);
468e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgexpected_minus_zero = mul(0);
478e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.org%OptimizeFunctionOnNextCall(mul);
488e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgassertEquals(expected_MinInt, mul(kMinInt));
498e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgassertOptimized(mul);
508e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgassertEquals(expected_minus_zero , mul(0));
518e36b5ba34174c8ceb04a47d7e10dcc8f43d94a4machenbach@chromium.orgassertOptimized(mul);
52