Re: Eliding of slice range checking

2019-10-31 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.l

Re: Eliding of slice range checking

2019-10-29 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 25 October 2019 at 21:33:26 UTC, Per Nordlöw wrote: But it requires the function to be qualified as @trusted which might hide a @system == operator. How common is it for a == operator to be unsafe? Ping.

Re: Eliding of slice range checking

2019-10-29 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 13:51:19 UTC, kinke wrote: You call this messy?! cmpq%rdi, %rdx jae .LBB0_2 xorl%eax, %eax retq .LBB0_2: movq%rdi, %rax testq %rdi, %rdi je .LBB0_3 pushq %rax .cfi_def_cfa_of

Re: Eliding of slice range checking

2019-10-29 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.l

Re: Eliding of slice range checking

2019-10-25 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 25 October 2019 at 15:22:12 UTC, Ali Çehreli wrote: On 10/25/2019 05:37 AM, Stefan Koch wrote: just replace x = a[i] with x = a.ptr[i]; That's a neat trick! Ali But it requires the function to be qualified as @trusted which might hide a @system == operator. How common is it for

Re: Eliding of slice range checking

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 05:37 AM, Stefan Koch wrote: just replace x = a[i] with x = a.ptr[i]; That's a neat trick! Ali

Re: Eliding of slice range checking

2019-10-25 Thread welkam via Digitalmars-d-learn
On Thursday, 24 October 2019 at 21:02:03 UTC, Per Nordlöw wrote: On Thursday, 24 October 2019 at 18:37:05 UTC, welkam wrote: I remember in some video Chandler Carruth said that value range propagation across function boundary was implemented in llvm but later removed because it produced no perf

Re: Eliding of slice range checking

2019-10-25 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 12:01:47 UTC, Per Nordlöw wrote: On Wednesday, 23 October 2019 at 11:33:56 UTC, kinke wrote: For your example, the template is inferred to be @safe, and `-release` only elides bounds checks in @system functions (corresponding to `-boundscheck=safeonly`). Use `-

Re: Eliding of slice range checking

2019-10-24 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 14:52:42 UTC, kinke wrote: godbolt.org supports D as well and is way more powerful than run.dlang.io, besides offering way more LDC versions to choose from. It can also be used to remove the 'cluttering': https://d.godbolt.org/z/ejEmrK Very useful. Especially

Re: Eliding of slice range checking

2019-10-24 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 24 October 2019 at 18:37:05 UTC, welkam wrote: I remember in some video Chandler Carruth said that value range propagation across function boundary was implemented in llvm but later removed because it produced no performance improvement for C and C++ code. I wonder how it fare when

Re: Eliding of slice range checking

2019-10-24 Thread welkam via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.l

Re: Eliding of slice range checking

2019-10-23 Thread kinke via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 13:08:34 UTC, Per Nordlöw wrote: Is it possible to remove cluttering? godbolt.org supports D as well and is way more powerful than run.dlang.io, besides offering way more LDC versions to choose from. It can also be used to remove the 'cluttering': https://d.g

Re: Eliding of slice range checking

2019-10-23 Thread kinke via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 13:08:34 UTC, Per Nordlöw wrote: The ASM- and IR-output from the following code is pretty messy for You call this messy?! cmpq%rdi, %rdx jae .LBB0_2 xorl%eax, %eax retq .LBB0_2: movq%rdi, %rax testq %rdi

Re: Eliding of slice range checking

2019-10-23 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:33:56 UTC, kinke wrote: Simply check the IR or asm, e.g., on run.dlang.io. If there's a call to `_d_arraybounds` in the function of interest, bounds checks are enabled. The ASM- and IR-output from the following code is pretty messy for ldc with flags `-r

Re: Eliding of slice range checking

2019-10-23 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:33:56 UTC, kinke wrote: For your example, the template is inferred to be @safe, and `-release` only elides bounds checks in @system functions (corresponding to `-boundscheck=safeonly`). Use `-boundscheck=off` to elide it in all functions. Thanks. But I'm ta

Re: Eliding of slice range checking

2019-10-23 Thread kinke via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: How can I investigate the codegen myself here? Simply check the IR or asm, e.g., on run.dlang.io. If there's a call to `_d_arraybounds` in the function of interest, bounds checks are enabled. For your example, the template is

Eliding of slice range checking

2019-10-23 Thread Per Nordlöw via Digitalmars-d-learn
Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.length >= needle.length) { return haystack[0 .. needle.l