porting inline Watcom asm to MSVC inline asm 
Author Message
 porting inline Watcom asm to MSVC inline asm

Hi,

 I'm trying to do a port of a program
 from Watcom  to MSVC (32 bit).
 However I'm not an asm expert and I
 dont have access to Watcoms docs - so
 can anybody help me convert these
 watcom 'inline asm functions' to their
 MSVC equivalents.

 For example for the first two we MODIFY
 (ie put the result into I think)
 [8087] but what is this ? In the last we
 'modify exact' again I dont know what this achieves.

 TIA

 PS If anyone does have the 'fast affine texture mapper

 ported under DirectX I'd like to know :).

void fist16two(long * dst, float * src);
#pragma aux fist16two = \
    "   fld    dword [ebx]          "\
    "   fmul   dword [Scale16]      "\
    "   fld    dword [ebx+4]        "\
    "   fmul   dword [Scale16]      "\
    "   fxch   st(1)                "\
    "   fistp  dword [eax]          "\
    "   fistp  dword [eax+4]        "\
    parm [eax] [ebx] modify [8087]

// *dst = (long) src;

void fist(long * dst, double src);
#pragma aux{*filter*}= \
    "   fistp  dword [eax]  "\
    parm [eax] [8087] modify [8087]

long idiv16(long x, long y);        // (x << 16) / y
#pragma aux idiv16 = \
    " mov   edx,eax    "\
    " sar   edx,16     "\
    " shl   eax,16     "\
    " idiv  ebx        "\
    parm [eax] [ebx] modify exact [eax edx] value [eax]



Tue, 04 Sep 2001 03:00:00 GMT  
 porting inline Watcom asm to MSVC inline asm
I omitted the comment
to fist16two:

static float Scale16 = 65536.0;

// dst[0] = (long) (src[0] * 65536.0);
// dst[1] = (long) (src[1] * 65536.0);

void fist16two(long * dst, float * src);
#pragma aux fist16two = \
    "   fld    dword [ebx]          "\
    "   fmul   dword [Scale16]      "\
    "   fld    dword [ebx+4]        "\
    "   fmul   dword [Scale16]      "\
    "   fxch   st(1)                "\
    "   fistp  dword [eax]          "\
    "   fistp  dword [eax+4]        "\
    parm [eax] [ebx] modify [8087]



Tue, 04 Sep 2001 03:00:00 GMT  
 porting inline Watcom asm to MSVC inline asm

Quote:

>  For example for the first two we MODIFY
>  (ie put the result into I think)
>  [8087] but what is this ? In the last we
>  'modify exact' again I dont know what this achieves.

MODIFY specifyes list of registers modified by the inline function.
REgisters used to pass arguments are assumed to be modified. MODIFY
EXACT specifies EXACT set of register modified by the function. This set
MAY exclude registers used to pass arguments

MODIFY EXACT []
means all registers are preserved ;) including ones with arguments..
Of course one should realy presrve then, otherwise compiler would count
on them and would{*filter*}up

Quote:

> void fist16two(long * dst, float * src);
> #pragma aux fist16two = \
>     parm [eax] [ebx] modify [8087]

PARM [EAX] [EBX]
Arguments are passed in EAX and EBX (in this case they are destroyed).
Also FPU registers are altered too (MODIFY [8087])

Quote:
> long idiv16(long x, long y);        // (x << 16) / y
> #pragma aux idiv16 = \
>     " mov   edx,eax    "\
>     " sar   edx,16     "\
>     " shl   eax,16     "\
>     " idiv  ebx        "\
>     parm [eax] [ebx] modify exact [eax edx] value [eax]

VALUE [EAX]
Return value is in EAX.. the rest is as above

Hope this helps

--

Regards,
Waleri



Tue, 04 Sep 2001 03:00:00 GMT  
 porting inline Watcom asm to MSVC inline asm

Quote:
>  I'm trying to do a port of a program from Watcom  to MSVC (32 bit).
>  However I'm not an asm expert and I dont have access to Watcoms docs
> - so can anybody help me convert these watcom 'inline asm functions'
> to their MSVC equivalents.

In many cases (expecially these ones) there are no equivalents in MSVC++
to WATCOM's inline assembly paradigm.  Microsoft/Borland's _asm { }
construct is simply inferior (as opposed to GNU C, which actually
supersets WATCOM's method, but uses AT&T syntax ASM which is a major pain
in the but.)

My best recommendation would be to eliminate the inline assembly and just
use C code.  The reasoning being that MSVC++ produces fairly reasonable
C++ code but is fairly weak at integrating with inline assembly.  (The
code you showed did not show any reason why the C compiler couldn't
produce code that was nearly as fast as the assembly.)

--
Paul Hsieh



Thu, 06 Sep 2001 03:00:00 GMT  
 porting inline Watcom asm to MSVC inline asm

Quote:


> >  I'm trying to do a port of a program from Watcom  to MSVC (32 bit).
> >  However I'm not an asm expert and I dont have access to Watcoms docs
> > - so can anybody help me convert these watcom 'inline asm functions'
> > to their MSVC equivalents.

> In many cases (expecially these ones) there are no equivalents in MSVC++
> to WATCOM's inline assembly paradigm.  Microsoft/Borland's _asm { }
> construct is simply inferior (as opposed to GNU C, which actually
> supersets WATCOM's method, but uses AT&T syntax ASM which is a major pain
> in the but.)

Yes, MSFT inline assembly is nothing but that, a blind insertion of
assembly in the higher level code.

Watcom actually gives mechanisms for telling the compiler which
registers
are used for input,output, not used,etc, all those pragmas, one can use
any calling convention to call subroutines,etc,etc..

Quote:

> My best recommendation would be to eliminate the inline assembly and just
> use C code.  The reasoning being that MSVC++ produces fairly reasonable
> C++ code but is fairly weak at integrating with inline assembly.  (The
> code you showed did not show any reason why the C compiler couldn't
> produce code that was nearly as fast as the assembly.)

I would agree to some extent, it becomes more of a problem of writing
C-code which the compiler compiles into the assembly code one really
wants..

Need to use a lot of "local register" variables, one for every variable,
but still the stupid compiler keeps saving stuff on the stack, stuff
which is
never used.. (as well as reading it back even if it still is in the
original register)

mov eax,whatever
...
mov [ebp+10],eax
...
mov ebx,[ebp+10]  (when nobody has touched eax)

One rule is not to use i everywhere, but local i0,i1,i2,i3, otherwise
the
compiler is going to save the first i(0) without noticing that the
second i(1)
is getting loaded with a new number before beeing used.

Another rule is to put all the manipulation in one "C-equation", so that
the
compiler doesn;t keep saving, pushing and popping, the temporary results
on the stack all the time..

And some even worse tricks to fool the compiler..

Gunnar

Nothing like Watcom + their assembly, pragmas ..



Sat, 15 Sep 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. MSVC 4.2 re-arranges inline asm

2. watcom c++ inline asm

3. Using DI with Watcom inline asm

4. newbie to Watcom inline asm, some ?s

5. GCC inline ASM -- calling C functions from __asm__

6. GCC inline ASM -- calling C functions from __asm__ blocks

7. Invert column and rows of a Matrix using inline ASM in c or c++

8. using PB6 w/ inline asm to generate pc-speaker tones

9. PBcc Inline ASM

10. Inline asm under linux?

11. gcc inline asm, can't do even simple things :-(

12. Inline Asm Pushing Double precision problem

 

 
Powered by phpBB® Forum Software