Re: How to profile compile times of a source code?

2021-01-31 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 31 January 2021 at 12:16:50 UTC, Imperatorn wrote: On Saturday, 30 January 2021 at 23:34:50 UTC, Stefan Koch wrote: On Saturday, 30 January 2021 at 22:47:39 UTC, Ahmet Sait wrote: [...] I have a way of getting the profile data your are after. Get the dmd_tracing_20942 branch from

Re: LDC relocation flags

2020-12-18 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 18 December 2020 at 13:00:45 UTC, Severin Teona wrote: Hi guys! Do you know how can I compile D code using LDC with the following gcc flags? * -msingle-pic-base * -mpic-register=r9 * -mno-pic-data-is-text-relative. As far as I know, there are no equivalents in D for these. Is is

Re: toStringz lifetime

2020-10-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 October 2020 at 10:03:44 UTC, Ali Çehreli wrote: Is it really safe? Imagine a multi-threaded environment where another D function is executed that triggers a GC collection right before the printf. Does the GC see that local variable 'name' that is on the C side? What I don't

Re: Order of static this() execution?

2020-02-23 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 23 February 2020 at 11:55:11 UTC, drathier wrote: On Sunday, 23 February 2020 at 11:41:25 UTC, Johan Engelen wrote: On Sunday, 23 February 2020 at 09:59:45 UTC, drathier wrote: I'm having some trouble with the order in which `static this()` runs. This is the order defined in the

Re: Order of static this() execution?

2020-02-23 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 23 February 2020 at 09:59:45 UTC, drathier wrote: I'm having some trouble with the order in which `static this()` runs. This is the order defined in the source file, numbered for convenience: To avoid confusion: you have all `static this()` in a single source file? Or across

Re: Default values in derived class

2019-12-28 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 28 December 2019 at 20:47:38 UTC, Mike Parker wrote: On Saturday, 28 December 2019 at 20:22:51 UTC, JN wrote: import std.stdio; class Base { bool b = true; } class Derived : Base { bool b = false; } void main() { // 1 Base b = new Derived(); writeln(b.b); // true

Re: static assert(version(x)) ?

2019-11-27 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 26 November 2019 at 12:53:02 UTC, Jonathan M Davis wrote: On Tuesday, November 26, 2019 4:29:18 AM MST S.G via Digitalmars-d-learn wrote: On Tuesday, 26 November 2019 at 10:24:00 UTC, Robert M. Münch wrote: > How can I write something like this to check if any of a set > of

Re: Final necessary for inline optimization?

2019-10-19 Thread Johan Engelen via Digitalmars-d-learn
Just a brief answer. On Saturday, 19 October 2019 at 15:58:08 UTC, IGotD- wrote: Which one is it, LDC recognizes TestClass isn't derived or is sure that the class (c) isn't derived in particular? It is the latter: the optimizer is able to prove that object c has a vtable that is known

Re: How does D distnguish managed pointers from raw pointers?

2019-10-04 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 3 October 2019 at 14:21:37 UTC, Andrea Fontana wrote: In D arrays are fat pointer instead: int[10] my_array; my_array is actually a pair ptr+length. ``` int[10] my_static_array; int[] my_dynamic_array; ``` my_static_array will not be a fat pointer. Length is known at compile

Re: Deprecation message sources

2019-09-17 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 17 September 2019 at 20:16:12 UTC, Anonymouse wrote: On Tuesday, 17 September 2019 at 19:31:53 UTC, Steven Schveighoffer wrote: I'd hate to say the answer is to special case Nullable for so many functions, but what other alternative is there? -Steve Nullable isn't alone,

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) { a = _a; b = _b;

Re: LDC won't find ld linker -why?

2019-07-10 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 9 July 2019 at 15:25:17 UTC, Dukc wrote: I just downloaded ldc 1.15.0 for Linux from GH releases. Testing it, it will make the object file out of a hello world application, but then complain: ``` collect2: fatal error: cannot find ‘ld’ compilation terminated. ``` Run LDC with

Re: Can D optimize?

2019-06-09 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 9 June 2019 at 05:24:56 UTC, Amex wrote: Can dmd or ldc optimize the following cases: foo(int x) { if (x > 10 && x < 100) bar1; else bar2; } ... for(int i = 23; i < 55; i++) foo(i); // equivalent to calling bar1(i) clearly i is within the range of the if in foo and so the

Re: Explicitly avoid GC of objects?

2019-05-21 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 13:23:54 UTC, Benjamin Schaaf wrote: On Tuesday, 21 May 2019 at 11:54:08 UTC, Robert M. Münch wrote: Is there a trick to accomplish 2 when objects are created from different scopes which need to be kept? So, I have one function creating the objects and one using

Re: LDC2 and classic profiling

2019-05-12 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 11 May 2019 at 11:34:35 UTC, Denis Feklushkin wrote: On Saturday, 11 May 2019 at 09:12:24 UTC, Johan Engelen wrote: Those calls are to templated functions I presume? No Then I don't understand how you'd see instrumentation on functions that you did not compile with

Re: LDC2 and classic profiling

2019-05-11 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 11 May 2019 at 06:59:52 UTC, Denis Feklushkin wrote: On Saturday, 11 May 2019 at 05:46:29 UTC, Denis Feklushkin wrote: All another calls is made inside of this lambda - maybe lambdas is not traced by profiler? Tried to remove lambda with same result. Command: llvm-profdata

Re: LDC2 and classic profiling

2019-05-10 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 10 May 2019 at 14:00:30 UTC, Denis Feklushkin wrote: Build with dub some package. Profiling are enabled by dub.json: "dflags-ldc": ["-fprofile-instr-generate", "-finstrument-functions", "-cov"], Resulting default.profraw (and generated default.profdata) contains only calls to

Re: D threading and shared variables

2019-04-07 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 7 April 2019 at 14:08:07 UTC, Archie Allison wrote: This generally works OK when tied to a Console but when link options are changed to be SUBSYSTEM:WINDOWS and ENTRY:mainCRTStartup it rarely does. Manually setting the entry point sounds problematic if no other precautions are

Re: Block statements and memory management

2019-03-16 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make

Re: Returning reference: why this works?

2019-03-13 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 13 March 2019 at 20:57:13 UTC, Denis Feklushkin wrote: import std.stdio; struct S { int x; } ref S func1(ref S i) // i is reference { return i; } ref S func2(S i) // i is not reference { return func1(i); // Works! Possibility to return reference to local object i?

How to use core.atomic.cas with (function) pointers?

2019-01-22 Thread Johan Engelen via Digitalmars-d-learn
The following code compiles: ``` alias T = shared(int)*; shared T a; shared T b; shared T c; void foo() { import core.atomic: cas; cas(, b, c); } ``` The type of T has to be a pointer to a shared int (you get a template match error for `cas` if `T = int*`), which is annoying but I

Re: Compiling to 68K processor (Maybe GDC?)

2019-01-21 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 21 January 2019 at 17:08:23 UTC, Johan Engelen wrote: For LDC, dereferencing `null` invokes Undefined Behavior [1]. For completeness, you can tell LDC that dereferencing `null` is _not_ UB in a particular function by specifying `@llvmAttr("null-pointer-is-valid", "true")`:

Re: Compiling to 68K processor (Maybe GDC?)

2019-01-21 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 19 January 2019 at 17:45:41 UTC, Patrick Schluter wrote: Afaict NULL pointer derefernecing must fault for D to be "usable". At least all code is written with that assumption. Dereferencing `null` in D is implementation defined (https://dlang.org/spec/arrays.html#pointers). For

Re: LDC2 with -fxray-instrument

2019-01-21 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 21 January 2019 at 14:36:15 UTC, Márcio Martins wrote: On Thursday, 17 January 2019 at 00:11:10 UTC, Johan Engelen wrote: OK, got it :-) LLVM 7 changed things a little, so it's broken with LDC 1.13 [*]. For now, you can use LDC 1.12 (LLVM 6). You also have to add `-L-lstdc++`

Re: LDC2 with -fxray-instrument

2019-01-16 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 23:29:45 UTC, Johan Engelen wrote: On Wednesday, 16 January 2019 at 22:10:14 UTC, Johan Engelen wrote: On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins wrote: On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen wrote: What platform are you

Re: LDC2 with -fxray-instrument

2019-01-16 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 22:10:14 UTC, Johan Engelen wrote: On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins wrote: On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen wrote: What platform are you on? Linux x64 OK, so that should work. What is your testcase? Try

Re: LDC2 with -fxray-instrument

2019-01-16 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 17:36:31 UTC, Márcio Martins wrote: On Tuesday, 15 January 2019 at 22:51:15 UTC, Johan Engelen wrote: What platform are you on? Linux x64 OK, so that should work. What is your testcase? Try with `-fxray-instruction-threshold=1` to also instrument small

Re: LDC2 with -fxray-instrument

2019-01-15 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 14:32:03 UTC, Márcio Martins wrote: Anyone has any idea how to build with LDC and -fxray-instrument? I am running LDC 1.13 on Linux (x64) The XRay section is in the binary, and the compiler-rt is linked in, but when I run the binary with

Re: one path skips constructor

2019-01-14 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 13 January 2019 at 16:29:27 UTC, Kagamin wrote: --- struct A { int a; this(int) { if(__ctfe)this(0,0); //Error: one path skips constructor else a=0; } this(int,int){ a=1; } } --- Is this supposed to not compile? Yes. See spec 14.14.8.1:

Re: Creating fixed array on stack

2019-01-11 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 11 January 2019 at 15:23:08 UTC, Dgame wrote: On Friday, 11 January 2019 at 14:46:36 UTC, Andrey wrote: Hi, In C++ you can create a fixed array on stack: int count = getCount(); int myarray[count]; Small correction: this is valid in C, but not in C++. In D the "count" is part of

Re: Segfault when adding a static destructor in druntime/src/rt/sections_elf_shared.d

2019-01-08 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 8 January 2019 at 12:54:11 UTC, RazvanN wrote: Hi all, I am working on issue 14650 [1] Great! (I am _extremely_ surprised that dtors are not called for globals.) and I would like to implement a solution where static destructors are destroying global variables. However, I have

Re: Bitwise rotate of integral

2019-01-08 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 7 January 2019 at 14:39:07 UTC, Per Nordlöw wrote: What's the preferred way of doing bitwise rotate of an integral value in D? Are there intrinsics for bitwise rotation available in LDC? LDC does not expose this intrinsic currently, but you can use LLVM's fshl:

Re: cas and interfaces

2018-12-27 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 27 December 2018 at 12:07:48 UTC, Rene Zwanenburg wrote: On Tuesday, 25 December 2018 at 22:07:07 UTC, Johannes Loher wrote: Thanks a lot for the info, that clarifies things a bit. But it still leaves the question, why it works correctly when inheriting from an abstract class

Re: Mysteries of the Underscore

2018-12-24 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 24 December 2018 at 11:18:44 UTC, Ron Tarrant wrote: I found a mention that in the definition of a delegate, a function parameter and its type could be replaced by an underscore: myTestRig.addOnDestroy(delegate void(Widget w) { quitApp(); } ); became:

Re: cas and interfaces

2018-12-24 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 23 December 2018 at 14:07:04 UTC, Johannes Loher wrote: I recently played around with atomic operations. While doing so, I noticed a problem with the interaction of interfaces and cas. Consider the following program: ``` import core.atomic; import std.stdio; interface

Re: LDC2 win64 calling convention

2018-12-01 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 29 November 2018 at 15:10:41 UTC, realhet wrote: In conclusion: Maybe LDC2 generates a lot of extra code, but I always make longer asm routines, so it's not a problem for me at all while it helps me a lot. An extra note: I recommend you look into using `ldc.llvmasm.__asm` to

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 03:05:07 UTC, Neia Neutuladh wrote: Virtual function calls have to do a dereference to figure out which potentially overrided function to call. "have to do a dereference" in terms of "dereference" as language semantic: yes. "have to do a dereference" in

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 07:47:14 UTC, Jonathan M Davis wrote: IMHO, requiring something in the spec like "it must segfault when dereferencing null" as has been suggested before is probably not a good idea is really getting too specific (especially considering that some folks have

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 November 2018 at 09:31:41 UTC, Patrick Schluter wrote: On Tuesday, 20 November 2018 at 23:14:27 UTC, Johan Engelen wrote: On Tuesday, 20 November 2018 at 19:11:46 UTC, Steven Schveighoffer wrote: On 11/20/18 1:04 PM, Johan Engelen wrote: D does not make dereferencing on

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-20 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 19:11:46 UTC, Steven Schveighoffer wrote: On 11/20/18 1:04 PM, Johan Engelen wrote: D does not make dereferencing on class objects explicit, which makes it harder to see where the dereference is happening. Again, the terms are confusing. You just said the

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-20 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 20 November 2018 at 03:38:14 UTC, Jonathan M Davis wrote: For @safe to function properly, dereferencing null _must_ be guaranteed to be memory safe, and for dmd it is, since it will always segfault. Unfortunately, as understand it, it is currently possible with ldc's optimizer to

Re: @safe - why does this compile?

2018-07-16 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 13 July 2018 at 14:51:17 UTC, ketmar wrote: yeah. in simple words: safe code is *predictable*, but not "segfault-less". segfaults (null dereferences) in safe code are allowed, 'cause they have completely predictable behavior (instant program termination). @safe doesn't free you

Re: GDC on Travis-CI

2018-06-02 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 2 June 2018 at 10:49:30 UTC, rjframe wrote: There is documentation for older Phobos versions online, but I don't remember the link and haven't found it by searching. https://docarchives.dlang.io/

Re: How are switches optimized

2018-06-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 June 2018 at 21:18:25 UTC, IntegratedDimensions wrote: What is the best optimizations that a compiler does to switches in general and in the D compilers? The best possible depends a lot on the specific case at hand. Best possible is to fully elide the switch, which does happen.

Re: ldc2 and dmd

2018-05-22 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 22 May 2018 at 16:17:48 UTC, Russel Winder wrote: Hi, I have a shared object (of DInotify) compiled with ldc2. I have a program (me-tv) which seems to work when compiled with ldc2. If I compile the program (me-tv) with dmd then it throws a SIGSEGV seemingly in

Re: Extra .tupleof field in structs with disabled postblit blocks non-GC-allocation trait

2018-05-11 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 10 May 2018 at 19:14:39 UTC, Meta wrote: So it looks like disabling a struct's postblit actually counts as having a __postblit and __xpostblit function (don't ask me why), in addition to a construction and opAssign... no idea why, and maybe this is a bug, but I bet there's a

Re: LDC phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

2018-05-04 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 3 May 2018 at 23:47:40 UTC, IntegratedDimensions wrote: trying to compile a simple program in x86. Compiles fine in dmd and ldcx64. Seems like ldc is using the wrong lib for some reason? phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with

Re: Link-time optimisation (LTO)

2018-03-30 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 30 March 2018 at 10:23:15 UTC, Cecil Ward wrote: Say that I use say GDC or LDC. I want to declare a routine as public in one compilation unit (.d src file) and be able to access it from other compilation units. Do I simply declare the routine with the word keyword public before

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-30 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 16:42:23 UTC, Johan Engelen wrote: On Tuesday, 27 March 2018 at 22:10:33 UTC, Per Nordlöw wrote: On Tuesday, 27 March 2018 at 22:00:42 UTC, Johan Engelen wrote: Indeed. Please try to manually link first (without dub) by modifying the command on which dub errors:

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-30 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 29 March 2018 at 08:44:21 UTC, Jacob Carlborg wrote: Please read the reply :), although it could be a bit more clear. I'll spell it out for you. Both `dflags` and `lflags` are being used already. With separate compilation and linking, there seems to be no way to pass flags to

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-28 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 28 March 2018 at 17:03:07 UTC, Seb wrote: dub supports dflags and lflags in the config file. lflags are the linker commands. Please read the thread. `lflags` is for passing flags to the _linker_ (i.e. those flags are prefixed with -L when passed to the _compiler_) Here,

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-28 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 22:10:33 UTC, Per Nordlöw wrote: On Tuesday, 27 March 2018 at 22:00:42 UTC, Johan Engelen wrote: Indeed. Please try to manually link first (without dub) by modifying the command on which dub errors: ``` ldmd2 -flto=thin

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-27 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 13:28:08 UTC, kinke wrote: On Monday, 26 March 2018 at 23:32:59 UTC, Nordlöw wrote: forwarded as `-L-flto=thin` but still errors as Which is wrong, it's not a ld command-line option (i.e., the `-L` prefix is wrong). Indeed. Please try to manually link first

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-26 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 26 March 2018 at 22:07:49 UTC, Nordlöw wrote: When I try build my application using LDC and -flto=thin it fails in the final linking You must also pass `-flto=thin` during linking (a special plugin is needed for LTO, and LDC will only pass the plugin to the linker when `-flto=` is

Re: Does the compiler inline the predicate functions to std.algorithm.sort?

2018-03-19 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 19 March 2018 at 12:45:58 UTC, tipdbmp wrote: the LLVM IR obtained with -output-ll might be easier to read than assembly.) I only seem to get assembly on d.godbolt.org, even with the -output-ll option. On d.godbolt.org, you can get LLVM IR with a trick: use `-output-s=false

Re: LDC / BetterC / _d_run_main

2018-03-10 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 10 March 2018 at 07:54:33 UTC, Mike Franklin wrote: On Saturday, 10 March 2018 at 02:25:38 UTC, Richard wrote: Hi, I've been trying to see if I can get an mbed project to work with Dlang basically compiling D code for use on a Cortex-M Proccessor You might be interested in the

Re: Speed of math function atan: comparison D and C++

2018-03-05 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 5 March 2018 at 06:01:27 UTC, J-S Caux wrote: On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote: On 05/03/2018 6:35 PM, J-S Caux wrote: I'm considering shifting a large existing C++ codebase into D (it's a scientific code making much use of functions like atan, log

Re: how to install latest lcd2 for armbain

2018-03-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 2 March 2018 at 08:25:51 UTC, dangbinghoo wrote: So, does anyone know how to install latest ldc2 from arm-debain? You can use the dlang install.sh script to download LDC and put it in your home dir: https://dlang.org/install.html -Johan

Re: Disk space used and free size of a Network share folder in Windows

2018-02-15 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 14 February 2018 at 12:22:09 UTC, Vino wrote: Hi All, Request your help on how to get the disk space used and free size of a Network share folder in Windows, tried with getSize but it return 0; See:

Re: D generates large assembly for simple function

2018-01-28 Thread Johan Engelen via Digitalmars-d-learn
On 01/27/2018 11:42 AM, Matt wrote: Godbolt link: https://godbolt.org/g/t5S976 Careful with these comparisons guys. Know what you are looking at. Rust does not eliminate setting the framepointer register, and so it looks "bad" [1]. Clang also sets the framepointer for macOS ABI regardless of

Re: D generates large assembly for simple function

2018-01-27 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 27 January 2018 at 19:45:35 UTC, Stefan Koch wrote: ah ... -betterC is only for dmd. `-betterC` works from LDC 1.1.0. - Johan

Re: __gshared as part of alias

2018-01-18 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 17 January 2018 at 22:56:09 UTC, kinke wrote: On Wednesday, 17 January 2018 at 22:01:57 UTC, Johan Engelen wrote: ``` struct GSharedVariable(AddrSpace as, T) { static __gshared T val; alias val this; } alias Global(T) = GSharedVariable!(AddrSpace.Global, T);

Re: __gshared as part of alias

2018-01-17 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 12 January 2018 at 04:25:25 UTC, Nicholas Wilson wrote: Is there a way to make __gshared part of an alias? Hi Nick, how about this? ``` struct GSharedVariable(AddrSpace as, T) { static __gshared T val; alias val this; } alias Global(T) = GSharedVariable!(AddrSpace.Global,

Re: Efficient way to pass struct as parameter

2018-01-02 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 2 January 2018 at 18:21:13 UTC, Tim Hsu wrote: I am creating Vector3 structure. I use struct to avoid GC. However, struct will be copied when passed as parameter to function struct Ray { Vector3f origin; Vector3f dir; @nogc @system this(Vector3f *origin, Vector3f

Re: Finding unsafe line of code

2017-12-29 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 29 December 2017 at 10:23:24 UTC, codephantom wrote: On Friday, 29 December 2017 at 09:38:50 UTC, Vino wrote: Let me re-frame the question with an example, as the Dsafe the below line of code is considered as unsafe(Pointer arithmetic), ... ini[10] a; int* p = [0]; for

Re: Does LDC support profiling at all?

2017-12-24 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 24 December 2017 at 02:48:32 UTC, Chris Katko wrote: It would probably be really helpful to get a clear Wiki guide for this information LDC. I'll write it myself if necessary once I try your recommendations and test them out. This would help us out a lot, thanks. -Johan

Re: Does LDC support profiling at all?

2017-12-23 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 22 December 2017 at 09:52:26 UTC, Chris Katko wrote: DMD can use -profile and -profile=gc. But I tried for HOURS to find the equivalent for LDC and came up with only profile-guided optimization--which I don't believe I want. Yet, if we can get PGO... where's the PROFILE itself it's

Re: Is there a way to get a function name within a function?

2017-12-20 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 20 December 2017 at 23:28:46 UTC, jicman wrote: Greetings! Imagine, //start int getMe(int i) { writefln(__LINE__); writefln(__FUNCTION_NAME__); So close! Use "__FUNCTION__" or "__PRETTY_FUNCTION__". https://dlang.org/spec/traits.html#specialkeywords -Johan

Re: std.range.interfaces : InputRange moveFront

2017-12-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 18:55:53 UTC, Steven Schveighoffer wrote: Once you popFront a byLine range, the element that was at front is now possibly invalid (the buffer may be reused). So in order to return the line from popFront, you have to store it somewhere. This means allocating

Re: std.range.interfaces : InputRange moveFront

2017-12-02 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 18:33:09 UTC, Ali Çehreli wrote: On 12/01/2017 07:21 AM, Steven Schveighoffer wrote: > On 12/1/17 4:29 AM, Johan Engelen wrote: >> (Also, I would expect "popFront" to return the element popped, but it >> doesn't, OK... > > pop removes the front element, but if

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 1 December 2017 at 09:11:40 UTC, Johan Engelen wrote: I tested it and it works like you wrote, but the behavior is different for an array of integers...: Hmm, I guess I misread what Ali meant. But the documentation is wrong/very confusing for moveFront: It says "moveFront --

Re: std.range.interfaces : InputRange moveFront

2017-12-01 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 30 November 2017 at 06:36:12 UTC, Ali Çehreli wrote: import std.range; struct S { int i; bool is_a_copy = false; this(this) { is_a_copy = true; } } void main() { auto r = [S(1)]; auto a = r.front; assert(a.is_a_copy); // yes, a is a

Re: Fast removal of character

2017-10-11 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 11 October 2017 at 22:45:14 UTC, Jonathan M Davis wrote: On Wednesday, October 11, 2017 22:22:43 Johan Engelen via Digitalmars-d- learn wrote: std.string.removechars is now deprecated. https://dlang.org/changelog/2.075.0.html#pattern-deprecate What is now the most efficient way

Fast removal of character

2017-10-11 Thread Johan Engelen via Digitalmars-d-learn
std.string.removechars is now deprecated. https://dlang.org/changelog/2.075.0.html#pattern-deprecate What is now the most efficient way to remove characters from a string, if only one type of character needs to be removed? ``` // old auto old(string s) { return s.removechars(",").to!int;

Re: Is there further documentation of core.atomic.MemoryOrder?

2017-09-17 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 13 September 2017 at 14:40:55 UTC, Nathan S. wrote: Is there a formal description of "hoist-load", "hoist-store", "sink-load", and "sink-store" as used in core.atomic.MemoryOrder (https://dlang.org/library/core/atomic/memory_order.html)? You can read this:

Re: Access Violation when passing the result of a C function directly to a D function?

2017-09-17 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 15 September 2017 at 04:01:13 UTC, Timothy Foster wrote: I've been calling it like so: ErrorFMOD(FMOD_System_Create(), "Error Creating System: "); Making the calls without my helper function doesn't cause an Access Violation. Calling it like this is the only thing that seems to

Re: performance cost of sample conversion

2017-09-07 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 7 September 2017 at 05:45:58 UTC, Ali Çehreli wrote: You have to measure. Indeed. Here's a start: The program has way too many things pre-defined, and the semantics are such that workWithDoubles can be completely eliminated... So you are not measuring what you want to be

Re: One path skips constructor - is this a bug?

2017-09-07 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 7 September 2017 at 16:08:53 UTC, Piotr Mitana wrote: main.d(17): Error: one path skips constructor main.d(15): Error: return without calling constructor http://www.digitalmars.com/d/archives/digitalmars/D/learn/Throwing_exception_in_constructor_28995.html

Re: SIMD under LDC

2017-09-07 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 20:43:01 UTC, Igor wrote: I opened a feature request on github. I also tried using the gccbuiltins but I got this error: LLVM ERROR: Cannot select: 0x2199c96fd70: v16i8 = X86ISD::PSHUFB 0x2199c74e9a8, 0x2199c74d6c0 That's because SSSE3 instructions are

Re: SIMD under LDC

2017-09-05 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 4 September 2017 at 20:39:11 UTC, Igor wrote: I found that I can't use __simd function from core.simd under LDC and that it has ldc.simd but I couldn't find how to implement equivalent to this with it: ubyte16* masks = ...; foreach (ref c; pixels) { c = __simd(XMM.PSHUFB,

Re: How to fix wrong deprecation message - dmd-2.075.1

2017-08-16 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 16:54:04 UTC, Pham wrote: On Wednesday, 16 August 2017 at 13:55:31 UTC, Steven Schveighoffer wrote: On 8/16/17 9:12 AM, Daniel Kozak via Digitalmars-d-learn wrote: It should not be print? AIAIK std.utf.toUTF16 is not deprecated:

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:15:48 UTC, amfvcg wrote: Change the parameter for this array size to be taken from stdin and I assume that these optimizations will go away. This is paramount for all of the testing, examining, and comparisons that are discussed in this thread. Full

Re: D outperformed by C++, what am I doing wrong?

2017-08-13 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 13 August 2017 at 09:08:14 UTC, Petar Kirov [ZombineDev] wrote: This instantiation: sum_subranges(std.range.iota!(int, int).iota(int, int).Result, uint) of the following function: auto sum_subranges(T)(T input, uint range) { import std.range : chunks, ElementType, array;

Re: Create class on stack

2017-08-08 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 7 August 2017 at 13:40:18 UTC, Moritz Maxeiner wrote: Thanks, I wasn't aware of this. I tried fooling around scope classes and DIP1000 for a bit and was surprised that this is allowed: Thanks for the test case :-) It was fun to see that ASan can catch this bug too. Because

Re: Express "Class argument may not be null" ?

2017-08-08 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 19:38:19 UTC, Steven Schveighoffer wrote: Note that C++ also can do this, so I'm not sure the & is accomplishing the correct goal: void foo(Klass&); int main() { Klass *k = NULL; foo(*k); } In C++, it is clear that the _caller_ is doing the

Re: Express "Class argument may not be null" ?

2017-08-08 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 8 August 2017 at 18:57:48 UTC, Steven Schveighoffer wrote: On 8/8/17 2:34 PM, Johan Engelen wrote: Hi all, How would you express the function interface intent that a reference to a class may not be null? For a function "void foo(Klass)", calling "foo(null)" is valid. How do I

Express "Class argument may not be null" ?

2017-08-08 Thread Johan Engelen via Digitalmars-d-learn
Hi all, How would you express the function interface intent that a reference to a class may not be null? For a function "void foo(Klass)", calling "foo(null)" is valid. How do I express that that is invalid? (let's leave erroring with a compile error aside for now) Something equivalent to

Re: Question on SSE intrinsics

2017-07-29 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 29 July 2017 at 16:01:07 UTC, piotrekg2 wrote: Hi, I'm trying to port some of my c++ code which uses sse2 instructions into D. The code calls the following intrinsics: - _mm256_loadu_si256 - _mm256_movemask_epi8 Do they have any equivalent intrinsics in D? Yes, with LDC

Re: Is align(16) respected for globals?

2017-07-23 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 23 July 2017 at 08:43:33 UTC, Guillaume Piolat wrote: I rely a lot on such constants for SSE: align(16) static immutable short[8] A = [ 1, 1, 1, 1, 3, 3, 3, 3 ]; Does such alignment actually work on all OS, at all times? Word on the street says align() doesn't work with

Re: Zero-cost version-dependent function call at -O0.

2017-06-26 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 23:02:28 UTC, Adam D. Ruppe wrote: On Sunday, 25 June 2017 at 22:53:07 UTC, Johan Engelen wrote: I meant semantically no call. In the existing language, I think version (or static if) at the usage and definition points both is as good as you're going to get. At

Re: Zero-cost version-dependent function call at -O0.

2017-06-26 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 23:02:28 UTC, Adam D. Ruppe wrote: That'd be kinda tricky because the arguments would still be liable to be evaluated... Well.. I guess someone might argue that's a mis-feature of my preprocessor example: "foo(i++)" may not do what you want. (So the C code

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 22:23:44 UTC, Moritz Maxeiner wrote: The solution obviously does *not* work if you change the premise of your question after the fact by artificially injecting instructions into all function bodies I meant semantically no call. I am asking for a little more

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote: On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: [...] If version(X) is not defined, there should be no call and no extra code at -O0. [...] In C, you could do something like: ``` #if X void foo() {..} #else

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 16:29:20 UTC, Anonymouse wrote: Am I missing something, or can't you just version both the function and the function ćall? version(X) void foo() { /* ... */ } void main() { version(X) { foo(); } } I am hoping for something where "foo()" would

Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
How would you solve this problem: do an optional function call depending on some version(X). If version(X) is not defined, there should be no call and no extra code at -O0. ``` { ... foo(); // either compiles to a function call, or to _nothing_. ... } ``` In C, you could do something

Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 18 June 2017 at 09:56:50 UTC, Steven Schveighoffer wrote: On Sunday, 18 June 2017 at 09:28:57 UTC, Johan Engelen wrote: Reviving this thread to see whether anything has changed on the topic. If Timon gets static for each into the language, it can look a little better. Can you

Re: Solution to "statement is not reachable" depending on template variables?

2017-06-18 Thread Johan Engelen via Digitalmars-d-learn
Reviving this thread to see whether anything has changed on the topic. I now have this monster: ``` struct FMT { // has immutable members. FMT cannot be assigned to. } FMT monsterThatCompilerAccepts(T)(){ alias TP = Tuple!(__traits(getAttributes, T)); foreach(i, att; TP){

Re: Is D slow?

2017-06-10 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 10 June 2017 at 11:43:06 UTC, Johan Engelen wrote: On Friday, 9 June 2017 at 16:21:22 UTC, Honey wrote: What seems particularly strange to me is that -boundscheck=off leads to a performance decrease. Strange indeed. `-release` should be synonymous with `-release

Re: Is D slow?

2017-06-10 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 9 June 2017 at 16:21:22 UTC, Honey wrote: What seems particularly strange to me is that -boundscheck=off leads to a performance decrease. Strange indeed. `-release` should be synonymous with `-release -boundscheck=off`. Investigating... - Johan

Re: how to disable inlining of ldc2 when 'dub build --build=release'?

2017-05-20 Thread Johan Engelen via Digitalmars-d-learn
On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote: Now, I try to disable inlining in "dub.json" like == "dflags":[ "-disable-inlining" ], == but it doesn't work, because then dub calls ldc2 like this: 'ldc2 -disable-inlining -release -enable-inlining

  1   2   >