optimization gcc vs fpc lazarus / 64-FPC development ---------------------------------------------------------------------- fcu · 2019-04-23 13:49 Hi just looking how fpc optimize this function compared with how gcc does gcc seems smarter, it reduce it to one instruction while fpc didn't noticed it require only one instruction both codes compiled with -O3 ---------------------------------------------------------------------- 440bx · 2019-04-23 14:01 Quote from: fcu on April 23, 2019, 03:49:54 pmjust looking how fpc optimize this function compared with how gcc does gcc seems smarter, it reduce it to one instruction while fpc didn't noticed it require only one instruction both codes compiled with -O3 You'll find many such cases.  A lot of C/C++ programmers are addicted to optimizing code.  That can be a good thing sometimes but, sometimes it isn't (no shortage of times when one looks at a piece of C/C++ code and thinks... what the hell is this supposed to do !?) ---------------------------------------------------------------------- marcov · 2019-04-23 14:11 This is a bit a specific case for C. Because there are so many C compilers, and umpteen codebases all have such constructs for endianswaps, they added a peephole. A more logical FPC way would be to simply declare an intrinsic. ---------------------------------------------------------------------- ASerge · 2019-04-23 18:13 By the way, this is assembler code for System.SwapEndian(X) Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ; SYSTEM_$$_SWAPENDIAN$LONGWORD$$LONGWORD mov %ecx,%eaxbswap  %eaxretqFPC 3.0.4, x64, Windows ---------------------------------------------------------------------- fcu · 2019-04-23 21:03 Quote from: ASerge on April 23, 2019, 08:13:08 pmBy the way, this is assembler code for System.SwapEndian(X) Code: ASM  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ; SYSTEM_$$_SWAPENDIAN$LONGWORD$$LONGWORD mov %ecx,%eaxbswap  %eaxretq what version do you have ? i am using 3.0.4 32bits  ,and this is the asm of this function ---------------------------------------------------------------------- ASerge · 2019-04-23 22:04 Quote from: fcu on April 23, 2019, 11:03:57 pmwhat version do you have ? i am using 3.0.4 32bits  ,and this is the asm of this function As I wrote 64-bit. Can be 32 bit code such because the BSWAP instruction is not supported on IA-32 processors earlier than the Intel 486 processor family?