Skip to content

[mlir][dxsa] Add dtof, ftod, dtoi, dtou, itod and utod instructions#187

Merged
tagolog merged 1 commit into
dxsa-mlirfrom
vshiryaev/dxsa-mlir-dtof-ftod-dtoi-dtou-itod-utod
Jun 26, 2026
Merged

[mlir][dxsa] Add dtof, ftod, dtoi, dtou, itod and utod instructions#187
tagolog merged 1 commit into
dxsa-mlirfrom
vshiryaev/dxsa-mlir-dtof-ftod-dtoi-dtou-itod-utod

Conversation

@tagolog

@tagolog tagolog commented Jun 19, 2026

Copy link
Copy Markdown

Example:
dxsa.dtof r<0, <x, y>>, r<1>
dxsa.ftod r<0>, r<1>
dxsa.dtoi r<0, <x, y>>, r<1>
dxsa.dtou r<0, <x, y>>, r<1>
dxsa.itod r<0>, r<1>
dxsa.utod r<0>, r<1>

@tagolog tagolog requested review from asavonic, asl and hvdijk June 19, 2026 18:26
@tagolog tagolog self-assigned this Jun 19, 2026
Comment thread mlir/lib/Target/DXSA/BinaryParser.cpp Outdated
case D3D11_1_SB_OPCODE_ITOD:
return UNARY_OP(Itod);
case D3D11_1_SB_OPCODE_UTOD:
return UNARY_OP(Utod);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We really should have some sort of order for the instructions in this file. I have, for lack of a better option, just kept the bitwise instructions I've added in alphabetical order; it's going to cause merge conflicts to have other unrelated instructions inserted in the middle of them when I add more. Do you have any particular preference on this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point. I've reworked this: the conversion opcodes now live together in a dedicated "Type conversion instructions" block in the main switch, kept in alphabetical order (dtof, dtoi, dtou, f16tof32, f32tof16, ftod, ftoi, ftou, itod, itof, utod, utof), so they no longer get inserted into the middle of your bitwise block.

@hvdijk

hvdijk commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What's the reason for putting the double conversions in their own file rather than in DXSATypeConversionOps.td?

The `dxsa.dtou` operation converts each double-precision component of
`$src` to an unsigned 32-bit integer using truncation (round toward zero)
and writes the result to `$dst`. Inputs are clamped to
[0.0, 4294967295.999] before conversion; NaN inputs produce zero.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that this is copied from the Microsoft documentation, but it doesn't make sense? 4294967295.999 isn't representable in double precision floating point, but clamping to [0.0, x] for any 4294967295.0 <= x < 4294967296.0 produces identical results, so it won't actually clamp to 4294967295.999 but also it doesn't make any difference what it actually clamps to, the decimals are just arbitrary. Do we want to just copy the documentation, or do we want to clear it up?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point. I've dropped the clamp/NaN wording from both dtoi and dtou so they now just state "rounding toward zero", matching the existing ftoi/ftou descriptions which omit it too.

@hvdijk hvdijk Jun 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think even though the wording didn't quite make sense, it was intended to express an important thing: it's well-defined to convert a double that is not in the range of unsigned using dtou, and likewise for the other ops. With LLVM's fptoui, this would be explicitly undefined, so highlighting that dtou is different seems worthwhile. But I'm not sure how to best express that. It's fine to say, IMO, that based on ftou's description also missing this we leave this as an issue to be resolved later; if so, shall I open an issue to make sure it's tracked (even if we never get to it)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've created an issue to address this later #204

@tagolog tagolog force-pushed the vshiryaev/dxsa-mlir-dtof-ftod-dtoi-dtou-itod-utod branch from d5a6a90 to f574de7 Compare June 25, 2026 20:49
@tagolog

tagolog commented Jun 25, 2026

Copy link
Copy Markdown
Author

What's the reason for putting the double conversions in their own file rather than in DXSATypeConversionOps.td?

I've merged them into DXSATypeConversionOps.td alongside the other conversions and dropped the separate DXSADoubleTypeConversionOps.td file.

@tagolog tagolog requested a review from hvdijk June 25, 2026 21:03
@tagolog tagolog force-pushed the vshiryaev/dxsa-mlir-dtof-ftod-dtoi-dtou-itod-utod branch from f574de7 to 8730e24 Compare June 25, 2026 21:06

@hvdijk hvdijk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, thanks. The same comment on the line order in the tests applies as in the other PR, and I left another comment on the description, but for both of those, we can decide not to make changes there and merge this as is IMO.

Example:
  dxsa.dtof r<0, <x, y>>, r<1>
  dxsa.ftod r<0>, r<1>
  dxsa.dtoi r<0, <x, y>>, r<1>
  dxsa.dtou r<0, <x, y>>, r<1>
  dxsa.itod r<0>, r<1>
  dxsa.utod r<0>, r<1>

Signed-off-by: Vladimir Shiryaev <vshiryaev@accesssoftek.com>
@tagolog tagolog force-pushed the vshiryaev/dxsa-mlir-dtof-ftod-dtoi-dtou-itod-utod branch from 8730e24 to a810793 Compare June 26, 2026 19:05
@tagolog tagolog merged commit 3231602 into dxsa-mlir Jun 26, 2026
5 checks passed
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.

2 participants