Skip to content

Instantly share code, notes, and snippets.

@nazarov-yuriy nazarov-yuriy/asm.c
Last active Dec 17, 2015

Embed
What would you like to do?
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
uint64_t time_delta(struct timeval *from, struct timeval *to) {
uint64_t delta = to->tv_sec * 1000000l + to->tv_usec;
return delta - (from->tv_sec * 1000000l + from->tv_usec);
}
int main(void) {
struct timeval start, end;
double res = 0, arg = 1.23;
gettimeofday(&start, 0);
__asm__ (
"jmp start\n"
"start:\n"
"finit\n"
"fld1\n"
"fldz\n"
"fldz\n"
"fldz\n"//0 0 0 1
"movq $100000000, %%rax\n"
"movq $0, %%rbx\n"
"loop:\n"
"fld %%st(0)\n"
"fcos\n"
"faddp %%st(0),%%st(2)\n"
"fadd %%st(3),%%st(0)\n"
"decq %%rax\n"
"jnz loop\n"
"fld %%st(1)\n"
"fstpl %0\n"
:"=m"(res):"m"(arg)
);
gettimeofday(&end, 0);
printf("Result: %0.20f\nDone in %f s\n", res, time_delta(&start, &end)/1000000.0);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <math.h>
uint64_t time_delta(struct timeval *from, struct timeval *to) {
uint64_t delta = to->tv_sec * 1000000l + to->tv_usec;
return delta - (from->tv_sec * 1000000l + from->tv_usec);
}
int main(void) {
struct timeval start, end;
int i;
double res = 0;
gettimeofday(&start, 0);
for(i=0;i<100000000;i++){
res += cos(i);
}
gettimeofday(&end, 0);
printf("Result: %0.20f\nDone in: %f s\n", res, time_delta(&start, &end)/1000000.0);
return 0;
}
#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>
#include <math.h>
uint64_t time_delta(struct timeval *from, struct timeval *to) {
uint64_t delta = to->tv_sec * 1000000l + to->tv_usec;
return delta - (from->tv_sec * 1000000l + from->tv_usec);
}
int main(void) {
struct timeval start, end;
int i;
long double res = 0;
gettimeofday(&start, 0);
for(i=0;i<100000000;i++){
res += cos(i);
}
gettimeofday(&end, 0);
printf("Result: %0.20f\nDone in: %f s\n", (double)res, time_delta(&start, &end)/1000000.0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.