Skip to content

Instantly share code, notes, and snippets.

@kostikbel
Last active March 5, 2021 04:43
Show Gist options
  • Save kostikbel/bc6e2256ed12de4dc67d1cac7478d717 to your computer and use it in GitHub Desktop.
Save kostikbel/bc6e2256ed12de4dc67d1cac7478d717 to your computer and use it in GitHub Desktop.
#include <math.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static double
read_xmm15(void)
{
double x;
asm volatile("movsd\t%%xmm15,%0" : "=x" (x));
return (x);
}
static void
write_xmm15(const double x)
{
asm volatile("movsd\t%0,%%xmm15" : : "x" (x) : "xmm15");
}
static void *
thrf(void *arg)
{
double x;
(void)arg;
x = read_xmm15();
printf("t %e\n", x);
return (NULL);
}
int
main(void)
{
pthread_t thr;
int error;
printf("m %e\n", M_PI);
write_xmm15(M_PI);
error = pthread_create(&thr, NULL, thrf, NULL);
if (error != 0) {
fprintf(stderr, "pthread_create %s\n", strerror(error));
exit(1);
}
error = pthread_join(thr, NULL);
if (error != 0) {
fprintf(stderr, "pthread_join %s\n", strerror(error));
exit(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment