cpu.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. This unit contains some routines to get informations about the
  5. processor
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit cpu;
  13. interface
  14. { returns true, if the processor supports the cpuid instruction }
  15. function cpuid_support : boolean;
  16. { returns true, if floating point is done by an emulator }
  17. function floating_point_emulation : boolean;
  18. { returns the contents of the cr0 register }
  19. function cr0 : longint;
  20. var
  21. is_sse3_cpu : boolean = false;
  22. implementation
  23. {$ASMMODE INTEL}
  24. function cpuid_support : boolean;assembler;
  25. {
  26. Check if the ID-flag can be changed, if changed then CpuID is supported.
  27. Tested under go32v1 and Linux on c6x86 with CpuID enabled and disabled (PFV)
  28. }
  29. asm
  30. push ebx
  31. pushfd
  32. pushfd
  33. pop eax
  34. mov ebx,eax
  35. xor eax,200000h
  36. push eax
  37. popfd
  38. pushfd
  39. pop eax
  40. popfd
  41. and eax,200000h
  42. and ebx,200000h
  43. cmp eax,ebx
  44. setnz al
  45. pop ebx
  46. end;
  47. function cr0 : longint;assembler;
  48. asm
  49. DB 0Fh,20h,0C0h
  50. { mov eax,cr0
  51. special registers are not allowed in the assembler
  52. parsers }
  53. end;
  54. function floating_point_emulation : boolean;
  55. begin
  56. {!!!! I don't know currently the position of the EM flag }
  57. { $4 after Ralf Brown's list }
  58. floating_point_emulation:=(cr0 and $4)<>0;
  59. end;
  60. {$ASMMODE ATT}
  61. function sse3_support : boolean;
  62. var
  63. _ecx : longint;
  64. begin
  65. if cpuid_support then
  66. begin
  67. asm
  68. pushl %ebx
  69. movl $1,%eax
  70. cpuid
  71. movl %ecx,_ecx
  72. popl %ebx
  73. end;
  74. sse3_support:=(_ecx and $1)<>0;
  75. end
  76. else
  77. { a cpu with without cpuid instruction supports never sse3 }
  78. sse3_support:=false;
  79. end;
  80. begin
  81. is_sse3_cpu:=sse3_support;
  82. end.