OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 __ ret(0); | 134 __ ret(0); |
135 | 135 |
136 CodeDesc desc; | 136 CodeDesc desc; |
137 assm.GetCode(&desc); | 137 assm.GetCode(&desc); |
138 // Call the function from C++. | 138 // Call the function from C++. |
139 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 139 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
140 CHECK_EQ(5, result); | 140 CHECK_EQ(5, result); |
141 } | 141 } |
142 | 142 |
143 | 143 |
| 144 TEST(AssemblerX64CmpbOperation) { |
| 145 // Allocate an executable page of memory. |
| 146 size_t actual_size; |
| 147 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 148 &actual_size, |
| 149 true)); |
| 150 CHECK(buffer); |
| 151 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 152 |
| 153 // Assemble a function that compare argument byte returing 1 if equal else 0. |
| 154 // On Windows, it compares rcx with rdx which does not require REX prefix; |
| 155 // on Linux, it compares rdi with rsi which requires REX prefix. |
| 156 |
| 157 Label done; |
| 158 __ movq(rax, Immediate(1)); |
| 159 __ cmpb(arg1, arg2); |
| 160 __ j(equal, &done); |
| 161 __ movq(rax, Immediate(0)); |
| 162 __ bind(&done); |
| 163 __ ret(0); |
| 164 |
| 165 CodeDesc desc; |
| 166 assm.GetCode(&desc); |
| 167 // Call the function from C++. |
| 168 int result = FUNCTION_CAST<F2>(buffer)(0x1002, 0x2002); |
| 169 CHECK_EQ(1, result); |
| 170 result = FUNCTION_CAST<F2>(buffer)(0x1002, 0x2003); |
| 171 CHECK_EQ(0, result); |
| 172 } |
| 173 |
| 174 |
144 TEST(AssemblerX64ImulOperation) { | 175 TEST(AssemblerX64ImulOperation) { |
145 // Allocate an executable page of memory. | 176 // Allocate an executable page of memory. |
146 size_t actual_size; | 177 size_t actual_size; |
147 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 178 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
148 &actual_size, | 179 &actual_size, |
149 true)); | 180 true)); |
150 CHECK(buffer); | 181 CHECK(buffer); |
151 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); | 182 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
152 | 183 |
153 // Assemble a simple function that multiplies arguments returning the high | 184 // Assemble a simple function that multiplies arguments returning the high |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 Handle<Code>())->ToObjectChecked()); | 737 Handle<Code>())->ToObjectChecked()); |
707 CHECK(code->IsCode()); | 738 CHECK(code->IsCode()); |
708 #ifdef OBJECT_PRINT | 739 #ifdef OBJECT_PRINT |
709 Code::cast(code)->Print(); | 740 Code::cast(code)->Print(); |
710 #endif | 741 #endif |
711 | 742 |
712 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); | 743 F6 f = FUNCTION_CAST<F6>(Code::cast(code)->entry()); |
713 CHECK_EQ(2, f(1.0, 2.0)); | 744 CHECK_EQ(2, f(1.0, 2.0)); |
714 } | 745 } |
715 #undef __ | 746 #undef __ |
OLD | NEW |