Created
June 14, 2021 05:03
-
-
Save doug65536/7e5769ac72201b884692a34595c64050 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <chrono> | |
#include <inttypes.h> | |
#include <math.h> | |
using Clock = std::chrono::high_resolution_clock; | |
using Timepoint = Clock::time_point; | |
static inline void mysincos(float a, float * __restrict s, float * __restrict c) | |
{ | |
__asm__( | |
"fsincos\n\t" | |
: [c] "+t" (a) | |
, [s] "=u" (*s) | |
); | |
*c = a; | |
} | |
int main() | |
{ | |
float c, s; | |
float p = 3.14159265358979323f; | |
size_t iters = 1048576; | |
float d = p / (iters * 0.5f); | |
float a = 0; | |
volatile float v; | |
Timepoint st = Clock::now(); | |
for (size_t i = 0; i < iters; ++i) { | |
float a = i * d - p; | |
mysincos(a, &s, &c); | |
v=s; | |
v=c; | |
} | |
Timepoint en = Clock::now(); | |
printf("fsincos %" PRIu64 "\n", (uint64_t)std::chrono::duration_cast< | |
std::chrono::nanoseconds>(en - st).count() / iters); | |
st = Clock::now(); | |
for (size_t i = 0; i < iters; ++i) { | |
float a = i * d - p; | |
s = sinf(a); | |
c = cosf(a); | |
v=s; | |
v=c; | |
} | |
en = Clock::now(); | |
printf("sin cos %" PRIu64 "\n", (uint64_t)std::chrono::duration_cast< | |
std::chrono::nanoseconds>(en - st).count() / iters); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment