<?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[SSE - Aktivierung notwendig? Mein SSE-Code ist 20x langsamer als Standard C]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich hoffe mir kann jemand helfen.<br />
Ich bin vor Kurzem intensiv in die SIMD-Programmierung eingestiegen. Ich verwende MS Visual Studio 6.0 und MS Visual Studio 2005 (beides getestet). Ich habe es sowohl mit den Compiler Intrinsics versucht, als auch mit dem Inline-Assembler. Zum testen der SSE-Funktionalitaet habe ich die Library &quot;asmlib&quot; verwendet, die unter <a href="http://www.agner.org/optimize/" rel="nofollow">http://www.agner.org/optimize/</a> zu finden ist. Prinzipiell ist also SSE-Unterstuetzung vorhanden.</p>
<p>Meine Standard C++ Implementierung habe ich mit MS Visual Studio 6.0 ohne ProzessorPack (!) erzeugt. Diese &quot;Standard-Implemetierung&quot; hat also keinerlei SSE Befehle verwendet. Vor Kurzem habe ich nun eine SSE-Version erzeugt, die zu meiner Ueberraschung statt doppelt so schnell 20 mal langsamer war. Bisher konnte ich auch nach intensiver Web-Recherche dieses Problem nicht beheben. Ich habe es mittlerweile auch mit MS Visual Studio 2005 versucht - kein Erfolg soweit. Die Option /arch:SSE bewirkt auch nichts.</p>
<p>Also, hier der relevante Code. Zuerst in der &quot;Standard-Version&quot;</p>
<pre><code>// pure C++-Code

for (i=0;i&lt;num;i++)
{
	// arithmetic operation
	temp = (*a1)*(*sT)+(*a2)*(*sTT)+(*cb1)*vT+(*cb2)*vTT;

	// save the result
	(*sTT)  = temp;

	// calculate sum
	b += temp;

	// increment the pointers
	sT++;
	sTT++;
	a1++;
	a2++;
	cb1++;
	cb2++;
}
</code></pre>
<p>Ziemlich straight-forward und ideal parallelisierbar.<br />
Hier mein Versuch mit dem Inline-Assembler:</p>
<pre><code>num4 = num/4;

__asm {
	// store variables
	push			ebx
	push			esi
	push			edi

	movss			xmm5,		vt1
	movss			xmm7,		vt2
	shufps			xmm5,		xmm5,		0x00
	shufps			xmm7,		xmm7,		0x00

	// load pointers
	mov			eax,		stateT
	mov			ebx,		stateTT
	mov			ecx,		a1
	mov			edx,		a2
	mov			esi,		cb1
	mov			edi,		cb2

	// begin loop
loop_begin:
	// load data
	movaps			xmm0,		[ecx]
	movaps			xmm2,		[edx]
	movaps			xmm4,		[esi]		
	movaps			xmm6,		[edi]		
	movaps			xmm1,		[eax]			
	movaps			xmm3,		[ebx]		

	// arithmetric operations
	mulps			xmm0,		xmm1
	add			eax,		16
	mulps			xmm2,		xmm3
	mulps			xmm4,		xmm5
	add			ecx,		16
	mulps			xmm6,		xmm7
	add			edx,		16
	addps			xmm0,		xmm2
	add			esi,		16
	addps			xmm4,		xmm6
	add			edi,		16
	addps			xmm0,		xmm4

	// store result 
	movaps			[ebx],			xmm0
	add			ebx,			16
	addps			xmm0,			[b4]
	movaps			[b4],			xmm0

	// increase pointers:  done in-between the arithmetic operations		

	// next cycle
	dec			num4
	jnz			loop_begin

	// restore variables 
	pop			edi
	pop			esi
	pop			ebx
}
</code></pre>
<p>Der drastische Performance-Unterschied (Faktor 20 in die falsche Richtung) kann kein Zufall sein. Die Arrays sind alle auf 16 Byte &quot;aligned&quot;, daran liegt es also auch nicht. Die Zahl der Iterationen ist num=1000, es kann also auch kaum an irgendeinem Funktionen-Oberhead liegen.</p>
<p>Wahrscheinlich ist es ein ziemlich bloeder Fehler - wie so oft. Ich hoffe irgendjemand von euch hat Erfahrungen mit SSE-Programmierung. Muss man die SSE-Anweisungen erst irgendwie aktivieren? Kann es sein, dass SSE bei mir emuliert wird?</p>
<p>Viele Gruesse,<br />
Stefan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/172853/sse-aktivierung-notwendig-mein-sse-code-ist-20x-langsamer-als-standard-c</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 08:58:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/172853.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Feb 2007 23:24:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SSE - Aktivierung notwendig? Mein SSE-Code ist 20x langsamer als Standard C on Thu, 08 Feb 2007 23:24:08 GMT]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich hoffe mir kann jemand helfen.<br />
Ich bin vor Kurzem intensiv in die SIMD-Programmierung eingestiegen. Ich verwende MS Visual Studio 6.0 und MS Visual Studio 2005 (beides getestet). Ich habe es sowohl mit den Compiler Intrinsics versucht, als auch mit dem Inline-Assembler. Zum testen der SSE-Funktionalitaet habe ich die Library &quot;asmlib&quot; verwendet, die unter <a href="http://www.agner.org/optimize/" rel="nofollow">http://www.agner.org/optimize/</a> zu finden ist. Prinzipiell ist also SSE-Unterstuetzung vorhanden.</p>
<p>Meine Standard C++ Implementierung habe ich mit MS Visual Studio 6.0 ohne ProzessorPack (!) erzeugt. Diese &quot;Standard-Implemetierung&quot; hat also keinerlei SSE Befehle verwendet. Vor Kurzem habe ich nun eine SSE-Version erzeugt, die zu meiner Ueberraschung statt doppelt so schnell 20 mal langsamer war. Bisher konnte ich auch nach intensiver Web-Recherche dieses Problem nicht beheben. Ich habe es mittlerweile auch mit MS Visual Studio 2005 versucht - kein Erfolg soweit. Die Option /arch:SSE bewirkt auch nichts.</p>
<p>Also, hier der relevante Code. Zuerst in der &quot;Standard-Version&quot;</p>
<pre><code>// pure C++-Code

for (i=0;i&lt;num;i++)
{
	// arithmetic operation
	temp = (*a1)*(*sT)+(*a2)*(*sTT)+(*cb1)*vT+(*cb2)*vTT;

	// save the result
	(*sTT)  = temp;

	// calculate sum
	b += temp;

	// increment the pointers
	sT++;
	sTT++;
	a1++;
	a2++;
	cb1++;
	cb2++;
}
</code></pre>
<p>Ziemlich straight-forward und ideal parallelisierbar.<br />
Hier mein Versuch mit dem Inline-Assembler:</p>
<pre><code>num4 = num/4;

__asm {
	// store variables
	push			ebx
	push			esi
	push			edi

	movss			xmm5,		vt1
	movss			xmm7,		vt2
	shufps			xmm5,		xmm5,		0x00
	shufps			xmm7,		xmm7,		0x00

	// load pointers
	mov			eax,		stateT
	mov			ebx,		stateTT
	mov			ecx,		a1
	mov			edx,		a2
	mov			esi,		cb1
	mov			edi,		cb2

	// begin loop
loop_begin:
	// load data
	movaps			xmm0,		[ecx]
	movaps			xmm2,		[edx]
	movaps			xmm4,		[esi]		
	movaps			xmm6,		[edi]		
	movaps			xmm1,		[eax]			
	movaps			xmm3,		[ebx]		

	// arithmetric operations
	mulps			xmm0,		xmm1
	add			eax,		16
	mulps			xmm2,		xmm3
	mulps			xmm4,		xmm5
	add			ecx,		16
	mulps			xmm6,		xmm7
	add			edx,		16
	addps			xmm0,		xmm2
	add			esi,		16
	addps			xmm4,		xmm6
	add			edi,		16
	addps			xmm0,		xmm4

	// store result 
	movaps			[ebx],			xmm0
	add			ebx,			16
	addps			xmm0,			[b4]
	movaps			[b4],			xmm0

	// increase pointers:  done in-between the arithmetic operations		

	// next cycle
	dec			num4
	jnz			loop_begin

	// restore variables 
	pop			edi
	pop			esi
	pop			ebx
}
</code></pre>
<p>Der drastische Performance-Unterschied (Faktor 20 in die falsche Richtung) kann kein Zufall sein. Die Arrays sind alle auf 16 Byte &quot;aligned&quot;, daran liegt es also auch nicht. Die Zahl der Iterationen ist num=1000, es kann also auch kaum an irgendeinem Funktionen-Oberhead liegen.</p>
<p>Wahrscheinlich ist es ein ziemlich bloeder Fehler - wie so oft. Ich hoffe irgendjemand von euch hat Erfahrungen mit SSE-Programmierung. Muss man die SSE-Anweisungen erst irgendwie aktivieren? Kann es sein, dass SSE bei mir emuliert wird?</p>
<p>Viele Gruesse,<br />
Stefan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1225405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1225405</guid><dc:creator><![CDATA[McCool]]></dc:creator><pubDate>Thu, 08 Feb 2007 23:24:08 GMT</pubDate></item><item><title><![CDATA[Reply to SSE - Aktivierung notwendig? Mein SSE-Code ist 20x langsamer als Standard C on Thu, 08 Feb 2007 23:30:23 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=403" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=1" rel="nofollow">MFC (Visual C++)</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1225408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1225408</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Thu, 08 Feb 2007 23:30:23 GMT</pubDate></item></channel></rss>