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

Switch to generic syntax for SIMD types while including the original aliases #70

Open
sirisian opened this issue Aug 6, 2022 · 2 comments

Comments

@sirisian
Copy link
Owner

sirisian commented Aug 6, 2022

WIP issue with thoughts.

Currently the SIMD types are:

boolean8x16, boolean16x8, boolean32x4, boolean64x2, boolean8x32, boolean16x16, boolean32x8, boolean64x4
int8x16, int16x8, int32x4, int64x2, int8x32, int16x16, int32x8, int64x4
uint8x16, uint16x8, uint32x4, uint64x2, uint8x32, uint16x16, uint32x8, uint64x4
float32x4, float64x2, float32x8, float64x4

Been thinking they could just be aliases. They're really nice to have as they make math code compact. One of the main reasons I originally defined them as separate types is because they need component accessors in the form of:

position: x, y, z, w
color: r, g, b, a
texture: s, t, p, q

These would be part of the swizzling operators on vectors of size 2 and 4.

There are vectors with sizes 2, 4, 8, 16, and 32. These could all be defined like:

type float32x8 = vector<float32, 8>;

We'd need to make the boolean bitflag types real: boolean8, boolean16, boolean32, boolean64. These array syntax to access bitflags probably.

const a:boolean8 = 2;
a[1]; // 1
@sirisian
Copy link
Owner Author

sirisian commented Dec 4, 2022

More thoughts related to this.

In the generics extension I refer to the point there's no int or uint base type. This can be remedied by changing the types to be uint<N> and int<N> where both extend from uint and int respectively.

Expand for all the ```int``` and ```uint``` types defined by default.
type int8 = int<8>;
type int16 = int<16>;
type int32 = int<32>;
type int64 = int<64>;

type uint8 = uint<8>;
type uint16 = uint<16>;
type uint32 = uint<32>;
type uint64 = uint<64>;

boolean at least for SIMD masks can be thought of as uint<1>.

type boolean1 = uint<1>;
type boolean8 = vector<boolean1, 8>;
type boolean8x16 = vector<boolean8, 16>; // vector<vector<uint<1>, 8>, 16>
Expand for all the SIMD types defined by default.
type boolean1 = uint<1>;
type boolean8 = vector<boolean1, 8>;
type boolean16 = vector<boolean1, 16>;
type boolean32 = vector<boolean1, 32>;
type boolean64 = vector<boolean1, 64>;

type boolean8x16 = vector<boolean8, 16>;
type boolean16x8 = vector<boolean16>, 8>;
type boolean32x4 = vector<boolean32>, 4>;
type boolean64x2 = vector<boolean64>, 2>;
type boolean8x32 = vector<boolean8>, 32>;
type boolean16x16 = vector<boolean16>, 16>;
type boolean32x8 = vector<boolean32>, 8>;
type boolean64x4 = vector<boolean64>, 4>;
type int8x16 = vector<int8, 16>;
type int16x8 = vector<int16, 8>;
type int32x4 = vector<int32, 4>;
type int64x2 = vector<int64, 2>;
type int8x32 = vector<int8, 32>;
type int16x16 = vector<int16, 16>;
type int32x8 = vector<int32, 8>;
type int64x4 = vector<int64, 4>;
type uint8x16 = vector<uint8, 16>;
type uint16x8 = vector<uint16, 8>;
type uint32x4 = vector<uint32, 4>;
type uint64x2 = vector<uint64, 2>;
type uint8x32 = vector<uint8, 32>;
type uint16x16 = vector<uint16, 16>;
type uint32x8 = vector<uint32, 8>;
type uint64x4 = vector<uint64, 4>;
type float32x4 = vector<float32, 4>;
type float64x2 = vector<float64, 2>;
type float32x8 = vector<float32, 8>;
type float64x4 = vector<float64, 4>;

Further down in the current spec I mention allowing bit fields. Weirdly enough ECMAScript is seeing use in embedded systems. Sometimes it's things like devices having web interfaces. As computing power continues to increase there are more low level libraries being used by developers.

class Vector2 {
  x:uint<4>; // 4 bits
  y:uint<4>; // 4 bits
}

It's important to quickly mock up such bitfield syntax and ensure the language defines the memory layout as it can't be changed later.

WIP: Continue this later...

@sirisian
Copy link
Owner Author

sirisian commented Dec 5, 2022

Updated https://github.com/sirisian/ecmascript-types/blob/master/README.md#types-proposed with these changes.

TODO: Update the bit-fields section and the memory layout sections to support bit alignment and sizes optionally.

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