benjamin@webkit.org | e324d43 | 2015-04-26 19:55:18 +0000 | [diff] [blame] | 1 | function mathClz32OnInteger(value) |
| 2 | { |
| 3 | return Math.clz32(value); |
| 4 | } |
| 5 | noInline(mathClz32OnInteger); |
| 6 | |
| 7 | // *** Test simple cases on integers. *** |
| 8 | function testMathClz32OnIntegers() |
| 9 | { |
| 10 | // Bounds. |
| 11 | var clzZero = mathClz32OnInteger(0); |
| 12 | if (clzZero != 32) |
| 13 | throw "mathClz32OnInteger(0) = " + clzZero; |
| 14 | |
| 15 | var clzIntMin = mathClz32OnInteger(-2147483648); |
| 16 | if (clzIntMin != 0) |
| 17 | throw "mathClz32OnInteger(-2147483648) = " + clzIntMin; |
| 18 | |
| 19 | var clzIntMax = mathClz32OnInteger(2147483647); |
| 20 | if (clzIntMax != 1) |
| 21 | throw "mathClz32OnInteger(2147483647) = " + clzIntMax; |
| 22 | |
| 23 | // Simple values. |
| 24 | var clzMinusOne = mathClz32OnInteger(-1); |
| 25 | if (clzMinusOne != 0) |
| 26 | throw "mathClz32OnInteger(-1) = " + clzMinusOne; |
| 27 | |
| 28 | var clzUltimateAnswer = mathClz32OnInteger(42); |
| 29 | if (clzUltimateAnswer != 26) |
| 30 | throw "mathClz32OnInteger(42) = " + clzUltimateAnswer; |
| 31 | |
| 32 | var clzMinusUltimateAnswer = mathClz32OnInteger(-42); |
| 33 | if (clzMinusUltimateAnswer != 0) |
| 34 | throw "mathClz32OnInteger(-42) = " + clzMinusUltimateAnswer; |
| 35 | } |
| 36 | noInline(testMathClz32OnIntegers); |
| 37 | |
| 38 | for (var i = 0; i < 1e4; ++i) { |
| 39 | testMathClz32OnIntegers(); |
| 40 | } |
| 41 | |
| 42 | // Make sure we don't do anything stupid when the type is unexpected. |
| 43 | function verifyMathClz32OnIntegerWithOtherTypes() |
| 44 | { |
| 45 | var clzPi = mathClz32OnInteger(Math.PI); |
| 46 | if (clzPi != 30) |
| 47 | throw "mathClz32OnInteger(Math.PI) = " + clzPi; |
| 48 | |
| 49 | var clzString = mathClz32OnInteger("42"); |
| 50 | if (clzString != 26) |
| 51 | throw "mathClz32OnInteger(\"42\") = " + clzString; |
| 52 | |
| 53 | var clzString = mathClz32OnInteger("WebKit"); |
| 54 | if (clzString != 32) |
| 55 | throw "mathClz32OnInteger(\"WebKit\") = " + clzString; |
| 56 | |
| 57 | var clzMinusZero = mathClz32OnInteger(-0); |
| 58 | if (clzMinusZero != 32) |
| 59 | throw "mathClz32OnInteger(\"-0\") = " + clzMinusZero; |
| 60 | } |
| 61 | noInline(verifyMathClz32OnIntegerWithOtherTypes); |
| 62 | |
| 63 | for (var i = 0; i < 1e4; ++i) { |
| 64 | verifyMathClz32OnIntegerWithOtherTypes(); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | // *** Test simple cases on doubles. *** |
| 69 | function mathClz32OnDouble(value) |
| 70 | { |
| 71 | return Math.clz32(value); |
| 72 | } |
| 73 | noInline(mathClz32OnInteger); |
| 74 | |
| 75 | // Test simple cases on integers. |
| 76 | function testMathClz32OnDoubles() |
| 77 | { |
| 78 | var value = mathClz32OnDouble(Math.PI); |
| 79 | if (value != 30) |
| 80 | throw "mathClz32OnDouble(Math.PI) = " + value; |
| 81 | |
| 82 | var value = mathClz32OnDouble(Math.E); |
| 83 | if (value != 30) |
| 84 | throw "mathClz32OnDouble(Math.E) = " + value; |
| 85 | |
| 86 | var value = mathClz32OnDouble(Math.LN2); |
| 87 | if (value != 32) |
| 88 | throw "mathClz32OnDouble(Math.LN2) = " + value; |
| 89 | |
| 90 | var value = mathClz32OnDouble(-0); |
| 91 | if (value != 32) |
| 92 | throw "mathClz32OnDouble(0) = " + value; |
| 93 | |
| 94 | var value = mathClz32OnDouble(NaN); |
| 95 | if (value != 32) |
| 96 | throw "mathClz32OnDouble(NaN) = " + value; |
| 97 | |
| 98 | var value = mathClz32OnDouble(Number.POSITIVE_INFINITI); |
| 99 | if (value != 32) |
| 100 | throw "mathClz32OnDouble(Number.POSITIVE_INFINITI) = " + value; |
| 101 | |
| 102 | var value = mathClz32OnDouble(Number.NEGATIVE_INFINITI); |
| 103 | if (value != 32) |
| 104 | throw "mathClz32OnDouble(Number.NEGATIVE_INFINITI) = " + value; |
| 105 | } |
| 106 | noInline(testMathClz32OnDoubles); |
| 107 | |
| 108 | for (var i = 0; i < 1e4; ++i) { |
| 109 | testMathClz32OnDoubles(); |
| 110 | } |
| 111 | |
| 112 | // Make sure we don't do anything stupid when the type is unexpected. |
| 113 | function verifyMathClz32OnDoublesWithOtherTypes() |
| 114 | { |
| 115 | var clzOne = mathClz32OnDouble(1); |
| 116 | if (clzOne != 31) |
| 117 | throw "mathClz32OnDouble(1) = " + clzOne; |
| 118 | |
| 119 | var clzString = mathClz32OnDouble("42"); |
| 120 | if (clzString != 26) |
| 121 | throw "mathClz32OnDouble(\"42\") = " + clzString; |
| 122 | |
| 123 | var clzString = mathClz32OnDouble("WebKit"); |
| 124 | if (clzString != 32) |
| 125 | throw "mathClz32OnDouble(\"WebKit\") = " + clzString; |
| 126 | |
| 127 | var clzMinusZero = mathClz32OnDouble({}); |
| 128 | if (clzMinusZero != 32) |
| 129 | throw "mathClz32OnDouble({}) = " + clzMinusZero; |
| 130 | } |
| 131 | noInline(verifyMathClz32OnDoublesWithOtherTypes); |
| 132 | |
| 133 | for (var i = 0; i < 1e4; ++i) { |
| 134 | verifyMathClz32OnDoublesWithOtherTypes(); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | // *** Unusual arguments. *** |
| 139 | function mathClz32NoArguments() |
| 140 | { |
| 141 | return Math.clz32(); |
| 142 | } |
| 143 | noInline(mathClz32NoArguments); |
| 144 | |
| 145 | function mathClz32TooManyArguments(a, b, c) |
| 146 | { |
| 147 | return Math.clz32(a, b, c); |
| 148 | } |
| 149 | noInline(mathClz32TooManyArguments); |
| 150 | |
| 151 | |
| 152 | for (var i = 0; i < 1e4; ++i) { |
| 153 | var value = mathClz32NoArguments(); |
| 154 | if (value !== 32) |
| 155 | throw "mathClz32NoArguments() = " + value; |
| 156 | |
| 157 | var value = mathClz32TooManyArguments(2, 3, 5); |
| 158 | if (value !== 30) |
| 159 | throw "mathClz32TooManyArguments() = " + value; |
| 160 | |
| 161 | } |
| 162 | |
| 163 | |
| 164 | // *** Constant as arguments. *** |
| 165 | function testMathClz32OnConstants() |
| 166 | { |
| 167 | var value = Math.clz32(0); |
| 168 | if (value !== 32) |
| 169 | throw "Math.clz32(0) = " + value; |
| 170 | var value = Math.clz32(-0); |
| 171 | if (value !== 32) |
| 172 | throw "Math.clz32(-0) = " + value; |
| 173 | var value = Math.clz32(1); |
| 174 | if (value !== 31) |
| 175 | throw "Math.clz32(1) = " + value; |
| 176 | var value = Math.clz32(-1); |
| 177 | if (value !== 0) |
| 178 | throw "Math.clz32(-1) = " + value; |
| 179 | var value = Math.clz32(42); |
| 180 | if (value !== 26) |
| 181 | throw "Math.clz32(42) = " + value; |
| 182 | var value = Math.clz32(-42); |
| 183 | if (value !== 0) |
| 184 | throw "Math.clz32(-42) = " + value; |
| 185 | var value = Math.clz32(NaN); |
| 186 | if (value !== 32) |
| 187 | throw "Math.clz32(NaN) = " + value; |
| 188 | var value = Math.clz32(Number.POSITIVE_INFINITI); |
| 189 | if (value !== 32) |
| 190 | throw "Math.clz32(Number.POSITIVE_INFINITI) = " + value; |
| 191 | var value = Math.clz32(Number.NEGATIVE_INFINITI); |
| 192 | if (value !== 32) |
| 193 | throw "Math.clz32(Number.NEGATIVE_INFINITI) = " + value; |
| 194 | var value = Math.clz32(Math.E); |
| 195 | if (value !== 30) |
| 196 | throw "Math.clz32(Math.E) = " + value; |
| 197 | } |
| 198 | noInline(testMathClz32OnConstants); |
| 199 | |
| 200 | for (var i = 0; i < 1e4; ++i) { |
| 201 | testMathClz32OnConstants(); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | // *** Struct transition. *** |
| 206 | function mathClz32StructTransition(value) |
| 207 | { |
| 208 | return Math.clz32(value); |
| 209 | } |
| 210 | noInline(mathClz32StructTransition); |
| 211 | |
| 212 | for (var i = 0; i < 1e4; ++i) { |
| 213 | var value = mathClz32StructTransition(42); |
| 214 | if (value !== 26) |
| 215 | throw "mathClz32StructTransition(42) = " + value; |
| 216 | } |
| 217 | |
| 218 | Math.clz32 = function() { return arguments[0] + 5; } |
| 219 | |
| 220 | var value = mathClz32StructTransition(42); |
| 221 | if (value !== 47) |
| 222 | throw "mathClz32StructTransition(42) after transition = " + value; |