Skip to content
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

Propose a new way to define intrinsic types #121

Closed
QuarticCat opened this issue Oct 25, 2021 · 0 comments
Closed

Propose a new way to define intrinsic types #121

QuarticCat opened this issue Oct 25, 2021 · 0 comments

Comments

@QuarticCat
Copy link

I recently tried to wrap RVV intrinsic types and functions into templates, but I found it painful. In addition to the changes proposed here, I would like to propose a new way to define intrinsic types.

The specific naming can be discussed further. I haven't given it much thought.

Motivation

The amount of RVV intrinsic types is huge. Sometimes we may want to parameterize these types, so that we can choose proper types automatically and do some compile-time evaluations. A parameterized representation also simplifies function APIs.

Design

The syntax is similar to the vector extension of GCC. For example, if we want to obtain a vint32m1_t, we can write

typedef int32_t my_vint32m1_t __attribute__ ((rvv_lmul (__m1)));

or in C++ style

using my_vint32m1_t [[__gnu__::__rvv_lmul__(__m1)]] = int32_t;

where __m1 is an enum defined like

enum __lmul {
    __m1 = 8,
    __m2 = 16,
    __m4 = 32,
    __m8 = 64,
    __mf2 = 4,
    __mf4 = 2,
    __mf8 = 1,
};

Mask types are similar.

typedef bool my_vbool1_t __attribute__ ((rvv_mask (1)));

Benefits

  • Available in C language. Although it is not in standard C, vector extensions and overloaded intrinsic functions are not either.

  • It makes RVV intrinsic types much easier to use in templates. To wrap it into templates, we can simply write

    template<class E, __lmul L>
    struct rvv_intrin {
        static_assert(sizeof(E) * L >= ELEN);
        using type [[__gnu__::__rvv_lmul__(L)]] = E;
        using element_type = E;
        inline constexpr static __lmul lmul = L;
    };

    This is way too better than a bunch of specializations or if constexprs, both for compilers and humans.

Compatibility

We can let types defined by attributes be aliases of existing types like vint32m1_t, so that it is backward compatible. Or reversely, let existing types be aliases of types defined by attributes.

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

No branches or pull requests

1 participant