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
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.
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.
32 #include "src/macro-assembler.h"
33 #include "src/factory.h"
34 #include "src/platform.h"
35 #include "src/serialize.h"
36 #include "test/cctest/cctest.h"
38 using namespace v8::internal;
41 #define STDCALL __attribute__((stdcall))
43 #define STDCALL __stdcall
46 typedef int STDCALL F0Type();
52 TEST(LoadAndStoreWithRepresentation) {
53 v8::internal::V8::Initialize(NULL);
55 // Allocate an executable page of memory.
57 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
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.
67 __ sub(esp, Immediate(1 * kPointerSize));
71 __ mov(eax, Immediate(1)); // Test number.
72 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
73 __ mov(ebx, Immediate(-1));
74 __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::UInteger8());
75 __ mov(ebx, Operand(esp, 0 * kPointerSize));
76 __ mov(edx, Immediate(255));
78 __ j(not_equal, &exit);
79 __ Load(ebx, Operand(esp, 0 * kPointerSize), Representation::UInteger8());
81 __ j(not_equal, &exit);
85 __ mov(eax, Immediate(2)); // Test number.
86 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
87 __ mov(ebx, Immediate(-1));
88 __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::Integer8());
89 __ mov(ebx, Operand(esp, 0 * kPointerSize));
90 __ mov(edx, Immediate(255));
92 __ j(not_equal, &exit);
93 __ Load(ebx, Operand(esp, 0 * kPointerSize), Representation::Integer8());
94 __ mov(edx, Immediate(-1));
96 __ j(not_equal, &exit);
99 __ mov(eax, Immediate(3)); // Test number.
100 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
101 __ mov(ebx, Immediate(-1));
102 __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::Integer16());
103 __ mov(ebx, Operand(esp, 0 * kPointerSize));
104 __ mov(edx, Immediate(65535));
106 __ j(not_equal, &exit);
107 __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::Integer16());
108 __ mov(ebx, Immediate(-1));
110 __ j(not_equal, &exit);
113 __ mov(eax, Immediate(4)); // Test number.
114 __ mov(Operand(esp, 0 * kPointerSize), Immediate(0));
115 __ mov(ebx, Immediate(-1));
116 __ Store(ebx, Operand(esp, 0 * kPointerSize), Representation::UInteger16());
117 __ mov(ebx, Operand(esp, 0 * kPointerSize));
118 __ mov(edx, Immediate(65535));
120 __ j(not_equal, &exit);
121 __ Load(edx, Operand(esp, 0 * kPointerSize), Representation::UInteger16());
123 __ j(not_equal, &exit);
126 __ mov(eax, Immediate(5)); // Test XMM move immediate.
129 __ ucomisd(xmm0, xmm1);
130 __ j(not_equal, &exit);
131 __ Move(xmm2, 991.01);
132 __ ucomisd(xmm0, xmm2);
134 __ Move(xmm0, 991.01);
135 __ ucomisd(xmm0, xmm2);
136 __ j(not_equal, &exit);
139 __ mov(eax, Immediate(6));
140 __ Move(edx, Immediate(0)); // Test Move()
141 __ cmp(edx, Immediate(0));
142 __ j(not_equal, &exit);
143 __ Move(ecx, Immediate(-1));
144 __ cmp(ecx, Immediate(-1));
145 __ j(not_equal, &exit);
146 __ Move(ebx, Immediate(0x77));
147 __ cmp(ebx, Immediate(0x77));
148 __ j(not_equal, &exit);
150 __ xor_(eax, eax); // Success.
152 __ add(esp, Immediate(1 * kPointerSize));
158 masm->GetCode(&desc);
159 // Call the function from C++.
160 int result = FUNCTION_CAST<F0>(buffer)();