Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

  1. /***
  2. *testfdiv.c - routine to test for correct operation of x86 FDIV instruction.
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Detects early steppings of Pentium with incorrect FDIV tables using
  8. * 'official' Intel test values. Returns 1 if flawed Pentium is detected,
  9. * 0 otherwise.
  10. *
  11. *Revision History:
  12. * 12-19-94 JWM file added
  13. * 12-22-94 JWM Now safe for TNT, et al
  14. * 01-13-95 JWM underscores added for ANSI compatibility
  15. * 12-12-95 SKS Skip redundant Pentium test on uni-processor systems
  16. * 12-13-95 SKS Call LoadLibrary() rather than GetModuleHandle()
  17. * since "kernel32.dll" is always going to be present.
  18. * 01-18-96 JWM Now handles possible failure of SetThreadAffinityMask(),
  19. * incorporating various suggestions of MarkL.
  20. * 05-29-96 JWM No longer loops through affinity mask; instead, uses MarkL's
  21. * new IsProcessorFeaturePresent() API if possible, only tests
  22. * 1st processor if not.
  23. *
  24. *******************************************************************************/
  25. #include <windows.h>
  26. int _ms_p5_test_fdiv(void)
  27. {
  28. double dTestDivisor = 3145727.0;
  29. double dTestDividend = 4195835.0;
  30. double dRslt;
  31. _asm {
  32. fld qword ptr [dTestDividend]
  33. fdiv qword ptr [dTestDivisor]
  34. fmul qword ptr [dTestDivisor]
  35. fsubr qword ptr [dTestDividend]
  36. fstp qword ptr [dRslt]
  37. }
  38. return (dRslt > 1.0);
  39. }
  40. /*
  41. * Multiprocessor Pentium test: returns 1 if any processor is a flawed
  42. * Pentium, 0 otherwise.
  43. */
  44. int _ms_p5_mp_test_fdiv(void)
  45. {
  46. #define PF_FLOATING_POINT_PRECISION_ERRATA 0
  47. HINSTANCE LibInst;
  48. FARPROC pIsProcessorFeaturePresent;
  49. if ((LibInst = GetModuleHandle("KERNEL32")) &&
  50. (pIsProcessorFeaturePresent = GetProcAddress(LibInst, "IsProcessorFeaturePresent")))
  51. return (*pIsProcessorFeaturePresent)(PF_FLOATING_POINT_PRECISION_ERRATA);
  52. else
  53. return _ms_p5_test_fdiv();
  54. }