Re: ASM access to array

2011-02-04 Thread bearophile
Heinz: > This results in a much robust code. That's the right way to do it, with a D fallback. > You are right too about the "load-load-load processing-processing-processing > store-store-store instead a load-processing-store load-processing-store > load-processing-store" thing. I'll modify m

Re: ASM access to array

2011-02-04 Thread Heinz
bearophile, Thank you so much for all your help. It seems you're very into ASM. I kept the D_InlineAsm_X86 in my code as you suggested. The code i gave here was just an example. But my code's version implementation looks like this: version(D_InlineAsm_X86) { // ASM Code. } else { // D cod

Re: ASM access to array

2011-02-04 Thread bearophile
Heinz: > void myFunct() > { > uint* p = myarray.ptr; > asm > { > mov EBX, p; > > mov EAX, [EBX + 4]; > rol EAX, 8; > mov [EBX + 4], EAX; > > mov EAX, [EBX + 8]; > rol EAX, 16; > mov [EBX + 8], EAX; > > mov EAX, [EBX + 1

Re: ASM access to array

2011-02-03 Thread Heinz
Thanks 4 the code (this goes to Matthias Pleh too): Both codes work amazingly fine after modifying them a bit to work with DMD1.030. This helped me a lot! Still don't know how the asm version implicitly returns a value (no return keyword needed). It seems that the returned value is EAX, not the v

Re: ASM access to array

2011-02-02 Thread Joel Christensen
What about my edited version: import std.stdio; uint rotl_d(uint value,ubyte rotation){ return (value<>(value.sizeof*8 - rotation)); } uint rotl_asm(uint value,ubyte rotation){ asm{ mov EAX, value; // get first argument mov CL , rotation; // how many bits to move

Re: ASM access to array

2011-02-02 Thread Matthias Pleh
As bearophile notet, unittest are always good!! But for the start, I always liked to make some pretty-printing functions ... ... so this is my version import std.stdio; uint rotl_d(uint value,ubyte rotation){ return (value<>(value.sizeof*8 - rotation)); } uint rotl_asm(uint value,ubyte rot

Re: ASM access to array

2011-02-01 Thread bearophile
Heinz: >(i have no way to verify it is working but looks like bits are being rotated >by rol).< Create an unittest and test if the output-input pairs are correct. >Is D_InlineAsm_X86 really needed?< Someday D will run on other CPUs, like 64 bit ones, so 32 bit X86 will not work. To avoid pro

Re: ASM access to array

2011-02-01 Thread Heinz
Wow, thanks for the reply. Changing the 'enum dsize' to 'uint dsize = 4;' seems to produce some results...i guess it's working now (i have no way to verify it is working but looks like bits are being rotated by rol). One thing, if i replace dsize with 4 in all lines, the code compiles but again it

Re: ASM access to array

2011-02-01 Thread bearophile
Heinz: Not tested much: import std.stdio: writeln; class MyClass { uint[] array; this() { array = new typeof(array)(4); array = [10, 20, 30, 40]; } void myFunc() { version (D_InlineAsm_X86) { auto aptr = array.ptr; enum dsize = ty

ASM access to array

2011-02-01 Thread Heinz
Hi there, Although i've been coding in D for the last 5 years, i've never got my hands into ASM until now. I'm trying to use the inline assembler now and i'm trying to apply opcodes to a class member, an uint array but don't know how. This is what i've been trying to accomplish: class MyClass {