<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Hello Andrew<div><div>Your idea looks good, but a question arises:</div><div><br></div><div>If I change emit_int16() to use Bytes::put_native_u2() then few platform might see perf penalty, </div></div><div>I found these platforms to do aligned store in put_native_u2() unconditionally:</div><div>ppc and arm32 doing same thing:</div><div><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";"><b>static</b> <b>inline</b> <b>void</b> put_native_u2(address p, u2 x) {</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    <b>if</b> ((intptr_t(p) & 1) == 0) {</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">      *(u2*)p = x;</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    } <b>else</b> {</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">      p[0] = x;</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">      p[1] = x >> 8;</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    }</p>
<p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">  }</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";"><br></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">and x86 doing  this ():</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";"><br></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";"> <b>static</b> <b>inline</b> <b>void</b> put_native_u2(address p, u2 x)   { put_native<u2>((<b>void</b>*)p, x); }</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue"; min-height: 15px;"><br></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">  <b>template</b> <<b>typename</b> T></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">  <b>static</b> <b>inline</b> <b>void</b> put_native(<b>void</b>* p, T x) {</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    assert(p != <b>NULL</b>, "null pointer");</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue"; min-height: 15px;"><br></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    <b>if</b> (is_aligned(p, <b>sizeof</b>(T))) {</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">      *(T*)p = x;</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    } <b>else</b> {</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">      memcpy(p, &x, <b>sizeof</b>(T));</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">    }</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">  }</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";"><br></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">Should I then make ppc/arm32/x86 to do aligned stores in put_native_u2 only if AvoidUnalignedAccesses is true ?</p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";"><br></p><p style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";">Thanks in advance, Vladimir.</p><blockquote type="cite"><div>27 марта 2023 г., в 12:55, Andrew Haley <aph-open@littlepinkcloud.com> написал(а):</div><br class="Apple-interchange-newline"><div><div>On 3/20/23 15:26, Vladimir Kempik wrote:<br><blockquote type="cite">Could you please suggest on best way to make emit_intX methods not perform misaligned memory stores ?<br></blockquote><br>You should change emit_int16() to use Bytes::put_native_u2(). You should change<br>RiscV's put_native_u2() to do whatever the back end needs, respecting<br>AvoidUnalignedAccesses.<br><br>-- <br>Andrew Haley  (he/him)<br>Java Platform Lead Engineer<br>Red Hat UK Ltd. <https://www.redhat.com><br>https://keybase.io/andrewhaley<br>EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671<br><br></div></div></blockquote></div><br></body></html>