compiler-optimization

android ndk hw debuggning memory

不想你离开。 提交于 2019-12-23 12:59:09
问题 Backgrond I am very experienced in C and pretty new to Android and Java, but this is rather environmental issues that programming. I have developed an administrative application in ANSI-C to be ported to any OS, just adding a UI in OS-dependent code. Well it uses quite some memory, especially for huge user files. I have a working Win32 program, trying to make an Android app using Android Studio with NDK. Android studio bundle NDK installation works fine I have installed and made a Win7

How can I instruct the MSVC compiler to use a 64bit/32bit division instead of the slower 128bit/64bit division?

谁说胖子不能爱 提交于 2019-12-23 12:19:49
问题 How can I tell the MSVC compiler to use the 64bit/32bit division operation to compute the result of the following function for the x86-64 target: #include <stdint.h> uint32_t ScaledDiv(uint32_t a, uint32_t b) { if (a > b) return ((uint64_t)b<<32) / a; //Yes, this must be casted because the result of b<<32 is undefined else return uint32_t(-1); } I would like the code, when the if statement is true, to compile to use the 64bit/32bit division operation, e.g. something like this: ; Assume

Are std::functions inlined by the C++11 compiler?

天大地大妈咪最大 提交于 2019-12-23 10:57:46
问题 I'm working on a small mathematical optimization framework in C++11, and I wonder what's the best way for the user to provide domain-specific logic. I could force her to define classes with hook methods that can be called by the framework, but I'd like to keep it lean and take advantage of the new C++11 facilities whenever I can. So I'm thinking about accepting std::function objects, possibly instantiated from lambda expressions, as parameters, and call them when needed. The only think I'm

Clang generates worse code for 7 comparisons than for 8 comparisons

半城伤御伤魂 提交于 2019-12-23 10:54:52
问题 I was intrigued by clang's ability to convert many == comparisons of small integers to to one big SIMD instruction, but then I noticed something strange. Clang generated "worse" code(in my amateur evaluation) when I had 7 comparisons compared to the code when I had 8 comparisons. bool f1(short x){ return (x==-1) | (x == 150) | (x==5) | (x==64) | (x==15) | (x==223) | (x==42) | (x==47); } bool f2(short x){ return (x==-1) | (x == 150) | (x==5) | (x==64) | (x==15) | (x==223) | (x==42); } My

Why is vector::push_back of local variable not move optimized? [duplicate]

我的未来我决定 提交于 2019-12-23 09:49:52
问题 This question already has answers here : Can compiler generate std::move for a last use of lvalue automatically? (3 answers) Do compilers automatically use move semantics when a movable object is used for the last time? (1 answer) Closed 2 years ago . In C++11 you can use std::vector::push_back in combination with std::move to avoid copies while inserting elements into a vector. Is there a section in the standard that forbids compilers to use std::move automatically with local variables that

Does the C# compiler optimize foreach blocks when its contents have the Conditional attribute?

不问归期 提交于 2019-12-23 08:54:14
问题 I'm writing some debug code at work, and I'm wondering if what I'm doing might hurt performance or not. Let's get to the code: foreach (var item in aCollection) Debug.WriteLine(item.Name); I know that the Debug class uses the Conditional attribute to avoid compilation in release mode (or whenever DEBUG is undefined), but would this end up as a futile/empty iteration when compiled in release mode or would it be optimized by the compiler? 回答1: The C# compiler will not optimize away the

Does the C# compiler optimize foreach blocks when its contents have the Conditional attribute?

做~自己de王妃 提交于 2019-12-23 08:52:17
问题 I'm writing some debug code at work, and I'm wondering if what I'm doing might hurt performance or not. Let's get to the code: foreach (var item in aCollection) Debug.WriteLine(item.Name); I know that the Debug class uses the Conditional attribute to avoid compilation in release mode (or whenever DEBUG is undefined), but would this end up as a futile/empty iteration when compiled in release mode or would it be optimized by the compiler? 回答1: The C# compiler will not optimize away the

Why is adding two std::vectors slower than raw arrays from new[]?

夙愿已清 提交于 2019-12-23 08:06:41
问题 I'm looking around OpenMP, partially because my program need to make additions of very large vectors (millions of elements). However i see a quite large difference if i use std::vector or raw array. Which i cannot explain. I insist that the difference is only on the loop, not the initialisation of course. The difference in time I refer to, is only timing the addition, especially not to take into account any initialization difference between vectors, arrays, etc. I'm really talking only about

Why does GCC generate a faster program than Clang in this recursive Fibonacci code?

六月ゝ 毕业季﹏ 提交于 2019-12-23 08:04:27
问题 This is the code that I tested: #include <iostream> #include <chrono> using namespace std; #define CHRONO_NOW chrono::high_resolution_clock::now() #define CHRONO_DURATION(first,last) chrono::duration_cast<chrono::duration<double>>(last-first).count() int fib(int n) { if (n<2) return n; return fib(n-1) + fib(n-2); } int main() { auto t0 = CHRONO_NOW; cout << fib(45) << endl; cout << CHRONO_DURATION(t0, CHRONO_NOW) << endl; return 0; } Of course, there are much faster ways of calculating

How to conditionally set compiler optimization for template headers

泄露秘密 提交于 2019-12-23 07:33:03
问题 I found a question somewhat interesting, and went on an attempt to answer it. The author wants to compile -one- source file (which relies on template libraries) with AVX optimizations, and the rest of the project without those. So, to see what would happen, I've created a test project like this: main.cpp #include <iostream> #include <string> #include "fn_normal.h" #include "fn_avx.h" int main(int argc, char* argv[]) { int number = 10; // this will come from input, but let's keep it simple for