Why would introducing useless MOV instructions speed up a tight loop in x86_64 assembly?

Background: While optimizing some Pascal code with embedded assembly language, I noticed an unnecessary MOV instruction, and removed it. To my surprise, removing the un-necessary instruction caused my program to slow down. I found that adding arbitrary, useless MOV instructions increased performance even further. The effect is erratic, and changes based on execution order: the … Read more

Why does GCC use multiplication by a strange number in implementing integer division?

I’ve been reading about div and mul assembly operations, and I decided to see them in action by writing a simple program in C: File division.c #include <stdlib.h> #include <stdio.h> int main() { size_t i = 9; size_t j = i / 5; printf(“%zu\n”,j); return 0; } And then generating assembly language code with: gcc … Read more

Submit to App Store issues: Unsupported Architecture x86

So I am trying to use the Shopify API. When I archive the app and validate it then there are no issues but when I submit it to the app store then it gives me the following issues. ERROR ITMS-90087: “Unsupported Architecture. Your executable contains unsupported architecture ‘[x86_64, i386]’.” ERROR ITMS-90209: “Invalid segment Alignment. The … Read more

Why does GCC generate 15-20% faster code if I optimize for size instead of speed?

I first noticed in 2009 that GCC (at least on my projects and on my machines) have the tendency to generate noticeably faster code if I optimize for size (-Os) instead of speed (-O2 or -O3), and I have been wondering ever since why. I have managed to create (rather silly) code that shows this … Read more