compiler-optimization Questions

3

I am trying to implement two classes A and B which contain data stored in std::unique_ptr container, and A could transform to B with some calculation. The class A and class B are shown as below. Th...
Origan asked 25/2, 2020 at 2:6

1

Solved

Recently we switched to a more recent GCC and it optimized away a whole function and replaced it with "null pointer access" trap code instead when optimizing for size. Looking at godbolt,...
Schnook asked 5/8 at 14:3

3

Solved

I'm have an Arduino Uno R3. I'm making logical objects for each of my sensors using C++. The Arduino has very limited on-board memory 32KB*, and, on average, my compiled objects are coming out arou...
Padishah asked 9/3, 2013 at 18:53

1

So someone on a forum asked why this C function (which I added const and restrict to, just in case): void foo(int *const restrict dest, const int *const restrict source) { *dest = (*source != -1) ...

4

Solved

I'm getting the error "The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed." This was working fine a few hours ...
Sladen asked 21/7, 2021 at 4:25

2

I was just playing around with some C++ code at Compiler Explorer and noticed some unexpected behavior when compiling a simple try/catch block. Both of the following snippets were compiled with gcc...

5

Solved

GCC and Clang both compile bool pred(); void f(); void g(); void h() { if (pred()) { f(); } else { g(); } } to some variation of # Clang -Os output. -O3 is the same h(): push rax call pred...
Parhelion asked 24/4 at 18:46

5

Solved

Is there a way to see how long a script took to execute/complete in VS Code? I'm looking for a message like: Program finished in 30ms
Vibrato asked 8/8, 2019 at 9:29

2

In C++, a compiler can assume that no UB will happen, affecting behaviour (even visible side-effects like I/O) in paths of execution that will encounter UB but haven't yet, if I understand the phra...

11

Solved

After over a decade of C/C++ coding, I've noticed the following pattern - very good programmers tend to have detailed knowledge of the innards of the compiler. I'm a reasonably good program...
Engle asked 6/7, 2009 at 5:0

1

I'm reading a C++ function that handles timestamps, and there's an expression like this: t % (60 * 60) % 60 I thought this expression was strictly equivalent to: t % 60 However, when I entered th...

2

Solved

Take for example this piece of code (for the talk LLVM Optimization Remarks - Ofek Shilon - CppCon 2022, at 21:28): void somefunc(const int&); int whateva(); void f(int i, int* res) { somefun...
Virelay asked 17/2 at 15:36

1

Solved

The following is a minimal reproducible example of code that I had to generate an 'array' (whose 1-byte elements are packed into the resulting uint_fast64_t) of 3D coordinates within octree branche...

6

Solved

I know that where possible you should use the const keyword when passing parameters around by reference or by pointer for readability reasons. Is there any optimizations that the compiler can do if...
Coronation asked 14/12, 2014 at 5:27

2

Solved

A restrict-qualified pointer parameter of a function is an effective way to allow compilers to optimize that function: int f(const int *restrict p) { int n=*p; printf("Debug\n"); retur...

3

double var = 0.; for(int i = 0; i < 1000000 ; i++) { var += sqrt(2.0); } std::cout << var << std::endl; Under MSVC2012, is it possible that under release with optimization turn on,...
Hintze asked 24/12, 2012 at 19:27

1

Solved

I am looking for compiler flags of GCC/CLANG to generate BEXTR instruction. template <auto uSTART, auto uLENGTH, typename Tunsigned> constexpr Tunsigned bit_extract(Tunsigned uInput) { retur...
Dominations asked 22/12, 2023 at 18:46

1

Let's consider this trivial code: #include <atomic> std::atomic<int> a; void f(){ for(int k=0;k<100;++k) a.load(std::memory_order_relaxed); } MSVC, Clang and GCC all perform 10...

6

Solved

I'm compiling my C++ app using GCC 4.3. Instead of manually selecting the optimization flags I'm using -march=native, which in theory should add all optimization flags applicable to the hardware I'...
Lurlenelurline asked 29/3, 2011 at 9:14

11

Solved

Suppose a1, b1, c1, and d1 point to heap memory, and my numerical code has the following core loop. const int n = 100000; for (int j = 0; j < n; j++) { a1[j] += b1[j]; c1[j] += d1[j]; } This...
Scornful asked 17/12, 2011 at 20:40

5

I have the following C/C++ code snippet: #define ARRAY_LENGTH 666 int g_sum = 0; extern int *g_ptrArray[ ARRAY_LENGTH ]; void test() { unsigned int idx = 0; // either enable or disable the che...
Writein asked 27/10, 2023 at 11:6

1

In C, I can output compiler optimization information using the following command: clang -O2 main.c -o main -fsave-optimization-record Does rust also have such options to output optimization inform...
Loaves asked 24/10, 2023 at 8:22

3

Problem summary I'm trying to do an in-memory database with transactions. I'm reaching bottlenecks on compiler level, specifically inlining limit. I don't have much knowledge about compilers and I ...

4

Solved

what should be the behavior in the following case: class C { boost::mutex mutex_; std::map<...> data_; }; C& get() { static C c; return c; } int main() { get(); // is compiler fre...
Verleneverlie asked 20/9, 2010 at 5:5

2

Solved

const isPositive = (n: number) => n > 0; function fitsIn(dividend: number, divisor: number, count: number, accum: number): number { if (accum + divisor > dividend) { return count; }...

© 2022 - 2024 — McMap. All rights reserved.