<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi Garry,</p>
<p>Hopefully I have fixed this issue now, which is also causing
problems elsewhere.</p>
<p><a class="moz-txt-link-freetext" href="https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/598">https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/598</a>
- just waiting on it to be verified, approved and merged.<br>
</p>
<p>Gareth aka. Kit<br>
</p>
<div class="moz-cite-prefix">On 20/02/2024 06:32, J. Gareth Moreton
via fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:38269e53-b326-4025-a375-453ff0921047@moreton-family.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Thanks for the report and especially your investigative work.
Ii'll take a look to see what's going on.<br>
</p>
<p>Gareth aka. Kit<br>
</p>
<div class="moz-cite-prefix">On 20/02/2024 01:30, Garry Wood via
fpc-devel wrote:<br>
</div>
<blockquote type="cite"
cite="mid:SEYPR06MB6614CED2E64D85091DAE6D3EEB502@SEYPR06MB6614.apcprd06.prod.outlook.com">
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<meta name="Generator"
content="Microsoft Word 15 (filtered medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-ligatures:standardcontextual;
mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
mso-fareast-language:EN-US;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Commit 6b2e4fa4 (main)
entitled “* arm: "OpCmp2OpS" moved to Pass 2 so it doesn't
conflict with AND; CMP -> TST optimisation” by Gareth
from Feb 11 2024 produces incorrect assembler in certain
cases.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><a
href="https://gitlab.com/freepascal.org/fpc/source/-/commit/6b2e4fa4133a496c1c3f89e3c71fffbdd7c192fb"
moz-do-not-send="true" class="moz-txt-link-freetext">https://gitlab.com/freepascal.org/fpc/source/-/commit/6b2e4fa4133a496c1c3f89e3c71fffbdd7c192fb</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This piece of code:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">function
CPUMaskCount(CPUMask:LongWord):LongWord;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">var<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Count:LongWord;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">begin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">{}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Result:=0;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> for Count:=CPU_ID_0
to CPU_ID_MAX do<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> begin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> if (CPUMask and (1
shl Count)) <> 0 then<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> begin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Inc(Result);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> end;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> end;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">end;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">when compiled with FPC
prior to commit 6b2e4fa4 produces the following working
assembler:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">00020528
<GLOBALCONFIG_$$_CPUMASKCOUNT$LONGWORD$$LONGWORD>:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20528:
e1a01000 mov r1, r0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
2052c: e3a00000 mov r0, #0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20530:
e3a02000 mov r2, #0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20534:
e3a03001 mov r3, #1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20538:
e0113213 ands r3, r1, r3, lsl r2<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
2053c: 12800001 addne r0, r0, #1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20540:
e2822001 add r2, r2, #1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20544:
e352001f cmp r2, #31<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20548:
9afffff9 bls 20534
<GLOBALCONFIG_$$_CPUMASKCOUNT$LONGWORD$$LONGWORD+0xc><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
2054c: e12fff1e bx
lr<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But when compiled with
FPC after commit 6b2e4fa4 it produces this assembler which
doesn’t work:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">00020528
<GLOBALCONFIG_$$_CPUMASKCOUNT$LONGWORD$$LONGWORD>:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20528:
e1a01000 mov r1, r0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
2052c: e3a00000 mov r0, #0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20530:
e3a02000 mov r2, #0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20534:
e3a03001 mov r3, #1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20538:
e1110003 tst r1, r3<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
2053c: 12800001 addne r0, r0, #1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20540:
e2822001 add r2, r2, #1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20544:
e352001f cmp r2, #31<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> 20548:
9afffff9 bls 20534
<GLOBALCONFIG_$$_CPUMASKCOUNT$LONGWORD$$LONGWORD+0xc><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
2054c: e12fff1e bx
lr<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">You can see that the
difference is the lack of lsl r2 on the end of the TST
instruction which means that the shl on the original code
is not being performed and the test is therefore invalid.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Similar code sequences
in multiple other places produce the same result with the
lsl suffix missing from the TST instruction.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Please let me know if
you need any further information.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Garry Wood.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a
class="moz-txt-link-abbreviated moz-txt-link-freetext"
href="mailto:fpc-devel@lists.freepascal.org"
moz-do-not-send="true">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext"
href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel"
moz-do-not-send="true">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
</body>
</html>