Skip to content

Commit

Permalink
add I16Vec and U16Vec (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawogi authored Nov 24, 2023
1 parent f613dca commit 03c2233
Show file tree
Hide file tree
Showing 53 changed files with 15,760 additions and 60 deletions.
78 changes: 78 additions & 0 deletions codegen/src/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ impl ContextBuilder {
Self::new_tvecn_swizzle_impl(4, "D")
}

pub fn new_i16vec2_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(2, "I16")
}

pub fn new_i16vec3_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(3, "I16")
}

pub fn new_i16vec4_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(4, "I16")
}

pub fn new_u16vec2_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(2, "U16")
}

pub fn new_u16vec3_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(3, "U16")
}

pub fn new_u16vec4_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(4, "U16")
}

pub fn new_ivec2_swizzle_impl() -> Self {
Self::new_tvecn_swizzle_impl(2, "I")
}
Expand Down Expand Up @@ -200,6 +224,30 @@ impl ContextBuilder {
Self::new_vecn(4).with_scalar_t("f64")
}

pub fn new_i16vec2() -> Self {
Self::new_vecn(2).with_scalar_t("i16")
}

pub fn new_i16vec3() -> Self {
Self::new_vecn(3).with_scalar_t("i16")
}

pub fn new_i16vec4() -> Self {
Self::new_vecn(4).with_scalar_t("i16")
}

pub fn new_u16vec2() -> Self {
Self::new_vecn(2).with_scalar_t("u16")
}

pub fn new_u16vec3() -> Self {
Self::new_vecn(3).with_scalar_t("u16")
}

pub fn new_u16vec4() -> Self {
Self::new_vecn(4).with_scalar_t("u16")
}

pub fn new_ivec2() -> Self {
Self::new_vecn(2).with_scalar_t("i32")
}
Expand Down Expand Up @@ -426,6 +474,30 @@ pub fn build_output_pairs() -> HashMap<&'static str, tera::Context> {
"src/swizzles/dvec4_impl.rs",
ContextBuilder::new_dvec4_swizzle_impl().build(),
),
(
"src/swizzles/i16vec2_impl.rs",
ContextBuilder::new_i16vec2_swizzle_impl().build(),
),
(
"src/swizzles/i16vec3_impl.rs",
ContextBuilder::new_i16vec3_swizzle_impl().build(),
),
(
"src/swizzles/i16vec4_impl.rs",
ContextBuilder::new_i16vec4_swizzle_impl().build(),
),
(
"src/swizzles/u16vec2_impl.rs",
ContextBuilder::new_u16vec2_swizzle_impl().build(),
),
(
"src/swizzles/u16vec3_impl.rs",
ContextBuilder::new_u16vec3_swizzle_impl().build(),
),
(
"src/swizzles/u16vec4_impl.rs",
ContextBuilder::new_u16vec4_swizzle_impl().build(),
),
(
"src/swizzles/ivec2_impl.rs",
ContextBuilder::new_ivec2_swizzle_impl().build(),
Expand Down Expand Up @@ -556,6 +628,12 @@ pub fn build_output_pairs() -> HashMap<&'static str, tera::Context> {
("src/f64/dvec2.rs", ContextBuilder::new_dvec2().build()),
("src/f64/dvec3.rs", ContextBuilder::new_dvec3().build()),
("src/f64/dvec4.rs", ContextBuilder::new_dvec4().build()),
("src/i16/i16vec2.rs", ContextBuilder::new_i16vec2().build()),
("src/i16/i16vec3.rs", ContextBuilder::new_i16vec3().build()),
("src/i16/i16vec4.rs", ContextBuilder::new_i16vec4().build()),
("src/u16/u16vec2.rs", ContextBuilder::new_u16vec2().build()),
("src/u16/u16vec3.rs", ContextBuilder::new_u16vec3().build()),
("src/u16/u16vec4.rs", ContextBuilder::new_u16vec4().build()),
("src/i32/ivec2.rs", ContextBuilder::new_ivec2().build()),
("src/i32/ivec3.rs", ContextBuilder::new_ivec3().build()),
("src/i32/ivec4.rs", ContextBuilder::new_ivec4().build()),
Expand Down
70 changes: 65 additions & 5 deletions codegen/templates/vec.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,48 @@
{% set vec4_t = "DVec4" %}
{% set from_types = ["Vec" ~ dim, "IVec" ~ dim, "UVec" ~ dim] %}
{% endif %}
{% elif scalar_t == "i16" %}
{% set is_signed = true %}
{% set is_float = false %}
{% set self_t = "I16Vec" ~ dim %}
{% set vec2_t = "I16Vec2" %}
{% set vec3_t = "I16Vec3" %}
{% set vec4_t = "I16Vec4" %}
{% set try_from_types = ["U16Vec" ~ dim, "IVec" ~ dim, "UVec" ~ dim, "I64Vec" ~ dim, "U64Vec" ~ dim] %}
{% elif scalar_t == "u16" %}
{% set is_signed = false %}
{% set is_float = false %}
{% set self_t = "U16Vec" ~ dim %}
{% set vec2_t = "U16Vec2" %}
{% set vec3_t = "U16Vec3" %}
{% set vec4_t = "U16Vec4" %}
{% set try_from_types = ["I16Vec" ~ dim, "IVec" ~ dim, "UVec" ~ dim, "I64Vec" ~ dim, "U64Vec" ~ dim] %}
{% elif scalar_t == "i32" %}
{% set is_signed = true %}
{% set is_float = false %}
{% set self_t = "IVec" ~ dim %}
{% set vec2_t = "IVec2" %}
{% set vec3_t = "IVec3" %}
{% set vec4_t = "IVec4" %}
{% set try_from_types = ["UVec" ~ dim, "U64Vec" ~ dim, "I64Vec" ~ dim] %}
{% set from_types = ["I16Vec" ~ dim, "U16Vec" ~ dim] %}
{% set try_from_types = ["UVec" ~ dim, "I64Vec" ~ dim, "U64Vec" ~ dim] %}
{% elif scalar_t == "u32" %}
{% set is_signed = false %}
{% set is_float = false %}
{% set self_t = "UVec" ~ dim %}
{% set vec2_t = "UVec2" %}
{% set vec3_t = "UVec3" %}
{% set vec4_t = "UVec4" %}
{% set try_from_types = ["IVec" ~ dim, "I64Vec" ~ dim, "U64Vec" ~ dim] %}
{% set from_types = ["U16Vec" ~ dim] %}
{% set try_from_types = ["I16Vec" ~ dim, "IVec" ~ dim, "I64Vec" ~ dim, "U64Vec" ~ dim] %}
{% elif scalar_t == "i64" %}
{% set is_signed = true %}
{% set is_float = false %}
{% set self_t = "I64Vec" ~ dim %}
{% set vec2_t = "I64Vec2" %}
{% set vec3_t = "I64Vec3" %}
{% set vec4_t = "I64Vec4" %}
{% set from_types = ["IVec" ~ dim] %}
{% set from_types = ["I16Vec" ~ dim, "U16Vec" ~ dim, "IVec" ~ dim, "UVec" ~ dim] %}
{% set try_from_types = ["U64Vec" ~ dim] %}
{% elif scalar_t == "u64" %}
{% set is_signed = false %}
Expand All @@ -69,8 +87,8 @@
{% set vec2_t = "U64Vec2" %}
{% set vec3_t = "U64Vec3" %}
{% set vec4_t = "U64Vec4" %}
{% set from_types = ["UVec" ~ dim] %}
{% set try_from_types = ["I64Vec" ~ dim] %}
{% set from_types = ["U16Vec" ~ dim, "UVec" ~ dim] %}
{% set try_from_types = ["I16Vec" ~ dim, "IVec" ~ dim, "I64Vec" ~ dim] %}
{% endif %}

{% if scalar_t == "f64" or scalar_t == "i64" or scalar_t == "u64" or dim == 4 %}
Expand Down Expand Up @@ -1651,6 +1669,48 @@ impl {{ self_t }} {
}
{% endif %}
{% endif %}
{% if scalar_t != "i16" %}
{% if dim == 2 %}
/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec2(&self) -> crate::I16Vec2 {
crate::I16Vec2::new(self.x as i16, self.y as i16)
}
{% elif dim == 3 %}
/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec3(&self) -> crate::I16Vec3 {
crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
}
{% elif dim == 4 %}
/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec4(&self) -> crate::I16Vec4 {
crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
}
{% endif %}
{% endif %}
{% if scalar_t != "u16" %}
{% if dim == 2 %}
/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec2(&self) -> crate::U16Vec2 {
crate::U16Vec2::new(self.x as u16, self.y as u16)
}
{% elif dim == 3 %}
/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec3(&self) -> crate::U16Vec3 {
crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
}
{% elif dim == 4 %}
/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec4(&self) -> crate::U16Vec4 {
crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
}
{% endif %}
{% endif %}
{% if scalar_t != "i32" %}
{% if dim == 2 %}
/// Casts all elements of `self` to `i32`.
Expand Down
12 changes: 12 additions & 0 deletions src/f32/coresimd/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,18 @@ impl Vec3A {
crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec3(&self) -> crate::I16Vec3 {
crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec3(&self) -> crate::U16Vec3 {
crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec3(&self) -> crate::IVec3 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/coresimd/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,18 @@ impl Vec4 {
crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec4(&self) -> crate::I16Vec4 {
crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec4(&self) -> crate::U16Vec4 {
crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec4(&self) -> crate::IVec4 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/scalar/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,18 @@ impl Vec3A {
crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec3(&self) -> crate::I16Vec3 {
crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec3(&self) -> crate::U16Vec3 {
crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec3(&self) -> crate::IVec3 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/scalar/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,18 @@ impl Vec4 {
crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec4(&self) -> crate::I16Vec4 {
crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec4(&self) -> crate::U16Vec4 {
crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec4(&self) -> crate::IVec4 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/sse2/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,18 @@ impl Vec3A {
crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec3(&self) -> crate::I16Vec3 {
crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec3(&self) -> crate::U16Vec3 {
crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec3(&self) -> crate::IVec3 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/sse2/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,18 @@ impl Vec4 {
crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec4(&self) -> crate::I16Vec4 {
crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec4(&self) -> crate::U16Vec4 {
crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec4(&self) -> crate::IVec4 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,18 @@ impl Vec2 {
crate::DVec2::new(self.x as f64, self.y as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec2(&self) -> crate::I16Vec2 {
crate::I16Vec2::new(self.x as i16, self.y as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec2(&self) -> crate::U16Vec2 {
crate::U16Vec2::new(self.x as u16, self.y as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec2(&self) -> crate::IVec2 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,18 @@ impl Vec3 {
crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec3(&self) -> crate::I16Vec3 {
crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec3(&self) -> crate::U16Vec3 {
crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec3(&self) -> crate::IVec3 {
Expand Down
12 changes: 12 additions & 0 deletions src/f32/wasm32/vec3a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,18 @@ impl Vec3A {
crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
}

/// Casts all elements of `self` to `i16`.
#[inline]
pub fn as_i16vec3(&self) -> crate::I16Vec3 {
crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
}

/// Casts all elements of `self` to `u16`.
#[inline]
pub fn as_u16vec3(&self) -> crate::U16Vec3 {
crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
}

/// Casts all elements of `self` to `i32`.
#[inline]
pub fn as_ivec3(&self) -> crate::IVec3 {
Expand Down
Loading

0 comments on commit 03c2233

Please sign in to comment.