import upstream maccel baseline
Tests / test_core_function (push) Failing after 12s

This commit is contained in:
2026-03-24 12:10:31 +00:00
parent 6e948d7b39
commit 5f1254d11a
108 changed files with 18930 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
#ifndef __ACCEL_LINEAR_H_
#define __ACCEL_LINEAR_H_
#include "../dbg.h"
#include "../fixedptc.h"
#include "../math.h"
struct linear_curve_args {
fpt accel;
fpt offset;
fpt output_cap;
};
static inline fpt linear_base_fn(fpt x, fpt accel,
fpt input_offset) {
fpt _x = x - input_offset;
fpt _x_square = fpt_mul(
_x, _x); // because linear in rawaccel is classic with exponent = 2
return fpt_mul(accel, fpt_div(_x_square, x));
}
/**
* Sensitivity Function for Linear Acceleration
*/
static inline fpt __linear_sens_fun(fpt input_speed,
struct linear_curve_args args) {
dbg("linear: accel %s", fptoa(args.accel));
dbg("linear: offset %s", fptoa(args.offset));
dbg("linear: output_cap %s", fptoa(args.output_cap));
if (input_speed <= args.offset) {
return FIXEDPT_ONE;
}
fpt sens = linear_base_fn(input_speed, args.accel, args.offset);
dbg("linear: base_fn sens %s", fptoa(args.accel));
fpt sign = FIXEDPT_ONE;
if (args.output_cap > 0) {
fpt cap = fpt_sub(args.output_cap, FIXEDPT_ONE);
if (cap < 0) {
cap = -cap;
sign = -sign;
}
sens = minsd(sens, cap);
}
return fpt_add(FIXEDPT_ONE, fpt_mul(sign, sens));
}
#endif // !__ACCEL_LINEAR_H_
+6
View File
@@ -0,0 +1,6 @@
#ifndef __ACCEL_MODE_H
#define __ACCEL_MODE_H
enum accel_mode : unsigned char { linear, natural, synchronous, no_accel };
#endif // !__ACCEL_MODE_H
+48
View File
@@ -0,0 +1,48 @@
#ifndef __ACCEL_NATURAL_H_
#define __ACCEL_NATURAL_H_
#include "../fixedptc.h"
struct natural_curve_args {
fpt decay_rate;
fpt offset;
fpt limit;
};
/**
* Gain Function for Natural Acceleration
*/
static inline fpt __natural_sens_fun(fpt input_speed,
struct natural_curve_args args) {
dbg("natural: decay_rate %s", fptoa(args.decay_rate));
dbg("natural: offset %s", fptoa(args.offset));
dbg("natural: limit %s", fptoa(args.limit));
if (input_speed <= args.offset) {
return FIXEDPT_ONE;
}
if (args.limit <= FIXEDPT_ONE) {
return FIXEDPT_ONE;
}
if (args.decay_rate <= 0) {
return FIXEDPT_ONE;
}
fpt limit = args.limit - FIXEDPT_ONE;
fpt accel = fpt_div(args.decay_rate, fpt_abs(limit));
fpt constant = fpt_div(-limit, accel);
dbg("natural: constant %s", fptoa(constant));
fpt offset_x = args.offset - input_speed;
fpt decay = fpt_exp(fpt_mul(accel, offset_x));
dbg("natural: decay %s", fptoa(decay));
fpt output_denom = fpt_div(decay, accel) - offset_x;
fpt output = fpt_mul(limit, output_denom) + constant;
return fpt_div(output, input_speed) + FIXEDPT_ONE;
}
#endif
+64
View File
@@ -0,0 +1,64 @@
#ifndef __ACCEL_SYNCHRONOUS_H_
#define __ACCEL_SYNCHRONOUS_H_
#include "../fixedptc.h"
struct synchronous_curve_args {
fpt gamma;
fpt smooth;
fpt motivity;
fpt sync_speed;
};
/**
* Sensitivity Function for `Synchronous` Acceleration
*/
static inline fpt __synchronous_sens_fun(fpt input_speed,
struct synchronous_curve_args args) {
fpt log_motivity = fpt_ln(args.motivity);
fpt gamma_const = fpt_div(args.gamma, log_motivity);
fpt log_syncspeed = fpt_ln(args.sync_speed);
fpt syncspeed = args.sync_speed;
fpt sharpness = args.smooth == 0 ? fpt_rconst(16.0)
: fpt_div(fpt_rconst(0.5), args.smooth);
int use_linear_clamp = sharpness >= fpt_rconst(16.0);
fpt sharpness_recip = fpt_div(FIXEDPT_ONE, sharpness);
fpt minimum_sens = fpt_div(FIXEDPT_ONE, args.motivity);
fpt maximum_sens = args.motivity;
// if sharpness >= 16, use linear clamp for activation function.
// linear clamp means: fpt_clamp(input_speed, -1, 1).
if (use_linear_clamp) {
fpt log_space = fpt_mul(gamma_const, (fpt_ln(input_speed) - log_syncspeed));
if (log_space < -FIXEDPT_ONE) {
return minimum_sens;
}
if (log_space > FIXEDPT_ONE) {
return maximum_sens;
}
return fpt_exp(fpt_mul(log_space, log_motivity));
}
if (input_speed == syncspeed) {
return FIXEDPT_ONE;
}
fpt log_x = fpt_ln(input_speed);
fpt log_diff = log_x - log_syncspeed;
if (log_diff > 0) {
fpt log_space = fpt_mul(gamma_const, log_diff);
fpt exponent =
fpt_pow(fpt_tanh(fpt_pow(log_space, sharpness)), sharpness_recip);
return fpt_exp(fpt_mul(exponent, log_motivity));
} else {
fpt log_space = fpt_mul(-gamma_const, log_diff);
fpt exponent =
-fpt_pow(fpt_tanh(fpt_pow(log_space, sharpness)), sharpness_recip);
return fpt_exp(fpt_mul(exponent, log_motivity));
}
}
#endif