Kernel/userspace: rework floating point math

SSE is now unconditionally enabled any where and most of math.h is now
actually implemented. using __builtin_<func> lead to many hangs where
the builtin function would just call itself.
This commit is contained in:
2024-11-03 20:25:35 +02:00
parent ed19bb11fe
commit f4be37700f
18 changed files with 827 additions and 210 deletions

View File

@@ -182,9 +182,7 @@ namespace Kernel
if (tid)
{
auto& thread = Thread::current();
#if __enable_sse
thread.save_sse();
#endif
if (isr == ISR::PageFault && Thread::current().is_userspace())
{
@@ -318,12 +316,8 @@ namespace Kernel
ASSERT(Thread::current().state() != Thread::State::Terminated);
done:
#if __enable_sse
done:
Thread::current().load_sse();
#else
return;
#endif
}
extern "C" void cpp_yield_handler(InterruptStack* interrupt_stack, InterruptRegisters* interrupt_registers)
@@ -376,9 +370,7 @@ done:
asm volatile("cli; 1: hlt; jmp 1b");
}
#if __enable_sse
Thread::current().save_sse();
#endif
if (!InterruptController::get().is_in_service(irq))
dprintln("spurious irq 0x{2H}", irq);
@@ -399,9 +391,7 @@ done:
ASSERT(Thread::current().state() != Thread::State::Terminated);
#if __enable_sse
Thread::current().load_sse();
#endif
}
void IDT::register_interrupt_handler(uint8_t index, void (*handler)())

View File

@@ -36,7 +36,6 @@ namespace Kernel
static pid_t s_next_tid = 1;
#if __enable_sse
alignas(16) static uint8_t s_default_sse_storage[512];
static bool s_default_sse_storage_initialized = false;
@@ -51,7 +50,6 @@ namespace Kernel
: [mxcsr]"m"(mxcsr)
);
}
#endif
BAN::ErrorOr<Thread*> Thread::create_kernel(entry_t entry, void* data, Process* process)
{
@@ -129,14 +127,12 @@ namespace Kernel
Thread::Thread(pid_t tid, Process* process)
: m_tid(tid), m_process(process)
{
#if __enable_sse
if (!s_default_sse_storage_initialized)
{
initialize_default_sse_storage();
s_default_sse_storage_initialized = true;
}
memcpy(m_sse_storage, s_default_sse_storage, sizeof(m_sse_storage));
#endif
}
Thread& Thread::current()
@@ -506,7 +502,6 @@ namespace Kernel
ASSERT_NOT_REACHED();
}
#if __enable_sse
void Thread::save_sse()
{
asm volatile("fxsave %0" :: "m"(m_sse_storage));
@@ -516,6 +511,5 @@ namespace Kernel
{
asm volatile("fxrstor %0" :: "m"(m_sse_storage));
}
#endif
}