View mode: basic / threaded / horizontal-split · Log in · Help
July 09, 2004
D inline assembler
I think it would be cool if the D inline Assembler would include an assember tag
or definition.  This would allow for different inline assemblers to be included
in a D source code tree or file.  The assembly source code would be more
portable.  Optionally a source code file could be compiled for x86 and Motorola
68K and 88k AMD 29K and Powerpc depending on the platform value at compilation
time. Also optionally the code could be cross compiled for multiple platforms
under D.  There could also be optional inline assemblers to support different
architectures and platforms. 

So if the compiler was hosted under the Motorola 68000 it would compile the
inline assembler for 68k.  If the compiler was under x86 it would compile that
code and if it was under the AMD 29k it would compile that code.  This is
strictly optional.  A cross compile option would build for all three.

This would mean that the compiler could selectively compile assembler code if it
is native and hosted on a particular cpu or platform.  Also having an inline
assembler type for D would be very advantageous over just an Asm inline block.

A D example would show the assembler type:

import std.c.stdio;
int main() {
static bit[] a = [ 0, 0, 0, 0,/**/, 0, 0, 0, 1,
1, 1, 0, 1,/**/, 1, 1, 0, 0 ];
bit[] b = a[1..9];
for (uint i = 0; i < a.length; i++) {
printf("a[%d] = %d\n", i, a[i]);
}
for (uint i = 0; i < b.length; i++) {
printf("b[%d] = %d\n", i, b[i]);
}
return 0;
}

// this is the assembler code for the AMD 29k
Asm asm_type_29K
{

// AMD 29k assembler code goes here
}

// If the cpu is 68K compile this
Asm asm_type_68K
{
// Motorola 68k assembler code goes here
}
// If the cpu is x86 compile this
Asm asm_type_x86
{
// Intel x86 assembler code goes here
}
July 09, 2004
Re: D inline assembler
Kublai Makaan wrote:
> // this is the assembler code for the AMD 29k
> Asm asm_type_29K
> {
> 
> // AMD 29k assembler code goes here
> }
> 
> // If the cpu is 68K compile this
> Asm asm_type_68K
> {
> // Motorola 68k assembler code goes here
> }
> // If the cpu is x86 compile this
> Asm asm_type_x86
> {
> // Intel x86 assembler code goes here
> }

You can do this already, using the version statement.  Consider:

version (X86) asm {
  ...
}
version (AMD64) asm {
  ...
}
version (StrongARM) asm {
  ...
}
version (SPARC) asm {
  ...
}

And so forth.

-Chris S.
-Invironz
Top | Discussion index | About this forum | D home