RFR: 8320347: Emulate vblendvp[sd] on ECore [v2]

Volodymyr Paprotski duke at openjdk.org
Tue Nov 21 21:36:08 UTC 2023


On Tue, 21 Nov 2023 19:32:22 GMT, Volodymyr Paprotski <duke at openjdk.org> wrote:

>> src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 1112:
>> 
>>> 1110:   void (MacroAssembler::*vblend)(XMMRegister, XMMRegister, XMMRegister, XMMRegister, int, bool, XMMRegister);
>>> 1111:   void (MacroAssembler::*vmaxmin)(XMMRegister, XMMRegister, XMMRegister, int);
>>> 1112:   void (MacroAssembler::*vcmp)(XMMRegister, XMMRegister, XMMRegister, int, int);
>> 
>> We do support C++11 dialect, you can use following declarations.
>> using vblend = void (*) (XMMRegister, XMMRegister, XMMRegister, XMMRegister, int, bool, XMMRegister);
>
> Its a member-function pointer, not a regular function pointer.. but `using` function pointer declaration is definitely an improvement I wasn't aware of. Trying to find chapter-and-verse in C++ spec on declaration of member-function pointers and their use with `using`. Will fix.

Keyword `using` is a rather poor search-engine word, couldn't find examples for member-function pointer declaration with the `using` syntax. So had to look at the standard itself. [C++17 draft](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf)

---

I think properly, its called an `alias-declaration` [dcl.dcl]. 

alias-declaration:
    using identifier attribute-specifier-seqopt = defining-type-id ;


At end of section 11.3.3 [dcl.mptr], seems to imply that function pointer declaration and member-function pointer declarations are different 

[ Note: See also 8.3 and 8.5. The type “pointer to member” is distinct from the type “pointer”, that is, a
pointer to member is declared only by the pointer to member declarator syntax, and never by the pointer
declarator syntax. There is no “reference-to-member” type in C++. — end note ]

That to me seems to mean that function pointer and member pointer will follow different BNF grammar rules, and might not arrive to both having support for the `using` declaration. I have been trying to find the BNF for it regardless, but its been many years, standard is big, hours of reading later, no closer to a definitive answer that member-function declaration do not support the using syntax.

---

Trial-and-error, perhaps the compiler would give me some hints as to where to look.. Section 11.1 Type names suggests removing the identifier to get the type:

It is possible to identify uniquely the location in the abstract-declarator where the identifier would appear if
the construction were a declarator in a declaration. The named type is then the same as the type of the
hypothetical identifier.

So, I tried syntax similar to what you suggested:

using vblend = void (MacroAssembler::*)(XMMRegister, XMMRegister, XMMRegister, XMMRegister, int, bool, XMMRegister);

Does not work:

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp:1134:12: error: expected unqualified-id before '=' token
 1134 |     vblend = &MacroAssembler::vblendvpd;
      |            ^
src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp:1156:17: error: expected primary-expression before ')' token
 1156 |   (this->*vblend)(atmp, a, b, mask, vlen_enc, true, btmp);
 ```
First message is bad, the `&` is required per `8.3.1 Unary operators` section 4 :

A pointer to member is only formed when an explicit & is used and its operand is a qualified-id not enclosed
in parentheses.

Second message is also bad, per section `8.5 Pointer-to-member operators`, cast, `.*`, `->*` are about all the operations allowed on pointer-to-member.

---

Looking through the standard, I came upon an alternative potential solution.


decltype(&MacroAssembler::vblendvps) vblend;

Confirmed to work. Not sure I like how imprecise it is, but it _is_ shorter.

---

TLDR: Perhaps there is no such thing as member-function declaration using `using`.. or g++ hasn't implemented it `per-spec` and another compiler does.. but we have to use g++ so that point is moot.

Unless someone else can get it to work, my preference would be to keep it as is, but the `decltype` option is there too.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16716#discussion_r1401224703


More information about the hotspot-compiler-dev mailing list