Skip to content

Instantly share code, notes, and snippets.

@hreese
Last active September 20, 2019 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hreese/67a26ad14a99d7317548917dec649186 to your computer and use it in GitHub Desktop.
Save hreese/67a26ad14a99d7317548917dec649186 to your computer and use it in GitHub Desktop.
Shows broken core on my AMD Ryzen 2700X (use taskset to pin to core 3 and run a few times)
#include <math.h>
#include <stdio.h>
struct transform {
double x1;
double y1;
double x2;
double y2;
};
double
do_transform (struct transform trf, double progress)
{
if (progress <= 0)
return 0;
if (progress >= 1)
return 1;
{
static const double epsilon = 0.00001;
double tmin, t, tmax;
//tmin = 0.0;
//tmax = 1.0;
tmin = 0.93507255859375005;
tmax = 0.93507255859375016;
t = progress;
double tmin_last = 1.0;
double tmax_last = 0.0;
while (tmin < tmax)
{
if (tmin_last == tmin && tmax_last == tmax) {
exit(1);
}
double sample;
sample = (((1.0 + 3 * trf.x1 - 3 * trf.x2) * t
+ -6 * trf.x1 + 3 * trf.x2) * t
+ 3 * trf.x1 ) * t;
double const delta = fabs(sample - progress);
printf("sample: %f, delta: %f\n", sample, delta);
if (delta < epsilon)
break;
tmin_last = tmin;
tmax_last = tmax;
if (progress > sample)
tmin = t;
else
tmax = t;
t = (tmax + tmin) * .5;
}
return (((1.0 + 3 * trf.y1 - 3 * trf.y2) * t
+ -6 * trf.y1 + 3 * trf.y2) * t
+ 3 * trf.y1 ) * t;
}
}
int main () {
struct transform volatile t = {0, 0, 0.57999999999999996, 1};
double const initial = 0.91668500000000031;
printf("result: %f\n", do_transform(t, initial));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment