zoo icon indicating copy to clipboard operation
zoo copied to clipboard

New Literals Utils

Open jamierpond opened this issue 10 months ago • 4 comments

moved this into a new PR for clarity. Literals can now be written like so:

static_assert(SWAR{Literals<32, u64>, {2, 1}}.value() == 0x00000002'00000001);
static_assert(SWAR{Literals<32, u64>, {1, 2}}.value() == 0x00000001'00000002);
static_assert(SWAR{Literals<16, u64>, {4, 3, 2, 1}}.value() == 0x0004'0003'0002'0001);
static_assert(SWAR{Literals<16, u64>, {1, 2, 3, 4}}.value() == 0x0001'0002'0003'0004);

jamierpond avatar Apr 16 '24 23:04 jamierpond

Improvements all around, but, like in the movie "Whiplash", still not quite my tempo. Loving the feedback. Thank you! Since you have given us the construction from literals, perhaps it is a good idea to do the opposite of having a conversion operator to array of values, constexpr operator std::array<T, Lanes>(); and a named conversion to_array I like the idea of this, will check it out.

jamierpond avatar Apr 19 '24 16:04 jamierpond

@thecppzoo maybe best to merge where we were happy and add the to_array in a seperate PR if we think that is interesting?

jamierpond avatar Apr 19 '24 18:04 jamierpond

My preference with this PR is to not just introduce the support for direct initialization of literals, but complete it with the following:

  1. Making the essential function from_array a part of the public interface (we ought to indicate the semantics is that of big endianness in the comments inline with the code), as a class-function, because it is a factory.
  2. Keep the Literals infrastructure you already made, extend with a constructor from std::array
  3. to_array

Separately, I think we can also add a header, such as SWAR_IO.h where the insertion and extraction operators are implemented. I don't think these things are unrelated: The ergonomics of the literals are highly cohesive with stream insertion and extraction. We need this "yesterday" for debugging and tracing.

Indicate if you'd like to split these features with me or prefer to do them all yourself.

thecppzoo avatar Apr 19 '24 18:04 thecppzoo

If you want to take on the std::array stuff and getting that to that could be nice.

From what I understood from playing around with this today we will require C++ >17 in order to use constexpr std::array in static_assert tests, but this may be a limitation of my understanding.

Even with C++23 am seeing failures to compiler on g++.

jamierpond avatar Apr 20 '24 00:04 jamierpond