Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 30, 2014 Avoiding Range Checks in Slice Expressions | ||||
---|---|---|---|---|
| ||||
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? |
March 30, 2014 Re: Avoiding Range Checks in Slice Expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | 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
|
March 31, 2014 Re: Avoiding Range Checks in Slice Expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Sun, 30 Mar 2014 15:40:43 -0400, Nordlöw <per.nordlow@gmail.com> wrote: > 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 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 |
March 31, 2014 Re: Avoiding Range Checks in Slice Expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | > 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.
|
March 31, 2014 Re: Avoiding Range Checks in Slice Expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | >
>> If not, what would it require to implement it?
That would be an interesting task to fix :)
DMD source references anyone?
|
Copyright © 1999-2021 by the D Language Foundation