|
|
@@ -37,6 +37,26 @@ unsigned int cpu_family_model(void)
|
|
|
return (family << 8) | model;
|
|
|
}
|
|
|
|
|
|
+/* An AP leaves INIT with CR0.NE clear and an x87 control word of 0x0040:
|
|
|
+ * every exception unmasked and 24-bit precision. With NE clear an
|
|
|
+ * unmasked exception (an inexact result, i.e. most floating-point
|
|
|
+ * operations) freezes the CPU at the next FPU instruction until an external
|
|
|
+ * interrupt -- the next 1 ms timer tick. QuickJS computes with doubles, so
|
|
|
+ * the browser's scripts ran several hundred times slower whenever it was
|
|
|
+ * scheduled on an AP, at 100% CPU, with single-precision results. QEMU
|
|
|
+ * models neither the freeze nor the precision. Native #MF reporting (NE),
|
|
|
+ * MP for WAIT, no emulation or task-switch trap, and FNINIT's 0x037F. */
|
|
|
+void cpu_init_fpu(void)
|
|
|
+{
|
|
|
+ unsigned int cr0;
|
|
|
+
|
|
|
+ __asm__ volatile ("mov %%cr0, %0" : "=r"(cr0));
|
|
|
+ cr0 |= (1u << 5) | (1u << 1); /* NE | MP */
|
|
|
+ cr0 &= ~((1u << 2) | (1u << 3)); /* EM | TS */
|
|
|
+ __asm__ volatile ("mov %0, %%cr0" :: "r"(cr0) : "memory");
|
|
|
+ __asm__ volatile ("fninit");
|
|
|
+}
|
|
|
+
|
|
|
void cpu_enable_sse(void)
|
|
|
{
|
|
|
unsigned int eax, ebx, ecx, edx, cr4;
|