<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
@font-face
        {font-family:Aptos;
        panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-DE" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Hi David and Julian,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">I just checked it with GCC (<a href="https://godbolt.org/z/qcYjn6dn9">https://godbolt.org/z/qcYjn6dn9</a>) and Clang (<a href="https://godbolt.org/z/zvfnba5Tf">https://godbolt.org/z/zvfnba5Tf</a>)
 in Godbolt: GCC without any optimizations discards the loop, Clang replaces it with a single jump, MSVC (<a href="https://godbolt.org/z/saj1sreen">https://godbolt.org/z/saj1sreen</a>) and ICC (<a href="https://godbolt.org/z/saj1sreenproduce">https://godbolt.org/z/saj1sreenproduce</a>)
 a  full loop.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">The change is therefore only a minor optimization on MSVC and ICC.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Johannes<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">From:
</span></b><span style="font-size:12.0pt;font-family:"Aptos",sans-serif;color:black">hotspot-dev <hotspot-dev-retn@openjdk.org> on behalf of David Holmes <david.holmes@oracle.com><br>
<b>Date: </b>Monday, 15. January 2024 at 03:49<br>
<b>To: </b>hotspot-dev@openjdk.org <hotspot-dev@openjdk.org><br>
<b>Subject: </b>Re: static_cast<void>(0) vs do while<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">[You don't often get email from david.holmes@oracle.com. Learn why this is important at
<a href="https://aka.ms/LearnAboutSenderIdentification">https://aka.ms/LearnAboutSenderIdentification</a> ]<br>
<br>
Hi Julian,<br>
<br>
On 12/01/2024 3:24 pm, Julian Waters wrote:<br>
> Hi all,<br>
><br>
> In my personal fork of HotSpot I have the following commit<br>
> <a href="https://github.com/TheShermanTanker/jdk/commit/54131b70d40a88ab4176d23821f4c32044c0043d">
https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FTheShermanTanker%2Fjdk%2Fcommit%2F54131b70d40a88ab4176d23821f4c32044c0043d&data=05%7C02%7Cjohannes.bechberger%40sap.com%7C87b0fb3aa6d44bb13f8208dc15749167%7C42f7676cf455423c82f6dc2d99791af7%7C0%7C0%7C638408837602750422%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dTWgX8aIQsZuS33M%2F047H4uu3L4ZRzQGIiwh%2FfKqdhc%3D&reserved=0</a><br>
> which replaces some occurrences of do while with a discarding<br>
> static_cast (static_cast<void>(0) is a nop), to avoid inefficiencies<br>
> in the compiled code for debug mode, when optimizations are turned off<br>
> (Namely a compare and jump back to the start of the loop on a<br>
> condition that is always false). Is this minor optimization worth<br>
> committing upstream to HotSpot? It should also mean that the compiled<br>
> code is clearer when the methods containing asserts are disassembled.<br>
<br>
Sorry that just looks weird to me - I'm thinking "what on earth is a<br>
cast doing here?". `do { ... } while (0)` is a long standing idiomatic<br>
way to write a multi-line macro so that it can be used as a statement. I<br>
would think any compiler worth its salt would see the loop never repeats<br>
and just discard it.<br>
<br>
Cheers,<br>
David<br>
<br>
> best regards,<br>
> Julian<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>