fpuctl.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Linux 386 fpu support
  3. * Mimic Plan9 floating point support
  4. */
  5. static void
  6. setfcr(ulong fcr)
  7. {
  8. __asm__( "xorb $0x3f, %%al\n\t"
  9. "pushw %%ax\n\t"
  10. "fwait\n\t"
  11. "fldcw (%%esp)\n\t"
  12. "popw %%ax\n\t"
  13. : /* no output */
  14. : "al" (fcr)
  15. );
  16. }
  17. static ulong
  18. getfcr(void)
  19. {
  20. ulong fcr = 0;
  21. __asm__( "pushl %%eax\n\t"
  22. "fwait\n\t"
  23. "fstcw (%%esp)\n\t"
  24. "popl %%eax\n\t"
  25. "xorb $0x3f, %%al\n\t"
  26. : "=a" (fcr)
  27. : "eax" (fcr)
  28. );
  29. return fcr;
  30. }
  31. static ulong
  32. getfsr(void)
  33. {
  34. ulong fsr = -1;
  35. __asm__( "fwait\n\t"
  36. "fstsw (%%eax)\n\t"
  37. "movl (%%eax), %%eax\n\t"
  38. "andl $0xffff, %%eax\n\t"
  39. : "=a" (fsr)
  40. : "eax" (&fsr)
  41. );
  42. return fsr;
  43. }
  44. static void
  45. setfsr(ulong fsr)
  46. {
  47. __asm__("fclex\n\t");
  48. }
  49. /* FCR */
  50. #define FPINEX (1<<5)
  51. #define FPUNFL ((1<<4)|(1<<1))
  52. #define FPOVFL (1<<3)
  53. #define FPZDIV (1<<2)
  54. #define FPINVAL (1<<0)
  55. #define FPRNR (0<<10)
  56. #define FPRZ (3<<10)
  57. #define FPRPINF (2<<10)
  58. #define FPRNINF (1<<10)
  59. #define FPRMASK (3<<10)
  60. #define FPPEXT (3<<8)
  61. #define FPPSGL (0<<8)
  62. #define FPPDBL (2<<8)
  63. #define FPPMASK (3<<8)
  64. /* FSR */
  65. #define FPAINEX FPINEX
  66. #define FPAOVFL FPOVFL
  67. #define FPAUNFL FPUNFL
  68. #define FPAZDIV FPZDIV
  69. #define FPAINVAL FPINVAL