Bug 150919

Summary: [JSC] Add B3-to-Air lowering for the shift opcodes
Product: WebKit Reporter: Benjamin Poulain <benjamin>
Component: New BugsAssignee: Benjamin Poulain <benjamin>
Status: RESOLVED FIXED    
Severity: Normal CC: fpizlo
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch fpizlo: review+

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>