compiler-optimization

Why do I have to turn on optimization in g++ for simple array access?

拥有回忆 提交于 2020-01-11 08:24:11
问题 I have written a simple Gaussian elimination algorithm using a std::vector of double s in C++ (gcc / Linux). Now I have seen that the runtime depends on the optimization level of the compiler (up to 5-times faster with -O3 ). I wrote a small test program and received similar results. The problem is not the allocation of the vector nor any resizing etc. It's the simple fact that the statement: v[i] = x + y / z; (or something like that) is much slower without optimization. I think the problem

Why do I have to turn on optimization in g++ for simple array access?

你说的曾经没有我的故事 提交于 2020-01-11 08:23:41
问题 I have written a simple Gaussian elimination algorithm using a std::vector of double s in C++ (gcc / Linux). Now I have seen that the runtime depends on the optimization level of the compiler (up to 5-times faster with -O3 ). I wrote a small test program and received similar results. The problem is not the allocation of the vector nor any resizing etc. It's the simple fact that the statement: v[i] = x + y / z; (or something like that) is much slower without optimization. I think the problem

Bloated EXE sizes, and unwanted dependencies with Qt/MingW

安稳与你 提交于 2020-01-11 03:11:38
问题 I'm trying to figure out how to shrink the sizes of EXE files compiled under the newest QT SDK (4.8.2) (mingw/g++ based). I was working on a vanilla c++ console app that has a simple loop and only #includes iostream, when I noticed that the exe's it generated are about 465kb; way bigger than they should be! Commenting out all the stream stuff brings it down to the expected 5kb range (although the remaining code would be mostly dead). This doesn't seem right at all, especially since another,

Why do Compilers put data inside .text(code) section of the PE and ELF files and how does the CPU distinguish between data and code?

梦想与她 提交于 2020-01-11 03:02:08
问题 So i am referencing this paper : Binary Stirring: Self-randomizing Instruction Addresses of Legacy x86 Binary Code https://www.utdallas.edu/~hamlen/wartell12ccs.pdf Code interleaved with data: Modern compilers aggressively interleave static data within code sections in both PE and ELF binaries for performance reasons. In the compiled binaries there is generally no means of distinguishing the data bytes from the code. Inadvertently randomizing the data along with the code breaks the binary,

How to disable compiler optimizations in gcc?

感情迁移 提交于 2020-01-09 08:27:28
问题 I am trying to learn assembly language. I have searched and found how to disassemble a .c file but I think it produces some optimized version of the program. Is there any way so that I can see the exact assembly code which corresponds to my C file. 回答1: The gcc option -O enables different levels of optimization. Use -O0 to disable them and use -S to output assembly. -O3 is the highest level of optimization. Starting with gcc 4.8 the optimization level -Og is available. It enables

How to force IAR to use desired Cortex-M0+ instructions (optimization will be disabled for this func.)

独自空忆成欢 提交于 2020-01-07 08:05:09
问题 I need to force IAR tp use certain Cortex-M0+ instruction in some part of my code while codding with C. Please do not offer pure asm functions or inline asm etc. I have managed to do this for 51 instruction but could not for ; ADR, BLX, RSBS, SBCS, SXTH instructions. Optimization is disabled for this function (#pragma optimization=none) I have tried many things by considering instruction behaviour. But IAR preferred to same function with different instructions. Did anyone else struggle with

How to force IAR to use desired Cortex-M0+ instructions (optimization will be disabled for this func.)

耗尽温柔 提交于 2020-01-07 08:05:06
问题 I need to force IAR tp use certain Cortex-M0+ instruction in some part of my code while codding with C. Please do not offer pure asm functions or inline asm etc. I have managed to do this for 51 instruction but could not for ; ADR, BLX, RSBS, SBCS, SXTH instructions. Optimization is disabled for this function (#pragma optimization=none) I have tried many things by considering instruction behaviour. But IAR preferred to same function with different instructions. Did anyone else struggle with

Filling the LLVM CloneFunction VMAP

五迷三道 提交于 2020-01-06 02:24:29
问题 I want to write some code that, given an LLVM function F, creates an exact copy in the same module (so the copy can be manipulated later while preserving the original). I want to do this with the CloneFunctionInto method. My current attempt involves trying to insert each (new arg,old arg) pair into the VMap. Previously I've tried inserting an uninitialised VMap and putting the pair the other way round. Impressively, all 3 have resulted in the exact same error message: Assertion `VMap.count(&I

Equivalents to gcc/clang's march=native in other compilers?

回眸只為那壹抹淺笑 提交于 2020-01-05 23:00:04
问题 I'd like to know if there are other compilers than gcc and clang that provide something like an -march=native option, and if so, what that option is. I already understand from another question (Automatically building for best available platform in visual c++ (equivalent to gcc's -march=native)) that Microsoft's compilers do not have that option (unless it's implied in the option that activates the SSE2 instruction set, up to and excluding AVX and higher at least). The use case is simple:

Equivalents to gcc/clang's march=native in other compilers?

时光毁灭记忆、已成空白 提交于 2020-01-05 22:54:19
问题 I'd like to know if there are other compilers than gcc and clang that provide something like an -march=native option, and if so, what that option is. I already understand from another question (Automatically building for best available platform in visual c++ (equivalent to gcc's -march=native)) that Microsoft's compilers do not have that option (unless it's implied in the option that activates the SSE2 instruction set, up to and excluding AVX and higher at least). The use case is simple: