<?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[Frage zur automatischen Vektorisierung]]></title><description><![CDATA[<p>Hi, ich habe eine Frage zur automatischen Vektorisierung. Folgenden Code gilt es zu vektorisieren:<br />
Es gibt 512 Kompilezeit-Konstanten, die zu einem Array aus 512 Elementen multipliziert werden sollen:</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
// Liste an Kompilezeit-Konstanten (in der &quot;richtigen&quot; Reihenfolge)
static const double c0 = 65.6758;
static const double c1 = 90.9146;
static const double c2 = 45.5458;
//..
static const double c511 = 54.6342;

void f(double *p)
{
	p[0] *= c0;
	p[1] *= c1;
	p[2] *= c2;
//...
	p[511] *= c511;
}

int main()
{
	double arr[512];
	for(int i=0; i!=512; ++i)
		arr[i] = (100.*std::rand())/RAND_MAX;

	f(arr);

	for(int i=0; i!=512; ++i)
		std::cout&lt;&lt;arr[i];
}
</code></pre>
<p>Das Problem: Clang und VS13 vektorisieren den Code, nur der gcc scheitert:</p>
<p>Clang 3.4 mit <strong>-mtune=native -march=native -Ofast</strong>: <a href="http://goo.gl/tLpIQ5" rel="nofollow">http://goo.gl/tLpIQ5</a><br />
g++ 4.8 mit <strong>-mtune=native -march=native -Ofast</strong>: <a href="http://goo.gl/jfC74j" rel="nofollow">http://goo.gl/jfC74j</a><br />
VS2013 mit <strong>/fp:fast /arch:AVX2 /Ox /Ot</strong>: Vektorisiert auch, aber dafür gibts leider keinen online Code <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Kann sich jemand vorstellen, was den gcc am vektorisieren hindert?</p>
<p>P.S.: Ich würde das Ganze gerne ohne Schleife lösen, weil es so meinem &quot;realen&quot; Problem näher kommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326648/frage-zur-automatischen-vektorisierung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 25 May 2026 12:32:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326648.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 29 Jun 2014 00:56:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zur automatischen Vektorisierung on Sun, 29 Jun 2014 00:56:16 GMT]]></title><description><![CDATA[<p>Hi, ich habe eine Frage zur automatischen Vektorisierung. Folgenden Code gilt es zu vektorisieren:<br />
Es gibt 512 Kompilezeit-Konstanten, die zu einem Array aus 512 Elementen multipliziert werden sollen:</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
// Liste an Kompilezeit-Konstanten (in der &quot;richtigen&quot; Reihenfolge)
static const double c0 = 65.6758;
static const double c1 = 90.9146;
static const double c2 = 45.5458;
//..
static const double c511 = 54.6342;

void f(double *p)
{
	p[0] *= c0;
	p[1] *= c1;
	p[2] *= c2;
//...
	p[511] *= c511;
}

int main()
{
	double arr[512];
	for(int i=0; i!=512; ++i)
		arr[i] = (100.*std::rand())/RAND_MAX;

	f(arr);

	for(int i=0; i!=512; ++i)
		std::cout&lt;&lt;arr[i];
}
</code></pre>
<p>Das Problem: Clang und VS13 vektorisieren den Code, nur der gcc scheitert:</p>
<p>Clang 3.4 mit <strong>-mtune=native -march=native -Ofast</strong>: <a href="http://goo.gl/tLpIQ5" rel="nofollow">http://goo.gl/tLpIQ5</a><br />
g++ 4.8 mit <strong>-mtune=native -march=native -Ofast</strong>: <a href="http://goo.gl/jfC74j" rel="nofollow">http://goo.gl/jfC74j</a><br />
VS2013 mit <strong>/fp:fast /arch:AVX2 /Ox /Ot</strong>: Vektorisiert auch, aber dafür gibts leider keinen online Code <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Kann sich jemand vorstellen, was den gcc am vektorisieren hindert?</p>
<p>P.S.: Ich würde das Ganze gerne ohne Schleife lösen, weil es so meinem &quot;realen&quot; Problem näher kommt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406145</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406145</guid><dc:creator><![CDATA[asdfasd]]></dc:creator><pubDate>Sun, 29 Jun 2014 00:56:16 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur automatischen Vektorisierung on Sun, 29 Jun 2014 11:32:34 GMT]]></title><description><![CDATA[<p>Vielleicht greift der Autovektorisierer vom GCC nur bei ausgeschriebenen Schleifen?</p>
<p>Ist klar, dass das im Prinzip eine geunrollte Schleife darstellen soll, aber das muss der Vektorisierer nicht wissen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406169</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 29 Jun 2014 11:32:34 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur automatischen Vektorisierung on Sun, 29 Jun 2014 13:34:10 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Vielleicht greift der Autovektorisierer vom GCC nur bei ausgeschriebenen Schleifen?</p>
</blockquote>
<p>Diesen Eindruck habe ich auch.<br />
Ausserdem sollte man sich noch um vernünftiges Alignment kümmern (bei clang scheint dass allerdings nicht zu helfen). <a href="http://goo.gl/tN4t8u" rel="nofollow">http://goo.gl/tN4t8u</a><br />
Aussgeschrieben dürfte der Spass allein schon wegen der Codegröße langsamer sein.<br />
-ffast-math ist dagegen nicht erforderlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406196</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406196</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sun, 29 Jun 2014 13:34:10 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zur automatischen Vektorisierung on Sun, 29 Jun 2014 13:42:06 GMT]]></title><description><![CDATA[<blockquote>
<p>-ffast-math ist dagegen nicht erforderlich.</p>
</blockquote>
<p>Warum, die Berechnung operiert doch mit Fließkommazahlen (laut dem <a href="https://gcc.gnu.org/projects/tree-ssa/vectorization.html#using" rel="nofollow">Manual</a> ist das Flag daher nötig)? Und <code>-ffast-math</code> wird doch durch <code>-Ofast</code> aktiviert?</p>
<p>Edit: Achso, man braucht es nur für Reduktionen, oder?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2406198</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2406198</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 29 Jun 2014 13:42:06 GMT</pubDate></item></channel></rss>