barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2019 Apple Inc. All rights reserved. |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 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 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 27 | |
mjs@apple.com | cc66821 | 2010-01-04 11:38:56 +0000 | [diff] [blame] | 28 | #if ENABLE(ASSEMBLER) && CPU(X86) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 29 | |
| 30 | #include "MacroAssemblerX86Common.h" |
| 31 | |
| 32 | namespace JSC { |
| 33 | |
| 34 | class MacroAssemblerX86 : public MacroAssemblerX86Common { |
| 35 | public: |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 36 | static constexpr unsigned numGPRs = 8; |
| 37 | static constexpr unsigned numFPRs = 8; |
fpizlo@apple.com | 1c12847 | 2016-07-18 19:51:45 +0000 | [diff] [blame] | 38 | |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 39 | static constexpr Scale ScalePtr = TimesFour; |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 40 | |
| 41 | using MacroAssemblerX86Common::add32; |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 42 | using MacroAssemblerX86Common::and32; |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 43 | using MacroAssemblerX86Common::branchAdd32; |
barraclough@apple.com | 70558a3 | 2011-10-04 01:16:46 +0000 | [diff] [blame] | 44 | using MacroAssemblerX86Common::branchSub32; |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 45 | using MacroAssemblerX86Common::sub32; |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 46 | using MacroAssemblerX86Common::or32; |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 47 | using MacroAssemblerX86Common::load32; |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 48 | using MacroAssemblerX86Common::load8; |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 49 | using MacroAssemblerX86Common::store32; |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 50 | using MacroAssemblerX86Common::store8; |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 51 | using MacroAssemblerX86Common::branch32; |
barraclough@apple.com | d7e1338 | 2009-02-19 22:51:40 +0000 | [diff] [blame] | 52 | using MacroAssemblerX86Common::call; |
fpizlo@apple.com | 4621171 | 2011-11-10 01:08:50 +0000 | [diff] [blame] | 53 | using MacroAssemblerX86Common::jump; |
ysuzuki@apple.com | 4987151 | 2019-08-14 20:15:04 +0000 | [diff] [blame] | 54 | using MacroAssemblerX86Common::farJump; |
barraclough@apple.com | e1227fc | 2011-09-22 01:10:31 +0000 | [diff] [blame] | 55 | using MacroAssemblerX86Common::addDouble; |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 56 | using MacroAssemblerX86Common::loadDouble; |
barraclough@apple.com | d910c0d | 2011-09-24 05:04:08 +0000 | [diff] [blame] | 57 | using MacroAssemblerX86Common::storeDouble; |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 58 | using MacroAssemblerX86Common::convertInt32ToDouble; |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 59 | using MacroAssemblerX86Common::branch8; |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 60 | using MacroAssemblerX86Common::branchTest8; |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 61 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 62 | void add32(TrustedImm32 imm, RegisterID src, RegisterID dest) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 63 | { |
nrotem@apple.com | a47b30a | 2013-11-28 20:33:44 +0000 | [diff] [blame] | 64 | m_assembler.leal_mr(imm.m_value, src, dest); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 65 | } |
| 66 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 67 | void add32(TrustedImm32 imm, AbsoluteAddress address) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 68 | { |
nrotem@apple.com | a47b30a | 2013-11-28 20:33:44 +0000 | [diff] [blame] | 69 | m_assembler.addl_im(imm.m_value, address.m_ptr); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 70 | } |
| 71 | |
fpizlo@apple.com | 327f237 | 2012-07-15 04:02:16 +0000 | [diff] [blame] | 72 | void add32(AbsoluteAddress address, RegisterID dest) |
| 73 | { |
| 74 | m_assembler.addl_mr(address.m_ptr, dest); |
| 75 | } |
| 76 | |
barraclough@apple.com | 6d410b0 | 2011-11-10 20:24:06 +0000 | [diff] [blame] | 77 | void add64(TrustedImm32 imm, AbsoluteAddress address) |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 78 | { |
barraclough@apple.com | 6d410b0 | 2011-11-10 20:24:06 +0000 | [diff] [blame] | 79 | m_assembler.addl_im(imm.m_value, address.m_ptr); |
| 80 | m_assembler.adcl_im(imm.m_value >> 31, reinterpret_cast<const char*>(address.m_ptr) + sizeof(int32_t)); |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 81 | } |
barraclough@apple.com | 6d410b0 | 2011-11-10 20:24:06 +0000 | [diff] [blame] | 82 | |
utatane.tea@gmail.com | 98d5890 | 2017-11-29 17:37:36 +0000 | [diff] [blame] | 83 | void getEffectiveAddress(BaseIndex address, RegisterID dest) |
| 84 | { |
| 85 | return x86Lea32(address, dest); |
| 86 | } |
| 87 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 88 | void and32(TrustedImm32 imm, AbsoluteAddress address) |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 89 | { |
| 90 | m_assembler.andl_im(imm.m_value, address.m_ptr); |
| 91 | } |
| 92 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 93 | void or32(TrustedImm32 imm, AbsoluteAddress address) |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 94 | { |
nrotem@apple.com | a47b30a | 2013-11-28 20:33:44 +0000 | [diff] [blame] | 95 | m_assembler.orl_im(imm.m_value, address.m_ptr); |
barraclough@apple.com | c32f32e | 2009-05-13 09:10:02 +0000 | [diff] [blame] | 96 | } |
fpizlo@apple.com | 327f237 | 2012-07-15 04:02:16 +0000 | [diff] [blame] | 97 | |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 98 | void or32(RegisterID reg, AbsoluteAddress address) |
| 99 | { |
| 100 | m_assembler.orl_rm(reg, address.m_ptr); |
| 101 | } |
rmorisset@apple.com | 694598d | 2019-11-13 20:07:29 +0000 | [diff] [blame] | 102 | |
| 103 | void or16(TrustedImm32 imm, AbsoluteAddress address) |
| 104 | { |
| 105 | m_assembler.orw_im(imm.m_value, address.m_ptr); |
| 106 | } |
fpizlo@apple.com | c7be5be0 | 2012-09-17 19:07:32 +0000 | [diff] [blame] | 107 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 108 | void sub32(TrustedImm32 imm, AbsoluteAddress address) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 109 | { |
| 110 | m_assembler.subl_im(imm.m_value, address.m_ptr); |
| 111 | } |
| 112 | |
barraclough@apple.com | 8328f63 | 2011-09-21 18:33:43 +0000 | [diff] [blame] | 113 | void load32(const void* address, RegisterID dest) |
eric@webkit.org | 667fa8a | 2010-08-08 06:04:59 +0000 | [diff] [blame] | 114 | { |
eric@webkit.org | b813098 | 2010-08-08 07:22:06 +0000 | [diff] [blame] | 115 | m_assembler.movl_mr(address, dest); |
eric@webkit.org | 667fa8a | 2010-08-08 06:04:59 +0000 | [diff] [blame] | 116 | } |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 117 | |
| 118 | void load8(const void* address, RegisterID dest) |
| 119 | { |
| 120 | m_assembler.movzbl_mr(address, dest); |
| 121 | } |
eric@webkit.org | 667fa8a | 2010-08-08 06:04:59 +0000 | [diff] [blame] | 122 | |
fpizlo@apple.com | fac5bed | 2014-05-14 03:57:18 +0000 | [diff] [blame] | 123 | void abortWithReason(AbortReason reason) |
| 124 | { |
| 125 | move(TrustedImm32(reason), X86Registers::eax); |
| 126 | breakpoint(); |
| 127 | } |
| 128 | |
fpizlo@apple.com | 407afe6 | 2014-06-13 18:56:58 +0000 | [diff] [blame] | 129 | void abortWithReason(AbortReason reason, intptr_t misc) |
| 130 | { |
| 131 | move(TrustedImm32(misc), X86Registers::edx); |
| 132 | abortWithReason(reason); |
| 133 | } |
| 134 | |
fpizlo@apple.com | d68b1f8 | 2012-07-05 22:55:51 +0000 | [diff] [blame] | 135 | ConvertibleLoadLabel convertibleLoadPtr(Address address, RegisterID dest) |
| 136 | { |
| 137 | ConvertibleLoadLabel result = ConvertibleLoadLabel(this); |
| 138 | m_assembler.movl_mr(address.offset, address.base, dest); |
| 139 | return result; |
| 140 | } |
| 141 | |
barraclough@apple.com | e1227fc | 2011-09-22 01:10:31 +0000 | [diff] [blame] | 142 | void addDouble(AbsoluteAddress address, FPRegisterID dest) |
| 143 | { |
| 144 | m_assembler.addsd_mr(address.m_ptr, dest); |
| 145 | } |
| 146 | |
commit-queue@webkit.org | 918d985 | 2014-05-13 20:57:07 +0000 | [diff] [blame] | 147 | void storeDouble(FPRegisterID src, TrustedImmPtr address) |
barraclough@apple.com | d910c0d | 2011-09-24 05:04:08 +0000 | [diff] [blame] | 148 | { |
commit-queue@webkit.org | 918d985 | 2014-05-13 20:57:07 +0000 | [diff] [blame] | 149 | ASSERT(address.m_value); |
keith_miller@apple.com | 6c2ac2e | 2018-03-08 02:26:55 +0000 | [diff] [blame] | 150 | m_assembler.movsd_rm(src, address.asPtr()); |
barraclough@apple.com | d910c0d | 2011-09-24 05:04:08 +0000 | [diff] [blame] | 151 | } |
| 152 | |
ggaren@apple.com | 540d71a6 | 2009-07-30 20:57:44 +0000 | [diff] [blame] | 153 | void convertInt32ToDouble(AbsoluteAddress src, FPRegisterID dest) |
| 154 | { |
| 155 | m_assembler.cvtsi2sd_mr(src.m_ptr, dest); |
| 156 | } |
| 157 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 158 | void store32(TrustedImm32 imm, void* address) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 159 | { |
| 160 | m_assembler.movl_i32m(imm.m_value, address); |
| 161 | } |
| 162 | |
mjs@apple.com | 9355370 | 2009-05-09 08:35:57 +0000 | [diff] [blame] | 163 | void store32(RegisterID src, void* address) |
| 164 | { |
eric@webkit.org | b813098 | 2010-08-08 07:22:06 +0000 | [diff] [blame] | 165 | m_assembler.movl_rm(src, address); |
mjs@apple.com | 9355370 | 2009-05-09 08:35:57 +0000 | [diff] [blame] | 166 | } |
fpizlo@apple.com | 3396171 | 2013-11-20 05:49:05 +0000 | [diff] [blame] | 167 | |
| 168 | void store8(RegisterID src, void* address) |
| 169 | { |
| 170 | m_assembler.movb_rm(src, address); |
| 171 | } |
mjs@apple.com | 9355370 | 2009-05-09 08:35:57 +0000 | [diff] [blame] | 172 | |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 173 | void store8(TrustedImm32 imm, void* address) |
| 174 | { |
utatane.tea@gmail.com | 997ca6b | 2016-07-17 14:33:26 +0000 | [diff] [blame] | 175 | TrustedImm32 imm8(static_cast<int8_t>(imm.m_value)); |
| 176 | m_assembler.movb_i8m(imm8.m_value, address); |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 177 | } |
fpizlo@apple.com | c14c8d3 | 2012-10-10 02:14:42 +0000 | [diff] [blame] | 178 | |
fpizlo@apple.com | c14c8d3 | 2012-10-10 02:14:42 +0000 | [diff] [blame] | 179 | void moveDoubleToInts(FPRegisterID src, RegisterID dest1, RegisterID dest2) |
| 180 | { |
julien.brianceau@gmail.com | 22e4270 | 2014-09-12 22:00:13 +0000 | [diff] [blame] | 181 | m_assembler.pextrw_irr(3, src, dest1); |
| 182 | m_assembler.pextrw_irr(2, src, dest2); |
| 183 | lshift32(TrustedImm32(16), dest1); |
| 184 | or32(dest1, dest2); |
commit-queue@webkit.org | 67812aa | 2015-12-23 11:52:39 +0000 | [diff] [blame] | 185 | moveFloatTo32(src, dest1); |
fpizlo@apple.com | c14c8d3 | 2012-10-10 02:14:42 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | void moveIntsToDouble(RegisterID src1, RegisterID src2, FPRegisterID dest, FPRegisterID scratch) |
| 189 | { |
commit-queue@webkit.org | 67812aa | 2015-12-23 11:52:39 +0000 | [diff] [blame] | 190 | move32ToFloat(src1, dest); |
| 191 | move32ToFloat(src2, scratch); |
fpizlo@apple.com | c14c8d3 | 2012-10-10 02:14:42 +0000 | [diff] [blame] | 192 | lshiftPacked(TrustedImm32(32), scratch); |
| 193 | orPacked(scratch, dest); |
| 194 | } |
fpizlo@apple.com | 69e2784 | 2012-09-19 21:43:10 +0000 | [diff] [blame] | 195 | |
barraclough@apple.com | 70558a3 | 2011-10-04 01:16:46 +0000 | [diff] [blame] | 196 | Jump branchAdd32(ResultCondition cond, TrustedImm32 imm, AbsoluteAddress dest) |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 197 | { |
barraclough@apple.com | 70558a3 | 2011-10-04 01:16:46 +0000 | [diff] [blame] | 198 | m_assembler.addl_im(imm.m_value, dest.m_ptr); |
| 199 | return Jump(m_assembler.jCC(x86Condition(cond))); |
| 200 | } |
| 201 | |
| 202 | Jump branchSub32(ResultCondition cond, TrustedImm32 imm, AbsoluteAddress dest) |
| 203 | { |
| 204 | m_assembler.subl_im(imm.m_value, dest.m_ptr); |
fpizlo@apple.com | 594887a | 2011-09-06 09:23:55 +0000 | [diff] [blame] | 205 | return Jump(m_assembler.jCC(x86Condition(cond))); |
| 206 | } |
| 207 | |
barraclough@apple.com | 03cd248 | 2011-04-20 18:44:35 +0000 | [diff] [blame] | 208 | Jump branch32(RelationalCondition cond, AbsoluteAddress left, RegisterID right) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 209 | { |
| 210 | m_assembler.cmpl_rm(right, left.m_ptr); |
barraclough@apple.com | 8f939c2 | 2009-05-15 21:11:10 +0000 | [diff] [blame] | 211 | return Jump(m_assembler.jCC(x86Condition(cond))); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 212 | } |
| 213 | |
barraclough@apple.com | 03cd248 | 2011-04-20 18:44:35 +0000 | [diff] [blame] | 214 | Jump branch32(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 215 | { |
| 216 | m_assembler.cmpl_im(right.m_value, left.m_ptr); |
barraclough@apple.com | 8f939c2 | 2009-05-15 21:11:10 +0000 | [diff] [blame] | 217 | return Jump(m_assembler.jCC(x86Condition(cond))); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 218 | } |
| 219 | |
mark.lam@apple.com | e1fc7a0 | 2018-03-14 20:05:37 +0000 | [diff] [blame] | 220 | Call call(PtrTag) |
barraclough@apple.com | d7e1338 | 2009-02-19 22:51:40 +0000 | [diff] [blame] | 221 | { |
| 222 | return Call(m_assembler.call(), Call::Linkable); |
| 223 | } |
| 224 | |
mark.lam@apple.com | 8214f83 | 2018-03-22 21:24:15 +0000 | [diff] [blame] | 225 | ALWAYS_INLINE Call call(RegisterID callTag) { return UNUSED_PARAM(callTag), call(NoPtrTag); } |
| 226 | |
fpizlo@apple.com | 4621171 | 2011-11-10 01:08:50 +0000 | [diff] [blame] | 227 | // Address is a memory location containing the address to jump to |
ysuzuki@apple.com | 4987151 | 2019-08-14 20:15:04 +0000 | [diff] [blame] | 228 | void farJump(AbsoluteAddress address, PtrTag) |
fpizlo@apple.com | 4621171 | 2011-11-10 01:08:50 +0000 | [diff] [blame] | 229 | { |
| 230 | m_assembler.jmp_m(address.m_ptr); |
| 231 | } |
| 232 | |
ysuzuki@apple.com | 4987151 | 2019-08-14 20:15:04 +0000 | [diff] [blame] | 233 | ALWAYS_INLINE void farJump(AbsoluteAddress address, RegisterID jumpTag) { UNUSED_PARAM(jumpTag), farJump(address, NoPtrTag); } |
barraclough@apple.com | d7e1338 | 2009-02-19 22:51:40 +0000 | [diff] [blame] | 234 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 235 | DataLabelPtr moveWithPatch(TrustedImmPtr initialValue, RegisterID dest) |
barraclough@apple.com | 0717324 | 2009-05-23 01:48:32 +0000 | [diff] [blame] | 236 | { |
fpizlo@apple.com | 0712be8 | 2012-08-21 23:30:19 +0000 | [diff] [blame] | 237 | padBeforePatch(); |
barraclough@apple.com | 0717324 | 2009-05-23 01:48:32 +0000 | [diff] [blame] | 238 | m_assembler.movl_i32r(initialValue.asIntptr(), dest); |
| 239 | return DataLabelPtr(this); |
| 240 | } |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 241 | |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 242 | Jump branch8(RelationalCondition cond, AbsoluteAddress left, TrustedImm32 right) |
| 243 | { |
utatane.tea@gmail.com | 997ca6b | 2016-07-17 14:33:26 +0000 | [diff] [blame] | 244 | TrustedImm32 right8(static_cast<int8_t>(right.m_value)); |
| 245 | m_assembler.cmpb_im(right8.m_value, left.m_ptr); |
fpizlo@apple.com | 09a6af0 | 2013-11-18 02:10:42 +0000 | [diff] [blame] | 246 | return Jump(m_assembler.jCC(x86Condition(cond))); |
| 247 | } |
| 248 | |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 249 | Jump branchTest8(ResultCondition cond, AbsoluteAddress address, TrustedImm32 mask = TrustedImm32(-1)) |
| 250 | { |
utatane.tea@gmail.com | 997ca6b | 2016-07-17 14:33:26 +0000 | [diff] [blame] | 251 | TrustedImm32 mask8(static_cast<int8_t>(mask.m_value)); |
| 252 | if (mask8.m_value == -1) |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 253 | m_assembler.cmpb_im(0, address.m_ptr); |
| 254 | else |
utatane.tea@gmail.com | 997ca6b | 2016-07-17 14:33:26 +0000 | [diff] [blame] | 255 | m_assembler.testb_im(mask8.m_value, address.m_ptr); |
fpizlo@apple.com | b75911b | 2012-06-13 20:53:52 +0000 | [diff] [blame] | 256 | return Jump(m_assembler.jCC(x86Condition(cond))); |
| 257 | } |
barraclough@apple.com | 0717324 | 2009-05-23 01:48:32 +0000 | [diff] [blame] | 258 | |
keith_miller@apple.com | 308f2ba | 2018-02-28 05:41:18 +0000 | [diff] [blame] | 259 | Jump branchPtrWithPatch(RelationalCondition cond, RegisterID left, DataLabelPtr& dataLabel, TrustedImmPtr initialRightValue = TrustedImmPtr(nullptr)) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 260 | { |
fpizlo@apple.com | 0712be8 | 2012-08-21 23:30:19 +0000 | [diff] [blame] | 261 | padBeforePatch(); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 262 | m_assembler.cmpl_ir_force32(initialRightValue.asIntptr(), left); |
| 263 | dataLabel = DataLabelPtr(this); |
barraclough@apple.com | 8f939c2 | 2009-05-15 21:11:10 +0000 | [diff] [blame] | 264 | return Jump(m_assembler.jCC(x86Condition(cond))); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 265 | } |
| 266 | |
keith_miller@apple.com | 308f2ba | 2018-02-28 05:41:18 +0000 | [diff] [blame] | 267 | Jump branchPtrWithPatch(RelationalCondition cond, Address left, DataLabelPtr& dataLabel, TrustedImmPtr initialRightValue = TrustedImmPtr(nullptr)) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 268 | { |
fpizlo@apple.com | 0712be8 | 2012-08-21 23:30:19 +0000 | [diff] [blame] | 269 | padBeforePatch(); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 270 | m_assembler.cmpl_im_force32(initialRightValue.asIntptr(), left.offset, left.base); |
| 271 | dataLabel = DataLabelPtr(this); |
barraclough@apple.com | 8f939c2 | 2009-05-15 21:11:10 +0000 | [diff] [blame] | 272 | return Jump(m_assembler.jCC(x86Condition(cond))); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 273 | } |
| 274 | |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 275 | Jump branch32WithPatch(RelationalCondition cond, Address left, DataLabel32& dataLabel, TrustedImm32 initialRightValue = TrustedImm32(0)) |
| 276 | { |
| 277 | padBeforePatch(); |
| 278 | m_assembler.cmpl_im_force32(initialRightValue.m_value, left.offset, left.base); |
| 279 | dataLabel = DataLabel32(this); |
| 280 | return Jump(m_assembler.jCC(x86Condition(cond))); |
| 281 | } |
| 282 | |
oliver@apple.com | be4e067 | 2011-03-28 17:14:57 +0000 | [diff] [blame] | 283 | DataLabelPtr storePtrWithPatch(TrustedImmPtr initialValue, ImplicitAddress address) |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 284 | { |
fpizlo@apple.com | 0712be8 | 2012-08-21 23:30:19 +0000 | [diff] [blame] | 285 | padBeforePatch(); |
barraclough@apple.com | fb4e1a7 | 2009-06-06 02:39:36 +0000 | [diff] [blame] | 286 | m_assembler.movl_i32m(initialValue.asIntptr(), address.offset, address.base); |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 287 | return DataLabelPtr(this); |
| 288 | } |
barraclough@apple.com | 8f939c2 | 2009-05-15 21:11:10 +0000 | [diff] [blame] | 289 | |
commit-queue@webkit.org | 96d7803 | 2019-03-21 16:29:32 +0000 | [diff] [blame] | 290 | static bool supportsFloatingPoint() { return true; } |
| 291 | static bool supportsFloatingPointTruncate() { return true; } |
| 292 | static bool supportsFloatingPointSqrt() { return true; } |
| 293 | static bool supportsFloatingPointAbs() { return true; } |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 294 | |
| 295 | template<PtrTag resultTag, PtrTag locationTag> |
| 296 | static FunctionPtr<resultTag> readCallTarget(CodeLocationCall<locationTag> call) |
fpizlo@apple.com | a147a4d | 2011-11-21 04:45:17 +0000 | [diff] [blame] | 297 | { |
yusukesuzuki@slowstart.org | 6836640 | 2018-08-19 22:50:05 +0000 | [diff] [blame] | 298 | intptr_t offset = WTF::unalignedLoad<int32_t>(bitwise_cast<int32_t*>(call.dataLocation()) - 1); |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 299 | return FunctionPtr<resultTag>(reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(call.dataLocation()) + offset)); |
fpizlo@apple.com | a147a4d | 2011-11-21 04:45:17 +0000 | [diff] [blame] | 300 | } |
barraclough@apple.com | 8f939c2 | 2009-05-15 21:11:10 +0000 | [diff] [blame] | 301 | |
fpizlo@apple.com | db01087 | 2012-11-13 01:55:42 +0000 | [diff] [blame] | 302 | static bool canJumpReplacePatchableBranchPtrWithPatch() { return true; } |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 303 | static bool canJumpReplacePatchableBranch32WithPatch() { return true; } |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 304 | |
| 305 | template<PtrTag tag> |
| 306 | static CodeLocationLabel<tag> startOfBranchPtrWithPatchOnRegister(CodeLocationDataLabelPtr<tag> label) |
fpizlo@apple.com | 32d42ce | 2012-11-21 00:22:08 +0000 | [diff] [blame] | 307 | { |
| 308 | const int opcodeBytes = 1; |
| 309 | const int modRMBytes = 1; |
| 310 | const int immediateBytes = 4; |
| 311 | const int totalBytes = opcodeBytes + modRMBytes + immediateBytes; |
| 312 | ASSERT(totalBytes >= maxJumpReplacementSize()); |
| 313 | return label.labelAtOffset(-totalBytes); |
| 314 | } |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 315 | |
| 316 | template<PtrTag tag> |
| 317 | static CodeLocationLabel<tag> startOfPatchableBranchPtrWithPatchOnAddress(CodeLocationDataLabelPtr<tag> label) |
fpizlo@apple.com | db01087 | 2012-11-13 01:55:42 +0000 | [diff] [blame] | 318 | { |
| 319 | const int opcodeBytes = 1; |
| 320 | const int modRMBytes = 1; |
| 321 | const int offsetBytes = 0; |
| 322 | const int immediateBytes = 4; |
| 323 | const int totalBytes = opcodeBytes + modRMBytes + offsetBytes + immediateBytes; |
| 324 | ASSERT(totalBytes >= maxJumpReplacementSize()); |
| 325 | return label.labelAtOffset(-totalBytes); |
| 326 | } |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 327 | |
| 328 | template<PtrTag tag> |
| 329 | static CodeLocationLabel<tag> startOfPatchableBranch32WithPatchOnAddress(CodeLocationDataLabel32<tag> label) |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 330 | { |
| 331 | const int opcodeBytes = 1; |
| 332 | const int modRMBytes = 1; |
| 333 | const int offsetBytes = 0; |
| 334 | const int immediateBytes = 4; |
| 335 | const int totalBytes = opcodeBytes + modRMBytes + offsetBytes + immediateBytes; |
| 336 | ASSERT(totalBytes >= maxJumpReplacementSize()); |
| 337 | return label.labelAtOffset(-totalBytes); |
| 338 | } |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 339 | |
| 340 | template<PtrTag tag> |
| 341 | static void revertJumpReplacementToBranchPtrWithPatch(CodeLocationLabel<tag> instructionStart, RegisterID reg, void* initialValue) |
fpizlo@apple.com | 32d42ce | 2012-11-21 00:22:08 +0000 | [diff] [blame] | 342 | { |
| 343 | X86Assembler::revertJumpTo_cmpl_ir_force32(instructionStart.executableAddress(), reinterpret_cast<intptr_t>(initialValue), reg); |
| 344 | } |
| 345 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 346 | template<PtrTag tag> |
| 347 | static void revertJumpReplacementToPatchableBranchPtrWithPatch(CodeLocationLabel<tag> instructionStart, Address address, void* initialValue) |
fpizlo@apple.com | db01087 | 2012-11-13 01:55:42 +0000 | [diff] [blame] | 348 | { |
| 349 | ASSERT(!address.offset); |
| 350 | X86Assembler::revertJumpTo_cmpl_im_force32(instructionStart.executableAddress(), reinterpret_cast<intptr_t>(initialValue), 0, address.base); |
| 351 | } |
| 352 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 353 | template<PtrTag tag> |
| 354 | static void revertJumpReplacementToPatchableBranch32WithPatch(CodeLocationLabel<tag> instructionStart, Address address, int32_t initialValue) |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 355 | { |
| 356 | ASSERT(!address.offset); |
| 357 | X86Assembler::revertJumpTo_cmpl_im_force32(instructionStart.executableAddress(), initialValue, 0, address.base); |
| 358 | } |
| 359 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 360 | template<PtrTag callTag, PtrTag destTag> |
| 361 | static void repatchCall(CodeLocationCall<callTag> call, CodeLocationLabel<destTag> destination) |
barraclough@apple.com | 96e7343 | 2009-07-22 03:24:34 +0000 | [diff] [blame] | 362 | { |
| 363 | X86Assembler::relinkCall(call.dataLocation(), destination.executableAddress()); |
| 364 | } |
| 365 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 366 | template<PtrTag callTag, PtrTag destTag> |
| 367 | static void repatchCall(CodeLocationCall<callTag> call, FunctionPtr<destTag> destination) |
barraclough@apple.com | 96e7343 | 2009-07-22 03:24:34 +0000 | [diff] [blame] | 368 | { |
| 369 | X86Assembler::relinkCall(call.dataLocation(), destination.executableAddress()); |
| 370 | } |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 371 | |
| 372 | private: |
| 373 | friend class LinkBuffer; |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 374 | |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 375 | template<PtrTag tag> |
| 376 | static void linkCall(void* code, Call call, FunctionPtr<tag> function) |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 377 | { |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 378 | if (call.isFlagSet(Call::Tail)) |
mark.lam@apple.com | a7b34fc | 2018-03-20 18:10:16 +0000 | [diff] [blame] | 379 | X86Assembler::linkJump(code, call.m_label, function.executableAddress()); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 380 | else |
mark.lam@apple.com | a7b34fc | 2018-03-20 18:10:16 +0000 | [diff] [blame] | 381 | X86Assembler::linkCall(code, call.m_label, function.executableAddress()); |
fpizlo@apple.com | 7a79726 | 2015-09-03 21:11:59 +0000 | [diff] [blame] | 382 | } |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 383 | }; |
| 384 | |
barraclough@apple.com | a36d999 | 2009-02-05 03:40:39 +0000 | [diff] [blame] | 385 | } // namespace JSC |
| 386 | |
| 387 | #endif // ENABLE(ASSEMBLER) |