compiler-optimization

Is it possible to strip type names from executable while keeping RTTI enabled?

最后都变了- 提交于 2019-12-21 06:25:11
问题 I recently disabled RTTI on my compiler (MSVC10) and the executable size decreased significantly. By comparing the produced executables using a text editor, I found that the RTTI-less version contains much less symbol names, explaining the saved space. AFAIK, those symbol names are only used to fill the type_info structure associated with each the polymorphic type, and one can programmatically access them calling type_info::name() . According to the standard, the format of the string returned

Is it possible to strip type names from executable while keeping RTTI enabled?

独自空忆成欢 提交于 2019-12-21 06:24:12
问题 I recently disabled RTTI on my compiler (MSVC10) and the executable size decreased significantly. By comparing the produced executables using a text editor, I found that the RTTI-less version contains much less symbol names, explaining the saved space. AFAIK, those symbol names are only used to fill the type_info structure associated with each the polymorphic type, and one can programmatically access them calling type_info::name() . According to the standard, the format of the string returned

Which one is faster ? Function call or Conditional if Statement?

青春壹個敷衍的年華 提交于 2019-12-21 04:40:59
问题 Please consider the branch prediction too before answering this question. I have some scenarios where i can replace a conditional statement with a call to a function with the help of function pointer.Some thing like this. (you can think of component based programming over inheritance for a similar type of senario) class Shape { float Area() { if(type == SQUARE) { return length*length; } else if(type == RECTANGLE) { return length*breadth; } } } The same class can be written like this. class

C++ constant folding a loop for prime numbers

青春壹個敷衍的年華 提交于 2019-12-21 03:55:19
问题 Having had a look at previous questions 1, 2 , I was wondering if I can force the compiler to perform a constant folding for the following code which prints prime numbers. #include <iostream> using namespace std; inline bool is_prime(int n) { if(n<2) return false; for(int i=2;i*i<=n;i++) if(n%i==0) return false; return true; } int main() { for(int i=0;i<20;i++) if(is_prime(i)) cout<<i<<endl; return 0; } And I build it via: g++ -O3 -S main.cpp -o main.asm As the result are a few: 2,3,5,7,11,13

Get GCC To Use Carry Logic For Arbitrary Precision Arithmetic Without Inline Assembly?

ぐ巨炮叔叔 提交于 2019-12-21 01:07:22
问题 When working with arbitrary precision arithmetic (e.g. 512-bit integers), is there any way to get GCC to use ADC and similar instructions without using inline assembly? A first glance at GMP's sourcecode shows that they simply have assembly implementations for every supported platform. Here is the test code I wrote, which adds two 128-bit numbers from the command line and prints the result. (Inspired by mini-gmp's add_n): #include <stdio.h> #include <stdint.h> #include <stdlib.h> int main

Why isn't this unused variable optimised away?

久未见 提交于 2019-12-20 16:12:46
问题 I played around with Godbolt's CompilerExplorer. I wanted to see how good certain optimizations are. My minimum working example is: #include <vector> int foo() { std::vector<int> v {1, 2, 3, 4, 5}; return v[4]; } The generated assembler (by clang 5.0.0, -O2 -std=c++14): foo(): # @foo() push rax mov edi, 20 call operator new(unsigned long) mov rdi, rax call operator delete(void*) mov eax, 5 pop rcx ret As one can see, clang knows the answer, but does quite a lot of stuff before returning. It

C Programming: difference between ++i and i=i+1 from an assembler point of view?

拜拜、爱过 提交于 2019-12-20 12:27:52
问题 This was an interview question. I said they were the same, but this was adjudged an incorrect response. From the assembler point of view, is there any imaginable difference? I have compiled two short C programs using default gcc optimization and -S to see the assembler output, and they are the same. 回答1: The interviewer may have wanted an answer something like this: i=i+1 will have to load the value of i , add one to it, and then store the result back to i . In contrast, ++i may simply

Disable compiler optimisation for a specific function or block of code (C#)

此生再无相见时 提交于 2019-12-20 11:24:26
问题 The compiler does a great job of optimising for RELEASE builds, but occasionally it can be useful to ensure that optimisation is turned off for a local function (but not the entire project by unticking Project Options > Optimize code ). In C++ this is achieved using the following (with the #pragma normally commented out): #pragma optimize( "", off ) // Some code such as a function (but not the whole project) #pragma optimize( "", on ) Is there an equivalent in C#? UPDATE Several excellent

Disable compiler optimisation for a specific function or block of code (C#)

拜拜、爱过 提交于 2019-12-20 11:24:10
问题 The compiler does a great job of optimising for RELEASE builds, but occasionally it can be useful to ensure that optimisation is turned off for a local function (but not the entire project by unticking Project Options > Optimize code ). In C++ this is achieved using the following (with the #pragma normally commented out): #pragma optimize( "", off ) // Some code such as a function (but not the whole project) #pragma optimize( "", on ) Is there an equivalent in C#? UPDATE Several excellent

Why would the .NET JIT compiler decide to not inline or optimize away calls to empty static methods that have no side effects?

时光怂恿深爱的人放手 提交于 2019-12-20 11:10:41
问题 I think I'm observing the .NET JIT compiler not inlining or optimizing away calls to empty static methods that have no side effects, which is a bit surprising given some bespoken online resources. My environment is Visual Studio 2013 on x64, Windows 8.1, .NET Framework 4.5. Given this simple test program (https://ideone.com/2BRCpC) class Program { static void EmptyBody() { } static void Main() { EmptyBody(); } } A release build with optimizations of the above program produces the following