4 ms·
Here's how to do inline assembler in D: int *_memset32(int *p, int value, size_t count) { asm { mov EDI,p ; mov EAX
by WalterBright 14y ago
Here's how to do inline assembler in D:
int *_memset32(int *p, int value, size_t count) {
asm {
mov EDI,p ;
mov EAX,value ;
mov ECX,count ;
mov EDX,EDI ;
rep ;
stosd ;
mov EAX,EDX ;
}
}
The compiler adds the function prolog/epilog for you, as well as any save/restore for used registers.
- strmpnk 14y agoWell, this article wasn't about _inline_ assembler. Regardless, inline forms have a number of problems, the biggest one being supporting multiple platforms w/o a bunch of preprocessor noise. That doesn't stop it from being useful for certain languages but it matters less and less given how compilers behave these days.
- WalterBright 14y agoThere is a steady drift away from using assembler even in languages that support it. Intrinsics, for example, often work better. But there are a few things where it really comes in handy.
- strmpnk 14y agoI wonder if we'll see more user-side emulation of intrinsics given new __attribute__ flags compilers are implementing. It certainly is easier to reason about. Go doesn't have anything like that yet but I wouldn't be surprised if an experimental implementation is done by one of the alternate compilers being worked on.