asm correctness

John Yates jyates@netezza.com
Tue Nov 7 17:54:00 GMT 2006


I am translating a C++ 128-bit arithmetic package for an embedded
environment from Diab asm functions to gcc asm statements wrapped
in C++ inline functions.  To minimize loads and stores the original
package used the PPC's string instructions (lswi/stswi).  I need to
preserve that size reduction strategy.

Here is my current cut at the assignment operator:


class int128 {
private:
    int hi;
    unsigned hl;
    unsigned lh;
    unsigned lo;
public:
    int128 const& operator = (int128 const& val);
};

inline int128 const& operator = (int128 const& val)
{
    asm (  "lswi	5,%[rhs],16\n"
        "	stswi	5,%[lhs],16"
        : [lhsmem] "=m" (*this)
        : [rhsmem]  "m" (val)
        , [lhs]     "b" (this)
        , [rhs]     "b" (&val)
        : "5", "6", "7", "8"
        );
    return *this;
}

void test(int128& a, int128& b)
{
    a = b;
}


This example compiles correctly and generates correct code.  Still
I would appreciate feedback on the approach.  In particular are the
the fake [rhsmem] and [lhsmem] operands the correct or best way to
express the memory accesses performed by the lswi and stswi?

TIA,

/john
--
John S. Yates, Jr.   508 665-6897 (voice)
Netezza Inc          508 665-6811 (fax)
200 Crossing Blvd.   Framingham, MA 01701
 



More information about the Gcc-help mailing list