compiler-optimization

The impact of multiple compiler definitions in system.codedom in web.config

六眼飞鱼酱① 提交于 2019-12-01 21:58:48
All my ASP.NET web projects are being developed exclusively in VB.NET. (And so are the satellite DLL projects, which is probably less relevant. When I look at the default web.config file, under the <system.codedom> tag, I always find compiler definitions present for both C# and VB.NET, as illustrated below. <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="WarnAsError"

Is it realistic to use -O3 or -Ofast to compile your benchmark code or will it remove code?

冷暖自知 提交于 2019-12-01 20:56:27
When compiling the benchmark code below with -O3 I was impressed by the difference it made in latency so i began to wonder whether the compiler is not "cheating" by removing code somehow. Is there a way to check for that? Am I safe to benchmark with -O3 ? Is it realistic to expect 15x gains in speed? Results without -O3 : Average: 239 nanos Min: 230 nanos (9 million iterations) Results with -O3 : Average: 14 nanos, Min: 12 nanos (9 million iterations) int iterations = stoi(argv[1]); int load = stoi(argv[2]); long long x = 0; for(int i = 0; i < iterations; i++) { long start = get_nano_ts(); //

What's up with gcc weird stack manipulation when it wants extra stack alignment?

我的梦境 提交于 2019-12-01 19:46:59
I've seen this r10 weirdness a few times, so let's see if anyone knows what's up. Take this simple function: #define SZ 4 void sink(uint64_t *p); void andpop(const uint64_t* a) { uint64_t result[SZ]; for (unsigned i = 0; i < SZ; i++) { result[i] = a[i] + 1; } sink(result); } It just adds 1 to each of the 4 64-bit elements of the passed-in array and stores it in a local and calls sink() on the result (to avoid the whole function being optimized away). Here's the corresponding assembly: andpop(unsigned long const*): lea r10, [rsp+8] and rsp, -32 push QWORD PTR [r10-8] push rbp mov rbp, rsp push

Can I tell javac to ignore the lack of `import foo.Bar`?

百般思念 提交于 2019-12-01 19:30:12
I'm using reflection to load MyClass.class (an external file) at runtime. MyClass.class uses the library Bar , which would mean that I need to place import foo.Bar; at the top of the file. However, the Bar library is already loaded in the main class loading MyClass . Is there a way for me to tell javac to ignore that Bar doesn't exist and just compile without it? No this is not possible. When compiling a class, the compiler has no "memory" of which classes were already "loaded" (don't confuse this with the concept related to classloading -- that's a completely different story). Whenever a

Regarding optimization for 'not a statment' in c?

眉间皱痕 提交于 2019-12-01 18:29:20
While Learning compiler Optimisation, I write codes in C under Linux with GCC version gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5.1) To understant not a statement (nop) in C. I written two codes first y.c second x.c and generate their compiled assembly code using gcc -S option. Fist code y.c desktop:~$ cat y.c main() { int i=0; } desktop:~$ gcc -S y.c desktop:~$ Second code x.c desktop:~$ cat x.c main() { int i=0; /* Loops and if*/ while(0); for(;0;); if(0); /* Arithmetic Operations */ i * i; i / i; i - i; i + i; i % i; +i; -i; /* Comparison operators */ i == i; i != i; i < i; i > i; i >=

Regarding optimization for 'not a statment' in c?

三世轮回 提交于 2019-12-01 17:43:21
问题 While Learning compiler Optimisation, I write codes in C under Linux with GCC version gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5.1) To understant not a statement (nop) in C. I written two codes first y.c second x.c and generate their compiled assembly code using gcc -S option. Fist code y.c desktop:~$ cat y.c main() { int i=0; } desktop:~$ gcc -S y.c desktop:~$ Second code x.c desktop:~$ cat x.c main() { int i=0; /* Loops and if*/ while(0); for(;0;); if(0); /* Arithmetic Operations */ i

Is Java evaluation order guaranteed in this case of method call and arguments passed in

大兔子大兔子 提交于 2019-12-01 17:41:28
I did some reading up on JLS 15.7.4 and 15.12.4.2 , but it doesn't guarantee that there won't be any compiler/runtime optimization that would change the order in which method arguments are evaluated. Assume the following code: public static void main (String[] args) { MyObject obj = new MyObject(); methodRelyingOnEvalOrder(obj, obj.myMethod()); } public static Object methodRelyingOnEvalOrder(MyObject obj, Object input) { if (obj.myBoolean()) return null; else return input; } Is it guaranteed that the compiler or runtime will not do a false optimization such as the following? This optimization

Can HotSpot optimize away redundant calls to pure methods without inlining them?

孤人 提交于 2019-12-01 17:02:35
问题 Pure methods are those without side effects: their only effect is to return a value which is a function of their arguments. Two calls to the same pure method with the same arguments will return the same value. So, given two calls to a pure method with identical arguments, can HotSpot optimize away the second call, simply re-using the value from the first call? For example: int add(int x, int y) { return x + y; } int addTwice(int x, int y) { return add(x, y) + add(x, y); } If HotSpot doesn't

Can HotSpot optimize away redundant calls to pure methods without inlining them?

£可爱£侵袭症+ 提交于 2019-12-01 16:56:37
Pure methods are those without side effects: their only effect is to return a value which is a function of their arguments. Two calls to the same pure method with the same arguments will return the same value. So, given two calls to a pure method with identical arguments, can HotSpot optimize away the second call, simply re-using the value from the first call? For example: int add(int x, int y) { return x + y; } int addTwice(int x, int y) { return add(x, y) + add(x, y); } If HotSpot doesn't inline add inside addTwice does it understand that add is pure and thus call add only once and double

Will compiler optimize out unused arguments of static function?

∥☆過路亽.° 提交于 2019-12-01 16:08:07
I have a group of functions that are all declared static and fastcall . Most of them make use of a pointer to a struct that serves more or less the role of this in C++. Some of the functions don't need anything in the struct, but for uniformity sake I want to pass them the pointer anyway. Will the compiler notice that the argument is not used and omit allocating a register to it? I wrote this nonsense program to test this. It's got some nonsense code in the function, and calls it several times because otherwise the compiler just inlined the whole function call making the test useless. (It's a