Jan 2, 2023

[C++/Rust] pragma nounroll

Reference:
https://stackoverflow.com/questions/74979866/how-to-stop-clang-from-overexpanding
https://clang.llvm.org/docs/AttributeReference.html#pragma-unroll-pragma-nounroll

Use #pragma nounroll to control loop unrolling optimization; for Rust counter part:

https://docs.rs/unroll/latest/unroll/

#include <iostream>
typedef long xint;
template<int N>
struct foz {
    template<int i=0>
    static void foo(xint t) {
        // #pragma nounroll
        for (int j=0; j<10; ++j) {
            foo<i+1> (t+j);
        }
    }
};

template<>
template<>
void foz<4>::foo<4>(xint t) {
    std::cout << t;
}

int main() {
    foz<4>::foo<0>(0);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.