OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 bind(&done); | 207 bind(&done); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 | 211 |
212 void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg, | 212 void MacroAssembler::ClampDoubleToUint8(XMMRegister input_reg, |
213 XMMRegister scratch_reg, | 213 XMMRegister scratch_reg, |
214 Register result_reg) { | 214 Register result_reg) { |
215 Label done; | 215 Label done; |
216 Label conv_failure; | 216 Label conv_failure; |
217 pxor(scratch_reg, scratch_reg); | 217 xorps(scratch_reg, scratch_reg); |
218 cvtsd2si(result_reg, input_reg); | 218 cvtsd2si(result_reg, input_reg); |
219 test(result_reg, Immediate(0xFFFFFF00)); | 219 test(result_reg, Immediate(0xFFFFFF00)); |
220 j(zero, &done, Label::kNear); | 220 j(zero, &done, Label::kNear); |
221 cmp(result_reg, Immediate(0x80000000)); | 221 cmp(result_reg, Immediate(0x1)); |
222 j(equal, &conv_failure, Label::kNear); | 222 j(overflow, &conv_failure, Label::kNear); |
223 mov(result_reg, Immediate(0)); | 223 sar(result_reg, 31); |
224 setcc(above, result_reg); | 224 not_(result_reg); |
225 sub(result_reg, Immediate(1)); | 225 movzx_b(result_reg, result_reg); |
226 and_(result_reg, Immediate(255)); | |
227 jmp(&done, Label::kNear); | 226 jmp(&done, Label::kNear); |
228 bind(&conv_failure); | 227 bind(&conv_failure); |
229 Set(result_reg, Immediate(0)); | 228 Set(result_reg, Immediate(0)); |
230 ucomisd(input_reg, scratch_reg); | 229 ucomisd(input_reg, scratch_reg); |
231 j(below, &done, Label::kNear); | 230 j(below, &done, Label::kNear); |
232 Set(result_reg, Immediate(255)); | 231 Set(result_reg, Immediate(255)); |
233 bind(&done); | 232 bind(&done); |
234 } | 233 } |
235 | 234 |
236 | 235 |
237 void MacroAssembler::ClampUint8(Register reg) { | 236 void MacroAssembler::ClampUint8(Register reg) { |
238 Label done; | 237 Label done; |
239 test(reg, Immediate(0xFFFFFF00)); | 238 test(reg, Immediate(0xFFFFFF00)); |
240 j(zero, &done, Label::kNear); | 239 j(zero, &done, Label::kNear); |
241 setcc(negative, reg); // 1 if negative, 0 if positive. | 240 sar(reg, 31); |
242 dec_b(reg); // 0 if negative, 255 if positive. | 241 not_(reg); |
243 bind(&done); | 242 bind(&done); |
244 } | 243 } |
245 | 244 |
246 | 245 |
247 void MacroAssembler::SlowTruncateToI(Register result_reg, | 246 void MacroAssembler::SlowTruncateToI(Register result_reg, |
248 Register input_reg, | 247 Register input_reg, |
249 int offset) { | 248 int offset) { |
250 DoubleToIStub stub(input_reg, result_reg, offset, true); | 249 DoubleToIStub stub(input_reg, result_reg, offset, true); |
251 call(stub.GetCode(isolate()), RelocInfo::CODE_TARGET); | 250 call(stub.GetCode(isolate()), RelocInfo::CODE_TARGET); |
252 } | 251 } |
253 | 252 |
254 | 253 |
255 void MacroAssembler::TruncateDoubleToI(Register result_reg, | 254 void MacroAssembler::TruncateDoubleToI(Register result_reg, |
256 XMMRegister input_reg) { | 255 XMMRegister input_reg) { |
257 Label done; | 256 Label done; |
258 cvttsd2si(result_reg, Operand(input_reg)); | 257 cvttsd2si(result_reg, Operand(input_reg)); |
259 cmp(result_reg, 0x80000000u); | 258 cmp(result_reg, 0x1); |
260 j(not_equal, &done, Label::kNear); | 259 j(no_overflow, &done, Label::kNear); |
261 | 260 |
262 sub(esp, Immediate(kDoubleSize)); | 261 sub(esp, Immediate(kDoubleSize)); |
263 movsd(MemOperand(esp, 0), input_reg); | 262 movsd(MemOperand(esp, 0), input_reg); |
264 SlowTruncateToI(result_reg, esp, 0); | 263 SlowTruncateToI(result_reg, esp, 0); |
265 add(esp, Immediate(kDoubleSize)); | 264 add(esp, Immediate(kDoubleSize)); |
266 bind(&done); | 265 bind(&done); |
267 } | 266 } |
268 | 267 |
269 | 268 |
270 void MacroAssembler::TruncateX87TOSToI(Register result_reg) { | 269 void MacroAssembler::TruncateX87TOSToI(Register result_reg) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 SlowTruncateToI(result_reg, esp, 0); | 366 SlowTruncateToI(result_reg, esp, 0); |
368 add(esp, Immediate(kDoubleSize)); | 367 add(esp, Immediate(kDoubleSize)); |
369 } else { | 368 } else { |
370 fstp(0); | 369 fstp(0); |
371 SlowTruncateToI(result_reg, input_reg); | 370 SlowTruncateToI(result_reg, input_reg); |
372 } | 371 } |
373 } else if (CpuFeatures::IsSupported(SSE2)) { | 372 } else if (CpuFeatures::IsSupported(SSE2)) { |
374 CpuFeatureScope scope(this, SSE2); | 373 CpuFeatureScope scope(this, SSE2); |
375 movsd(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); | 374 movsd(xmm0, FieldOperand(input_reg, HeapNumber::kValueOffset)); |
376 cvttsd2si(result_reg, Operand(xmm0)); | 375 cvttsd2si(result_reg, Operand(xmm0)); |
377 cmp(result_reg, 0x80000000u); | 376 cmp(result_reg, 0x1); |
378 j(not_equal, &done, Label::kNear); | 377 j(no_overflow, &done, Label::kNear); |
379 // Check if the input was 0x8000000 (kMinInt). | 378 // Check if the input was 0x8000000 (kMinInt). |
380 // If no, then we got an overflow and we deoptimize. | 379 // If no, then we got an overflow and we deoptimize. |
381 ExternalReference min_int = ExternalReference::address_of_min_int(); | 380 ExternalReference min_int = ExternalReference::address_of_min_int(); |
382 ucomisd(xmm0, Operand::StaticVariable(min_int)); | 381 ucomisd(xmm0, Operand::StaticVariable(min_int)); |
383 j(not_equal, &slow_case, Label::kNear); | 382 j(not_equal, &slow_case, Label::kNear); |
384 j(parity_even, &slow_case, Label::kNear); // NaN. | 383 j(parity_even, &slow_case, Label::kNear); // NaN. |
385 jmp(&done, Label::kNear); | 384 jmp(&done, Label::kNear); |
386 | 385 |
387 // Slow case. | 386 // Slow case. |
388 bind(&slow_case); | 387 bind(&slow_case); |
(...skipping 3232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3621 imul(dividend); | 3620 imul(dividend); |
3622 if (divisor > 0 && ms.multiplier() < 0) add(edx, dividend); | 3621 if (divisor > 0 && ms.multiplier() < 0) add(edx, dividend); |
3623 if (divisor < 0 && ms.multiplier() > 0) sub(edx, dividend); | 3622 if (divisor < 0 && ms.multiplier() > 0) sub(edx, dividend); |
3624 if (ms.shift() > 0) sar(edx, ms.shift()); | 3623 if (ms.shift() > 0) sar(edx, ms.shift()); |
3625 } | 3624 } |
3626 | 3625 |
3627 | 3626 |
3628 } } // namespace v8::internal | 3627 } } // namespace v8::internal |
3629 | 3628 |
3630 #endif // V8_TARGET_ARCH_IA32 | 3629 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |