Skip to content

Instantly share code, notes, and snippets.

@spoonincode
Created May 30, 2020 17:59
Show Gist options
  • Save spoonincode/8de7529aa6c09ed0e467a2dcd0fcff23 to your computer and use it in GitHub Desktop.
Save spoonincode/8de7529aa6c09ed0e467a2dcd0fcff23 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <softfloat.h>
const double mul = 1.0000001;
double doit(double in, long unsigned iteration) {
#pragma nounroll
for(long unsigned u = 0; u < iteration; ++u)
in *= mul;
return in;
}
double doit_soft(double in, long unsigned iteration) {
float64_t x;
float64_t m;
memcpy((char*)&x, (char*)&in, 8);
memcpy((char*)&m, (char*)&mul, 8);
#pragma nounroll
for(long unsigned u = 0; u < iteration; ++u)
x = f64_mul(x, m);
double ret;
memcpy((char*)&ret, (char*)&x, 8);
return ret;
}
int main() {
double in = 4;
unsigned long it = 1000000000;
unsigned long long start, end;
start = __builtin_readcyclecounter();
double out = doit(in, it);
end = __builtin_readcyclecounter();
printf("%lf -- %llu\n", out, end-start);
start = __builtin_readcyclecounter();
double softout = doit_soft(in, it);
end = __builtin_readcyclecounter();
printf("%lf -- %llu\n", out, end-start);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment