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

Method FIST

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

Store integer to memory (possibly with truncation)

Source from the content-addressed store, hash-verified

150
151// Store integer to memory (possibly with truncation)
152void OpDispatchBuilder::FIST(OpcodeArgs, bool Truncate) {
153 const auto Size = OpSizeFromSrc(Op);
154 Ref Data = _ReadStackValue(0);
155
156 // For 16-bit integers, we need to manually check for overflow
157 // since _F80CVTInt doesn't handle 16-bit overflow detection properly
158 if (Size == OpSize::i16Bit) {
159 // Extract the 80-bit float value to check for special cases
160 // Get the upper 64 bits which contain sign and exponent and then the exponent from upper.
161 Ref Upper = _VExtractToGPR(OpSize::i128Bit, OpSize::i64Bit, Data, 1);
162 Ref Exponent = _And(OpSize::i64Bit, Upper, Constant(0x7fff));
163
164 // Check for NaN/Infinity: exponent = 0x7fff
165 SaveNZCV();
166 _TestNZ(OpSize::i64Bit, Exponent, Constant(0x7fff));
167 Ref IsSpecial = _NZCVSelect01({COND_EQ});
168
169 // For overflow detection, check if exponent indicates a value >= 2^15
170 // Biased exponent for 2^15 is 0x3fff + 15 = 0x400e
171 SubWithFlags(OpSize::i64Bit, Exponent, 0x400e);
172 Ref IsOverflow = _NZCVSelect01({COND_UGE});
173
174 // Set Invalid Operation flag if overflow or special value
175 Ref InvalidFlag = _Or(OpSize::i64Bit, IsSpecial, IsOverflow);
176 SetRFLAG<FEXCore::X86State::X87FLAG_IE_LOC>(InvalidFlag);
177 }
178
179 Data = _F80CVTInt(Size, Data, Truncate);
180
181 StoreResult_WithOpSize(GPRClass, Op, Op->Dest, Data, Size, OpSize::i8Bit);
182
183 if ((Op->TableInfo->Flags & X86Tables::InstFlags::FLAGS_POP) != 0) {
184 _PopStackDestroy();
185 }
186}
187
188void OpDispatchBuilder::FADD(OpcodeArgs, IR::OpSize Width, bool Integer, OpDispatchBuilder::OpResult ResInST0) {
189 if (Op->Src[0].IsNone()) { // Implicit argument case

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected