3 ms·
> Right, and that’s GCC’s problems — MSVC-produced code is optimized, and is free from the described issue. > You know how I found that? I’ve made a version po
by ordu 8y ago
> Right, and that’s GCC’s problems — MSVC-produced code is optimized, and is free from the described issue.
> You know how I found that? I’ve made a version portable across compilers, built with VC++ and run on Windows: https://github.com/Const-me/MemoryAccessCosts https://github.com/Const-me/MemoryAccessCosts I don’t have Intel compiler but my expectation is it’ll work even better.
Yes! You have found that optimization doesn't allow you to make a comparison. Code is free of the described issue, so you cannot measure effect this issue have on the speed. As I understand from asm listings, you are comparing now not 1 iteration with 16 iteration, but 1 iteration with some vectorized code. In the original article this case is covered, with hand-crafted vectorized code.
Do you see? When optimization is turned on you cannot compare 16 iterations with 1 iteration or with vectorized code. It is the basics of experimental method: you need to control independant variable, and to measure dependant one. When using compiler optimizations it is the way harder, you would need to check generated code.
Turn off vectorization of code in msvc, and hopefully you'll get the same results.
- Const-me 8y ago> you are comparing now not 1 iteration with 16 iteration GCC made code with zero iterations, it unrolled the complete inner loop and produced 16 scalar add instructions. MSVC made code with two iterations, each iteration containing two paddd SSE2 instructions, which stand for _mm_add_epi32. > Turn off vectorization of code in msvc I can’t. When I try, the compiler says “Command line warning D9002: ignoring unknown option '/arch:IA32'” SSE2 is a requirement for AMD64 CPUs, that’s why the MS compiler doesn’t support scalar code anymore. And the data size is too large for 32 bit builds, it’s not enough address space for a 8GB vector.
- ordu 8y ago> GCC made code with zero iterations, it unrolled the complete inner loop and produced 16 scalar add instructions. It doesn't matter really. It is amount of work that needed for experiment. > I can’t. When I try, the compiler says “Command line warning D9002: ignoring unknown option '/arch:IA32'” I have zero experience with msvc, but I believe you are doing it wrong. You need not to change arch, you need to control over optimizations. For example, gcc has options -ftree-vectorize, -ftree-loop-vectorize, and -fno-tree-vectorize and so on. You need to find docs on compiler optimization techniques and on options that allow to control them. > MS compiler doesn’t support scalar code anymore. Strange, but ok. If we return to the starting question "why the author didn't write the code portably", than we now know the answer. There are no way to write scalar code with MSVC. MSVC doesn't allow make this kind of experiments, so there are no reasons to make such tests portable to msvc.
- Const-me 8y ago> You need not to change arch See the pics: http://const.me/tmp/vc/codegen.png http://const.me/tmp/vc/codegen.png http://const.me/tmp/vc/optimize.png http://const.me/tmp/vc/optimize.png > You need to find docs on compiler optimization techniques Indeed, #pragma loop(no_vector) in the source code before the inner loop did the trick. The results are very close to GCC.