v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-macro-assembler-ia32.cc
Go to the documentation of this file.
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include <stdlib.h>
29 
30 #include "v8.h"
31 
32 #include "macro-assembler.h"
33 #include "factory.h"
34 #include "platform.h"
35 #include "serialize.h"
36 #include "cctest.h"
37 
38 using namespace v8::internal;
39 
40 #if __GNUC__
41 #define STDCALL __attribute__((stdcall))
42 #else
43 #define STDCALL __stdcall
44 #endif
45 
46 typedef int STDCALL F0Type();
47 typedef F0Type* F0;
48 
49 #define __ masm->
50 
51 
52 TEST(LoadAndStoreWithRepresentation) {
54 
55  // Allocate an executable page of memory.
56  size_t actual_size;
57  byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
58  &actual_size,
59  true));
60  CHECK(buffer);
61  Isolate* isolate = CcTest::i_isolate();
62  HandleScope handles(isolate);
63  MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
64  MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
65  __ push(ebx);
66  __ push(edx);
67  __ sub(esp, Immediate(1 * kPointerSize));
68  Label exit;
69 
70  // Test 1.
71  __ mov(eax, Immediate(1)); // Test number.
72  __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
73  __ mov(ebx, Immediate(-1));
75  __ mov(ebx, Operand(esp, 0 * kPointerSize));
76  __ mov(edx, Immediate(255));
77  __ cmp(ebx, edx);
78  __ j(not_equal, &exit);
80  __ cmp(ebx, edx);
81  __ j(not_equal, &exit);
82 
83 
84  // Test 2.
85  __ mov(eax, Immediate(2)); // Test number.
86  __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
87  __ mov(ebx, Immediate(-1));
89  __ mov(ebx, Operand(esp, 0 * kPointerSize));
90  __ mov(edx, Immediate(255));
91  __ cmp(ebx, edx);
92  __ j(not_equal, &exit);
94  __ mov(edx, Immediate(-1));
95  __ cmp(ebx, edx);
96  __ j(not_equal, &exit);
97 
98  // Test 3.
99  __ mov(eax, Immediate(3)); // Test number.
100  __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
101  __ mov(ebx, Immediate(-1));
103  __ mov(ebx, Operand(esp, 0 * kPointerSize));
104  __ mov(edx, Immediate(65535));
105  __ cmp(ebx, edx);
106  __ j(not_equal, &exit);
108  __ mov(ebx, Immediate(-1));
109  __ cmp(ebx, edx);
110  __ j(not_equal, &exit);
111 
112  // Test 4.
113  __ mov(eax, Immediate(4)); // Test number.
114  __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
115  __ mov(ebx, Immediate(-1));
117  __ mov(ebx, Operand(esp, 0 * kPointerSize));
118  __ mov(edx, Immediate(65535));
119  __ cmp(ebx, edx);
120  __ j(not_equal, &exit);
122  __ cmp(ebx, edx);
123  __ j(not_equal, &exit);
124 
125  // Test 5.
127  CpuFeatureScope scope(masm, SSE2);
128  __ mov(eax, Immediate(5)); // Test XMM move immediate.
129  __ Move(xmm0, 0.0);
130  __ Move(xmm1, 0.0);
131  __ ucomisd(xmm0, xmm1);
132  __ j(not_equal, &exit);
133  __ Move(xmm2, 991.01);
134  __ ucomisd(xmm0, xmm2);
135  __ j(equal, &exit);
136  __ Move(xmm0, 991.01);
137  __ ucomisd(xmm0, xmm2);
138  __ j(not_equal, &exit);
139  }
140 
141  // Test 6.
142  __ mov(eax, Immediate(6));
143  __ Move(edx, Immediate(0)); // Test Move()
144  __ cmp(edx, Immediate(0));
145  __ j(not_equal, &exit);
146  __ Move(ecx, Immediate(-1));
147  __ cmp(ecx, Immediate(-1));
148  __ j(not_equal, &exit);
149  __ Move(ebx, Immediate(0x77));
150  __ cmp(ebx, Immediate(0x77));
151  __ j(not_equal, &exit);
152 
153  __ xor_(eax, eax); // Success.
154  __ bind(&exit);
155  __ add(esp, Immediate(1 * kPointerSize));
156  __ pop(edx);
157  __ pop(ebx);
158  __ ret(0);
159 
160  CodeDesc desc;
161  masm->GetCode(&desc);
162  // Call the function from C++.
163  int result = FUNCTION_CAST<F0>(buffer)();
164  CHECK_EQ(0, result);
165 }
166 
167 #undef __
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
static Representation UInteger8()
static bool Initialize(Deserializer *des)
Definition: v8.cc:61
#define CHECK_EQ(expected, value)
Definition: checks.h:252
const Register esp
static const int kMinimalBufferSize
Definition: assembler.h:89
static bool IsSupported(CpuFeature f)
Definition: assembler-arm.h:68
#define CHECK(condition)
Definition: checks.h:75
static Representation Integer16()
uint8_t byte
Definition: globals.h:185
const Register eax
const XMMRegister xmm1
void GetCode(CodeDesc *desc)
const int kPointerSize
Definition: globals.h:268
const Register ecx
static i::Isolate * i_isolate()
Definition: cctest.h:102
void Load(const v8::FunctionCallbackInfo< v8::Value > &args)
Definition: shell.cc:171
const Register ebx
static void * Allocate(const size_t requested, size_t *allocated, bool is_executable)
static Representation UInteger16()
static Representation Integer8()
const XMMRegister xmm2
const Register edx
int STDCALL F0Type()
#define __
#define STDCALL
const XMMRegister xmm0
F0Type * F0