<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[memcpy?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte gerne wissen wie der memcpy Befehl funktioniert.<br />
a.) ist es ein single CPU Befehl oder ist es eine Funktion die für z.B. 72000Bytes auch 72000(/4) CPU Befehle zum Kopieren im Speicher abschickt?<br />
b.) wie lange hält sich das im CPU Cache, wenn z.B. alle 33ms ein Copy mit 72kb ausgeführt wird?<br />
c.) gibt es derzeit effektivere Befehle um CPU Zeit zu sparen?</p>
<p>Grüße<br />
TheNoName</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275015/memcpy</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 07:55:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275015.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Oct 2010 09:21:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to memcpy? on Thu, 07 Oct 2010 09:21:36 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte gerne wissen wie der memcpy Befehl funktioniert.<br />
a.) ist es ein single CPU Befehl oder ist es eine Funktion die für z.B. 72000Bytes auch 72000(/4) CPU Befehle zum Kopieren im Speicher abschickt?<br />
b.) wie lange hält sich das im CPU Cache, wenn z.B. alle 33ms ein Copy mit 72kb ausgeführt wird?<br />
c.) gibt es derzeit effektivere Befehle um CPU Zeit zu sparen?</p>
<p>Grüße<br />
TheNoName</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962447</guid><dc:creator><![CDATA[thenoname]]></dc:creator><pubDate>Thu, 07 Oct 2010 09:21:36 GMT</pubDate></item><item><title><![CDATA[Reply to memcpy? on Thu, 07 Oct 2010 09:58:08 GMT]]></title><description><![CDATA[<p>kommt auf den compiler an und in wie fern du ihm freie hand lässt.</p>
<p>falls du deinem compiler nicht traust und dort auch noch das letzte qäuntchen geschwindigkeit herausholen willst:<br />
<a href="http://www.asmcommunity.net/board/index.php?topic=12804.0" rel="nofollow">http://www.asmcommunity.net/board/index.php?topic=12804.0</a></p>
<p>vll hilft dir ads ja weiter.</p>
<p>bb</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962464</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962464</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 07 Oct 2010 09:58:08 GMT</pubDate></item><item><title><![CDATA[Reply to memcpy? on Thu, 07 Oct 2010 10:01:19 GMT]]></title><description><![CDATA[<p>a) memcpy hat lineare Zeitkomplexität<br />
b) Kommt auf deine CPU an. Zeit spielt beim Cache aber eigentlich keine Rolle.<br />
c) Du kannst memcpy selbst implementieren, wenn du dich auf eine Zielplattform spezialisieren willst:<br />
<a href="http://www.eetimes.com/design/memory-design/4024961/Optimizing-Memcpy-improves-speed" rel="nofollow">http://www.eetimes.com/design/memory-design/4024961/Optimizing-Memcpy-improves-speed</a><br />
Du darfst aber davon ausgehen, dass die Version deines Compilers ziemlich gut ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962465</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 07 Oct 2010 10:01:19 GMT</pubDate></item><item><title><![CDATA[Reply to memcpy? on Thu, 07 Oct 2010 13:36:55 GMT]]></title><description><![CDATA[<p>Also eine X86 CPU kennt einen Befehl der Speicherbereiche Kopieren kann.</p>
<pre><code class="language-cpp">rep movs
</code></pre>
<p>Dieser wird aber in Moderne CPUs eh intern in kleine Befehle zerlegt.<br />
so etwa:</p>
<pre><code class="language-cpp">while(Count--) *pDes++ = *pSrc++;
</code></pre>
<p>Nehmen wir mal an das die CPU pro Kopiervorgang einen Takt braucht und gleichzeitig 4 Byte Transferiert, dann sind das bei 65KByte auf einem 2 GHz Prozessor. ca. 0,000008 sek.</p>
<p>Bei einen Zyklus von 33 ms fällt diese Zeit von ~10 us gar nicht ins Gewicht und der Cache wird sicher (Auf einen Normalen Betriebssystem) immer Invalid sein.</p>
<p>Lichtlein</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962553</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962553</guid><dc:creator><![CDATA[Lichtlein]]></dc:creator><pubDate>Thu, 07 Oct 2010 13:36:55 GMT</pubDate></item><item><title><![CDATA[Reply to memcpy? on Thu, 07 Oct 2010 15:17:48 GMT]]></title><description><![CDATA[<p>b) memcpy führt unweigerlich zu Cache-Pollution, deswegen wird in den meisten Fällen ein Cache-Write-Through empfohlen.<br />
Damit kann die CPU/Chipsatz die Memory-Zugriffe noch optimieren.</p>
<p>c) Hier ein Code-Beispiel vom AMD-Speed-Guide, funktioniert ab SSE2</p>
<pre><code class="language-cpp">void nontemporal_copy(char* outbuff, char* inbuff, int size) 
{
const int step = 64; // cache line
while(size &gt; step) {
  _mm_prefetch(inbuff + 320, _MM_HINT_NTA); // non-temporal prefetch
  __m128i A = _mm_loadu_si128((__m128i*) (inbuff +  0));
  __m128i B = _mm_loadu_si128((__m128i*) (inbuff + 16));
  __m128i C = _mm_loadu_si128((__m128i*) (inbuff + 32));
  __m128i D = _mm_loadu_si128((__m128i*) (inbuff + 48));

  // destination address must be 16-byte aligned!
  _mm_stream_si128((__m128i*) (outbuff +  0), A);
  _mm_stream_si128((__m128i*) (outbuff + 16), B);
  _mm_stream_si128((__m128i*) (outbuff + 32), C);
  _mm_stream_si128((__m128i*) (outbuff + 48), D);

  inbuff  += step;
  outbuff += step;
  size -= step;
}
_mm_mfence();
}
</code></pre>
<p>Falls ein Cache-Write-Through nicht erwünsch ist, lohnt sich das prefetchen trotzdem.<br />
Je nach Größe der Cacheline der CPU kann man die Funktion noch anpassen, diese ist quasi hardcoded für 64byte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962609</guid><dc:creator><![CDATA[nurf]]></dc:creator><pubDate>Thu, 07 Oct 2010 15:17:48 GMT</pubDate></item></channel></rss>