16bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// Copyright 2013 the V8 project authors. All rights reserved. 26bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// Redistribution and use in source and binary forms, with or without 36bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// modification, are permitted provided that the following conditions are 46bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// met: 56bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// 66bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// * Redistributions of source code must retain the above copyright 76bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// notice, this list of conditions and the following disclaimer. 86bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// * Redistributions in binary form must reproduce the above 96bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// copyright notice, this list of conditions and the following 106bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// disclaimer in the documentation and/or other materials provided 116bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// with the distribution. 126bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// * Neither the name of Google Inc. nor the names of its 136bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// contributors may be used to endorse or promote products derived 146bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// from this software without specific prior written permission. 156bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// 166bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org 286bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org// Flags: --allow-natives-syntax 296bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org 306bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.orgfunction foo(word, nBits) { 316bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org return (word[1] >>> nBits) | (word[0] << (32 - nBits)); 326bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org} 336bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org 346bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.orgword = [0x1001, 0]; 356bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org 366bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.orgvar expected = foo(word, 1); 376bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.orgfoo(word, 1); 386bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.org%OptimizeFunctionOnNextCall(foo); 396bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.orgvar optimized = foo(word, 1); 406bec0093ef661b53a1e338a233d7aafb9536a307mvstanton@chromium.orgassertEquals(expected, optimized) 41