3 ms·
> The in-place version of swap is generally discouraged because compilers are smart Isn’t that more because CPUs slow down when there are dependencies between
by Someone 2y ago
> The in-place version of swap is generally discouraged because compilers are smart
Isn’t that more because CPUs slow down when there are dependencies between instructions?
Compilers could (and may even do) fairly easily detect that pattern (like they do with some versions of popcnt. See for example https://langdev.stackexchange.com/questions/3942/what-are-the-ways-compilers-recognize-complex-patterns https://langdev.stackexchange.com/questions/3942/what-are-th..., discussed here in https://news.ycombinator.com/item?id=40987123 https://news.ycombinator.com/item?id=40987123) and compile it to whatever is fastest on the target CPU/in the given context (in some contexts, it can be compiled to nothing, just changing the mapping between local variables and the registers they’re stored in)
- gpderetta 2y ago> Isn’t that more because CPUs slow down when there are dependencies between instructions? Indeed, while reg-reg moves can be resolved at the rename stage and are effectively free latency-wise.
- Almondsetat 2y agoCPUs have shortcuts in the pipeline to provide the results to the dependent operation in time