How do I enable SSE for my freestanding bootable code?

前端 未结 2 390
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 12:16

(This question was originally about the CVTSI2SD instruction and the fact that I thought it didn\'t work on the Pentium M CPU, but in fact it\'s because I\'m us

相关标签:
2条回答
  • 2020-11-29 12:59

    I suggest that you consult Intel's manual when you have such questions.

    It's clearly stated in the manual that CVTSI2SD is an SSE2 instruction.

    0 讨论(0)
  • 2020-11-29 13:00

    If you're running an ancient or custom OS that doesn't support saving XMM regs on context switches, it won't have set the SSE-enabling bits in the machine control registers. In that case all instructions that touch xmm regs will fault.

    Took me a sec to find, but http://wiki.osdev.org/SSE explains how to alter CR0 and CR4 to allow SSE instructions to run on bare metal without #UD.


    My first thought on your old version of the question was that you might have compiled your program with -mavx, -march=sandybridge or equivalent, causing the compiler to emit the VEX-encoded version of everything.

    CVTSI2SD   xmm1, xmm2/m32         ; SSE2
    VCVTSI2SD  xmm1, xmm2, xmm3/m32   ; AVX
    

    See https://stackoverflow.com/tags/x86/info for links, including to Intel's insn set ref manual.


    Related: Which versions of Windows support/require which CPU multimedia extensions? has some details about how to check for support for AVX and AVX512 (which also introduce new architectural state, so the OS has to set a bit or the HW will fault). It's coming at it from the other angle, but the links should indicate how to activate / disable AVX support.

    0 讨论(0)
提交回复
热议问题