Skip to content

Incorrect value after truncating cast  #92349

@TechPizzaDev

Description

@TechPizzaDev

Description

When running a Release build, performing a (ushort)(uint) cast on int and storing the result in a ushort* seems to write out 32 bits instead of 16 bits.

Reproduction Steps

  1. Clone repo https://github.com/TechPizzaDev/SoftwareRasterizer
  2. Checkout branch net8-upgrade
  3. Download Castle folder from https://github.com/rawrunprotected/rasterizer/tree/master/SoftwareRasterizer and put next to built SoftwareRasterizer.exe
  4. Run project in Release mode to see broken render (it works in Debug mode)
  5. Remove BUG define (https://github.com/TechPizzaDev/SoftwareRasterizer/blob/318adc376bcdaee1b6c863dd9384871aed82897e/SoftwareRasterizer/Avx2Rasterizer.cs#L2)
  6. Run project again to see correct render

Expected behavior

Correct raster like in net7:
image

Actual behavior

image

Regression?

Regression in net8, worked on net7 and net6.

Known Workarounds

Rewriting the code seems like the only workaround. The project also works in Debug mode.

Configuration

.NET: 8.0.0-rc.1.23419.4
OS: Microsoft Windows 11 Home (10.0.22621 version 22621)
CPU: 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz
Arch: x64

Env variables

DOTNET_EnableAVX512F=0: Required since net8 seems to cause unexpected AccessViolationExceptions.

Other information

Sse41.MinHorizontal(Vector128<ushort>) returns a Vector128<ushort> where the first ushort element is the minimum value from the vector, and the second ushort element is the index of the min element within the vector.

Problematic code: https://github.com/TechPizzaDev/SoftwareRasterizer/blob/318adc376bcdaee1b6c863dd9384871aed82897e/SoftwareRasterizer/Avx2Rasterizer.cs#L1262-L1264

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions