News for hackers. Stuff that matters.
Re:Why do arrays start at 0? by sgtnoodle on Wednesday August 24, 2022 @04:37PM (#32585412)
Sure, why wouldn't it be? As far as a cache is concerned, I don't think reverse sequential iteration would be any different than forward sequential. The actual RAM accesses may be less optimal if there's some speculative pre-fetching with assumed forward sequential access, but that's conjecture.
Re:Why do arrays start at 0? by ehvatum on Thursday August 25, 2022 @01:52AM (#32590035)
With some exceptions, hardware prefetch works in terms of ascending accesses. To learn if a particular CPU will prefetch for descending access, benchmarking is essential. Best to use soft prefetch calls if performance is critical.
Re:Why do arrays start at 0? by chii on Wednesday August 24, 2022 @10:48PM (#32588844)
i would suspect that the cache prefetch/prediction could use the "velocity" of the memory access to predict the next access; so if the access pattern was going backwards, the "velocity" would be negative, but prefetching would still work if they just followed the predicted pattern.