Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/coreclr/jit/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,17 +802,33 @@ TBase EvaluateBinaryScalarSpecialized(genTreeOps oper, TBase arg0, TBase arg1)
case GT_ROL:
{
// Normalize the "rotate by" value
arg1 %= (sizeof(TBase) * BITS_PER_BYTE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the behavioral difference for negative inputs, since %= is remainder of truncating division and so handles signed values differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. It was different for negative inputs. For eg. one of the test case has the rotate count show up as -2 in here.

if ((arg1 < 0) || (arg1 >= (sizeof(TBase) * BITS_PER_BYTE)))
{
// EvaluateBinaryScalarRSZ allows overshifting and treats
// it as zeroing.
// But ROL ensures the rotateAmount is masked
// to be within range, so we pre-calculates this.
unsigned rotateCountMask = (sizeof(TBase) * BITS_PER_BYTE) - 1;
arg1 &= rotateCountMask;
}
return EvaluateBinaryScalarSpecialized<TBase>(GT_LSH, arg0, arg1) |
EvaluateBinaryScalarRSZ<TBase>(arg0, (sizeof(TBase) * 8) - arg1);
EvaluateBinaryScalarRSZ<TBase>(arg0, (sizeof(TBase) * BITS_PER_BYTE) - arg1);
}

case GT_ROR:
{
// Normalize the "rotate by" value
arg1 %= (sizeof(TBase) * BITS_PER_BYTE);
if ((arg1 < 0) || (arg1 >= (sizeof(TBase) * BITS_PER_BYTE)))
{
// EvaluateBinaryScalarRSZ allows overshifting and treats
// it as zeroing.
// But ROR ensures the rotateAmount is masked
// to be within range, so we pre-calculates this.
unsigned rotateCountMask = (sizeof(TBase) * BITS_PER_BYTE) - 1;
arg1 &= rotateCountMask;
}
return EvaluateBinaryScalarRSZ<TBase>(arg0, arg1) |
EvaluateBinaryScalarSpecialized<TBase>(GT_LSH, arg0, (sizeof(TBase) * 8) - arg1);
EvaluateBinaryScalarSpecialized<TBase>(GT_LSH, arg0, (sizeof(TBase) * BITS_PER_BYTE) - arg1);
}

case GT_RSH:
Expand Down