deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / test / cctest / test-macro-assembler-ia32.cc
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 "src/v8.h"
31 #include "test/cctest/cctest.h"
32
33 #include "src/base/platform/platform.h"
34 #include "src/factory.h"
35 #include "src/macro-assembler.h"
36
37 using namespace v8::internal;
38
39 #if __GNUC__
40 #define STDCALL  __attribute__((stdcall))
41 #else
42 #define STDCALL  __stdcall
43 #endif
44
45 typedef int STDCALL F0Type();
46 typedef F0Type* F0;
47
48 #define __ masm->
49
50
51 TEST(LoadAndStoreWithRepresentation) {
52   // Allocate an executable page of memory.
53   size_t actual_size;
54   byte* buffer = static_cast<byte*>(v8::base::OS::Allocate(
55       Assembler::kMinimalBufferSize, &actual_size, true));
56   CHECK(buffer);
57   Isolate* isolate = CcTest::i_isolate();
58   HandleScope handles(isolate);
59   MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
60   MacroAssembler* masm = &assembler;  // Create a pointer for the __ macro.
61   __ push(ebx);
62   __ push(edx);
63   __ sub(esp, Immediate(1 * kPointerSize));
64   Label exit;
65
66   // Test 1.
67   __ mov(eax, Immediate(1));  // Test number.
68   __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
69   __ mov(ebx, Immediate(-1));
70   __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::UInteger8());
71   __ mov(ebx, Operand(esp, 0 * kPointerSize));
72   __ mov(edx, Immediate(255));
73   __ cmp(ebx, edx);
74   __ j(not_equal, &exit);
75   __ Load(ebx, Operand(esp, 0 * kPointerSize), Representation::UInteger8());
76   __ cmp(ebx, edx);
77   __ j(not_equal, &exit);
78
79
80   // Test 2.
81   __ mov(eax, Immediate(2));  // Test number.
82   __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
83   __ mov(ebx, Immediate(-1));
84   __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::Integer8());
85   __ mov(ebx, Operand(esp, 0 * kPointerSize));
86   __ mov(edx, Immediate(255));
87   __ cmp(ebx, edx);
88   __ j(not_equal, &exit);
89   __ Load(ebx, Operand(esp, 0 * kPointerSize), Representation::Integer8());
90   __ mov(edx, Immediate(-1));
91   __ cmp(ebx, edx);
92   __ j(not_equal, &exit);
93
94   // Test 3.
95   __ mov(eax, Immediate(3));  // Test number.
96   __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
97   __ mov(ebx, Immediate(-1));
98   __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::Integer16());
99   __ mov(ebx, Operand(esp, 0 * kPointerSize));
100   __ mov(edx, Immediate(65535));
101   __ cmp(ebx, edx);
102   __ j(not_equal, &exit);
103   __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::Integer16());
104   __ mov(ebx, Immediate(-1));
105   __ cmp(ebx, edx);
106   __ j(not_equal, &exit);
107
108   // Test 4.
109   __ mov(eax, Immediate(4));  // Test number.
110   __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
111   __ mov(ebx, Immediate(-1));
112   __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::UInteger16());
113   __ mov(ebx, Operand(esp, 0 * kPointerSize));
114   __ mov(edx, Immediate(65535));
115   __ cmp(ebx, edx);
116   __ j(not_equal, &exit);
117   __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::UInteger16());
118   __ cmp(ebx, edx);
119   __ j(not_equal, &exit);
120
121   // Test 5.
122   __ mov(eax, Immediate(5));  // Test XMM move immediate.
123   __ Move(xmm0, 0.0);
124   __ Move(xmm1, 0.0);
125   __ ucomisd(xmm0, xmm1);
126   __ j(not_equal, &exit);
127   __ Move(xmm2, 991.01);
128   __ ucomisd(xmm0, xmm2);
129   __ j(equal, &exit);
130   __ Move(xmm0, 991.01);
131   __ ucomisd(xmm0, xmm2);
132   __ j(not_equal, &exit);
133
134   // Test 6.
135   __ mov(eax, Immediate(6));
136   __ Move(edx, Immediate(0));  // Test Move()
137   __ cmp(edx, Immediate(0));
138   __ j(not_equal, &exit);
139   __ Move(ecx, Immediate(-1));
140   __ cmp(ecx, Immediate(-1));
141   __ j(not_equal, &exit);
142   __ Move(ebx, Immediate(0x77));
143   __ cmp(ebx, Immediate(0x77));
144   __ j(not_equal, &exit);
145
146   __ xor_(eax, eax);  // Success.
147   __ bind(&exit);
148   __ add(esp, Immediate(1 * kPointerSize));
149   __ pop(edx);
150   __ pop(ebx);
151   __ ret(0);
152
153   CodeDesc desc;
154   masm->GetCode(&desc);
155   // Call the function from C++.
156   int result = FUNCTION_CAST<F0>(buffer)();
157   CHECK_EQ(0, result);
158 }
159
160 #undef __