compiler-optimization

C# Alias an Attribute (such as Inline Hinting)

六眼飞鱼酱① 提交于 2019-12-12 00:38:29
问题 I've been wanting for a while to shorten the (no- using -pollution) "inline" attribute from the absurdity that is: [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] to, well, [InlineHint] or [MyCompilerSvcs.InlineHint] or similar- something both quicker to type and quicker to mentally parse. Is there any way to actually do that? Right now the only "sane" options I can see are to either add using System.Runtime.CompilerServices;

How to find the address & length of a C++ function at runtime (MinGW)

淺唱寂寞╮ 提交于 2019-12-11 19:19:57
问题 As this is my first post to stackoverflow I want to thank you all for your valuable posts that helped me a lot in the past. I use MinGW (gcc 4.4.0) on Windows-7(64) - more specifically I use Nokia Qt + MinGW but Qt is not involved in my Question. I need to find the address and -more important- the length of specific functions of my application at runtime, in order to encode/decode these functions and implement a software protection system. I already found a solution on how to compute the

How can I reduce the size of a compiled Delphi code? [duplicate]

南楼画角 提交于 2019-12-11 15:11:50
问题 This question already has answers here : EXE Size is too big in Delphi XE2 (2 answers) Closed 6 years ago . I just wrote a really short and simple code in Delphi with no even arrays neither data structures and when I compile it I get a 11 MB exe file , it was compiled for 32 bits architecture under RAD Studio X3 IDE for 64 bits. I think this isn't optimal , even a jar would weigh less! Are there any settings I can do so I get a smaller compiled? Maybe any units I can dismiss in the code? 回答1:

How is speculative fault due to compiler optimization implemented under the hood?

☆樱花仙子☆ 提交于 2019-12-11 12:06:21
问题 This question is a follow-up question on Can the C compiler optimizer violate short-circuiting and reorder memory accesses for operands in a logical-AND expression?. Consider the following code. if (*p && *q) { /* do something */ } Now as per the discussion at Can the C compiler optimizer violate short-circuiting and reorder memory accesses for operands in a logical-AND expression? (especially David Schwartz comment and answer) it is possible for the optimizer of a standard-conformant C

How much instruction-level optimisation can a JIT apply?

一笑奈何 提交于 2019-12-11 11:22:02
问题 To what extent can a JIT replace platform independent code with processor-specific machine instructions? For example, the x86 instruction set includes the BSWAP instruction to reverse a 32-bit integer's byte order. In Java the Integer.reverseBytes() method is implemented using multiple bitwise masks and shifts, even though in x86 native code it could be implemented in a single instruction using BSWAP . Are JITs (or static compilers for that matter) able to make the change automatically or is

__int128 alignment segment fault with gcc -O SSE optimize

谁说胖子不能爱 提交于 2019-12-11 09:51:49
问题 I use __int128 as struct's member. It works find with -O0 (no optimization). However it crashes for segment fault if optimization enabled ( -O1 ). It crashes at instruction movdqa , which need the var aligned by 16. While the address is allocated by malloc() which align only by 8. I tried to disable SSE optimization by -mno-sse , but it fails to compile: /usr/include/x86_64-linux-gnu/bits/stdlib-float.h:27:1: error: SSE register return with SSE disabled So what can I do if I want to use _

Are there multiple member functions compiled for each C++ object?

£可爱£侵袭症+ 提交于 2019-12-11 08:57:43
问题 I know that when we create multiple objects of a given class type, multiple copies of the member variables are created. Each object has it's separate set of member variables. Does this work the same way with member functions too? If my class has a lot of functions, do the member functions get duplicated for each object that is created? Does each created object have it's own set of the member functions? class demo { public: int height; int width; void setheight(int height) { this->height =

Why does main initialize stack frame when there are no variables

僤鯓⒐⒋嵵緔 提交于 2019-12-11 07:57:31
问题 why does this code: #include "stdio.h" int main(void) { puts("Hello, World!"); } decide to initialize a stack frame? Here is the assembly code: .LC0: .string "Hello, World!" main: push rbp mov rbp, rsp mov edi, OFFSET FLAT:.LC0 call puts mov eax, 0 pop rbp ret Why does the compiler initialize a stack frame only for it to be destroyed later, withoput it ever being used? This surely wont cause any errors on the outside of the main function because I never use the stack, so I wont cause any

How to read a file into a vector elegantly and efficiently?

梦想与她 提交于 2019-12-11 07:13:17
问题 #include <fstream> #include <vector> #include <algorithm> #include <iterator> using namespace std; vector<char> f1() { ifstream fin{ "input.txt", ios::binary }; return { istreambuf_iterator<char>(fin), istreambuf_iterator<char>() }; } vector<char> f2() { vector<char> coll; ifstream fin{ "input.txt", ios::binary }; char buf[1024]; while (fin.read(buf, sizeof(buf))) { copy(begin(buf), end(buf), back_inserter(coll)); } copy(begin(buf), begin(buf) + fin.gcount(), back_inserter(coll)); return coll

Do C++ compilers avoid copying when returning by value?

断了今生、忘了曾经 提交于 2019-12-11 06:42:47
问题 Consider the following code: LargeObject getLargeObject() { LargeObject glo; // do some initialization stuff with glo return glo; } void test() { LargeObject tlo = getLargeObject(); // do sth. with tlo; } A simple compiler would create a local LargeObject glo on the getLargeObject() stack and then assign it to tlo in test() when returning, which involves a copy operation. But shouldn't a clever compiler realize that glo is going to be assigned to tlo and thus just use tlo's memory in the