mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added initial intvec/floatvec operator
This commit is contained in:
committed by
Christoffer Lerno
parent
3d110850df
commit
3a09f71830
@@ -3,7 +3,7 @@ module std::bits;
|
||||
/**
|
||||
* @require types::is_intlike($typeof(i)) `The input must be an integer or integer vector`
|
||||
**/
|
||||
macro popcount(i)
|
||||
macro popcount(i) @operator(intvec)
|
||||
{
|
||||
return $$popcount(i);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ macro bswap(i) @builtin
|
||||
/**
|
||||
* @require types::is_intlike($typeof(i)) `The input must be an integer or integer vector`
|
||||
**/
|
||||
macro ctz(i) @builtin
|
||||
macro ctz(i) @operator(intvec) @builtin
|
||||
{
|
||||
return $$ctz(i);
|
||||
}
|
||||
@@ -35,15 +35,14 @@ macro ctz(i) @builtin
|
||||
/**
|
||||
* @require types::is_intlike($typeof(i)) `The input must be an integer or integer vector`
|
||||
**/
|
||||
macro clz(i) @builtin
|
||||
macro clz(i) @operator(intvec) @builtin
|
||||
{
|
||||
return $$clz(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @require types::is_intlike($typeof(hi)) && types::is_intlike($typeof(lo)) && types::is_intlike($typeof(shift)) `The input must be an integer or integer vector`
|
||||
* @require types::is_same_type(hi, lo) `Hi and low arguments must have the same type`
|
||||
* @require types::is_same_type(hi, shift) `The shift value must have the same type as shifted types`
|
||||
* @require types::@has_same(hi, lo, shift) `Hi, low and shift arguments must have the same type`
|
||||
**/
|
||||
macro fshl(hi, lo, shift) @builtin
|
||||
{
|
||||
@@ -52,8 +51,7 @@ macro fshl(hi, lo, shift) @builtin
|
||||
|
||||
/**
|
||||
* @require types::is_intlike($typeof(hi)) && types::is_intlike($typeof(lo)) && types::is_intlike($typeof(shift)) `The input must be an integer or integer vector`
|
||||
* @require types::is_same_type(hi, lo) `Hi and low arguments must have the same type`
|
||||
* @require types::is_same_type(hi, shift) `The shift value must have the same type as shifted types`
|
||||
* @require types::@has_same(hi, lo, shift) `Hi, low and shift arguments must have the same type`
|
||||
**/
|
||||
macro fshr(hi, lo, shift) @builtin
|
||||
{
|
||||
@@ -62,18 +60,18 @@ macro fshr(hi, lo, shift) @builtin
|
||||
|
||||
/**
|
||||
* @require types::is_intlike($typeof(i)) && types::is_intlike($typeof(shift)) `The input must be an integer or integer vector`
|
||||
* @require types::is_same_type(i, shift) `The shift value must have the same type as shifted types`
|
||||
* @require types::@has_same(i, shift) `The shift value must have the same type as shifted types`
|
||||
**/
|
||||
macro rotl(i, shift) @builtin
|
||||
macro rotl(i, shift) @operator(intvec) @builtin
|
||||
{
|
||||
return $$fshl(i, i, shift);
|
||||
}
|
||||
|
||||
/**
|
||||
* @require types::is_intlike($typeof(i)) && types::is_intlike($typeof(shift)) `The input must be an integer or integer vector`
|
||||
* @require types::is_same_type(i, shift) `The shift value must have the same type as shifted types`
|
||||
* @require types::@has_same(i, shift) `The shift value must have the same type as shifted types`
|
||||
**/
|
||||
macro rotr(i, shift) @builtin
|
||||
macro rotr(i, shift) @operator(intvec) @builtin
|
||||
{
|
||||
return $$fshr(i, i, shift);
|
||||
}
|
||||
|
||||
@@ -134,6 +134,18 @@ macro bool is_intlike($Type)
|
||||
$endswitch;
|
||||
}
|
||||
|
||||
macro bool is_floatlike($Type)
|
||||
{
|
||||
$switch ($Type.kind):
|
||||
$case FLOAT:
|
||||
return true;
|
||||
$case VECTOR:
|
||||
return $Type.inner.kind == TypeKind.FLOAT;
|
||||
$default:
|
||||
return false;
|
||||
$endswitch;
|
||||
}
|
||||
|
||||
macro bool is_vector($Type)
|
||||
{
|
||||
return $Type.kind == TypeKind.VECTOR;
|
||||
@@ -144,9 +156,18 @@ macro bool is_same($TypeA, $TypeB)
|
||||
return $TypeA.typeid == $TypeB.typeid;
|
||||
}
|
||||
|
||||
macro bool is_same_type(a, b)
|
||||
macro bool @has_same(#a, #b, ...)
|
||||
{
|
||||
return $typeof(a).typeid == $typeof(b).typeid;
|
||||
var $type_a = $typeof(#a).typeid;
|
||||
$if ($type_a != $typeof(#b).typeid):
|
||||
return false;
|
||||
$endif;
|
||||
$for (var $i = 0; $i < $vacount; $i++):
|
||||
$if ($typeof($vaexpr($i)).typeid != $type_a):
|
||||
return false;
|
||||
$endif;
|
||||
$endfor;
|
||||
return true;
|
||||
}
|
||||
|
||||
macro bool is_equatable_value(value)
|
||||
|
||||
@@ -96,47 +96,60 @@ fn double log2(double x) @inline
|
||||
return $$log2(x);
|
||||
}
|
||||
|
||||
fn double log(double x) @inline
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
**/
|
||||
macro log(f)
|
||||
{
|
||||
return $$log(x);
|
||||
return $$log(f);
|
||||
}
|
||||
|
||||
fn double cos(double x) @inline
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
**/
|
||||
macro cos(f)
|
||||
{
|
||||
return $$cos(x);
|
||||
return $$cos(f);
|
||||
}
|
||||
|
||||
fn float cosf(float x) @inline
|
||||
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
**/
|
||||
macro sin(f)
|
||||
{
|
||||
return $$cos(x);
|
||||
return $$sin(f);
|
||||
}
|
||||
|
||||
fn double sin(double x) @inline
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
**/
|
||||
macro exp(f)
|
||||
{
|
||||
return $$sin(x);
|
||||
return $$exp(f);
|
||||
}
|
||||
|
||||
fn float sinf(float x) @inline
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
* @require types::@has_same(f, exp) `Parameters must have the same type`
|
||||
**/
|
||||
macro pow(f, exp) @operator(floatvec)
|
||||
{
|
||||
return $$sin(x);
|
||||
return $$pow(f, exp);
|
||||
}
|
||||
|
||||
fn double exp(double x) @inline
|
||||
{
|
||||
return $$exp(x);
|
||||
}
|
||||
|
||||
fn double pow(double x, double y) @inline
|
||||
{
|
||||
return $$pow(x, y);
|
||||
}
|
||||
|
||||
fn double trunc(double x) @inline
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
**/
|
||||
macro trunc(x) @operator(floatvec)
|
||||
{
|
||||
return $$trunc(x);
|
||||
}
|
||||
|
||||
fn double ceil(double x) @inline
|
||||
/**
|
||||
* @require types::is_floatlike($typeof(f)) `The input must be a floating point value or float vector`
|
||||
**/
|
||||
macro ceil(x) @operator(floatvec)
|
||||
{
|
||||
return $$ceil(x);
|
||||
}
|
||||
|
||||
@@ -341,8 +341,8 @@ fn Matrix4x4 Matrix4x4.translate(Matrix4x4* m, float[<3>] v)
|
||||
fn Matrix3x3 Matrix3x3.rotate(Matrix3x3* m, float r)
|
||||
{
|
||||
return m.mul(Matrix3x3 {
|
||||
math::cosf(r), -math::sinf(r), 0,
|
||||
math::sinf(r), math::cosf(r), 0,
|
||||
math::cos(r), -math::sin(r), 0,
|
||||
math::sin(r), math::cos(r), 0,
|
||||
0, 0, 1,
|
||||
});
|
||||
}
|
||||
@@ -351,8 +351,8 @@ fn Matrix3x3 Matrix3x3.rotate(Matrix3x3* m, float r)
|
||||
fn Matrix4x4 Matrix4x4.rotate_z(Matrix4x4* m, float r)
|
||||
{
|
||||
return m.mul(Matrix4x4 {
|
||||
math::cosf(r), -math::sinf(r), 0, 0,
|
||||
math::sinf(r), math::cosf(r), 0, 0,
|
||||
math::cos(r), -math::sin(r), 0, 0,
|
||||
math::sin(r), math::cos(r), 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
});
|
||||
@@ -362,9 +362,9 @@ fn Matrix4x4 Matrix4x4.rotate_z(Matrix4x4* m, float r)
|
||||
fn Matrix4x4 Matrix4x4.rotate_y(Matrix4x4* m, float r)
|
||||
{
|
||||
return m.mul(Matrix4x4 {
|
||||
math::cosf(r), 0, -math::sinf(r), 0,
|
||||
math::cos(r), 0, -math::sin(r), 0,
|
||||
0, 1, 0, 0,
|
||||
math::sinf(r), 0, math::cosf(r), 0,
|
||||
math::sin(r), 0, math::cos(r), 0,
|
||||
0, 0, 0, 1,
|
||||
});
|
||||
}
|
||||
@@ -374,8 +374,8 @@ fn Matrix4x4 Matrix4x4.rotate_x(Matrix4x4* m, float r)
|
||||
{
|
||||
return m.mul(Matrix4x4 {
|
||||
1, 0, 0, 0,
|
||||
0, math::cosf(r), -math::sinf(r), 0,
|
||||
0, math::sinf(r), math::cosf(r), 0,
|
||||
0, math::cos(r), -math::sin(r), 0,
|
||||
0, math::sin(r), math::cos(r), 0,
|
||||
0, 0, 0, 1,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user