mark.lam@apple.com | 6f5a902 | 2015-12-22 16:20:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "JITNegGenerator.h" |
| 28 | |
| 29 | #if ENABLE(JIT) |
| 30 | |
| 31 | namespace JSC { |
| 32 | |
| 33 | void JITNegGenerator::generateFastPath(CCallHelpers& jit) |
| 34 | { |
| 35 | ASSERT(m_scratchGPR != m_src.payloadGPR()); |
| 36 | ASSERT(m_scratchGPR != m_result.payloadGPR()); |
| 37 | ASSERT(m_scratchGPR != InvalidGPRReg); |
| 38 | #if USE(JSVALUE32_64) |
| 39 | ASSERT(m_scratchGPR != m_src.tagGPR()); |
| 40 | ASSERT(m_scratchGPR != m_result.tagGPR()); |
| 41 | #endif |
| 42 | |
| 43 | m_didEmitFastPath = true; |
| 44 | |
| 45 | jit.moveValueRegs(m_src, m_result); |
| 46 | CCallHelpers::Jump srcNotInt = jit.branchIfNotInt32(m_src); |
| 47 | |
| 48 | // -0 should produce a double, and hence cannot be negated as an int. |
| 49 | // The negative int32 0x80000000 doesn't have a positive int32 representation, and hence cannot be negated as an int. |
| 50 | m_slowPathJumpList.append(jit.branchTest32(CCallHelpers::Zero, m_src.payloadGPR(), CCallHelpers::TrustedImm32(0x7fffffff))); |
| 51 | |
| 52 | jit.neg32(m_result.payloadGPR()); |
| 53 | #if USE(JSVALUE64) |
| 54 | jit.boxInt32(m_result.payloadGPR(), m_result); |
| 55 | #endif |
| 56 | m_endJumpList.append(jit.jump()); |
| 57 | |
| 58 | srcNotInt.link(&jit); |
| 59 | m_slowPathJumpList.append(jit.branchIfNotNumber(m_src, m_scratchGPR)); |
| 60 | |
| 61 | // For a double, all we need to do is to invert the sign bit. |
| 62 | #if USE(JSVALUE64) |
| 63 | jit.move(CCallHelpers::TrustedImm64((int64_t)(1ull << 63)), m_scratchGPR); |
| 64 | jit.xor64(m_scratchGPR, m_result.payloadGPR()); |
| 65 | #else |
| 66 | jit.xor32(CCallHelpers::TrustedImm32(1 << 31), m_result.tagGPR()); |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | } // namespace JSC |
| 71 | |
| 72 | #endif // ENABLE(JIT) |