/* $Id: fcalc.c,v 1.2 2010/03/21 19:36:47 kostik Exp $ */ #include #include #include #include #include #include double calc1(double x) { return (x + 1.0); } static void fadd1(void *p) __attribute((noinline)); void fadd1(void *p) { static const double one = 1.0; __asm volatile( "movsd %1,%%xmm0\n\t" "movsd (%2),%%xmm1\n\t" "addsd %%xmm0,%%xmm1\n\t" "movsd %%xmm1,(%0)" : "=r" (p) : "m" (one), "r" (p) : "memory", "xmm0", "xmm1"); } double calc2(double x) __attribute((noinline)); double calc2(double x) { fadd1(&x); return (x); } double calc3(double x) { int fd; int res; fd = open("/dev/kernfpu", O_RDWR); if (fd == -1) err(1, "open /dev/kernfpu"); res = write(fd, &x, sizeof(x)); if (res == -1) err(1, "write to kernfpu"); else if (res != sizeof(x)) errx(1, "short write"); res = read(fd, &x, sizeof(x)); if (res == -1) err(1, "read from kernfpu"); else if (res != sizeof(x)) errx(1, "short read"); return (x); } int main(int argc, char *argv[]) { double b, c1, c2, c3; b = 2.0; c1 = calc1(b); printf("%e\n", c1); c2 = calc2(b); printf("%e\n", c2); c3 = calc3(b); printf("%e\n", c3); return (0); }