Implement more @export / @private improvements. Make @private default… (#729)

This commit is contained in:
Christoffer Lerno
2023-02-13 08:31:40 +01:00
committed by GitHub
parent 3b49b87784
commit 5e457be605
88 changed files with 697 additions and 624 deletions

View File

@@ -395,13 +395,13 @@ macro tanh(x) => (exp(2.0 * x) - 1.0) / (exp(2.0 * x) + 1.0);
**/
macro trunc(x) => $$trunc(x);
private macro lerp(x, y, amount) => x + (y - x) * amount;
private macro reflect(x, y)
macro lerp(x, y, amount) @private => x + (y - x) * amount;
macro reflect(x, y) @private
{
var dot = x.dot(y);
return x - 2 * y * dot;
}
private macro normalize(x)
macro normalize(x) @private
{
var len = x.length();
if (len == 0) return x;
@@ -662,7 +662,7 @@ macro next_power_of_2(x)
return y;
}
private macro equals_vec(v1, v2)
macro equals_vec(v1, v2) @private
{
var $elements = v1.len;
var abs_diff = math::abs(v1 - v2);

View File

@@ -412,19 +412,19 @@ fn Matrix4x4 perspective(Real fov, Real aspect_ratio, Real near, Real far)
}
private macro matrix_component_mul(mat, val)
macro matrix_component_mul(mat, val) @private
{
var $Type = Real[<$typeof(mat.m).len>];
return $typeof(*mat) { .m = val * ($Type)mat.m };
}
private macro matrix_add(mat, mat2)
macro matrix_add(mat, mat2) @private
{
var $Type = Real[<$typeof(mat.m).len>];
return $typeof(*mat) { .m = ($Type)mat.m + ($Type)mat2.m };
}
private macro matrix_sub(mat, mat2)
macro matrix_sub(mat, mat2) @private
{
var $Type = Real[<$typeof(mat.m).len>];
return $typeof(*mat) { .m = ($Type)mat.m - ($Type)mat2.m };

View File

@@ -5,16 +5,16 @@ struct SimpleRandom
long seed;
}
private const long SIMPLE_RANDOM_MULTIPLIER = 0x5DEECE66D;
private const long SIMPLE_RANDOM_ADDEND = 0xB;
private const long SIMPLE_RANDOM_MASK = (1i64 << 48) - 1;
const long SIMPLE_RANDOM_MULTIPLIER @private = 0x5DEECE66D;
const long SIMPLE_RANDOM_ADDEND @private = 0xB;
const long SIMPLE_RANDOM_MASK @private = (1i64 << 48) - 1;
private fn long simple_random_initial_scramble(long seed)
fn long simple_random_initial_scramble(long seed) @private
{
return (seed ^ SIMPLE_RANDOM_MULTIPLIER) & SIMPLE_RANDOM_MASK;
}
private fn int SimpleRandom.next(SimpleRandom* r, int bits)
fn int SimpleRandom.next(SimpleRandom* r, int bits) @private
{
long nextseed = (r.seed * SIMPLE_RANDOM_MULTIPLIER + SIMPLE_RANDOM_ADDEND) & SIMPLE_RANDOM_MASK;
r.seed = nextseed;

View File

@@ -196,6 +196,6 @@ fn float elastic_inout(float t, float b, float c, float d) @inline
: a * math::pow(2.0f, -10 * t) * math::sin((t * d - s) * (2 * (float)math::PI) / p) * 0.5f + c + b;
}
private macro sq(x) => x * x;
private macro cube(x) => x * x * x;
macro sq(x) @private => x * x;
macro cube(x) @private => x * x * x;

View File

@@ -70,7 +70,7 @@ fn int128 __modti3(int128 a, int128 b) @extern("__modti3") @weak
return __umodti3(unsigned_a, unsigned_b) ^ sign + (-sign);
}
private union Int128bits
union Int128bits @private
{
struct
{
@@ -139,7 +139,7 @@ fn int128 __ashlti3(int128 a, uint b) @extern("__ashlti3") @weak
// Returns: a * b
private fn int128 __mulddi3(ulong a, ulong b)
fn int128 __mulddi3(ulong a, ulong b) @private
{
Int128bits r;
const ulong LOWER_MASK = 0xffff_ffff;
@@ -177,7 +177,7 @@ fn int128 __fixdfti(double a) @weak @extern("__fixdfti") => fixint(a);
fn int128 __fixsfti(float a) @weak @extern("__fixsfti") => fixint(a);
private macro float_from_i128($Type, a)
macro float_from_i128($Type, a) @private
{
var $Rep;
$switch ($Type):
@@ -236,7 +236,7 @@ private macro float_from_i128($Type, a)
return bitcast((($Rep)sign & SIGN_BIT) | ((($Rep)e + ($Rep)EXP_BIAS) << SIGNIFICANT_BITS) | (($Rep)a & ($Rep)MANTISSA_MASK), $Type);
}
private macro float_from_u128($Type, a)
macro float_from_u128($Type, a) @private
{
var $Rep;
$switch ($Type):
@@ -291,7 +291,7 @@ private macro float_from_u128($Type, a)
}
private macro fixuint(a)
macro fixuint(a) @private
{
var $Rep;
$switch ($typeof(a)):
@@ -335,7 +335,7 @@ private macro fixuint(a)
return (uint128)significand << (exponent - SIGNIFICANT_BITS);
}
private macro fixint(a)
macro fixint(a) @private
{
var $Rep;
$switch ($typeof(a)):

View File

@@ -19,10 +19,10 @@ $if (!env::COMPILER_LIBC_AVAILABLE):
*/
/* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */
private const double C0 = -0x1ffffffd0c5e81.0p-54; /* -0.499999997251031003120 */
private const double C1 = 0x155553e1053a42.0p-57; /* 0.0416666233237390631894 */
private const double C2 = -0x16c087e80f1e27.0p-62; /* -0.00138867637746099294692 */
private const double C3 = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */
const double C0 @private = -0x1ffffffd0c5e81.0p-54; /* -0.499999997251031003120 */
const double C1 @private = 0x155553e1053a42.0p-57; /* 0.0416666233237390631894 */
const double C2 @private = -0x16c087e80f1e27.0p-62; /* -0.00138867637746099294692 */
const double C3 @private = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */
fn float __cosdf(double x) @extern("__cosdf") @weak
{

View File

@@ -2,21 +2,21 @@ module std::math::nolibc::atan;
$if (!env::COMPILER_LIBC_AVAILABLE):
private const double[*] ATANHI = {
const double[*] ATANHI @private = {
4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */
1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */
};
private const double[*] ATANLO = {
const double[*] ATANLO @private = {
2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */
3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */
1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */
6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */
};
private const double[*] AT = {
const double[*] AT @private = {
3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */
-1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */
1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */
@@ -91,21 +91,21 @@ fn double _atan(double x) @weak @extern("atan")
return sign ? -z : z;
}
private const float[*] ATANHIF = {
const float[*] ATANHIF @private = {
4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */
7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */
9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */
1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */
};
private const float[*] ATANLOF = {
const float[*] ATANLOF @private = {
5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */
3.7748947079e-08, /* atan(1.0)lo 0x33222168 */
3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */
7.5497894159e-08, /* atan(inf)lo 0x33a22168 */
};
private const float[*] ATF = {
const float[*] ATF @private = {
3.3333328366e-01,
-1.9999158382e-01,
1.4253635705e-01,
@@ -177,9 +177,9 @@ fn float _atanf(float x) @weak @extern("atanf")
return sign ? -z : z;
}
private const PI_LO = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
const PI_LO @private = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
private macro void extract_words(double d, uint* hi, uint* lo)
macro void extract_words(double d, uint* hi, uint* lo) @private
{
ulong rep = bitcast(d, ulong);
*hi = (uint)(rep >> 32);
@@ -254,8 +254,8 @@ fn double _atan2(double y, double x) @weak @extern("atan2")
}
}
private const float PI_F = 3.1415927410e+00; /* 0x40490fdb */
private const float PI_LO_F = -8.7422776573e-08; /* 0xb3bbbd2e */
const float PI_F @private = 3.1415927410e+00; /* 0x40490fdb */
const float PI_LO_F @private = -8.7422776573e-08; /* 0xb3bbbd2e */
fn float _atan2f(float y, float x) @weak @extern("atan2f")
{

View File

@@ -2,7 +2,7 @@ module std::math::nolibc;
$if (!env::COMPILER_LIBC_AVAILABLE):
private macro uint _top12f(float x) => bitcast(x, uint) >> 20;
macro uint _top12f(float x) @private => bitcast(x, uint) >> 20;
fn float _exp2f(float x) @extern("exp2f") @weak
@@ -44,7 +44,7 @@ fn float _exp2f(float x) @extern("exp2f") @weak
return (float)y;
}
private fn double _exp2_specialcase(double tmp, ulong sbits, ulong ki)
fn double _exp2_specialcase(double tmp, ulong sbits, ulong ki) @private
{
if (ki & 0x80000000 == 0)
{
@@ -77,7 +77,7 @@ private fn double _exp2_specialcase(double tmp, ulong sbits, ulong ki)
}
private macro uint _top12d(double x)
macro uint _top12d(double x) @private
{
return (uint)(bitcast(x, ulong) >> 52);
}

View File

@@ -3,15 +3,15 @@ module std::math::nolibc;
const double TOINT = 1 / math::DOUBLE_EPSILON;
const double TOINT15 = 1.5 / math::DOUBLE_EPSILON;
const float TOINTF = (float)(1 / math::FLOAT_EPSILON);
private const double S1PI2 = math::PI_2; /* 0x3FF921FB, 0x54442D18 */
private const double S2PI2 = math::PI; /* 0x400921FB, 0x54442D18 */
private const double S3PI2 = math::PI + math::PI_2; /* 0x4012D97C, 0x7F3321D2 */
private const double S4PI2 = math::PI + math::PI; /* 0x401921FB, 0x54442D18 */
const double S1PI2 @private = math::PI_2; /* 0x3FF921FB, 0x54442D18 */
const double S2PI2 @private = math::PI; /* 0x400921FB, 0x54442D18 */
const double S3PI2 @private = math::PI + math::PI_2; /* 0x4012D97C, 0x7F3321D2 */
const double S4PI2 @private = math::PI + math::PI; /* 0x401921FB, 0x54442D18 */
// Shared between expf, exp2f and powf.
private const EXP2F_TABLE_BITS = 5;
private const EXP2F_POLY_ORDER = 3;
private struct Exp2fData
const EXP2F_TABLE_BITS @private = 5;
const EXP2F_POLY_ORDER @private = 3;
struct Exp2fData @private
{
ulong[1 << EXP2F_TABLE_BITS] tab;
double shift_scaled;
@@ -21,7 +21,7 @@ private struct Exp2fData
double[EXP2F_POLY_ORDER] poly_scaled;
}
private const Exp2fData __EXP2F_DATA = {
const Exp2fData __EXP2F_DATA @private = {
.tab = {
0x3ff0000000000000, 0x3fefd9b0d3158574, 0x3fefb5586cf9890f, 0x3fef9301d0125b51,
0x3fef72b83c7d517b, 0x3fef54873168b9aa, 0x3fef387a6e756238, 0x3fef1e9df51fdee1,
@@ -49,7 +49,7 @@ const EXP_TABLE_BITS = 7;
const EXP_POLY_ORDER = 5;
const EXP2_POLY_ORDER = 5;
const EXP_DATA_WIDTH = 1 << EXP_TABLE_BITS;
private struct Exp2Data
struct Exp2Data @private
{
double invln2N;
double shift;

View File

@@ -78,7 +78,7 @@ fn Vec3 Vec3.rotate_axis(Vec3 v, Vec3 axis, double angle) => rotate_axis_angle(v
fn Vec3f Vec3f.unproject(Vec3f v, Matrix4f projection, Matrix4f view) => unproject3(v, projection, view);
fn Vec3 Vec3.unproject(Vec3 v, Matrix4 projection, Matrix4 view) => unproject3(v, projection, view);
private macro towards(v, target, max_distance)
macro towards(v, target, max_distance) @private
{
var delta = target - v;
var square = delta.length_sq();
@@ -90,7 +90,7 @@ private macro towards(v, target, max_distance)
return v + delta * max_distance / dist;
}
private macro clamp_magnitude(v, min, max)
macro clamp_magnitude(v, min, max) @private
{
var length = v.dot(v);
if (length > 0)
@@ -103,14 +103,14 @@ private macro clamp_magnitude(v, min, max)
return v;
}
private macro rotate(v, angle)
macro rotate(v, angle) @private
{
var c = math::cos(angle);
var s = math::sin(angle);
return $typeof(v) { v[0] * c - v[1] * s, v[0] * s + v[1] * c };
}
private macro perpendicular3(v)
macro perpendicular3(v) @private
{
var min = math::abs(v[0]);
$typeof(v) cardinal_axis = { 1, 0, 0 };
@@ -129,20 +129,20 @@ private macro perpendicular3(v)
return cross3(v, cardinal_axis);
}
private macro cross3(v1, v2)
macro cross3(v1, v2) @private
{
var a = v1.yzx * v2.zxy;
var b = v1.zxy * v2.yzx;
return a - b;
}
private macro transform2(v, mat)
macro transform2(v, mat) @private
{
return $typeof(v) { mat.m00 * v[0] + mat.m10 * v[1] + mat.30,
mat.m01 * v[0] + mar.m11 * v[1] + mat.31 };
}
private macro transform3(v, mat)
macro transform3(v, mat) @private
{
return $typeof(v) {
mat.m00 * v[0] + mat.m10 * v[1] + mat.m20 * v[2] + mat.m30,
@@ -152,21 +152,21 @@ private macro transform3(v, mat)
}
private macro angle3(v1, v2)
macro angle3(v1, v2) @private
{
var len = v1.cross(v2).length();
var dot = v1.dot(v2);
return math::atan2(len, dot);
}
private macro void ortho_normalize3(v1, v2)
macro void ortho_normalize3(v1, v2) @private
{
var v1n = *v1 = v1.normalize();
var vn1 = v1n.cross(*v2).normalize();
*v2 = v1n.cross(vn1);
}
private macro rotate_by_quat3(v, q)
macro rotate_by_quat3(v, q) @private
{
return $typeof(v) {
v[0] * (q.i * q.i + q.l * q.l - q.j * q.j - q.k * q.k)
@@ -181,7 +181,7 @@ private macro rotate_by_quat3(v, q)
};
}
private macro rotate_axis_angle(v, axis, angle)
macro rotate_axis_angle(v, axis, angle) @private
{
axis = axis.normalize();
@@ -195,7 +195,7 @@ private macro rotate_axis_angle(v, axis, angle)
return v + wv + wwv;
}
private macro matrix_look_at($Type, eye, target, up)
macro matrix_look_at($Type, eye, target, up) @private
{
var vz = (eye - target).normalize();
var vx = up.cross(vz).normalize();
@@ -209,7 +209,7 @@ private macro matrix_look_at($Type, eye, target, up)
};
}
private macro unproject3(v, m1, m2)
macro unproject3(v, m1, m2) @private
{
return v;
/*
@@ -233,7 +233,7 @@ return v;
};*/
}
private macro barycenter3(p, a, b, c)
macro barycenter3(p, a, b, c) @private
{
var v0 = b - a;
var v1 = c - a;
@@ -249,7 +249,7 @@ private macro barycenter3(p, a, b, c)
return $typeof(p) { 1 - y - z, y, z };
}
private macro refract3(v, n, r)
macro refract3(v, n, r) @private
{
var dot = v.dot(n);
var d = 1 - r * r * (1 - dot * dot);