Re: std.container.Array deep-copy?
On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote: On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote: How can you deep-copy a std.container.Array instance? Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of Array!X instances? You will just need to slice it to provide a range.
Re: object hijacked ?
On 09/10/14 22:06, Dicebot wrote: I think this is an issue with the import resolution, not module system. The way it is implemented right now DMD stops searching for object.d / object.di once it has found one. So while your module name is not interpreted as "object" _original_ object.di does not get imported and you get lot of different issues from missing declarations. So it just picks the first filename matching "object" and doesn't care about its module name. -- /Jacob Carlborg
Re: Splitting Ranges using Lambda Predicates
On Thursday, 9 October 2014 at 22:01:31 UTC, monarch_dodra wrote: My quick guess is you are missing the *global* imports for the restraints. The compiler doesn't complain because the constraint is in a "is(typeof(...))" test. The reason the typeof fails is simply cause the compiler has no idea what unaryFun is. I don't understand. The restraints are commented out at https://github.com/nordlow/justd/blob/master/slicer.d I made a couple of changes and now it works but I don't quite understand why... Thanks anyway.
Re: What is a sink delegate?
On 10/09/2014 08:06 PM, Joel wrote: On Tuesday, 30 September 2014 at 17:27:09 UTC, Adam D. Ruppe wrote: On Tuesday, 30 September 2014 at 17:22:44 UTC, Gary Willoughby wrote: What is a sink delegate? Instead of string toString() { return "foo"; } for example, you would use: void toString(void delegate(string) sink) { sink("foo"); } The sink argument there is then free to view and discard the data or to make a private copy using whatever scheme it desires. How do you use that toString? Maybe an example? Below is my failed effort. import std.stdio; struct Try { string name; long age; void toString(void delegate(string) sink) { sink("foo"); } } void main() { Try t = Try("Joel", 35); writeln(t); } The signature of that toString is different from what I have been seeing and using. The following works: void toString(void delegate(const(char)[]) sink) const { Ali
Re: What is a sink delegate?
On Friday, 10 October 2014 at 03:06:33 UTC, Joel wrote: How do you use that toString? Maybe an example? void main() { Try t = Try("Joel", 35); t.toString(s => writeln(s)); }
Re: What is a sink delegate?
On Tuesday, 30 September 2014 at 17:27:09 UTC, Adam D. Ruppe wrote: On Tuesday, 30 September 2014 at 17:22:44 UTC, Gary Willoughby wrote: What is a sink delegate? Instead of string toString() { return "foo"; } for example, you would use: void toString(void delegate(string) sink) { sink("foo"); } The sink argument there is then free to view and discard the data or to make a private copy using whatever scheme it desires. How do you use that toString? Maybe an example? Below is my failed effort. import std.stdio; struct Try { string name; long age; void toString(void delegate(string) sink) { sink("foo"); } } void main() { Try t = Try("Joel", 35); writeln(t); }
Re: building shared library from D code to import into cython
On Wednesday, 8 October 2014 at 00:25:57 UTC, Laeeth Isharc wrote: Hi. Thanks for the quick response. The -defaultlib was left around from trying all kinds of combinations of dmd and gcc. I am not used to gcc, and it will take me some time to become properly acquainted with all the options. I managed to get it to compile with default dmd rpm: https://github.com/ariovistus/cythonic_d fedora 20, x86_64 Are you aware of pyd? (https://bitbucket.org/ariovistus/pyd) It knows how to build shared libraries, so I recommend you play with it, if only to watch how it does that. Biggest gotcha is starting up druntime.
Re: How do I write __simd(void16*, void16) ?
On 2014-10-09 17:32, Etienne wrote: That's very helpful, the problem remains that the API is unfamiliar. I think most of the time, simd code will only need to be translated from basic function calls, it would've been nice to have equivalents :-p Sorry, I think I had a bad understanding. I found out through a github issue that you need to use pragma(LDC_intrinsic, "llvm.*") [function declaration] https://github.com/ldc-developers/ldc/issues/627 And the possible gcc-style intrinsics are defined here: https://www.opensource.apple.com/source/clamav/clamav-158/clamav.Bin/clamav-0.98/libclamav/c++/llvm/include/llvm/Intrinsics.gen This really begs for at binding hat works with all compilers.
Re: Splitting Ranges using Lambda Predicates
On Thursday, 9 October 2014 at 21:55:03 UTC, Nordlöw wrote: On Wednesday, 11 June 2014 at 08:58:58 UTC, monarch_dodra wrote: auto slicer(alias isTerminator, Range)(Range input) if (((isRandomAccessRange!Range && hasSlicing!Range) || isSomeString!Range) && is(typeof(unaryFun!isTerminator(input.front { return SlicerResult!(unaryFun!isTerminator, Range)(input); } ... Your solution copied here https://github.com/nordlow/justd/blob/master/slicer.d errors as /home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/algorithm.d(5752,24): Error: template std.functional.not!(isUpper).not cannot deduce function from argument types !()(dchar), candidates are: /home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/functional.d(393,10): std.functional.not!(isUpper).not(T...)(T args) if (is(typeof(!unaryFun!pred(args))) || is(typeof(!binaryFun!pred(args slicer.d(29,31): Error: template instance std.algorithm.find!(not, string) error instantiating slicer.d(16,12):instantiated from here: Slicer!(isUpper, string) slicer.d(85,30):instantiated from here: slicer!(isUpper, string) What's wrong? My quick guess is you are missing the *global* imports for the restraints. The compiler doesn't complain because the constraint is in a "is(typeof(...))" test. The reason the typeof fails is simply cause the compiler has no idea what unaryFun is.
Re: Splitting Ranges using Lambda Predicates
On Wednesday, 11 June 2014 at 08:58:58 UTC, monarch_dodra wrote: auto slicer(alias isTerminator, Range)(Range input) if (((isRandomAccessRange!Range && hasSlicing!Range) || isSomeString!Range) && is(typeof(unaryFun!isTerminator(input.front { return SlicerResult!(unaryFun!isTerminator, Range)(input); } ... Your solution copied here https://github.com/nordlow/justd/blob/master/slicer.d errors as /home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/algorithm.d(5752,24): Error: template std.functional.not!(isUpper).not cannot deduce function from argument types !()(dchar), candidates are: /home/per/opt/x86_64-unknown-linux-gnu/dmd/linux/bin64/src/phobos/std/functional.d(393,10): std.functional.not!(isUpper).not(T...)(T args) if (is(typeof(!unaryFun!pred(args))) || is(typeof(!binaryFun!pred(args slicer.d(29,31): Error: template instance std.algorithm.find!(not, string) error instantiating slicer.d(16,12):instantiated from here: Slicer!(isUpper, string) slicer.d(85,30):instantiated from here: slicer!(isUpper, string) What's wrong?
Re: Advanced (HTML5/JS) client webpage connecting to vibe.d server backend
On Wednesday, 8 October 2014 at 23:34:47 UTC, Rikki Cattermole wrote: I have a client side templating solution you might be interested in [0]. But not a fully featured sort of thing. [0] https://github.com/rikkimax/client-templating Thanks.
Re: How do I write __simd(void16*, void16) ?
On Wednesday, 8 October 2014 at 18:56:31 UTC, Etienne wrote: I can't seem to find this function anywhere: __simd(void16*, void16) MOVDQU => void _mm_storeu_si128 ( __m128i *p, __m128i a) MOVDQU => __m128i _mm_loadu_si128 ( __m128i *p) Is there a module by now that allows to directly write Intel intrinsics?
Re: How do I write __simd(void16*, void16) ?
On 2014-10-09 5:05 PM, David Nadlinger wrote: On Thursday, 9 October 2014 at 20:29:44 UTC, Benjamin Thaut wrote: Unforunately the gcc.buildints module seems to be generated during compilation of gdc, so you might want to get a binary version or compile it yourself to see the module. By the way, LDC has ldc.gccbuiltins_x86 too. LLVM doesn't export all the GCC-style intrinsics, though, if they are easily representable in normal LLVM IR (thus ldc.simd). Daivd That's very helpful, the problem remains that the API is unfamiliar. I think most of the time, simd code will only need to be translated from basic function calls, it would've been nice to have equivalents :-p
Re: std.container.Array deep-copy?
On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote: How can you deep-copy a std.container.Array instance? Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of Array!X instances?
Re: How do I write __simd(void16*, void16) ?
On 2014-10-09 4:29 PM, Benjamin Thaut wrote: I think a good starting point would be Manu's std.simd module. I don't know if he is still working on it, but a old version can be found here: https://github.com/TurkeyMan/simd/blob/master/std/simd.d That's a great reference! I can do a lot from that. I wish it wasn't an EDSL, makes it really hard to translate the simd code to D. You can also find the druntime versions of ldc and gdc on github. For example: https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/simd.di https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/builtins.d Unforunately the gcc.buildints module seems to be generated during compilation of gdc, so you might want to get a binary version or compile it yourself to see the module. OK, thanks !
std.container.Array deep-copy?
How can you deep-copy a std.container.Array instance? The actual array data is heap-allocated and reference-counted. Assignment and .dup only create additional references. Using a copy constructor yields an error: Array!Foo x; Array!Foo y = Array!Foo(x); Error: template std.container.Array!(Foo).Array.__ctor cannot deduce function from argument types !()(Array!(Foo)), candidates are: /opt/compilers/dmd2/include/std/container.d(2652): std.container.Array!(Foo).Array.__ctor(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) /opt/compilers/dmd2/include/std/container.d(2670): std.container.Array!(Foo).Array.__ctor(Stuff)(Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T) && !is(Stuff == T[])) The question came up in a reddit discussion: http://www.reddit.com/r/programming/comments/2ipdpa/floss_weekly_311_the_d_language/cl4yv8w
Re: How do I write __simd(void16*, void16) ?
On Thursday, 9 October 2014 at 20:29:44 UTC, Benjamin Thaut wrote: Unforunately the gcc.buildints module seems to be generated during compilation of gdc, so you might want to get a binary version or compile it yourself to see the module. By the way, LDC has ldc.gccbuiltins_x86 too. LLVM doesn't export all the GCC-style intrinsics, though, if they are easily representable in normal LLVM IR (thus ldc.simd). Daivd
Re: How do I write __simd(void16*, void16) ?
Am 09.10.2014 21:04, schrieb Etienne: On 2014-10-09 2:32 PM, Benjamin Thaut wrote: I know that GDC stopped supporting D style inline asm a while ago. If you need inline asm with GDC you have to use the gcc style inline assembly. I don't know about ldc though. But generally you want to use the official intrinsics with gdc and ldc because they won't perform any optimizations on inline assembly. Kind Regards Benjamin Thaut Any idea where I can find the headers in D for it? I think a good starting point would be Manu's std.simd module. I don't know if he is still working on it, but a old version can be found here: https://github.com/TurkeyMan/simd/blob/master/std/simd.d If you have further questions you might be well advised to ask him: turkey...@gmail.com You can also find the druntime versions of ldc and gdc on github. For example: https://github.com/ldc-developers/druntime/blob/ldc/src/ldc/simd.di https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/builtins.d Unforunately the gcc.buildints module seems to be generated during compilation of gdc, so you might want to get a binary version or compile it yourself to see the module. Kind Regards Benjamin Thaut
Re: object hijacked ?
I think this is an issue with the import resolution, not module system. The way it is implemented right now DMD stops searching for object.d / object.di once it has found one. So while your module name is not interpreted as "object" _original_ object.di does not get imported and you get lot of different issues from missing declarations.
Re: Byte Array Literal
ketmar: additionally to all bearophile said, there is another interesting thing in D: special string literals for hex data. immutable ubyte[] n = cast(typeof(n))x"deadf00d"; or even: immutable ubyte[] n = cast(typeof(n))x"de ad f 0 0 d"; spaces doesn't matter, only digits do. The problem is that cast. No one wants a string, most people want a ubyte[]. See: https://issues.dlang.org/show_bug.cgi?id=3850 https://issues.dlang.org/show_bug.cgi?id=5909 https://issues.dlang.org/show_bug.cgi?id=10454 Bye, bearophile
Re: Simple import question
On 10/9/14 3:30 PM, Adam D. Ruppe wrote: On Thursday, 9 October 2014 at 18:21:32 UTC, WhatMeWorry wrote: "To import one module from another, specify the name of the module in an import declaration. The name must include the relative path computed from the directory where compilation takes place" This is not true. It is a REALLY common misconception, but it is not true. The import name must match the name given in the module declaration of the file. So in the file you're importing, add "module your.name;" to the top. In the main file, import it as "import your.name;". If those two don't match, it will complain "cannot import module "foo" as "foo.bar"" or something like that. Yes, but in order to read the file, it has to be passed to the compiler, or reside at the location dictated by that module name. This is something quite different from C/C++, because the location in the filesystem doesn't matter at all for the compiler, only the preprocessor. Here, the file location AND module declaration are important. It is recommended that the module name match the file name and folder name, but it is the module declaration at the top that matters, not the file/folder name. You will encounter great pains to not do this (match folder/file names with package/module names). -Steve
object hijacked ?
I have a file named "Object.d", in a directory called "foo". The module name of this file is "foo.Object". As it happens, I'm using OS X which uses a case insensitive file system. I also have another file, say "Bar.d" in "foo", with the module name "foo.Bar". When I try to compile/run Bar.d with rdmd as follows: rdmd foo/Bar.d I get a lot of errors like "undefined identifier string" and "undefined identifier size_t" from some modules in druntime and Phobos. If I rename "foo/Object.d" to "foo/Object2.d", leaving the module name as "foo.Object" everything works as expected. WAT?? I thought D's module system would prevent mistakes like this. Is this the expected behavior? I think the issue is that "rdmd" adds a flag, "-Ifoo", when running dmd to get the dependencies. But the module system should still prevent it. It seems like the compiler uses the filename instead of the declared module name as the module name. -- /Jacob Carlborg
Re: Forward Reference
On Thursday, 9 October 2014 at 19:29:13 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 09 Oct 2014 19:04:55 + Anibal via Digitalmars-d-learn wrote: Hi everyone, I'm trying to something like a tree structure. The following: import std.container; class Tree { private SList!Tree subTree; } Produces: class Tree no size yet for forward reference. How i should proceed in order to keep this declaration? do you really need single-linked list for that? D has dynamic arrays, which can be used instead. class Tree { private Tree[] subTree; } you can append items to dynamic array with "~=", get it length with .length and so on. seems that you trying to copy some C code (or writing in C manner), amirite? it is possible to use D as "better C", but D has alot more to offer. did you seen this excellent book: http://ddili.org/ders/d.en/ ? it will teach you some nice things which are absent in C. read it even if you are seasoned C programmer. you'll see a joy of dynamic arrays, slices, ranges and templates, nicely explained. Thanks a lot, declaring it as an array solved mi troubles!
Re: Simple import question
On Thursday, 9 October 2014 at 18:21:32 UTC, WhatMeWorry wrote: "To import one module from another, specify the name of the module in an import declaration. The name must include the relative path computed from the directory where compilation takes place" This is not true. It is a REALLY common misconception, but it is not true. The import name must match the name given in the module declaration of the file. So in the file you're importing, add "module your.name;" to the top. In the main file, import it as "import your.name;". If those two don't match, it will complain "cannot import module "foo" as "foo.bar"" or something like that. It is recommended that the module name match the file name and folder name, but it is the module declaration at the top that matters, not the file/folder name. Ok, but how does one determine where compilation takes place? The directory from which you run the compiler. But the best way is to explicitly pass all the file names to the compiler: dmd yourfile.d file2.d folder/file3.d and so on... Doing that will serve you best in the long run, it will work with any module name and will link better too.
Re: Forward Reference
On Thursday, 9 October 2014 at 19:04:56 UTC, Anibal wrote: Hi everyone, I'm trying to something like a tree structure. The following: import std.container; class Tree { private SList!Tree subTree; } Produces: class Tree no size yet for forward reference. How i should proceed in order to keep this declaration? Thanks a lot! PD: (You guys are incredibly quick to answer, that's awesome!) make a pointer list instead, which has a fixed size: --- import std.container; class Tree { private SList!(Tree*) subTree; } ---
Re: Forward Reference
On Thu, 09 Oct 2014 19:04:55 + Anibal via Digitalmars-d-learn wrote: > Hi everyone, > > I'm trying to something like a tree structure. > > The following: > > import std.container; > class Tree > { > private SList!Tree subTree; > } > > Produces: class Tree no size yet for forward reference. > > How i should proceed in order to keep this declaration? do you really need single-linked list for that? D has dynamic arrays, which can be used instead. class Tree { private Tree[] subTree; } you can append items to dynamic array with "~=", get it length with .length and so on. seems that you trying to copy some C code (or writing in C manner), amirite? it is possible to use D as "better C", but D has alot more to offer. did you seen this excellent book: http://ddili.org/ders/d.en/ ? it will teach you some nice things which are absent in C. read it even if you are seasoned C programmer. you'll see a joy of dynamic arrays, slices, ranges and templates, nicely explained. signature.asc Description: PGP signature
Re: Byte Array Literal
On Thu, 09 Oct 2014 15:26:52 + Anibal via Digitalmars-d-learn wrote: additionally to all bearophile said, there is another interesting thing in D: special string literals for hex data. immutable ubyte[] n = cast(typeof(n))x"deadf00d"; or even: immutable ubyte[] n = cast(typeof(n))x"de ad f 0 0 d"; spaces doesn't matter, only digits do. signature.asc Description: PGP signature
Re: How do I write __simd(void16*, void16) ?
On 2014-10-09 2:32 PM, Benjamin Thaut wrote: I know that GDC stopped supporting D style inline asm a while ago. If you need inline asm with GDC you have to use the gcc style inline assembly. I don't know about ldc though. But generally you want to use the official intrinsics with gdc and ldc because they won't perform any optimizations on inline assembly. Kind Regards Benjamin Thaut Any idea where I can find the headers in D for it?
Forward Reference
Hi everyone, I'm trying to something like a tree structure. The following: import std.container; class Tree { private SList!Tree subTree; } Produces: class Tree no size yet for forward reference. How i should proceed in order to keep this declaration? Thanks a lot! PD: (You guys are incredibly quick to answer, that's awesome!)
Re: Byte Array Literal
On Thursday, 9 October 2014 at 15:41:48 UTC, bearophile wrote: You want ubytes (unsigned bytes) because 0x04 is 164 that is bigger than byte.max. I'd like bytes to be named sbyte and ubyte in D, but Walter has refused this. Bye, bearophile Got it to work, thanks a lot!
Re: dupping to allow vector operation?
Marc Schütz: It's equivalent to: int[] tmp = a1[] * 3; int[] a4 = tmp.dup; The first part is of course identical to line 3, so this should be an error, too. Normal rules for evaluation order require `a1[] * 3` to be evaluated before `(...).dup`, so where is it supposed to store the intermediate result? So do we need a new different syntax to do it? :-) Bye, bearophile
Re: Simple import question
It's the current working directory, i.e. the directory from where you run the compiler. IDEs usually use the root directory of the project as working directory.
Re: How do I write __simd(void16*, void16) ?
Am 08.10.2014 21:12, schrieb Etienne: On 2014-10-08 3:04 PM, Benjamin Thaut wrote: I strongly advise to not use core.simd at this point. It is in a horribly broken state and generates code that is far from efficient. If I think I'll have to re-write the xmmintrin.h functions I need as string mixins to inline the assembly. Is that supposed to be compatible with LDC/GDC anyways? I know that GDC stopped supporting D style inline asm a while ago. If you need inline asm with GDC you have to use the gcc style inline assembly. I don't know about ldc though. But generally you want to use the official intrinsics with gdc and ldc because they won't perform any optimizations on inline assembly. Kind Regards Benjamin Thaut
Simple import question
Hope this question is not too simple minded but, In the TDPL it says: "To import one module from another, specify the name of the module in an import declaration. The name must include the relative path computed from the directory where compilation takes place" Ok, but how does one determine where compilation takes place? Is it: 1) The directory where main() resides. 2) The directory where the executable resides after it is built. 3) The directory of where the dmd compiler is at.
Re: dupping to allow vector operation?
On Thursday, 9 October 2014 at 11:29:14 UTC, bearophile wrote: Observe: void main() { int[3] a1 = [1, 3, 6]; int[] a2 = a1[] * 3; // line 3, Error int[] a3 = a1.dup[] *= 3; // line 4, OK? int[] a4 = (a1[] * 3).dup; // line 5, Error } Currently the operation in line 4 is accepted: test.d(3,17): Error: array operation a1[] * 3 without destination memory not allowed test.d(5,18): Error: array operation a1[] * 3 without destination memory not allowed Is it a good idea to support something like line 5? It's equivalent to: int[] tmp = a1[] * 3; int[] a4 = tmp.dup; The first part is of course identical to line 3, so this should be an error, too. Normal rules for evaluation order require `a1[] * 3` to be evaluated before `(...).dup`, so where is it supposed to store the intermediate result?
Re: dupping to allow vector operation?
On Thursday, 9 October 2014 at 11:29:14 UTC, bearophile wrote: Observe: void main() { int[3] a1 = [1, 3, 6]; int[] a2 = a1[] * 3; // line 3, Error int[] a3 = a1.dup[] *= 3; // line 4, OK? int[] a4 = (a1[] * 3).dup; // line 5, Error } Currently the operation in line 4 is accepted: test.d(3,17): Error: array operation a1[] * 3 without destination memory not allowed test.d(5,18): Error: array operation a1[] * 3 without destination memory not allowed Is it a good idea to support something like line 5? Bye, bearophile Why not? Looks fine to me, you've explicitly allocated some new memory for the result to sit in, the lack of which is the motivation for lines 3 an 5 being errors.
Re: Building a dmd that works on old systems: TLS problems with libc
On Friday, 3 October 2014 at 10:47:11 UTC, David Nadlinger wrote: On Friday, 3 October 2014 at 08:47:07 UTC, Atila Neves wrote: ld: <...>/libphobos2.a(sections_linux_570_420.o): undefined reference to symbol '__tls_get_addr@@GLIBC_2.3' /lib64/ld-linux-x86-64.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status So to be clear, this is with a libphobos2.a built on the target system? The error message looks like you might have a Phobos library built for a newer libc. David I am experiencing a similar problem trying to build a static executable, exactly as described in https://issues.dlang.org/show_bug.cgi?id=12268 . I don't know if the root cause is a gcc issue or a phobos issue.
Re: Byte Array Literal
You want ubytes (unsigned bytes) because 0x04 is 164 that is bigger than byte.max. I'd like bytes to be named sbyte and ubyte in D, but Walter has refused this. Bye, bearophile
Re: Byte Array Literal
Anibal: byte[] arr = [ 0x00, 0xA4, 0x04]; This throws a int[] to byte[] cast error You want ubytes (unsigned bytes) because 0x04 is 164 that is bigger than byte.max. So use: ubyte[] arr = [ 0x00, 0xA4, 0x04]; I also tried byte[] arr = [cast(byte) 0x00, cast(byte)0xA4, cast(byte) 0x04]; and this at least compiles Generally in D try to mimize as much as possible the usage of cast(). Bye, bearophile
Byte Array Literal
Hi everyone, I'm just starting with D and i need a way to declare a byte array something like: byte[] arr = [ 0x00, 0xA4, 0x04]; This throws a int[] to byte[] cast error Tried also these ones byte[] arr = "\x00\xA4\x04"; byte[] arr = [ '\x00', '\xA4', '\x04']; byte[] arr = [ u'\x00', u'\xA4', u'\x04']; byte[] arr = [ b'\x00', b'\xA4', b'\x04']; I also tried byte[] arr = [cast(byte) 0x00, cast(byte)0xA4, cast(byte) 0x04]; and this at least compiles I read the online book and nowhere there is a byte literal mentioned. Is there another way besides casting to byte? Thanks in Advance.
Re: Multithreading in D
On 10/09/2014 03:10 AM, Konstantin wrote: Are you looking for parallel? http://dlang.org/library/std/parallelism/parallel.html I have seen this, but I'm not sure how to use it. I have the following chapter with some examples: http://ddili.org/ders/d.en/parallelism.html If concurrency is more suited to your application, then there is the following as well: http://ddili.org/ders/d.en/concurrency.html Ali
Re: Using inline assembler
On 2014-10-09 9:46 AM, anonymous wrote: I'm out of my knowledge zone here, but it seems to work when you move the pointers to registers first: void store(__m128i* src, __m128i* dst) { asm { mov RAX, src; mov RBX, dst; movdqu XMM0, [RAX]; movdqu [RBX], XMM0; } } Absolutely incredible! My first useful working assembler code. You save the day. Now I can probably write a whole SIMD library ;)
Re: Using inline assembler
On Thursday, 9 October 2014 at 13:29:27 UTC, Etienne wrote: On 2014-10-09 8:54 AM, anonymous wrote: This compiles: align(16) union __m128i { ubyte[16] data; } /* note the position of the semicolon */ void store(__m128i* src, __m128i* dst) { asm { movdqu XMM0, [src]; /* note: [src] */ movdqu [dst], XMM0; } } Yes, this does compile, but the value from src never ends up stored in dst. void main() { __m128i src; src.data[0] = 255; __m128i dst; writeln(src.data); // shows 255 at offset 0 store(&src, &dst); writeln(dst.data); // remains set as the initial array } http://x86.renejeschke.de/html/file_module_x86_id_184.html Is this how it's meant to be used? I'm out of my knowledge zone here, but it seems to work when you move the pointers to registers first: void store(__m128i* src, __m128i* dst) { asm { mov RAX, src; mov RBX, dst; movdqu XMM0, [RAX]; movdqu [RBX], XMM0; } }
Re: Using inline assembler
Maybe someone can help with the more specific problem. I'm translating a crypto engine here: https://github.com/etcimon/botan/blob/master/source/botan/block/aes_ni/aes_ni.d But I need this to work on DMD, LDC and GDC. I decided to write the assembler code directly for the functions in this module: https://github.com/etcimon/botan/blob/master/source/botan/utils/simd/xmmintrin.d If there's anything someone can tell me about this, I'd be thankful. I'm very experienced in every aspect of programming, but still at my first baby steps in assembler.
Re: Using inline assembler
On 2014-10-09 8:54 AM, anonymous wrote: This compiles: align(16) union __m128i { ubyte[16] data; } /* note the position of the semicolon */ void store(__m128i* src, __m128i* dst) { asm { movdqu XMM0, [src]; /* note: [src] */ movdqu [dst], XMM0; } } Yes, this does compile, but the value from src never ends up stored in dst. void main() { __m128i src; src.data[0] = 255; __m128i dst; writeln(src.data); // shows 255 at offset 0 store(&src, &dst); writeln(dst.data); // remains set as the initial array } http://x86.renejeschke.de/html/file_module_x86_id_184.html Is this how it's meant to be used?
Re: Using inline assembler
On Thursday, 9 October 2014 at 12:37:20 UTC, Etienne wrote: I'm a bit new to the inline assembler, I'm trying to use the `movdqu` operation to move a 128 bit double quadword from a pointer location into another location like this: align(16) union __m128i { ubyte[16] data }; void store(__m128i* src, __m128i* dst) { asm { movdqu [dst], src; } } The compiler complains about a "bad type/size of operands 'movdqu'", but these two data segments are 16 byte align so they should be in an XMM# register? Is there something I'm missing here? I know virtually nothing about SSE, but you can't move directly from memory to memory, can you? You need go through a register, no? This compiles: align(16) union __m128i { ubyte[16] data; } /* note the position of the semicolon */ void store(__m128i* src, __m128i* dst) { asm { movdqu XMM0, [src]; /* note: [src] */ movdqu [dst], XMM0; } }
Using inline assembler
I'm a bit new to the inline assembler, I'm trying to use the `movdqu` operation to move a 128 bit double quadword from a pointer location into another location like this: align(16) union __m128i { ubyte[16] data }; void store(__m128i* src, __m128i* dst) { asm { movdqu [dst], src; } } The compiler complains about a "bad type/size of operands 'movdqu'", but these two data segments are 16 byte align so they should be in an XMM# register? Is there something I'm missing here?
dupping to allow vector operation?
Observe: void main() { int[3] a1 = [1, 3, 6]; int[] a2 = a1[] * 3; // line 3, Error int[] a3 = a1.dup[] *= 3; // line 4, OK? int[] a4 = (a1[] * 3).dup; // line 5, Error } Currently the operation in line 4 is accepted: test.d(3,17): Error: array operation a1[] * 3 without destination memory not allowed test.d(5,18): Error: array operation a1[] * 3 without destination memory not allowed Is it a good idea to support something like line 5? Bye, bearophile
Re: Multithreading in D
On Thursday, 9 October 2014 at 10:10:20 UTC, Konstantin wrote: Are you looking for parallel? http://dlang.org/library/std/parallelism/parallel.html I have seen this, but I'm not sure how to use it. Maybe: float[][] maps = new float[#threads][resolution * resolution]; foreach(i, ref elem; parallel(maps)){ elem = generateTerrain(...); } Does this look right? Yeah, it is.
Re: Multithreading in D
Are you looking for parallel? http://dlang.org/library/std/parallelism/parallel.html I have seen this, but I'm not sure how to use it. Maybe: float[][] maps = new float[#threads][resolution * resolution]; foreach(i, ref elem; parallel(maps)){ elem = generateTerrain(...); } Does this look right?
Re: Search Engine
On Wednesday, 8 October 2014 at 20:15:33 UTC, Chris Williams wrote: On Wednesday, 8 October 2014 at 18:15:08 UTC, ANtlord wrote: It would be stable? I mean program, that will use C++ extern interface. Trying to link to C++ code will cause some work to solve build issues, but there shouldn't be any stability impacts other than recognizing that C++ won't be using memory management. Ok, I have got it. So... I think, that topic is over. Thank you.