<story><title>Optimization story: Switching from GMP to gcc&apos;s __int128 reduced run time by 95%</title><url>https://www.nu42.com/2016/01/excellent-optimization-story.html</url></story><parent_chain></parent_chain><comment><author>sebcat</author><text>FWIW, __int128 and the optimizations mentioned works in clang too, my guess is that the author just runs an old version.&lt;p&gt;&lt;pre&gt;&lt;code&gt;    #include &amp;lt;stdio.h&amp;gt;
    
    int main() {
    	FILE *fp;
    	__int128 v=1234;
    
    	fp = fopen(&amp;quot;foo12&amp;quot;, &amp;quot;w&amp;quot;);
    	fwrite(&amp;amp;v, sizeof(v), 1, fp);
    	fclose(fp);
    
    	return 0;
    }
&lt;/code&gt;&lt;/pre&gt;
with -O2 -march=native -ffinite-math-only -fno-math-errno, for clang 3.5.0, linux&amp;#x2F;amd64, gives me:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    4005d0:	53                   	push   %rbx
    4005d1:	48 83 ec 10          	sub    $0x10,%rsp
    4005d5:	48 c7 44 24 08 00 00 	movq   $0x0,0x8(%rsp)
    4005dc:	00 00 
    4005de:	48 c7 04 24 d2 04 00 	movq   $0x4d2,(%rsp)
    4005e5:	00 
    4005e6:	bf b0 06 40 00       	mov    $0x4006b0,%edi
    4005eb:	be b6 06 40 00       	mov    $0x4006b6,%esi
    4005f0:	e8 bb fe ff ff       	callq  4004b0 &amp;lt;fopen@plt&amp;gt;
    4005f5:	48 89 c3             	mov    %rax,%rbx
    4005f8:	48 8d 3c 24          	lea    (%rsp),%rdi
    4005fc:	be 10 00 00 00       	mov    $0x10,%esi
    400601:	ba 01 00 00 00       	mov    $0x1,%edx
    400606:	48 89 d9             	mov    %rbx,%rcx
    400609:	e8 b2 fe ff ff       	callq  4004c0 &amp;lt;fwrite@plt&amp;gt;
    40060e:	48 89 df             	mov    %rbx,%rdi
    400611:	e8 6a fe ff ff       	callq  400480 &amp;lt;fclose@plt&amp;gt;
    400616:	31 c0                	xor    %eax,%eax
    400618:	48 83 c4 10          	add    $0x10,%rsp
    40061c:	5b                   	pop    %rbx
    40061d:	c3                   	retq   
    40061e:	66 90                	xchg   %ax,%ax&lt;/code&gt;&lt;/pre&gt;</text></comment>
<story><title>Optimization story: Switching from GMP to gcc&apos;s __int128 reduced run time by 95%</title><url>https://www.nu42.com/2016/01/excellent-optimization-story.html</url></story><parent_chain></parent_chain><comment><author>soldergenie</author><text>I ran into the need for this recently, except for a program written in Java...   I really wish the JVM had a 128 bit data type (or at least a muldiv function, in which muldiv(a, b, c) = a&lt;i&gt;b&amp;#x2F;c, but the intermediate a&lt;/i&gt;b result can exceed 64 bits.</text></comment>