Skip to content

Fix sign extension for fractional power-of-two fixed-point products - #14

Open
nindanaoto wants to merge 2 commits into
fserre:masterfrom
virtualsecureplatform:sign-ext
Open

nindanaoto wants to merge 2 commits into
fserre:masterfrom
virtualsecureplatform:sign-ext

Conversation

@nindanaoto

Copy link
Copy Markdown

Summary

Fix fixed-point multiplication by positive fractional powers of two for negative operands.

SGen optimizes multiplication by constants such as 0.5 and 0.25 into shifts. For fractional constants, the generated RTL previously filled the high bits with zeros, effectively performing a logical right shift.

Because FixedPoint values use signed two's-complement representation, negative operands require an arithmetic right shift. The previous behavior could therefore turn a negative result into a large positive value.

Fix

Replicate the input sign bit when shifting right by a fractional power-of-two constant.

Positive operands retain the existing behavior, while negative operands now preserve their sign.

Tests

Add regression coverage for multiplication by:

  • 0.5 with positive and negative operands
  • 0.25 with positive and negative operands

The first commit adds the regression test and demonstrates the failure on the existing implementation. The second commit applies the fix and makes the test pass.

Tested with:

sbt "testOnly ir.rtl.hardwaretype.FixedPointTest"

Result:

Tests: succeeded 3, failed 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant