Skip to content

[HLSL] LinAlg HLK: Use a checked-arithmetic type for oracle size computations #8728

Description

Goal

Replace the bool return plus out-parameter shape of checkedMultiply and checkedAdd in LinAlgTests.cpp with a type that composes, so chained overflow-checked size computations read as arithmetic rather than as a cascade of early returns.

Why

Every other helper added by #8666 returns std::optional; these two are the exception and they are the older, weaker shape. Converting them to a bare std::optional is a strict improvement in isolation, but on the sites that actually matter — the buffer-size and element-offset computations, which chain three to four checked operations feeding each other — a bare optional trades one form of noise for another.

A small Checked{} wrapper with operator overloads collapses those chains to ordinary expressions and keeps a single validity test at the end. It should be designed against the real chained call sites, which is why this was deferred out of #8666 rather than done inline: there are 14 call sites in that PR and 43 by the end of the current stack.

Required work

  • Design a minimal checked-integer type with the operators the oracle actually uses; do not build a general-purpose numerics facility.
  • Convert checkedMultiply and checkedAdd and every call site.
  • Preserve the existing overflow diagnostics, including the raw-value logging.

Acceptance criteria

  • No overflow-checked helper in LinAlgTests.cpp uses an out-parameter.
  • Overflow behaviour is unchanged, with a host test covering at least one overflowing and one non-overflowing chained computation.
  • LinAlgCPUOracleTests and LinAlg::DxilConf_SM610_LinAlg::* are unchanged test for test.

Blocked on

Nothing, but it is cheaper after the current LinAlg HLK PR stack has landed, since the call site count roughly triples across it.

Public references

Out of scope

  • Templating the oracle (tracked separately).
  • Any change to expected values or coverage.

Assisted-by: GitHub Copilot

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions