Bug 150919 - [JSC] Add B3-to-Air lowering for the shift opcodes
Summary: [JSC] Add B3-to-Air lowering for the shift opcodes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Benjamin Poulain
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-04 19:10 PST by Benjamin Poulain
Modified: 2015-11-04 21:50 PST (History)
1 user (show)

See Also:


Attachments
Patch (30.53 KB, patch)
2015-11-04 19:11 PST, Benjamin Poulain
fpizlo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Poulain 2015-11-04 19:10:54 PST
[JSC] Add B3-to-Air lowering for the shift opcodes
Comment 1 Benjamin Poulain 2015-11-04 19:11:16 PST
Created attachment 264835 [details]
Patch
Comment 2 Filip Pizlo 2015-11-04 20:33:41 PST
Comment on attachment 264835 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=264835&action=review

> Source/JavaScriptCore/b3/B3Const32Value.cpp:105
> +Value* Const32Value::shlConstant(Procedure& proc, Value* other) const
> +{
> +    if (!other->hasInt32())
> +        return nullptr;
> +    return proc.add<Const32Value>(origin(), m_value << other->asInt32());
> +}
> +
> +Value* Const32Value::sShrConstant(Procedure& proc, Value* other) const
> +{
> +    if (!other->hasInt32())
> +        return nullptr;
> +    return proc.add<Const32Value>(origin(), m_value >> other->asInt32());
> +}
> +
> +Value* Const32Value::zShrConstant(Procedure& proc, Value* other) const
> +{
> +    if (!other->hasInt32())
> +        return nullptr;
> +    return proc.add<Const32Value>(origin(), static_cast<int32_t>(static_cast<uint32_t>(m_value) >> other->asInt32()));
> +}
> +

You should explicitly mask the shift amount.

I propose that we define shifts in B3 to be defined so that:

    Shl(a, b)

where a is In32 is:

    a << (b & 31)

and where a is Int64 it's:

    a << (b & 63)

The reason why this is important is that this matches exactly what X86_64 and ARM do, and it's what FTL lowering will expect.

But in C, the upper bits of the shit amount have an undefined effect on the outcome of the shift.

Therefore, when using C code to fold shifts, we need to mask.

And of course I had to file: https://bugs.webkit.org/show_bug.cgi?id=150924
Comment 3 Benjamin Poulain 2015-11-04 21:50:53 PST
Committed r192051: <http://trac.webkit.org/changeset/192051>