3 ms·
Or better yet, memset(v, 0, 10); A smart memset implementation will also vectorize that, setting memory a word at a time instead of a byte at a time. (Not
by nostrademons 12y ago
Or better yet,
memset(v, 0, 10);
A smart memset implementation will also vectorize that, setting memory a word at a time instead of a byte at a time. (Not all stdlib implementations are smart, but both Google and Facebook have custom replacements of the C stdlib that do this.)
- kazinator 12y ago... and screwed up by assuming v is an array of char, so the number elements is the size. What we want is: memset(v, 0, sizeof v); If this is intended to initialize v, this may be suitable: int v[10] = { 0 }; /* or whatever type */ By the way, all-zero-bit memory is not required to give us null pointers or floating-point values of 0.0; it's just de facto very portable.
- nostrademons 12y agosizeof(v) is dangerous - if v is passed in (as opposed to being a local), it'll be the size of a pointer, not the full array. ...which is what we get for debating C in a thread that started with an example that isn't even legal C code.
- amelius 12y agoShouldn't the compiler be able to figure out that such an optimization is possible?
- velox_io 12y agoYou would think so.. I find it strange that only specialised software (such as graphics) makes use of SIMD instructions, when much of the code inside loops could be vectorised. Running on parts of the CPU which are also under-utilised. I think this is something that will change. There's only so much you can run code in parallel before cores are starved. Intel is bringing out AVX-512 which could be interesting - http://en.wikipedia.org/wiki/Advanced_Vector_Extensions#AVX-512 http://en.wikipedia.org/wiki/Advanced_Vector_Extensions#AVX-...