1 function mathClz32OnInteger(value
)
3 return Math
.clz32(value
);
5 noInline(mathClz32OnInteger
);
7 // *** Test simple cases on integers. ***
8 function testMathClz32OnIntegers()
11 var clzZero
= mathClz32OnInteger(0);
13 throw "mathClz32OnInteger(0) = " + clzZero
;
15 var clzIntMin
= mathClz32OnInteger(-2147483648);
17 throw "mathClz32OnInteger(-2147483648) = " + clzIntMin
;
19 var clzIntMax
= mathClz32OnInteger(2147483647);
21 throw "mathClz32OnInteger(2147483647) = " + clzIntMax
;
24 var clzMinusOne
= mathClz32OnInteger(-1);
26 throw "mathClz32OnInteger(-1) = " + clzMinusOne
;
28 var clzUltimateAnswer
= mathClz32OnInteger(42);
29 if (clzUltimateAnswer
!= 26)
30 throw "mathClz32OnInteger(42) = " + clzUltimateAnswer
;
32 var clzMinusUltimateAnswer
= mathClz32OnInteger(-42);
33 if (clzMinusUltimateAnswer
!= 0)
34 throw "mathClz32OnInteger(-42) = " + clzMinusUltimateAnswer
;
36 noInline(testMathClz32OnIntegers
);
38 for (var i
= 0; i
< 1e4
; ++i
) {
39 testMathClz32OnIntegers();
42 // Make sure we don't do anything stupid when the type is unexpected.
43 function verifyMathClz32OnIntegerWithOtherTypes()
45 var clzPi
= mathClz32OnInteger(Math
.PI
);
47 throw "mathClz32OnInteger(Math.PI) = " + clzPi
;
49 var clzString
= mathClz32OnInteger("42");
51 throw "mathClz32OnInteger(\"42\") = " + clzString
;
53 var clzString
= mathClz32OnInteger("WebKit");
55 throw "mathClz32OnInteger(\"WebKit\") = " + clzString
;
57 var clzMinusZero
= mathClz32OnInteger(-0);
58 if (clzMinusZero
!= 32)
59 throw "mathClz32OnInteger(\"-0\") = " + clzMinusZero
;
61 noInline(verifyMathClz32OnIntegerWithOtherTypes
);
63 for (var i
= 0; i
< 1e4
; ++i
) {
64 verifyMathClz32OnIntegerWithOtherTypes();
68 // *** Test simple cases on doubles. ***
69 function mathClz32OnDouble(value
)
71 return Math
.clz32(value
);
73 noInline(mathClz32OnInteger
);
75 // Test simple cases on integers.
76 function testMathClz32OnDoubles()
78 var value
= mathClz32OnDouble(Math
.PI
);
80 throw "mathClz32OnDouble(Math.PI) = " + value
;
82 var value
= mathClz32OnDouble(Math
.E
);
84 throw "mathClz32OnDouble(Math.E) = " + value
;
86 var value
= mathClz32OnDouble(Math
.LN2
);
88 throw "mathClz32OnDouble(Math.LN2) = " + value
;
90 var value
= mathClz32OnDouble(-0);
92 throw "mathClz32OnDouble(0) = " + value
;
94 var value
= mathClz32OnDouble(NaN
);
96 throw "mathClz32OnDouble(NaN) = " + value
;
98 var value
= mathClz32OnDouble(Number
.POSITIVE_INFINITI
);
100 throw "mathClz32OnDouble(Number.POSITIVE_INFINITI) = " + value
;
102 var value
= mathClz32OnDouble(Number
.NEGATIVE_INFINITI
);
104 throw "mathClz32OnDouble(Number.NEGATIVE_INFINITI) = " + value
;
106 noInline(testMathClz32OnDoubles
);
108 for (var i
= 0; i
< 1e4
; ++i
) {
109 testMathClz32OnDoubles();
112 // Make sure we don't do anything stupid when the type is unexpected.
113 function verifyMathClz32OnDoublesWithOtherTypes()
115 var clzOne
= mathClz32OnDouble(1);
117 throw "mathClz32OnDouble(1) = " + clzOne
;
119 var clzString
= mathClz32OnDouble("42");
121 throw "mathClz32OnDouble(\"42\") = " + clzString
;
123 var clzString
= mathClz32OnDouble("WebKit");
125 throw "mathClz32OnDouble(\"WebKit\") = " + clzString
;
127 var clzMinusZero
= mathClz32OnDouble({});
128 if (clzMinusZero
!= 32)
129 throw "mathClz32OnDouble({}) = " + clzMinusZero
;
131 noInline(verifyMathClz32OnDoublesWithOtherTypes
);
133 for (var i
= 0; i
< 1e4
; ++i
) {
134 verifyMathClz32OnDoublesWithOtherTypes();
138 // *** Unusual arguments. ***
139 function mathClz32NoArguments()
143 noInline(mathClz32NoArguments
);
145 function mathClz32TooManyArguments(a
, b
, c
)
147 return Math
.clz32(a
, b
, c
);
149 noInline(mathClz32TooManyArguments
);
152 for (var i
= 0; i
< 1e4
; ++i
) {
153 var value
= mathClz32NoArguments();
155 throw "mathClz32NoArguments() = " + value
;
157 var value
= mathClz32TooManyArguments(2, 3, 5);
159 throw "mathClz32TooManyArguments() = " + value
;
164 // *** Constant as arguments. ***
165 function testMathClz32OnConstants()
167 var value
= Math
.clz32(0);
169 throw "Math.clz32(0) = " + value
;
170 var value
= Math
.clz32(-0);
172 throw "Math.clz32(-0) = " + value
;
173 var value
= Math
.clz32(1);
175 throw "Math.clz32(1) = " + value
;
176 var value
= Math
.clz32(-1);
178 throw "Math.clz32(-1) = " + value
;
179 var value
= Math
.clz32(42);
181 throw "Math.clz32(42) = " + value
;
182 var value
= Math
.clz32(-42);
184 throw "Math.clz32(-42) = " + value
;
185 var value
= Math
.clz32(NaN
);
187 throw "Math.clz32(NaN) = " + value
;
188 var value
= Math
.clz32(Number
.POSITIVE_INFINITI
);
190 throw "Math.clz32(Number.POSITIVE_INFINITI) = " + value
;
191 var value
= Math
.clz32(Number
.NEGATIVE_INFINITI
);
193 throw "Math.clz32(Number.NEGATIVE_INFINITI) = " + value
;
194 var value
= Math
.clz32(Math
.E
);
196 throw "Math.clz32(Math.E) = " + value
;
198 noInline(testMathClz32OnConstants
);
200 for (var i
= 0; i
< 1e4
; ++i
) {
201 testMathClz32OnConstants();
205 // *** Struct transition. ***
206 function mathClz32StructTransition(value
)
208 return Math
.clz32(value
);
210 noInline(mathClz32StructTransition
);
212 for (var i
= 0; i
< 1e4
; ++i
) {
213 var value
= mathClz32StructTransition(42);
215 throw "mathClz32StructTransition(42) = " + value
;
218 Math
.clz32 = function() { return arguments
[0] + 5; }
220 var value
= mathClz32StructTransition(42);
222 throw "mathClz32StructTransition(42) after transition = " + value
;