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.

111 lines
2.5 KiB

  1. /**
  2. *** Copyright (C) 1985-1998 Intel Corporation.
  3. ***
  4. *** The information and source code contained herein is the exclusive property
  5. *** of Intel Corporation and may not be disclosed, examined, or
  6. *** reproduced in whole or in part without explicit written authorization from
  7. *** the Company.
  8. ***
  9. *** static char sccs_id[] = "@(#)cpu_disp.c 1.9 06/06/00 14:08:14";
  10. ***
  11. **/
  12. #include <sect_attribs.h>
  13. #include <cruntime.h>
  14. #include <internal.h>
  15. #undef leave
  16. #define CPU_HAS_SSE2(x) (((x) & (1 << 26)) != 0)
  17. #ifdef _MSC_VER
  18. int __sse2_available_init(void);
  19. #pragma data_seg(".CRT$XIC")
  20. _CRTALLOC(".CRT$XIC") static _PIFV pinit = __sse2_available_init;
  21. #pragma data_seg()
  22. #endif /* _MSC_VER */
  23. int __sse2_available;
  24. int __use_sse2_mathfcns;
  25. static int
  26. has_osfxsr_set()
  27. {
  28. int ret = 0;
  29. __try {
  30. __asm movapd xmm0, xmm1;
  31. ret = 1;
  32. }
  33. __except(1) {
  34. }
  35. return ret;
  36. }
  37. __declspec(naked) int __sse2_available_init()
  38. {
  39. int cpu_feature;
  40. __asm
  41. {
  42. push ebp
  43. mov ebp, esp
  44. sub esp, __LOCAL_SIZE
  45. push ebx
  46. push edi
  47. push esi
  48. pushfd /* if we can't write to bit 21 */
  49. pop eax /* of the eflags, then we don't */
  50. mov ecx, eax /* have a cpuid instruction. */
  51. xor eax, 0x200000
  52. push eax
  53. popfd
  54. pushfd
  55. pop edx
  56. sub edx, ecx
  57. je DONE /* CPUID not available */
  58. push ecx /* restore eflags */
  59. popfd
  60. mov eax, 1
  61. cpuid
  62. DONE :
  63. mov cpu_feature, edx
  64. }
  65. __use_sse2_mathfcns = __sse2_available = 0;
  66. if (CPU_HAS_SSE2(cpu_feature)) {
  67. if (has_osfxsr_set()) {
  68. __sse2_available = 1;
  69. #if !defined(_SYSCRT)
  70. /*
  71. * The VC++ CRT will automatically enable the SSE2 implementations
  72. * when possible. The system CRT will not, so existing apps don't
  73. * start seeing different results on a Pentium4.
  74. */
  75. __use_sse2_mathfcns = 1;
  76. #endif
  77. }
  78. }
  79. __asm
  80. {
  81. xor eax, eax
  82. pop esi
  83. pop edi
  84. pop ebx
  85. leave
  86. ret
  87. }
  88. }
  89. _CRTIMP int __cdecl _set_SSE2_enable(int flag)
  90. {
  91. return __use_sse2_mathfcns = flag ? __sse2_available : 0;
  92. }