News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Int128 in assembler

Started by bigbadbob, June 13, 2018, 02:04:43 PM

Previous topic - Next topic

bigbadbob

So I did this in C#:


    [StructLayout(LayoutKind.Sequential)]
    public struct Int128
    {
        private Int64 loQWORD;
        private Int64 hiQWORD;

        [DllImport("BigBadInt128.dll")]
        private static extern Int128 Int128Add(ref Int128 addend1, ref Int128 addend2);

        public static Int128 operator+ (Int128 addend1, Int128 addend2)
        {
            return Int128Add(ref addend1, ref addend2);
        }
}


And this in 64-bit assembly:

Int128Add PROC
   mov r10, QWORD PTR [rdx]
   mov r11, QWORD PTR [rdx+8]
   add r10, QWORD PTR [r8]
   adc r11, QWORD PTR [r8+8]
   mov QWORD PTR [rcx], r10
   mov QWORD PTR [rcx+8], r11
   mov rax, rcx
   ret 
Int128Add ENDP 

nidud

#31
deleted

aw27

Come on nidud, you should know this  :redface:

typedef struct
{
   __int64 num1;
   __int64 num2;
}_m128t;

int main()
{
   _m128t in1 = { 1,1 };
   _m128t in2 = { 2,2 };

   _m128t myNum = Int128Add(&in1, &in2);

    return 0;
}

   _m128t myNum = Int128Add(&in1, &in2);
000000013F124D50  lea         r8,[in2] 
000000013F124D54  lea         rdx,[in1] 
000000013F124D58  lea         rcx,[rbp+188h] 
000000013F124D5F  call        Int128Add (013F121375h) 


Look at how RCX is used, lol.

nidud

#33
deleted

aw27

I am talking about Windows ABI since the beginning of this thread and you are talking about a feature of the GCC compiler (a more sophisticated compiler according to you  :icon_eek:)

nidud

#35
deleted

aw27

I know you will end winning any discussion due to fatigue of the opponent.

I will keep only this for the record:
Quote
Unless he uses a more sophisticated compiler this will not be possible given the maximum returned integer value is 64-bit.
:bgrin:

nidud

#37
deleted

aw27

Quote from: nidud on June 16, 2018, 01:58:34 AM
As for your usual (your all idiots because you don't know what I just learn five minutes ago from google) babble, that's just entertainment.
You are a bad loser, you should recognize the nonsense you have been saying. This kind of ignorance is not acceptable from someone that is developing an assembler supposed to be compliant with the Windows ABI. Or is it compliant with the GCC ABI?
Bob is saying that he is a C# developer since the first message and you don't stop push selling your GCC ideas.

bigbadbob

I would like to learn the Windows ABI way of doing it.  I'll be using C# from Windows.  I might also use it from C++, but it will be the Visual Studio compiler.

hutch--

Bob,

Don't take any notice of the "kiddies", its just a form of sport.  :P

Kiddies,

Behave yourself ! ;)

nidud

#41
deleted

aw27

Quote
What I've been saying is that using VS your limited to 64-bit size arguments and return values so you have to use pointers.
What's wrong with using pointers? We all know that XMM registers are bad doing integer operations, and they don't any 128-bit operation! They are just carriers  :badgrin:, so you will have to offload their content to make something useful. People usually forget that! It is the same with the VectorCall convention, people forget that the XMM registers have to be loaded and this takes CPU cycles. Don't embark in buzz words, experiment and test by yourself.

Quote
bla, bla bla, ...

No comments. You insist that C# has 128-bit data types. It has NOT.

Quote
As already mention, C# is not bound to a specific ABI. It's created to be used on different computer platforms without being rewritten for specific architectures.
Welcome to planet Earth, please land now that there is no fog. Things here are quite different.  :biggrin:

hutch--

 :biggrin:

> What I've been saying is that using VS your limited to 64-bit size arguments and return values so you have to use pointers.

VS does have a technique for writing 128 and 256 bit data types, its called MASM. That is why Microsoft supply MASM in both the old 32 bit version and the 64 bit version. Now you can be sure that nether will run on a Motorola MAC, MIPS, PDP8 or Lunix but both can produce binaries for the OS they are supplied for, Windows.  :P

nidud

#44
deleted