| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Test the paths in the code generator where values in specific | 28 // Flags: --nofull-compiler --nofast-compiler |
| 29 // registers get moved around so that the shift operation can use | |
| 30 // register ECX on ia32 for the shift amount. Other codegen coverage | |
| 31 // tests should go here too. | |
| 32 | 29 |
| 33 | 30 // Test paths in the code generator where values in specific registers |
| 34 | 31 // get moved around. |
| 35 function identity(x) { | 32 function identity(x) { |
| 36 return x; | 33 return x; |
| 37 } | 34 } |
| 38 | 35 |
| 39 function cover_codegen_paths() { | 36 function cover_codegen_paths() { |
| 40 var x = 1; | 37 var x = 1; |
| 41 var a; // Register EAX | 38 |
| 42 var b; // Register EBX | 39 // This test depends on the fixed order of register allocation. We try to |
| 43 var c; // Register ECX | 40 // get values in specific registers (ia32, x64): |
| 44 var d; // Register EDX | 41 var a; // Register eax, rax. |
| 45 // Register ESI is already used. | 42 var b; // Register ebx, rbx. |
| 46 var di; // Register EDI | 43 var c; // Register ecx, rcx. |
| 44 var d; // Register edx, rdx. |
| 45 var di; // Register edi, rdi. |
| 47 | 46 |
| 48 while (x == 1) { | 47 while (x == 1) { |
| 48 // The call will spill registers and leave x in {eax,rax}. |
| 49 x = identity(1); | 49 x = identity(1); |
| 50 // The add will spill x and reuse {eax,rax} for the result. |
| 50 a = x + 1; | 51 a = x + 1; |
| 52 // A fresh register {ebx,rbx} will be allocated for x, then reused for |
| 53 // the result. |
| 54 b = x + 1; |
| 55 // Et cetera. |
| 51 c = x + 1; | 56 c = x + 1; |
| 52 d = x + 1; | 57 d = x + 1; |
| 53 b = x + 1; | |
| 54 di = x + 1; | 58 di = x + 1; |
| 55 // Locals are in the corresponding registers here. | 59 // Locals are in the corresponding registers here. |
| 56 assertEquals(c << a, 8); | 60 assertEquals(8, c << a); |
| 57 | 61 |
| 58 x = identity(1); | 62 x = identity(1); |
| 59 a = x + 1; | 63 a = x + 1; |
| 64 b = x + 1; |
| 60 c = x + 1; | 65 c = x + 1; |
| 61 d = x + 1; | 66 d = x + 1; |
| 62 b = x + 1; | |
| 63 di = x + 1; | 67 di = x + 1; |
| 64 // Locals are in the corresponding registers here. | 68 assertEquals(8, a << c); |
| 65 assertEquals(a << c, 8); | |
| 66 | 69 |
| 67 x = identity(1); | 70 x = identity(1); |
| 68 a = x + 1; | 71 a = x + 1; |
| 72 b = x + 1; |
| 69 c = x + 1; | 73 c = x + 1; |
| 70 d = x + 1; | 74 d = x + 1; |
| 71 b = x + 1; | |
| 72 di = x + 1; | 75 di = x + 1; |
| 73 // Locals are in the corresponding registers here. | |
| 74 c = 0; // Free register ecx. | 76 c = 0; // Free register ecx. |
| 75 assertEquals(a << d, 8); | 77 assertEquals(8, a << d); |
| 76 | 78 |
| 77 x = identity(1); | 79 x = identity(1); |
| 78 a = x + 1; | 80 a = x + 1; |
| 81 b = x + 1; |
| 79 c = x + 1; | 82 c = x + 1; |
| 80 d = x + 1; | 83 d = x + 1; |
| 84 di = x + 1; |
| 85 b = 0; // Free register ebx. |
| 86 assertEquals(8, a << d); |
| 87 |
| 88 // Test the non-commutative subtraction operation with a smi on the |
| 89 // left, all available registers on the right, and a non-smi result. |
| 90 x = identity(-1073741824); // Least (31-bit) smi. |
| 91 a = x + 1; // Still a smi, the greatest smi negated. |
| 81 b = x + 1; | 92 b = x + 1; |
| 93 c = x + 1; |
| 94 d = x + 1; |
| 82 di = x + 1; | 95 di = x + 1; |
| 83 // Locals are in the corresponding registers here. | 96 // Subtraction should overflow the 31-bit smi range. The result |
| 84 b = 0; // Free register ebx. | 97 // (1073741824) is outside the 31-bit smi range so it doesn't hit the |
| 85 assertEquals(a << d, 8); | 98 // "unsafe smi" code that spills a register. |
| 99 assertEquals(1073741824, 1 - a); |
| 100 |
| 101 x = identity(-1073741824); |
| 102 a = x + 1; |
| 103 b = x + 1; |
| 104 c = x + 1; |
| 105 d = x + 1; |
| 106 di = x + 1; |
| 107 assertEquals(1073741824, 1 - b); |
| 108 |
| 109 x = identity(-1073741824); |
| 110 a = x + 1; |
| 111 b = x + 1; |
| 112 c = x + 1; |
| 113 d = x + 1; |
| 114 di = x + 1; |
| 115 assertEquals(1073741824, 1 - c); |
| 116 |
| 117 x = identity(-1073741824); |
| 118 a = x + 1; |
| 119 b = x + 1; |
| 120 c = x + 1; |
| 121 d = x + 1; |
| 122 di = x + 1; |
| 123 assertEquals(1073741824, 1 - d); |
| 124 |
| 125 x = identity(-1073741824); |
| 126 a = x + 1; |
| 127 b = x + 1; |
| 128 c = x + 1; |
| 129 d = x + 1; |
| 130 di = x + 1; |
| 131 assertEquals(1073741824, 1 - di); |
| 86 | 132 |
| 87 x = 3; | 133 x = 3; |
| 88 } | 134 } |
| 89 } | 135 } |
| 90 | 136 |
| 91 cover_codegen_paths(); | 137 cover_codegen_paths(); |
| OLD | NEW |