| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
*/ |
| 4 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 7 |
|
| 8 |
#include "jit/MacroAssembler.h" |
| 9 |
|
| 10 |
#include "jsapi-tests/tests.h" |
| 11 |
#include "jsapi-tests/testsJit.h" |
| 12 |
|
| 13 |
#include "jit/MacroAssembler-inl.h" |
| 14 |
|
| 15 |
using namespace js; |
| 16 |
using namespace js::jit; |
| 17 |
|
| 18 |
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || \ |
| 19 |
defined(JS_CODEGEN_ARM) || defined(JS_CODEGEN_ARM64) |
| 20 |
|
| 21 |
static bool GenerateAndRunSub32FromMem(JSContext* cx, int32_t init, int delta) { |
| 22 |
js::LifoAlloc lifo(4096, js::MallocArena); |
| 23 |
TempAllocator alloc(&lifo); |
| 24 |
JitContext jc(cx); |
| 25 |
StackMacroAssembler masm(cx, alloc); |
| 26 |
AutoCreatedBy acb(masm, __func__); |
| 27 |
|
| 28 |
volatile int32_t memory = init; |
| 29 |
const Register Reg = CallTempReg0; |
| 30 |
|
| 31 |
PrepareJit(masm); |
| 32 |
|
| 33 |
Label itWentNegative, fail, end; |
| 34 |
masm.mov(ImmPtr((void*)&memory, ImmPtr::NoCheckToken()), Reg); |
| 35 |
CodeOffset patchAt = masm.sub32FromMemAndBranchIfNegativeWithPatch( |
| 36 |
Address(Reg, 0), &itWentNegative); |
| 37 |
if (init >= delta) { |
| 38 |
// The initial value is >= the delta. So we don't expect the value to go |
| 39 |
// negative. |
| 40 |
masm.jump(&end); |
| 41 |
masm.bind(&itWentNegative); |
| 42 |
masm.printf("Failed\n"); |
| 43 |
masm.breakpoint(); |
| 44 |
} else { |
| 45 |
// The initial value is < the delta. We *do* expect the value to go |
| 46 |
// negative. |
| 47 |
masm.printf("Failed\n"); |
| 48 |
masm.breakpoint(); |
| 49 |
masm.bind(&itWentNegative); |
| 50 |
} |
| 51 |
masm.bind(&end); |
| 52 |
|
| 53 |
masm.patchSub32FromMemAndBranchIfNegative(patchAt, Imm32(delta)); |
| 54 |
if (!ExecuteJit(cx, masm)) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
MOZ_ASSERT(init - delta == memory); |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
BEGIN_TEST(testWasmSub32FromMem) { |
| 63 |
return GenerateAndRunSub32FromMem(cx, 1, 123) && |
| 64 |
GenerateAndRunSub32FromMem(cx, 120, 3) && |
| 65 |
GenerateAndRunSub32FromMem(cx, 2, 2); |
| 66 |
} |
| 67 |
END_TEST(testWasmSub32FromMem) |
| 68 |
|
| 69 |
#endif |