MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / GetX87FTW_Helper

Method GetX87FTW_Helper

FEXCore/Source/Interface/Core/OpcodeDispatcher/X87.cpp:334–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334Ref OpDispatchBuilder::GetX87FTW_Helper() {
335 // AbridgedFTWIndex has 1-bit per slot (8 slots). Duplicate each bit to get
336 // 2-bits per slot (16-bit result). Duplicating bits is equivalent to
337 // Morton interleaving a number with itself. To interleave efficiently two
338 // bytes, we use the well-known bit twiddling algorithm:
339 //
340 // https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
341 Ref X = LoadContext(AbridgedFTWIndex);
342 X = _Orlshl(OpSize::i32Bit, X, X, 4);
343 X = _And(OpSize::i32Bit, X, Constant(0x0f0f0f0f));
344 X = _Orlshl(OpSize::i32Bit, X, X, 2);
345 X = _And(OpSize::i32Bit, X, Constant(0x33333333));
346 X = _Orlshl(OpSize::i32Bit, X, X, 1);
347 X = _And(OpSize::i32Bit, X, Constant(0x55555555));
348 X = _Orlshl(OpSize::i32Bit, X, X, 1);
349
350 // The above sequence sets valid to 11 and empty to 00, so invert to finalize.
351 static_assert(static_cast<uint8_t>(FPState::X87Tag::Valid) == 0b00);
352 static_assert(static_cast<uint8_t>(FPState::X87Tag::Empty) == 0b11);
353 return _Xor(OpSize::i32Bit, X, Constant(0xffff));
354}
355
356void OpDispatchBuilder::X87FNSTENV(OpcodeArgs) {
357

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected