RESOLVED FIXED 129479
Implement Number.prototype.clz()
https://bugs.webkit.org/show_bug.cgi?id=129479
Summary Implement Number.prototype.clz()
Dániel Bátyai
Reported 2014-02-28 03:27:44 PST
There is a Number.prototype.clz() specification in the ES6 standard, which is not yet implemented in JSC.
Attachments
Proposed patch (9.03 KB, patch)
2014-02-28 04:42 PST, Dániel Bátyai
no flags
Proposed patch (9.19 KB, patch)
2014-03-03 09:18 PST, Dániel Bátyai
no flags
Dániel Bátyai
Comment 1 2014-02-28 04:42:23 PST
Created attachment 225453 [details] Proposed patch
Anders Carlsson
Comment 2 2014-02-28 06:44:40 PST
Comment on attachment 225453 [details] Proposed patch View in context: https://bugs.webkit.org/attachment.cgi?id=225453&action=review > Source/JavaScriptCore/runtime/NumberPrototype.cpp:472 > + int zeroCount = 0; > + for (int i = 31; i >= 0; i--) { > + if (!(number >> i)) > + zeroCount++; > + else > + break; > + } > + return JSValue::encode(jsString(exec, String::numberToStringECMAScript(zeroCount))); I think this should be a separate function and also use __builtin_clz when building with compilers that support it (GCC, clang).
Geoffrey Garen
Comment 3 2014-02-28 10:45:55 PST
Comment on attachment 225453 [details] Proposed patch Is coz really supposed to return a string? That seems impossible, given that its goal is performance.
Geoffrey Garen
Comment 4 2014-02-28 10:46:03 PST
*clz
Sam Weinig
Comment 5 2014-03-01 11:07:04 PST
(In reply to comment #3) > (From update of attachment 225453 [details]) > Is [clz] really supposed to return a string? That seems impossible, given that its goal is performance. http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.prototype.clz Seems like the answer is it is not supposed to return a string.
Dániel Bátyai
Comment 6 2014-03-03 09:18:58 PST
Created attachment 225661 [details] Proposed patch Modified according to comments. Unfortunately, __builtin_clz(0) was returning 31 instead of the 32 specified in the standard, so I had to add a check for that.
WebKit Commit Bot
Comment 7 2014-03-04 03:21:34 PST
Comment on attachment 225661 [details] Proposed patch Clearing flags on attachment: 225661 Committed r165047: <http://trac.webkit.org/changeset/165047>
WebKit Commit Bot
Comment 8 2014-03-04 03:21:36 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.