<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 25 Mar 2013, at 01:55, Xiangrong Fang wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">Why the "External: SIGFPE" error not reported on the line it was generated?<br>e.g. In the following code:<br><br>1: if SomeCondition then begin<br>2: Y := exp(Y);<br>3: end;<br>4: d := Data[X];<br><br>The SIGFPE is generated on line 2, because Y is too big. But while the<br>program is running in IDE, it told me that line 4 is generating SIGFPE?<br></span></span></blockquote></div><br><div>Because that is how the 80x86 architecture works. Back when the original 8086 came out, the FPU was a separate co-processor you had to plug in. It worked in parallel with the main cpu (so the cpu didn't wait for the co-processor to finish with an instruction before continuing), so when it wanted to raise an exception it waited for the next FPU instruction to be dispatched rather than do so immediately (so the exception would always be raised in the same place, rather than at a random address). The FPU had no clue about the address of the original instruction, and hence could not report it.</div><div><br></div><div>We are now several decades later, but for compatibility reasons the FPU on the x86 processors still uses the same logic. It is possible to get the exception at the place where it happened by inserting fwait instructions after every fpu operation. Those tell the cpu to stop executing until the FPU has finished executing the previous instruction. That obviously slows down the code significantly. FPC has no option to do this.</div><div><br></div><div><br></div><div>Jonas</div></body></html>