Bug 129479 - Implement Number.prototype.clz()
Summary: Implement Number.prototype.clz()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-28 03:27 PST by Dániel Bátyai
Modified: 2014-03-04 09:48 PST (History)
5 users (show)

See Also:


Attachments
Proposed patch (9.03 KB, patch)
2014-02-28 04:42 PST, Dániel Bátyai
no flags Details | Formatted Diff | Diff
Proposed patch (9.19 KB, patch)
2014-03-03 09:18 PST, Dániel Bátyai
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dániel Bátyai 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.
Comment 1 Dániel Bátyai 2014-02-28 04:42:23 PST
Created attachment 225453 [details]
Proposed patch
Comment 2 Anders Carlsson 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).
Comment 3 Geoffrey Garen 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.
Comment 4 Geoffrey Garen 2014-02-28 10:46:03 PST
*clz
Comment 5 Sam Weinig 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.
Comment 6 Dániel Bátyai 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.
Comment 7 WebKit Commit Bot 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>
Comment 8 WebKit Commit Bot 2014-03-04 03:21:36 PST
All reviewed patches have been landed.  Closing bug.