digitalmars.D.learn - Avoiding Range Checks in Slice Expressions
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (7/7) Mar 30 2014 Does DMD currently avoid range checks in array slice expressions
- bearophile (6/10) Mar 30 2014 You have two simple ways to answer your question: try to go past
- Steven Schveighoffer (11/16) Mar 31 2014 as
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (6/8) Mar 31 2014 $/n is of course always within range if n is positive integer >=
- =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= (2/3) Mar 31 2014 That would be an interesting task to fix :)
Does DMD currently avoid range checks in array slice expressions such as f(x[0..$/2]) f(x[$/2..$]) typically found in divide-and-conquer algorithms such as quicksort? If not, what would it require to implement it?
Mar 30 2014
Nordlöw:Does DMD currently avoid range checks in array slice expressions such as f(x[0..$/2]) f(x[$/2..$])You have two simple ways to answer your question: try to go past the slices and look if D raises an error, and look at the asm produced with various compiler switches. Bye, bearophile
Mar 30 2014
On Sun, 30 Mar 2014 15:40:43 -0400, Nordl=C3=B6w <per.nordlow gmail.com>= wrote:Does DMD currently avoid range checks in array slice expressions such =asf(x[0..$/2]) f(x[$/2..$]) typically found in divide-and-conquer algorithms such as quicksort?If they are range-checked, it would be a good addition to the optimizer = to = remove them. My guess is that it is range-checked.If not, what would it require to implement it?As a hack, you can use the pointer, which will not be range checked: f(x.ptr[0..x.length/2]) // note you can't use $ because the pointer = doesn't have length f(x.ptr[x.length/2..x.length]) -Steve
Mar 31 2014
If they are range-checked, it would be a good addition to the optimizer to remove them. My guess is that it is range-checked.$/n is of course always within range if n is positive integer >= 1. But what about in the general indexing/slicing case? In that case it would be useful if we could reuse value range propagation (VRP) in DMD, to figure out which other expressions that don't need range checking.
Mar 31 2014
That would be an interesting task to fix :) DMD source references anyone?If not, what would it require to implement it?
Mar 31 2014