News for hackers. Stuff that matters.
Re:Ask HN: Do you feel the quality of SWE has gone down? by QuestionPixel on Saturday November 23, 2019 @04:29PM (#21616695)
I'm currently studying EE and would like to get into embedded programming/semiconductor design, could you explain the optimal way to loop over the pixels if not with two nested for loops? Would it be something related to how in memory it's effectively a 1-D array?
Re:Ask HN: Do you feel the quality of SWE has gone down? by fyp on Saturday November 23, 2019 @06:13PM (#21617263)
It's a really deep problem actually! Doing y then x is better but it's far from "optimal".

These parallel programming course notes have an example of using z-order curves which is slightly better yet: http://ppc.cs.aalto.fi/ch2/v7/

And the best solution requires something like Halide https://halide-lang.org/ to find the best traversal order.

Re:Ask HN: Do you feel the quality of SWE has gone down? by jfim on Saturday November 23, 2019 @04:36PM (#21616735)
The loops should be inverted. It should be for y, then for x, which accesses the memory in a linear fashion instead of in stride.

This presentation (PDF) explains why: https://www.aristeia.com/TalkNotes/ACCU2011_CPUCaches.pdf

Re:Ask HN: Do you feel the quality of SWE has gone down? by kamih on Saturday November 23, 2019 @04:34PM (#21616724)
At the very least, the inner loop should be over X, since that is how the pixels are packed.
Re:Ask HN: Do you feel the quality of SWE has gone down? by RhysU on Saturday November 23, 2019 @04:35PM (#21616733)
It is precisely the linear ordering in memory. Whether X-then-Y or Y-then-X is best depends upon if the data is stored row- or column-major.