Skip to content

Add vblend vector operation #7729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged

Add vblend vector operation #7729

merged 1 commit into from
Apr 29, 2025

Conversation

gita-omr
Copy link
Contributor

@gita-omr gita-omr commented Apr 15, 2025

  • similar to vbitselect but works on lanes and under control of the mask (third child)
  • if lane is not set in the mask the value from the first vector is chosen
  • the lane from the second vector is chosen otherwise

@gita-omr
Copy link
Contributor Author

@gita-omr
Copy link
Contributor Author

Jenkins build all

@gita-omr
Copy link
Contributor Author

Fixed build errors.

@gita-omr
Copy link
Contributor Author

Jenkins build all

@gita-omr
Copy link
Contributor Author

RISC build failed due to unrelated reasons (machine is offline).

@0xdaryl
Copy link
Contributor

0xdaryl commented Apr 16, 2025

What is the type and semantics of the "mask" child? i.e., how does it describe how the the first and second children are blended?

@gita-omr
Copy link
Contributor Author

All three arguments have the same number of elements. Mask element is a boolean value. If it's true, corresponding element of the first vector is chosen. If it's false, element from the second argument is chosen.

@gita-omr gita-omr changed the title Add vblend vector operation WIP: Add vblend vector operation Apr 17, 2025
@gita-omr
Copy link
Contributor Author

Actually, it's a good question. Let me think what the exact semantic should be.

@hzongaro
Copy link
Contributor

vblend is similar to vselect

What is vselect? Or did you mean select?

All three arguments have the same number of elements. Mask element is a boolean value. If it's true, corresponding element of the first vector is chosen. If it's false, element from the second argument is chosen.

If this is meant to be analogous to select, should the first argument be the mask, rather than the third?

@gita-omr gita-omr changed the title WIP: Add vblend vector operation Add vblend vector operation Apr 17, 2025
@gita-omr
Copy link
Contributor Author

Updated with expected semantics.

@BradleyWood

@gita-omr
Copy link
Contributor Author

gita-omr commented Apr 17, 2025

If this is meant to be analogous to select, should the first argument be the mask, rather than the third?

We have vbitselect vector operation. It selects bits from the second vector if corresponding bit in the third vector is set. Otherwise, the bit from the first vector is selected.

@hzongaro
Copy link
Contributor

We have vbitselect vector operation. It selects bits from the second vector if corresponding bit in the third vector is set. Otherwise, the bit from the first vector is selected.

I see. It's unfortunate that the order of the operands differs from those of iselect, et al.

@BradleyWood
Copy link
Contributor

Thanks for doing this @gita-omr. Did you find out the reason that the vbitselect opcode had a strange extra operand?

@gita-omr
Copy link
Contributor Author

gita-omr commented Apr 17, 2025

We have vbitselect vector operation. It selects bits from the second vector if corresponding bit in the third vector is set. Otherwise, the bit from the first vector is selected.

I see. It's unfortunate that the order of the operands differs from those of iselect, et al.

This is a common meaning for vector blend operations and that's how corresponding instructions work at least on Intel and Power. Essentially, we blend second vector into the first one based on the third vector or mask.

@gita-omr
Copy link
Contributor Author

To reviewers: please let me know if you have any other questions.

/* .reverseBranchOperation = */ TR::vBadOperation, \
/* .booleanCompareOpCode = */ TR::BadILOp, \
/* .ifCompareOpCode = */ TR::BadILOp, \
/* .description = vector blend witn mask operator */ \
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be helpful if your clarification on semantics were documented here in the code rather than in a PR comment.

/* .reverseBranchOperation = */ TR::vBadOperation, \
/* .booleanCompareOpCode = */ TR::BadILOp, \
/* .ifCompareOpCode = */ TR::BadILOp, \
/* .description = vector blend witn mask operator */ \
Copy link
Contributor

Choose a reason for hiding this comment

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

sp. "with"

@0xdaryl
Copy link
Contributor

0xdaryl commented Apr 28, 2025

As new opcodes are normally discussed at OMR Architecture Meetings, I'd like at least one committer other than me to formally approve this before merging.

@gita-omr
Copy link
Contributor Author

Addressed comments above.

/* .description = vector blend operator */ \
/* blends second vector into first based on mask (third child) */ \
/* if lane is not set in the mask the value from the first vector is chosen */ \
/* the lane from the second vector is chosen otherwise */
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry to nit about something like this, but the commenting style is a bit awkward. I'm not clear why you use \ at the end of each comment line except the last one, and why each line has its own comment.

Something like you have for the vcompressbits opcode seems more visually appealing (to me at least).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took it from here:

/* .description = Compare two blocks of memory and returning a lexical ordering constant. */ \

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But you are right vcompressbits looks better. Let me change.

@gita-omr
Copy link
Contributor Author

Improved opcode description comment.

@0xdaryl
Copy link
Contributor

0xdaryl commented Apr 28, 2025

Thanks. Please squash commits and I can re-launch testing. I'd appreciate a +1 from another committer please.

@gita-omr
Copy link
Contributor Author

Squashed.

@0xdaryl
Copy link
Contributor

0xdaryl commented Apr 28, 2025

Jenkins build all

Copy link
Contributor

@jdmpapin jdmpapin left a comment

Choose a reason for hiding this comment

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

I'm not sure that vblend should have ILProp2::Select. To me, that suggests that it works like an xselect opcode (where x is one of the basic data types), but there are a number of differences between them:

  • xselect chooses based on a single zero/nonzero integer vs. the vector mask that vblend uses;
  • the result of xselect is the result of one of the two value children, whereas the result of vblend can be a combination of the two;
  • the operand indicating which choice(s) to make is the first child for xselect, but the third child for vblend; and
  • the boolean choice is interpreted in the opposite order with respect to the two values, with the first of them corresponding to true for xselect but false for vblend.

This also applies to vbitselect (though the specifics of the differences won't be exactly the same). At the moment, vbitselect appears to be the only operation other than xselect that has the ILProp2::Select property.

I can easily imagine some logic trying to operate generically on the various xselect opcodes and trying to identify them simply by calling isSelect() on the opcode. The ILProp2::Select property on vblend (and vbitselect) would thoroughly confuse any such logic. However, I looked and I was unable to find any existing place where this happens without an additional condition that the select node be address-typed, integral-typed, or have an opcode that also satisfies isInteger(). So I don't think it could cause a functional issue with the current uses of isSelect(), but it could potentially be a footgun in the future.

@gita-omr
Copy link
Contributor Author

Thanks @jdmpapin for the great observation in #7729 (review). I agree that both vblend and vbitselect should not have ILProp2::Select property set. I think it was a bit of a mistake to model vbitselect after xselect. Perhaps it should've been called vbitblend instead.

For now, I will just remove ILProp2::Select property from vblend.

- similar to vbitselect but works on lanes and under control of the mask (third child)
- if lane is not set in the mask the value from the first vector is chosen
- the lane from the second vector is chosen otherwise
@gita-omr
Copy link
Contributor Author

gita-omr commented Apr 28, 2025

Removed ILProp2::Select from vblend.

We can discuss vbitselect at OMR Architecture Meeting. @0xdaryl

@jdmpapin
Copy link
Contributor

Jenkins build all

@0xdaryl
Copy link
Contributor

0xdaryl commented Apr 29, 2025

The Eclipse CI infrastructure has been down for a few days (no ETA as far as I know). @gita-omr, can you manually verify this PR builds and passes the OMR tests on either X or P please and confirm here. Thanks.

@gita-omr
Copy link
Contributor Author

gita-omr commented Apr 29, 2025

The Eclipse CI infrastructure has been down for a few days (no ETA as far as I know). @gita-omr, can you manually verify this PR builds and passes the OMR tests on either X or P please and confirm here. Thanks.

I built this PR on Intel and Power. I also ran OMR tests on Power and only porttest failed, which I think is unrelated.

@0xdaryl 0xdaryl self-assigned this Apr 29, 2025
@0xdaryl
Copy link
Contributor

0xdaryl commented Apr 29, 2025

CI infrastructure is down, but I am satisfied with the offline testing done on this.

@0xdaryl 0xdaryl merged commit 31a1e55 into eclipse-omr:master Apr 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants