setfcr-MacOSX-386.c 721 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Linux 386 fpu support
  3. * Mimic Plan9 floating point support
  4. */
  5. #include "lib9.h"
  6. void
  7. setfcr(ulong fcr)
  8. {
  9. __asm__( "xorb $0x3f, %%al\n\t"
  10. "pushw %%ax\n\t"
  11. "fwait\n\t"
  12. "fldcw (%%esp)\n\t"
  13. "popw %%ax\n\t"
  14. : /* no output */
  15. : "al" (fcr)
  16. );
  17. }
  18. ulong
  19. getfcr(void)
  20. {
  21. ulong fcr = 0;
  22. __asm__( "pushl %%eax\n\t"
  23. "fwait\n\t"
  24. "fstcw (%%esp)\n\t"
  25. "popl %%eax\n\t"
  26. "xorb $0x3f, %%al\n\t"
  27. : "=a" (fcr)
  28. : "eax" (fcr)
  29. );
  30. return fcr;
  31. }
  32. ulong
  33. getfsr(void)
  34. {
  35. ulong fsr = -1;
  36. __asm__( "fwait\n\t"
  37. "fstsw (%%eax)\n\t"
  38. "movl (%%eax), %%eax\n\t"
  39. "andl $0xffff, %%eax\n\t"
  40. : "=a" (fsr)
  41. : "eax" (&fsr)
  42. );
  43. return fsr;
  44. }
  45. void
  46. setfsr(ulong fsr)
  47. {
  48. __asm__("fclex\n\t");
  49. }