<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	「Step to UEFI (159）UEFI 下的排序」的评论	</title>
	<atom:link href="https://www.lab-z.com/sortuefi/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lab-z.com/sortuefi/</link>
	<description></description>
	<lastBuildDate>Fri, 28 Jun 2019 02:35:05 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>
	<item>
		<title>
		评论者：ziv2013		</title>
		<link>https://www.lab-z.com/sortuefi/#comment-61505</link>

		<dc:creator><![CDATA[ziv2013]]></dc:creator>
		<pubDate>Fri, 28 Jun 2019 02:35:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.lab-z.com/?p=5872#comment-61505</guid>

					<description><![CDATA[回复给 &lt;a href=&quot;https://www.lab-z.com/sortuefi/#comment-61489&quot;&gt;zeevoo7O&lt;/a&gt;。

不错，长知识。谢谢！]]></description>
			<content:encoded><![CDATA[<p>回复给 <a href="https://www.lab-z.com/sortuefi/#comment-61489">zeevoo7O</a>。</p>
<p>不错，长知识。谢谢！</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		评论者：hoo6hohV		</title>
		<link>https://www.lab-z.com/sortuefi/#comment-61490</link>

		<dc:creator><![CDATA[hoo6hohV]]></dc:creator>
		<pubDate>Thu, 27 Jun 2019 14:32:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.lab-z.com/?p=5872#comment-61490</guid>

					<description><![CDATA[回复给 &lt;a href=&quot;https://www.lab-z.com/sortuefi/#comment-61489&quot;&gt;zeevoo7O&lt;/a&gt;。

比如说除以 29，clang 编译出来的汇编，edi 输入，eax 输出：
[code]
   0:	48 63 c7             	movsxd rax,edi
   3:	48 69 c8 09 cb 3d 8d 	imul   rcx,rax,0xffffffff8d3dcb09
   a:	48 c1 e9 20          	shr    rcx,0x20
   e:	01 c8                	add    eax,ecx
  10:	89 c1                	mov    ecx,eax
  12:	c1 e9 1f             	shr    ecx,0x1f
  15:	c1 f8 04             	sar    eax,0x4
  18:	01 c8                	add    eax,ecx
[/code]]]></description>
			<content:encoded><![CDATA[<p>回复给 <a href="https://www.lab-z.com/sortuefi/#comment-61489">zeevoo7O</a>。</p>
<p>比如说除以 29，clang 编译出来的汇编，edi 输入，eax 输出：</p>
<pre class="brush: plain; title: ; notranslate">
   0:	48 63 c7             	movsxd rax,edi
   3:	48 69 c8 09 cb 3d 8d 	imul   rcx,rax,0xffffffff8d3dcb09
   a:	48 c1 e9 20          	shr    rcx,0x20
   e:	01 c8                	add    eax,ecx
  10:	89 c1                	mov    ecx,eax
  12:	c1 e9 1f             	shr    ecx,0x1f
  15:	c1 f8 04             	sar    eax,0x4
  18:	01 c8                	add    eax,ecx
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		评论者：zeevoo7O		</title>
		<link>https://www.lab-z.com/sortuefi/#comment-61489</link>

		<dc:creator><![CDATA[zeevoo7O]]></dc:creator>
		<pubDate>Thu, 27 Jun 2019 14:24:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.lab-z.com/?p=5872#comment-61489</guid>

					<description><![CDATA[C 标准库有 qsort：https://en.cppreference.com/w/c/algorithm/qsort
C++ 标准库有 std::sort：https://en.cppreference.com/w/cpp/algorithm/sort

据说 benchmark 下来 C++ 的 std::sort 比 C 标准库的 qsort 快，原因在于 C++ 会 inline 这个 compare：https://stackoverflow.com/q/4708105/1190191

说到性能，算法是第一的。在算法一样的情况下，实现以及编译器优化也会影响性能。前阶段看见一个 benchmark：
https://benchmarksgame-team.pages.debian.net/benchmarksgame/which-programs-are-fastest.html
发现（比 C 更“高级”，有更多抽象）Rust 语言平均性能竟然可以比 C 更好（通常我们认为高级语言性能比不过底层语言）。我最近学了一下，随便写了一个性能测试的代码，正好 Rust 版本跑得比 C 快。我估计和数值计算里面 Fortran 可以优化得性能超过 C 类似，一些语言性能能辅助编译器优化（比如 Rust 里面的 immutable 和 borrowing）。建议有空学一下：https://www.rust-lang.org/learn

之前我知道我手写汇编性能不如 C，但不知道更高级的语言现在也能有类似现象（同样算法 Java 一般还是比不过 C 的）。在 C 这个层面，编译器很多优化我手写很难做（而且容易出错）。最简单的是整数除法 int x = y/5; 这种编译器用（溢出）的乘法和位运算能高效计算除以常数，比 div 高效得多。还有 vectorization，充分利用新的指令集等等。]]></description>
			<content:encoded><![CDATA[<p>C 标准库有 qsort：https://en.cppreference.com/w/c/algorithm/qsort<br />
C++ 标准库有 std::sort：https://en.cppreference.com/w/cpp/algorithm/sort</p>
<p>据说 benchmark 下来 C++ 的 std::sort 比 C 标准库的 qsort 快，原因在于 C++ 会 inline 这个 compare：https://stackoverflow.com/q/4708105/1190191</p>
<p>说到性能，算法是第一的。在算法一样的情况下，实现以及编译器优化也会影响性能。前阶段看见一个 benchmark：<br />
<a href="https://benchmarksgame-team.pages.debian.net/benchmarksgame/which-programs-are-fastest.html" rel="nofollow ugc">https://benchmarksgame-team.pages.debian.net/benchmarksgame/which-programs-are-fastest.html</a><br />
发现（比 C 更“高级”，有更多抽象）Rust 语言平均性能竟然可以比 C 更好（通常我们认为高级语言性能比不过底层语言）。我最近学了一下，随便写了一个性能测试的代码，正好 Rust 版本跑得比 C 快。我估计和数值计算里面 Fortran 可以优化得性能超过 C 类似，一些语言性能能辅助编译器优化（比如 Rust 里面的 immutable 和 borrowing）。建议有空学一下：https://www.rust-lang.org/learn</p>
<p>之前我知道我手写汇编性能不如 C，但不知道更高级的语言现在也能有类似现象（同样算法 Java 一般还是比不过 C 的）。在 C 这个层面，编译器很多优化我手写很难做（而且容易出错）。最简单的是整数除法 int x = y/5; 这种编译器用（溢出）的乘法和位运算能高效计算除以常数，比 div 高效得多。还有 vectorization，充分利用新的指令集等等。</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
