mirror of
https://github.com/gomson/TimothyLottes.github.io.git
synced 2026-08-04 14:48:49 +00:00
10 lines
8.3 KiB
HTML
10 lines
8.3 KiB
HTML
<html><head><link rel="stylesheet" href="style.css"></head><body><div class="page">
|
|
<h1>20101005 - MSVC Optimizing Static Constant Data Copy?</h1>
|
|
<br>
|
|
|
|
Yes. All extra copies factored out.<br /><br /><!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #8f5902; font-style: italic">#include <stdio.h></span><br /><br /><span style="color: #204a87; font-weight: bold">typedef</span> <span style="color: #204a87; font-weight: bold">struct</span> <span style="color: #000000; font-weight: bold">{</span> <br /> <span style="color: #204a87; font-weight: bold">int</span> <span style="color: #000000">a</span><span style="color: #000000; font-weight: bold">;</span><br /> <span style="color: #204a87; font-weight: bold">int</span> <span style="color: #000000">b</span><span style="color: #000000; font-weight: bold">;</span><br /> <span style="color: #204a87; font-weight: bold">int</span> <span style="color: #000000">c</span><span style="color: #000000; font-weight: bold">;</span><br /> <span style="color: #204a87; font-weight: bold">int</span> <span style="color: #000000">d</span><span style="color: #000000; font-weight: bold">;</span><br /><span style="color: #000000; font-weight: bold">}</span> <span style="color: #000000">DataA</span><span style="color: #000000; font-weight: bold">;</span><br /><br /><span style="color: #204a87; font-weight: bold">typedef</span> <span style="color: #204a87; font-weight: bold">struct</span> <span style="color: #000000; font-weight: bold">{</span><br /> <span style="color: #204a87; font-weight: bold">int</span> <span style="color: #000000">a</span><span style="color: #000000; font-weight: bold">;</span><br /> <span style="color: #204a87; font-weight: bold">int</span> <span style="color: #000000">d</span><span style="color: #000000; font-weight: bold">;</span><br /><span style="color: #000000; font-weight: bold">}</span> <span style="color: #000000">DataB</span><span style="color: #000000; font-weight: bold">;</span><br /><br /><span style="color: #204a87; font-weight: bold">static</span> <span style="color: #204a87; font-weight: bold">const</span> <span style="color: #000000">DataA</span> <span style="color: #000000">dataA</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000; font-weight: bold">{</span> <span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #0000cf; font-weight: bold">1</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #0000cf; font-weight: bold">2</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #0000cf; font-weight: bold">3</span> <span style="color: #000000; font-weight: bold">};</span><br /><br /><span style="color: #204a87; font-weight: bold">static</span> <span style="color: #204a87; font-weight: bold">__forceinline</span> <span style="color: #204a87; font-weight: bold">void</span> <span style="color: #000000">DataCopy</span><span style="color: #000000; font-weight: bold">(</span><br /><span style="color: #000000">DataB</span><span style="color: #ce5c00; font-weight: bold">*</span> <span style="color: #000000">__restrict</span> <span style="color: #204a87; font-weight: bold">const</span> <span style="color: #000000">dataB</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #204a87; font-weight: bold">const</span> <span style="color: #000000">DataA</span><span style="color: #ce5c00; font-weight: bold">*</span> <span style="color: #000000">__restrict</span> <span style="color: #204a87; font-weight: bold">const</span> <span style="color: #000000">dataA</span><span style="color: #000000; font-weight: bold">)</span> <span style="color: #000000; font-weight: bold">{</span><br /> <span style="color: #000000">dataB</span><span style="color: #ce5c00; font-weight: bold">-></span><span style="color: #000000">a</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">dataA</span><span style="color: #ce5c00; font-weight: bold">-></span><span style="color: #000000">a</span><span style="color: #000000; font-weight: bold">;</span><br /> <span style="color: #000000">dataB</span><span style="color: #ce5c00; font-weight: bold">-></span><span style="color: #000000">d</span> <span style="color: #ce5c00; font-weight: bold">=</span> <span style="color: #000000">dataA</span><span style="color: #ce5c00; font-weight: bold">-></span><span style="color: #000000">d</span><span style="color: #000000; font-weight: bold">;</span> <span style="color: #000000; font-weight: bold">}</span><br /><br /><span style="color: #204a87; font-weight: bold">void</span> <span style="color: #000000">main</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #204a87; font-weight: bold">void</span><span style="color: #000000; font-weight: bold">)</span> <span style="color: #000000; font-weight: bold">{</span><br /> <span style="color: #000000">DataB</span> <span style="color: #000000">dataB</span><span style="color: #000000; font-weight: bold">;</span><br /> <span style="color: #000000">DataCopy</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #ce5c00; font-weight: bold">&</span><span style="color: #000000">dataB</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #ce5c00; font-weight: bold">&</span><span style="color: #000000">dataA</span><span style="color: #000000; font-weight: bold">);</span><br /> <span style="color: #000000">printf</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"dataB.d = %d\n"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">dataB</span><span style="color: #000000; font-weight: bold">.</span><span style="color: #000000">d</span><span style="color: #000000; font-weight: bold">);</span> <span style="color: #000000; font-weight: bold">}</span><br /></pre></div><br /><br />Trimmed part of /FAs assembly output,<br /><br /><!-- HTML generated using hilite.me --><div style="background: #f8f8f8; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #000000">PUBLIC</span> <span style="color: #000000">_main</span><br /><span style="color: #000000">EXTRN</span> <span style="color: #000000">_printf</span><span style="color: #000000; font-weight: bold">:</span><span style="color: #000000">PROC</span><br /><span style="color: #8f5902; font-style: italic">; Function compile flags: /Ogtpy</span><br /><span style="color: #000000">_TEXT</span> <span style="color: #204a87; font-weight: bold">SEG</span><span style="color: #000000">MENT</span><br /><span style="color: #000000">_main</span> <span style="color: #000000">PROC</span><br /><br /><span style="color: #8f5902; font-style: italic">; 56 : DataB dataB;</span><br /><span style="color: #8f5902; font-style: italic">; 57 : DataCopy(&dataB, &dataA);</span><br /><span style="color: #8f5902; font-style: italic">; 58 : printf("dataB.d = %d\n", dataB.d); } </span><br /><br /> <span style="color: #000000">push</span> <span style="color: #0000cf; font-weight: bold">3</span><br /> <span style="color: #000000">push</span> <span style="color: #000000">OFFSET</span> <span style="color: #204a87; font-weight: bold">$</span><span style="color: #000000">SG3859</span><br /> <span style="color: #000000">call</span> <span style="color: #000000">_printf</span><br /> <span style="color: #000000">add</span> <span style="color: #204a87">esp</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #0000cf; font-weight: bold">8</span><br /> <span style="color: #000000">xor</span> <span style="color: #204a87">eax</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #204a87">eax</span><br /> <span style="color: #000000">ret</span> <span style="color: #0000cf; font-weight: bold">0</span><br /><span style="color: #000000">_main</span> <span style="color: #000000">ENDP</span><br /></pre></div>
|
|
|
|
</div></body></html>
|
|
|
|
|