<div dir="ltr">Pieter, better to stick to what tests <b>show </b>to be best, not what "intuition" suggests <b>should</b> be. ;)<br><br>A Pentium CPU doesn't have opcodes for floating point... but it does have an FPU which does. The 32-bit Delphi compiler may not make the absolute best use of the available silicon (e.g. MMX), but it will at least make use of the FPU.<br>
<br>But the 32-bit Delphi compiler doesn't use CPU opcodes for Int64 operations - even if they are present in the hardware) which I think is why - in <b>tests</b> - Int64 arithmetic Is significantly less efficient than Double arithmetic.<br>
<br><br>Something was bugging me that I had forgotten something... and I had...<br><br>There is also the "Comp" type. This is listed as a "real" type in most documentation but is in fact an Int64. The difference is that operations involving this type are performed in the FPU, rather than through software emulation of a 64-bit integer. So it's possible that Comp might provide a performance advantage over Double.<br>
<br>Again, testing will be the key to answering the question of whether or not it does in practice.
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 18 August 2014 08:37, Pieter De Wit <span dir="ltr"><<a href="mailto:pieter@insync.za.net" target="_blank">pieter@insync.za.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="font-size:10pt;font-family:Verdana,Geneva,sans-serif">
<p>Hi,</p>
<p> </p>
<p>No, it appears I was wrong.</p>
<p> </p>
<p>Delphi (at least pascal and by default, I assume then delphi) stores "real"'s as per the IEEE std.</p>
<p> </p>
<p>See : <a href="https://www.informatik.uni-hamburg.de/RZ/software/SUNWspro/pascal/lang_ref/ref_data.doc.html" target="_blank">https://www.informatik.uni-hamburg.de/RZ/software/SUNWspro/pascal/lang_ref/ref_data.doc.html</a></p>
<p> </p>
<p>It's a weird layout which results in (if I understand this correctly) a multiply instruction to even set the value:</p>
<p>A real number is represented by this form:</p>
<p>(-1)sign * 2 exponent-bias *1.f<br>f is the bits in the fraction</p>
<p> </p>
<p>I would hate to work out the CPU cycles needed to multiply real's...</p>
<p> </p>
<p>Either way - you going to end up with a LOT more CPU usage multiplying real's vs int - *unless* you need a real, stick to int :)</p>
<p> </p>
<p>A tip from me - I would load the source ints into a few arrays and then use threading to make it faster/use more cores.</p>
<p> </p>
<p>(This did spark off a talk about if Intel/AMD include a math co-pro with each core - if not, you really have to stick to threaded int64 - even more so if your CPUs are hyperthreaded, then you need int64 as a single core serves 2 HT cores - research the early days of HT for more info on this :) )</p>
<p> </p>
<p>Cheers,</p><span class="HOEnZb"><font color="#888888">
<p> </p>
<p>Pieter</p></font></span><div><div class="h5">
<p> </p>
<p>On 17/08/2014 20:09, Cameron Hart wrote:</p>
<blockquote type="cite" style="padding-left:5px;border-left:#1010ff 2px solid;margin-left:5px">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d">I'm confused now as I'm pretty sure Delphi uses a standard format to represent float (the same format used anywhere else for that matter). In which case a float is essentially two int32 (or other int's depending on the scale of the float). Ie a single used two int16.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d">One int represented the mantissa the other the exponent (in essence the decimal portion). Together they resulted in the floating point value.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d">How would you describe this otherwise?</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:'Calibri','sans-serif';color:#1f497d"> </span></p>
<p class="MsoNormal"><strong><span style="font-size:10.0pt;font-family:'Tahoma','sans-serif'">From:</span></strong><span style="font-size:10.0pt;font-family:'Tahoma','sans-serif'"> <a href="mailto:delphi-bounces@listserver.123.net.nz" target="_blank">delphi-bounces@listserver.123.net.nz</a> [mailto:<a href="mailto:delphi-bounces@listserver.123.net.nz" target="_blank">delphi-bounces@listserver.123.net.nz</a>] <strong>On Behalf Of </strong>Jolyon Smith<br>
<strong>Sent:</strong> Sunday, 17 August 2014 12:54 p.m.<br> <strong>To:</strong> NZ Borland Developers Group - Delphi List<br> <strong>Subject:</strong> Re: [DUG] Int64 or floating point faster?</span></p>
<p class="MsoNormal"> </p>
<div>
<p class="MsoNormal">That's curious. Who are "they" ? It doesn't sound like any floating point implementation I ever came across in Delphi (or anywhere else, for that matter). O.o</p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> </p>
<div>
<p class="MsoNormal">On 17 August 2014 12:28, Pieter De Wit <<a href="mailto:pieter@insync.za.net" target="_blank">pieter@insync.za.net</a>> wrote:</p>
<div>
<div>
<p class="MsoNormal">Hi Jolyon,<br> <br> From memory, they used 2 int32's to make a float - this could have been int16's - memory is very vague on this :) The one was used to represent the whole numbers and the other was to show the decimal numbers<br>
<br> Cheers,<br> <br> Pieter</p>
<div>
<div>
<p class="MsoNormal"><br> <br> On 17/08/2014 12:05, Jolyon Smith wrote:</p>
</div>
</div>
</div>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">@Pieter - I don't understand what you mean when you say that "float was int32.int32". For starters, "float" is an imprecise term. If you mean "single" then the entire value was always 32 bit in it's entirety. If you mean double then it was always 64 bit. What is this "in32.int32" type of which you speak ? O.o</p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> </p>
<div>
<p class="MsoNormal">On 17 August 2014 11:52, Jolyon Smith <<a href="mailto:jsmith@deltics.co.nz" target="_blank">jsmith@deltics.co.nz</a>> wrote:</p>
<div>
<p class="MsoNormal">I think there are too many variables involved to give an answer to this question without some of those variables being reduced to known values.<br> <br> e.g. what hardware ? what version of Delphi ? x64 target or x86 ? what precision of floating point ?<br>
<br> Having said that, in a quick test knocked up in my Smoketest framework I found that Double comfortably outperforms Int64 when compiling for Win32 but that both Double and Int64 demonstrated improved performance when compiling for Win64 and that whilst Double still showed some advantage it was not as significant (and in some test runs the difference was negligible).<br>
<br> If you are targeting FireMonkey you will have to bear in mind that the back-end compiler is different to the x86/x64 backend, so results obtained using the WinXX compilers will not necessarily be indicative of performance on the ARM or LLVM platforms. </p>
<div>
<p class="MsoNormal"><br> <br> Conditions: </p>
<div>
<p class="MsoNormal"><br> - Delphi XE4</p>
</div>
<div>
<p class="MsoNormal"> - Running in a 64-bit Win 7 VM</p>
</div>
<div>
<div>
<p class="MsoNormal"> - No testing was done for correctness of the results.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> </p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> </p>
<div>
<div>
<p class="MsoNormal">On 16 August 2014 15:30, Ross Levis <<a href="mailto:ross@stationplaylist.com" target="_blank">ross@stationplaylist.com</a>> wrote:</p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<div>
<p class="MsoNormal"><span style="color:#1f497d">Would I be correct that int64 multiplications would be faster than floating point in Delphi? My app needs to do several million.</span></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span></p>
</div>
</div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">_______________________________________________<br> NZ Borland Developers Group - Delphi mailing list<br> Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br> Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank"> delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</p>
</div>
</blockquote>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
<p class="MsoNormal"> </p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"> </p>
<pre>_______________________________________________</pre>
<pre>NZ Borland Developers Group - Delphi mailing list</pre>
<pre>Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a></pre>
<pre>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a></pre>
<pre>Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</pre>
</blockquote>
<p class="MsoNormal"> </p>
</div>
</div>
</div>
<p class="MsoNormal"><br> _______________________________________________<br> NZ Borland Developers Group - Delphi mailing list<br> Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br> Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank"> delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</p>
</div>
<p class="MsoNormal"> </p>
</div>
</div>
<br>
<pre>_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe
</pre>
</blockquote>
<p> </p>
<div> </div>
</div></div></div>
<br>_______________________________________________<br>
NZ Borland Developers Group - Delphi mailing list<br>
Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>
Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<br></blockquote></div><br></div>