Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help with returning vector (_m128)

Hi,

I could google for an answer but it would take me longer than ask here. How can I return _m128 instead of making dummy vector and returning him in operator overload function like this:
[code]
inline Vector operator +(Vector &a) const {
Vector vRet;
__asm
{
mov esi, this
mov edi, a
movaps xmm1, [edi]
movaps xmm0, [esi]
addps xmm0, xmm1
movaps vRet, xmm0
}
return vRet;
}
[/code]

Thanks!
Regards

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : Hi,
    :
    : I could google for an answer but it would take me longer than ask
    : here. How can I return _m128 instead of making dummy vector and
    : returning him in operator overload function like this:
    : [code]:
    : inline Vector operator +(Vector &a) const {
    : Vector vRet;
    : __asm
    : {
    : mov esi, this
    : mov edi, a
    : movaps xmm1, [edi]
    : movaps xmm0, [esi]
    : addps xmm0, xmm1
    : movaps vRet, xmm0
    : }
    : return vRet;
    : }
    : [/code]:
    :
    : Thanks!
    : Regards
    :

    You'd need to look up the calling convention for the compiler you are using. Most likely, the address to the object in memory is returned in EAX.

    I have a question about your code, though: I see you're modifying an entire class object through assembly, rather than modifying specific properties. You are aware that an instance of an object in memory is more than just the sum of it's properties? (For instance, there is a vtable at the beginning of the objects memory location for virtual function look-ups).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • DobarDabarDobarDabar Member Posts: 8
    : : Hi,
    : :
    : : I could google for an answer but it would take me longer than ask
    : : here. How can I return _m128 instead of making dummy vector and
    : : returning him in operator overload function like this:
    : : [code]: :
    : : inline Vector operator +(Vector &a) const {
    : : Vector vRet;
    : : __asm
    : : {
    : : mov esi, this
    : : mov edi, a
    : : movaps xmm1, [edi]
    : : movaps xmm0, [esi]
    : : addps xmm0, xmm1
    : : movaps vRet, xmm0
    : : }
    : : return vRet;
    : : }
    : : [/code]: :
    : :
    : : Thanks!
    : : Regards
    : :
    :
    : You'd need to look up the calling convention for the compiler you
    : are using. Most likely, the address to the object in memory is
    : returned in EAX.
    :
    : I have a question about your code, though: I see you're modifying an
    : entire class object through assembly, rather than modifying specific
    : properties. You are aware that an instance of an object in memory is
    : more than just the sum of it's properties? (For instance, there is a
    : vtable at the beginning of the objects memory location for virtual
    : function look-ups).
    :
    : Best Regards,
    : Richard
    :
    : The way I see it... Well, it's all pretty blurry
    Hi Richard :)

    If you see, this function returns Vector, not Vector*, so I have to return value, not address. Value is 128 bits long so somehow I have to put it in four registers. I saw some examples of returning large integers through eax:edx.

    I'm not shure I understand your question, but I feel that you can point me in right direction, I just started using Assembly and SSE instructions and just doing some labs to learn something, and offcourse have fun. Basically I want to make fast code that is human readable through Vector, Vertex, Triangle, Matrix classes. What do you mean by modifying specific properties? fields (public members)? or properties->C# (get/set)?

    Best Regards!
    No wonder you see blurry :) -> "The complement of truth is clearness."
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    :
    : If you see, this function returns Vector, not Vector*, so I have to
    : return value, not address. Value is 128 bits long so somehow I have
    : to put it in four registers. I saw some examples of returning large
    : integers through eax:edx.

    I think I made a bad assumption (I took Vector to be a Class). However, I probably understand now: Vector is defined as _m128 (128 bits integer), right?

    I don't know what the standard is on returning 128 bits numbers (
Sign In or Register to comment.