1 // Copyright 2009 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 // Flags: --nofull-compiler --nofast-compiler 29 30 // Test paths in the code generator where values in specific registers 31 // get moved around. 32 function identity(x) { 33 return x; 34 } 35 36 function cover_codegen_paths() { 37 var x = 1; 38 39 // This test depends on the fixed order of register allocation. We try to 40 // get values in specific registers (ia32, x64): 41 var a; // Register eax, rax. 42 var b; // Register ebx, rbx. 43 var c; // Register ecx, rcx. 44 var d; // Register edx, rdx. 45 var di; // Register edi, rdi. 46 47 while (x == 1) { 48 // The call will spill registers and leave x in {eax,rax}. 49 x = identity(1); 50 // The add will spill x and reuse {eax,rax} for the result. 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. 56 c = x + 1; 57 d = x + 1; 58 di = x + 1; 59 // Locals are in the corresponding registers here. 60 assertEquals(8, c << a); 61 62 x = identity(1); 63 a = x + 1; 64 b = x + 1; 65 c = x + 1; 66 d = x + 1; 67 di = x + 1; 68 assertEquals(8, a << c); 69 70 x = identity(1); 71 a = x + 1; 72 b = x + 1; 73 c = x + 1; 74 d = x + 1; 75 di = x + 1; 76 c = 0; // Free register ecx. 77 assertEquals(8, a << d); 78 79 x = identity(1); 80 a = x + 1; 81 b = x + 1; 82 c = 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. 92 b = x + 1; 93 c = x + 1; 94 d = x + 1; 95 di = x + 1; 96 // Subtraction should overflow the 31-bit smi range. The result 97 // (1073741824) is outside the 31-bit smi range so it doesn't hit the 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); 132 133 x = 3; 134 } 135 } 136 137 cover_codegen_paths(); 138