"""libm import stubs (float functions) for the emulator, behaving like 2009 Darwin i386 libm. i386 float functions return their result in x87 ST0. A Python hook cannot push the x87 stack directly, so the stub stores the float in a scratch word and jumps to a tiny trampoline `flds [scratch]; ret` (the caller's return address is still on the stack, so the trampoline's `ret` returns to the caller, which pops ST0 as usual). sinf/cosf: Darwin's libm of that era evaluates them in double precision and rounds to float, i.e. the result is the correctly rounded float of the double result. The double sin/cos of the host libm is used for that. Setting `g.h_libm_host = True` makes the stubs call the host's sinf/cosf instead (the libm a port runs on), so a differential test can separate libm rounding differences from differences in the ported code. Helpers are prefixed h_ so the stub loader (which registers callables starting with a single '_') skips them. """ import ctypes import math import struct from unicorn.x86_const import UC_X86_REG_ESP, UC_X86_REG_EIP def h_f32(x): return struct.unpack('