void[] vs ubyte[] - differences?

2025-07-16 Thread z via Digitalmars-d-learn
```D import std; void main() { void[] a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0x12345678]; void[] b = cast(ubyte[])[0, 1, 2, 3, 4, 5, 6, 7, 8]; ubyte[] c = cast(ubyte[])(cast(void[])[0, 1, 2, 3, 4, 5, 6, 7, 8,0x12345678]); ubyte[] d = [0, 1, 2, 3, 4, 5, 6, 7, 8]; void[] e = cast(uby

Re: Want a function that determines a double or float given its 80-bit IEEE 754 SANE (big endian) representation

2023-08-22 Thread z via Digitalmars-d-learn
On Tuesday, 22 August 2023 at 22:38:23 UTC, dan wrote: Hi, I'm parsing some files, each containing (among other things) 10 bytes said to represent an IEEE 754 extended floating point number, in SANE (Standard Apple Numerical Environment) form, as SANE existed in the early 1990s (so, big endia

Re: Is this code correct?

2023-04-07 Thread z via Digitalmars-d-learn
On Saturday, 1 April 2023 at 15:32:27 UTC, Dennis wrote: On Friday, 31 March 2023 at 13:11:58 UTC, z wrote: I've tried to search before but was only able to find articles for 3D triangles, and documentation for OpenGL, which i don't use. The first function you posted takes a 3D triangle as in

Re: Writing a dejargoniser - producing read ke analysis output in English that explains GDC / LDC asm code’s parameters and clobbers

2023-04-05 Thread z via Digitalmars-d-learn
On Wednesday, 5 April 2023 at 15:19:55 UTC, Cecil Ward wrote: How much code do you thing I would need to write for this? I’m still thinking about its feasibility. I don’t want to invent the wheel and write a custom parser by hand, so’d rather steal the code using sim eg called ‘a library’. :-)

Re: Is this code correct?

2023-03-31 Thread z via Digitalmars-d-learn
On Thursday, 30 March 2023 at 12:59:31 UTC, Dennis wrote: On Thursday, 30 March 2023 at 10:29:25 UTC, z wrote: Is this code correct or logically sound? You need to be exact on what 'correct' is. The comment above `triangleFacesCamera` says: Indicates wether a triangle faces an imaginary vi

Is this code correct?

2023-03-30 Thread z via Digitalmars-d-learn
Is this code correct or logically sound? ```D import std; enum {side/depth/height and side/height x,//0 y,//1 z //2 } /** Indicates wether a triangle faces an imaginary view point. */ bool triangleFacesCamera(float[3] tA, float[3] tB, float[3] tC) { float r1, r2; r1 = atan2(tB[x] - tA[x], tB

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-27 Thread z via Digitalmars-d-learn
On Sunday, 26 March 2023 at 18:07:03 UTC, ryuukk_ wrote: ``shared`` is even more ugly since everything must be shared afterwards The limitations of `shared` can be bypassed with a "function" that removes type qualifiers. `return *cast(Unqual!T*) &foo`(example, doesn't work as is for arrays.)

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-27 Thread z via Digitalmars-d-learn
On Sunday, 26 March 2023 at 18:07:03 UTC, ryuukk_ wrote: ``shared`` is even more ugly since everything must be shared afterwards The limitations of `shared` can be bypassed with a "function" that removes type qualifiers. `return *cast(Unqual!T*) &foo`(example, doesn't work as is for arrays.)

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-27 Thread z via Digitalmars-d-learn
On Sunday, 26 March 2023 at 18:07:03 UTC, ryuukk_ wrote: ``shared`` is even more ugly since everything must be shared afterwards The limitations of `shared` can be bypassed with a "function" that removes type qualifiers. `return *cast(Unqual!T*) &foo`(example, doesn't work as is for arrays.)

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-27 Thread z via Digitalmars-d-learn
On Sunday, 26 March 2023 at 18:07:03 UTC, ryuukk_ wrote: ``shared`` is even more ugly since everything must be shared afterwards The limitations of `shared` can be bypassed with a "function" that removes type qualifiers. `return *cast(Unqual!T*) &foo`(example, doesn't work as is for arrays.)

Re: Drawing a line code

2022-11-06 Thread z via Digitalmars-d-learn
On Sunday, 6 November 2022 at 20:07:47 UTC, z wrote: whenever the counter is above `1` I meant above or equal(`>=`), woops

Re: Drawing a line code

2022-11-06 Thread z via Digitalmars-d-learn
On Sunday, 6 November 2022 at 16:48:24 UTC, Joel wrote: I want my code fixed up so that works from any two points. You can add a condition to prevent writing out of the image/framebuffer/whatever memory so it won't do any out of bounds write. Another valid algorithm could be testing all pix

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread z via Digitalmars-d-learn
On Friday, 4 November 2022 at 10:57:12 UTC, Hipreme wrote: ... What do we use instead? I won't lie about the fact package.d forced me to workaround elusive "bugs" in my usage(1) but what is the alternative if we don't want to work around it? (1)(ime : had cases of package.d requiring compil

Re: Hipreme's #1 Tip of the day

2022-10-19 Thread z via Digitalmars-d-learn
On Wednesday, 19 October 2022 at 23:28:46 UTC, Hipreme wrote: Hey guys, I'm going to start making a tip of the day (although I'm pretty sure I won't be able to give every day a tip), but those things are really interesting to newcomers to know and may be obvious to some of the old schoolers the

Re: vectorization of a simple loop -- not in DMD?

2022-07-14 Thread z via Digitalmars-d-learn
On Monday, 11 July 2022 at 18:15:16 UTC, Ivan Kazmenko wrote: Hi. I'm looking at the compiler output of DMD (-O -release), LDC (-O -release), and GDC (-O3) for a simple array operation: ``` void add1 (int [] a) { foreach (i; 0..a.length) a[i] += 1; } ``` Here are the outputs: htt

Re: How to debug thread code

2022-07-10 Thread z via Digitalmars-d-learn
On Sunday, 10 July 2022 at 21:27:08 UTC, Hipreme wrote: I'm stuck in a racing condition right now and I'm unable to run a debugger on the code. Usually I was using Visual Studio 2019 for debugging my code, but it shows the following message: "Your app has entered a break state, but there is no

Re: a struct as an multidimensional array index

2022-06-11 Thread z via Digitalmars-d-learn
On Saturday, 11 June 2022 at 15:01:05 UTC, Ali Çehreli wrote: On 6/11/22 00:09, z wrote: > I rechecked and it should be `X Y Z` for static array, but `Z Y X` for > indexing/dynamic array creating with `new` How so? i meant with the syntax in (1), the spec's documentation appears to say they

Re: a struct as an multidimensional array index

2022-06-11 Thread z via Digitalmars-d-learn
On Saturday, 11 June 2022 at 03:56:32 UTC, Chris Katko wrote: On Friday, 10 June 2022 at 17:26:48 UTC, Ali Çehreli wrote: On 6/10/22 08:13, z wrote: > arrays of arrays has different order for declaration and addressing, > and declaring array of arrays has different order depending on how you >

Re: a struct as an multidimensional array index

2022-06-10 Thread z via Digitalmars-d-learn
On Friday, 10 June 2022 at 08:08:45 UTC, Chris Katko wrote: Is it somehow possible to use a struct as a [multidimensional] array index: D struct indexedPair { size_t x, y; } bool isMapPassable[100][100]; auto p = indexedPair(50, 50); if(isMapPassable[p]) return true; Probably not,

Graphing a D function : possible?

2022-06-01 Thread z via Digitalmars-d-learn
Is there a quick way of obtaining the graph of D functions like these? ```d T f(T) if (isScalarType!T){} ``` or ```D T[2] f(T, T)if (isScalarType!T){} ``` I know that there are graphing calculators already, but these don't support low level black magic like int <-> float conversions and i'm los

Union member positions?

2021-08-17 Thread z via Digitalmars-d-learn
Is it possible to set a "position" on a union member? or is there is a language-integrated equivalent? For example, to get access to each byte in an unsigned integer while still supporting the original type. ```D ///a single uint that would be accessed as two ushort, or four separate ubyte uni

Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread z via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote: On Windows: ``` ::> dmd curl_get.d ::> .\curl_get.exe object.Error@(0): Access Violation 0x0283CA66 0x0041DE8D 0x004023A2 0x00402308 0x00414D33 0x00414CAD 0x00414B48 0x0040D41F 0x00402363 0x74B96359 in BaseThreadInitThunk 0

Re: Parallel For

2021-06-15 Thread z via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 06:39:24 UTC, seany wrote: ... This is the best I could do: https://run.dlang.io/is/dm8LBP For some reason, LDC refuses to vectorize or even just unroll the nonparallel version, and more than one `parallel` corrupts the results. But judging by the results you expec

Re: ugly and/or useless features in the language.

2021-05-23 Thread z via Digitalmars-d-learn
On Saturday, 15 May 2021 at 14:31:08 UTC, Alain De Vos wrote: Which parts in dlang don't you use and why ? Auto return types i find dangerous to use. I found `auto` and `ref`(yes just `ref`) return types very useful for bypassing the type system, eg.: ```D ///function requires lvalue and the

Re: What's a good approach to DRY with the block code of a case-statement?

2021-04-28 Thread z via Digitalmars-d-learn
I'd recommend you to use templates with alias parameters but you mentioned that you need to retain function context(for gotos, continue, break, etc...) One thing you could do is mix the ugly mixin solution with the good one: ```D //inside the function, so that you can access locals pragma(inlin

Re: AliasSeq different from just using the symbol name(s)?

2021-04-17 Thread z via Digitalmars-d-learn
On Thursday, 15 April 2021 at 19:53:57 UTC, Paul Backus wrote: They're not *exactly* the same. When you write auto seq = AliasSeq!(a, b, c); ...you are declaring a sequence of three *new* array variables [1] and initializing them with copies of the original arrays. It's as though you'd wr

Re: AliasSeq different from just using the symbol name(s)?

2021-04-15 Thread z via Digitalmars-d-learn
On Thursday, 15 April 2021 at 19:38:04 UTC, z wrote: ```D int[] a,b,c,d,e; void templatef(args...){/*...*/} //... auto seq = AliasSeq!(b,c,d); templatef!(a,seq,e); templatef!(a,b,c,d,e); //am i being mistaken for thinking these two template calls should be equivalent in behavior? ``` woops, me

Re: AliasSeq different from just using the symbol name(s)?

2021-04-15 Thread z via Digitalmars-d-learn
On Thursday, 15 April 2021 at 18:58:40 UTC, Paul Backus wrote: Without an example that shows the actual problem you encountered, it will be almost impossible for anyone to help you figure out what is causing it. Since you were not able to trigger it, it seems likely that the problem is relate

AliasSeq different from just using the symbol name(s)?

2021-04-15 Thread z via Digitalmars-d-learn
I've tried to group together a bundle of alias template parameters with AliasSeq, but while without it works just fine, when the verbose parameters are grouped with multiple AliasSeqs, the lengths of the array parameters passed through AliasSeq are 0(inside the templated function, before the ca

Re: dub commands do not run correctly.

2021-04-10 Thread z via Digitalmars-d-learn
On Saturday, 10 April 2021 at 13:15:19 UTC, Alain De Vos wrote: dub fetch lint Getting a release version failed: (1): Error: Got JSON of type null_, expected object. Retry with ~master... (1): Error: Got JSON of type null_, expected object. He meant `dub lint`, with the working directory in t

Re: Extern/scope issue

2021-04-03 Thread z via Digitalmars-d-learn
On Saturday, 3 April 2021 at 10:17:14 UTC, DLearner wrote: Does this mean D has no equivalent of C globals? What is the D way of doing this? With __gshared. If the global is defined from within another language, apparently you'd have to do [extern(C) extern __gshared *name*](https://dlang.org

Re: Casting lvalues

2021-04-02 Thread z via Digitalmars-d-learn
On Friday, 2 April 2021 at 12:47:35 UTC, z wrote: ```d T processArray(T)(ref T[] p){/*...*/} //function calls .reserve ``` i meant `void` for the function return type.

Casting lvalues

2021-04-02 Thread z via Digitalmars-d-learn
```d shared TT[] a; T processArray(T)(ref T[] p){/*...*/} //function calls .reserve on its parameter a.processArray; ``` Template *name* cannot deduce function from argument types !()(shared(T[]))... Even if the function is changed to only accept shared parameters, .reserve does not appear t

Re: Using YMM registers causes an undefined label error

2021-03-19 Thread z via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 20:33:01 UTC, z wrote: On Tuesday, 9 March 2021 at 20:23:48 UTC, z wrote: On Friday, 5 March 2021 at 12:57:43 UTC, z wrote: ... Then it seems the only way to get AVX-compatible inline assembly(ldc.llvmasm excluded) is to use an external assembler. For example :

Re: Using YMM registers causes an undefined label error

2021-03-09 Thread z via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 20:23:48 UTC, z wrote: On Friday, 5 March 2021 at 12:57:43 UTC, z wrote: ... Then it seems the only way to get AVX-compatible inline assembly(ldc.llvmasm excluded) is to use an external assembler. For example : ... But i'm not really sure how to integrate that i

Re: Using YMM registers causes an undefined label error

2021-03-09 Thread z via Digitalmars-d-learn
On Friday, 5 March 2021 at 12:57:43 UTC, z wrote: ... Then it seems the only way to get AVX-compatible inline assembly(ldc.llvmasm excluded) is to use an external assembler. For example : import std.stdio; extern(C) void vxorps_d(ubyte[32]*); void main() { ubyte[32] a = 2;

Re: Optimizing for SIMD: best practices?(i.e. what features are allowed?)

2021-03-07 Thread z via Digitalmars-d-learn
On Friday, 26 February 2021 at 03:57:12 UTC, tsbockman wrote: static foreach(size_t i; 0 .. 3/+typeof(a).length+/){ distance += a[i].abs;//abs required by the caller (a * a) above is always positive for real numbers. You don't need the call to abs unless you're trying to guarantee that

Re: Optimizing for SIMD: best practices?(i.e. what features are allowed?)

2021-03-07 Thread z via Digitalmars-d-learn
On Thursday, 25 February 2021 at 14:28:40 UTC, Guillaume Piolat wrote: On Thursday, 25 February 2021 at 11:28:14 UTC, z wrote: How does one optimize code to make full use of the CPU's SIMD capabilities? Is there any way to guarantee that "packed" versions of SIMD instructions will be used?(e.g.

Re: Optimizing for SIMD: best practices?(i.e. what features are allowed?)

2021-03-07 Thread z via Digitalmars-d-learn
On Thursday, 25 February 2021 at 11:28:14 UTC, z wrote: ... It seems that using static foreach with pointer parameters exclusively is the best way to "guide" LDC into optimizing code.(using arr1[] += arr2[] syntax resulted in worse performance for me.) However, AVX512 support seems limited to

Re: dmd -> ldmd2: /usr/bin/ld.gold: error: .o: multiple definition of 'bool ldc.attributes...

2021-03-07 Thread z via Digitalmars-d-learn
On Saturday, 6 March 2021 at 22:14:26 UTC, kdevel wrote: After replacing dmd with ldmd2 (LDC 1.25.1) I get tons of link errors all of the form mentioned in the subject. Any idea what can be done about it? (With a handcrafted single compile/link statement using ldc2 everything compiles but id

Re: Using YMM registers causes an undefined label error

2021-03-05 Thread z via Digitalmars-d-learn
On Friday, 5 March 2021 at 16:10:02 UTC, Rumbu wrote: First of all, in 64 bit ABI, parameters are not passed on stack, therefore a[RBP] is a nonsense. void complement32(simdbytes* a, simdbytes* b) a is in RCX, b is in RDX on Windows a is in RDI, b is in RSI on Linux I'm confused, with your hel

Using YMM registers causes an undefined label error

2021-03-05 Thread z via Digitalmars-d-learn
XMM registers work, but as soon as they are changed into YMM DMD outputs "bad type/size of operands %s" and LDC outputs an "label YMM0 is undefined" error. Are they not supported? To illutrate : https://run.dlang.io/is/IqDHlK By the way, how can i use instructions that are not listed in [1]?(v

Optimizing for SIMD: best practices?(i.e. what features are allowed?)

2021-02-25 Thread z via Digitalmars-d-learn
How does one optimize code to make full use of the CPU's SIMD capabilities? Is there any way to guarantee that "packed" versions of SIMD instructions will be used?(e.g. vmulps, vsqrtps, etc...) To give some context, this is a sample of one of the functions that could benefit from better SIMD usa

Struct delegate access corruption

2021-02-17 Thread z via Digitalmars-d-learn
So i've upgraded one of my structs to use the more flexible delegates instead of function pointers but when the member function tries to access the struct's members, the contents are random and the program fails. i've isolated the problem by adding writefln calls before calling the delegate a

Re: Fastest way to "ignore" elements from array without removal

2021-02-16 Thread z via Digitalmars-d-learn
On Tuesday, 16 February 2021 at 06:03:50 UTC, H. S. Teoh wrote: It depends on what your goal is. Do you want to permanently remove the items from the array? Or only skip over some items while iterating over it? For the latter, see std.algorithm.iteration.filter. The array itself is read only

Re: Fastest way to "ignore" elements from array without removal

2021-02-16 Thread z via Digitalmars-d-learn
On Tuesday, 16 February 2021 at 04:43:33 UTC, Paul Backus wrote: On Tuesday, 16 February 2021 at 04:20:06 UTC, z wrote: What would be the overall best manner(in ease of implementation and speed) to arbitrarily remove an item in the middle of an array while iterating through it? http://phobos.

Fastest way to "ignore" elements from array without removal

2021-02-15 Thread z via Digitalmars-d-learn
What would be the overall best manner(in ease of implementation and speed) to arbitrarily remove an item in the middle of an array while iterating through it? So far i've thought about simply using D's standard [0...x] ~ [x+1..$] with an array of indexes but wouldn't that just cause slow reallo

Re: A variation of issue 11977?

2021-01-21 Thread z via Digitalmars-d-learn
On Thursday, 21 January 2021 at 14:11:15 UTC, kdevel wrote: Creating a scope works around the issue. Another way to work around the issue is to use «asm {jmp label;}» (replace jmp by whatever equivalent is there on the target architecture.) Yes it's ugly, but it bypasses the arbitrary limita

Re: writeln and write at CTFE

2021-01-13 Thread z via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 11:50:26 UTC, Andrey wrote: Function "ctfeWriteln" doens't exist. pragma(msg, ...) is used only for CT values. Today is 2021. Dlang still doesn't have ctfe write functions? Yes.(afaik) It has shot me on the foot once, to the point i abandoned the idea of eve

Re: Undefined reference error at linktime with unittests

2020-12-10 Thread z via Digitalmars-d-learn
On Thursday, 10 December 2020 at 14:51:51 UTC, ag0aep6g wrote: ... Thank you for the explanation on mangles. The problem was caused by an «unittest{ void main() }» declaration in an import's source file, and for some reason it had both passed compilation and not resulted in the usual "undef

Undefined reference error at linktime with unittests

2020-12-10 Thread z via Digitalmars-d-learn
When compiling with unit tests(via «dub test», or adding «dflags "-unittest"»), i'm getting this error at link time : lld-link: error: undefined symbol: _D5packagename9subpackage9__mixin119type8toStringMFZAya The same occurs with OPTLINK. Curiously, looking at the incriminated .lib file with

Re: Local libraries/packages with dub: How?

2020-12-01 Thread z via Digitalmars-d-learn
On Tuesday, 1 December 2020 at 07:39:31 UTC, rikki cattermole wrote: That isn't right. Thank you, this was the problem apparently. Dub ignored the malformed dependency declaration instead of displaying a warning or an error.(this is apparently a bug.[0][1]) [0] https://github.com/dlang/dub/

Re: Local libraries/packages with dub: How?

2020-11-30 Thread z via Digitalmars-d-learn
On Tuesday, 1 December 2020 at 04:50:03 UTC, rikki cattermole wrote: ... What puzzles me is that the dependencies are indeed declared, but "dub describe" refuses to recognize the dependencies and "dub build" fails. "dub list" does recognize the root folder, but trying to get a subpackage to

Local libraries/packages with dub: How?

2020-11-30 Thread z via Digitalmars-d-learn
How does one set up a dub package so that it contains multiple sublibraries that may or may not depend on these same libraries?(but never co-dependant) So far i've tried using add-local and add-path with subpackage declarations in the root folder's dub.sdl but to no avail. (dub does not complain

Re: Alias overload of function

2019-06-09 Thread Basile-z via Digitalmars-d-learn
On Sunday, 9 June 2019 at 10:22:36 UTC, Andrey wrote: Hello, I have got 2 functions: void myFunc(string name, int a)(wstring value) {} void myFunc(string name, int a)() {} I want to make an alias (for example for second function without argument): alias myAlias(int a) = myFunc!("Name", a);