Mail Archives: djgpp/1997/03/18/14:53:19
From: | tph1001 AT cus DOT cam DOT ac DOT uk (T.P Harte)
|
Newsgroups: | comp.sys.sun.hardware,comp.lang.c++,comp.os.msdos.djgpp,comp.lang.asm.x86
|
Subject: | g++ assembler templates
|
Date: | 18 Mar 1997 14:21:29 GMT
|
Organization: | University of Cambridge, England
|
Lines: | 219
|
Message-ID: | <5gm8d9$96@lyra.csx.cam.ac.uk>
|
NNTP-Posting-Host: | ursa.cus.cam.ac.uk
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
i picked up some code recently and need to translate its
80386-compatible g++assembler templates (see below)
into something that i can run on my SPARC.
trouble is, i haven't done any assembly for years (it was on
a 8086 then) and don't know how to do so for a SPARC.
i want to know if code such as below can be translated into
something that can be compiled for a SPARCclassic or
whether it is generic Intel asm stuff and would need major re-working
obviously some degree of rooting around is going to have to be done
but i don't know if the job is too large as the architectures
are obviously substantially different being RISC/CISC resp.
the asm templates are ~1% of the actual code but render the whole thing
meaningless if they're left out.
_-_-_-_
thomas @ medical informatics
cambridge university -_-_-_-
_-_-_-_+44 1223 330305
PS could anyone point me in the direction of a g++ Solaris 2.3 binary?
here's the code. it's for making modular arithmetic reasonably
efficient and implements basic things such as multiplication &c.
and is thus concerned (mainly) with overloading the basic
arithmetic operators:
inline mersenne&
operator *=(const mersenne &b)
{
unsigned dummy;
asm("mull %3;addl %1,%0;adcl %4,%0"
: "=d,a" (value), "=a,d" (dummy)
: "%a" (value), "rm" (b.value), "ir" (0)
: "cc");
return *this;
}
inline friend mersenne
operator *(const mersenne &a, const mersenne &b)
{
unsigned r, dummy;
asm("mull %3;addl %1,%0;adcl %4,%0"
: "=d,a" (r), "=a,d" (dummy)
: "%a" (a.value), "rm" (b.value), "ir" (0)
: "cc");
return r;
}
inline mersenne &
operator +=(const mersenne &b)
{
asm("addl %2,%0;adcl %3,%0"
: "=r" (value)
: "%0" (value), "g" (b.value), "ir" (0)
: "cc");
return *this;
}
inline friend mersenne
operator +(const mersenne&a, const mersenne&b)
{
unsigned r;
asm("addl %2,%0;adcl %3,%0"
: "=r" (r)
: "%0" (value), "g" (b.value), "ir" (0)
: "cc");
return r;
}
inline mersenne &
operator -=(const mersenne &b)
{
asm("subl %2,%0;sbbl %3,%0"
: "=r" (value)
: "0" (value), "g" (b.value), "ir" (0)
: "cc");
return *this;
}
inline friend mersenne
operator -(const mersenne &a)
{
return ~a.value;
}
inline friend mersenne
operator -(const mersenne&a, const mersenne&b)
{
unsigned r;
asm("subl %2,%0;sbbl %3,%0"
: "=r" (r)
: "0" (value), "g" (b.value), "ir" (0)
: "cc");
return r;
}
inline
mersenne & operator >>=(unsigned width)
{
asm("ror %2,%0"
: "=g" (value)
: "0" (value), "ic" ((unsigned char)width)
: "cc");
return *this;
}
inline friend
mersenne operator >>(unsigned width)
{
unsigned r;
asm("ror %2,%0"
: "=g" (r)
: "0" (value), "ic" ((unsigned char)width)
: "cc");
return r;
}
inline
mersenne & operator <<=(unsigned width)
{
asm("rol %2,%0"
: "=g" (value)
: "0" (value), "ic" ((unsigned char)width)
: "cc");
return *this;
}
inline friend
mersenne operator <<(unsigned width)
{
unsigned r;
asm("rol %2,%0"
: "=g" (r)
: "0" (value), "ic" ((unsigned char)width)
: "cc");
return r;
}
// next file
inline modular<modul>&
operator *=(const modular<modul> &b)
{
asm("mull %2;divl %3"
: "=&d" (value)
: "%&a" (value), "mr0" (b.value) , "mr" (
: "%&a" (value), "mr0" (b.value) , "mr" (*modul)
: "cc");
return *this;
}
inline friend modular<modul>
operator *(const modular<modul> &a, const modular<modul> &b)
{
unsigned r;
asm("mull %2;divl %3"
: "=&d" (r)
: "%&a" (a.value), "mr0" (b.value) , "mr" (*modul)
: "cc");
return r;
}
inline modular<modul>&
operator +=(const modular<modul>&b)
{
asm("addl %2,%0;jnc 1f;0:subl %3,%0;jnc 0b;1:"
: "=&r" (value)
: "%0" (value), "g" (b.value), "ri" (*modul)
: "cc");
return *this;
}
inline friend modular<modul>
operator +(const modular<modul>&a, const modular<modul>&b)
{
unsigned r;
asm("addl %2,%0;jnc 1f;0:subl %3,%0;jnc 0b;1:"
: "=&r" (r)
: "%0" (a.value), "g" (b.value), "ri" (*modul)
: "cc");
return r;
}
inline modular<modul>&
operator -=(const modular<modul>&b)
{
asm("subl %2,%0;jnc 1f;0:addl %3,%0;jnc 0b;1:"
: "=&r" (value)
: "0" (value), "g" (b.value), "ri" (*modul)
: "cc");
return *this;
}
inline friend modular<modul>
operator -(const modular<modul>&a)
{
unsigned r;
asm("negl %0;jnc 1f;0:addl %2,%0;jnc 0b;1:"
: "=&r" (r)
: "0" (a.value), "ri" (*modul)
: "cc");
return r;
}
inline friend modular<modul>
operator -(const modular<modul>&a, const modular<modul> &b)
{
unsigned r;
asm("subl %2,%0;jnc 1f;0:addl %3,%0;jnc 0b;1:"
: "=&r" (r)
: "0" (a.value), "g" (b.value), "ri" (*modul)
: "cc");
return r;
}
- Raw text -