pragmas.h cleanup part 1: separate into pragmas.h, pragmas_arm.h, pragmas_ppc.h, pragmas_x86_gcc.h and pragmas_x86_msvc.h.

Remove "boundmulscale" as it was unused.

git-svn-id: https://svn.eduke32.com/eduke32@4601 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2014-09-30 04:04:53 +00:00
parent 683a5eb11f
commit 361300d3c4
6 changed files with 2190 additions and 2201 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,69 @@
//
// GCC Inline Assembler version (ARM)
//
#ifndef __pragmas_arm_h__
#define __pragmas_arm_h__
#define _scaler(a) \
static inline int32_t mulscale##a(int32_t eax, int32_t edx) \
{ \
return dw((qw(eax) * qw(edx)) >> by(a)); \
} \
\
static inline int32_t dmulscale##a(int32_t eax, int32_t edx, int32_t esi, int32_t edi) \
{ \
return dw(((qw(eax) * qw(edx)) + (qw(esi) * qw(edi))) >> by(a)); \
} \
\
static inline int32_t tmulscale##a(int32_t eax, int32_t edx, int32_t ebx, int32_t ecx, int32_t esi, int32_t edi) \
{ \
return dw(((qw(eax) * qw(edx)) + (qw(ebx) * qw(ecx)) + (qw(esi) * qw(edi))) >> by(a)); \
} \
PRAGMA_FUNCS _scaler(32)
#undef _scaler
static inline void swapchar(void* a, void* b) { char t = *((char*) b); *((char*) b) = *((char*) a); *((char*) a) = t; }
static inline void swapchar2(void* a, void* b, int32_t s) { swapchar(a, b); swapchar((char*) a+1, (char*) b+s); }
static inline void swapshort(void* a, void* b) { int16_t t = *((int16_t*) b); *((int16_t*) b) = *((int16_t*) a); *((int16_t*) a) = t; }
static inline void swaplong(void* a, void* b) { int32_t t = *((int32_t*) b); *((int32_t*) b) = *((int32_t*) a); *((int32_t*) a) = t; }
static inline void swap64bit(void* a, void* b) { int64_t t = *((int64_t*) b); *((int64_t*) b) = *((int64_t*) a); *((int64_t*) a) = t; }
static inline char readpixel(void* s) { return (*((char*) (s))); }
static inline void drawpixel(void* s, char a) { *((char*) (s)) = a; }
static inline void drawpixels(void* s, int16_t a) { *((int16_t*) (s)) = a; }
static inline void drawpixelses(void* s, int32_t a) { *((int32_t*) (s)) = a; }
static inline int32_t mul3(int32_t a) { return (a<<1)+a; }
static inline int32_t mul5(int32_t a) { return (a<<2)+a; }
static inline int32_t mul9(int32_t a) { return (a<<3)+a; }
static inline int32_t divmod(int32_t a, int32_t b) { uint32_t _a=(uint32_t) a, _b=(uint32_t) b; dmval = _a%_b; return _a/_b; }
static inline int32_t moddiv(int32_t a, int32_t b) { uint32_t _a=(uint32_t) a, _b=(uint32_t) b; dmval = _a/_b; return _a%_b; }
static inline int32_t klabs(int32_t a) { if (a < 0) return -a; return a; }
static inline int32_t ksgn(int32_t a) { if (a > 0) return 1; if (a < 0) return -1; return 0; }
static inline int32_t umin(int32_t a, int32_t b) { if ((uint32_t) a < (uint32_t) b) return a; return b; }
static inline int32_t umax(int32_t a, int32_t b) { if ((uint32_t) a < (uint32_t) b) return b; return a; }
static inline int32_t kmin(int32_t a, int32_t b) { if ((int32_t) a < (int32_t) b) return a; return b; }
static inline int32_t kmax(int32_t a, int32_t b) { if ((int32_t) a < (int32_t) b) return b; return a; }
static inline int32_t sqr(int32_t eax) { return (eax) * (eax); }
static inline int32_t scale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * qw(edx)) / qw(ecx)); }
static inline int32_t mulscale(int32_t eax, int32_t edx, int32_t ecx) { return dw((qw(eax) * qw(edx)) >> by(ecx)); }
static inline int32_t dmulscale(int32_t eax, int32_t edx, int32_t esi, int32_t edi, int32_t ecx) { return dw(((qw(eax) * qw(edx)) + (qw(esi) * qw(edi))) >> by(ecx)); }
void qinterpolatedown16(intptr_t bufptr, int32_t num, int32_t val, int32_t add);
void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t add);
void clearbuf(void* d, int32_t c, int32_t a);
void copybuf(const void* s, void* d, int32_t c);
void swapbuf4(void* a, void* b, int32_t c);
void clearbufbyte(void *D, int32_t c, int32_t a);
void copybufbyte(const void *S, void *D, int32_t c);
void copybufreverse(const void *S, void *D, int32_t c);
#endif

View file

@ -0,0 +1,338 @@
// GCC Inline Assembler version (PowerPC)
#ifdef __pragmas_h__
#ifndef __pragmas_ppc_h__
#define __pragmas_ppc_h__
#define sqr(a) ((a)*(a))
int32_t scale(int32_t a, int32_t d, int32_t c);
static inline int32_t mulscale(int32_t a, int32_t d, int32_t c)
{
int32_t mullo, mulhi;
__asm__(
" mullw %0, %2, %3\n"
" mulhw %1, %2, %3\n"
" srw %0, %0, %4\n"
" slw %1, %1, %5\n"
" or %0, %0, %1\n"
: "=&r"(mullo), "=&r"(mulhi)
: "r"(a), "r"(d), "r"(c), "r"(32-c)
: "xer"
);
return mullo;
}
#define _scaler(x) \
static inline int32_t mulscale##x(int32_t a, int32_t d) \
{ \
int32_t mullo, mulhi; \
__asm__ ( \
" mullw %0, %2, %3\n" \
" mulhw %1, %2, %3\n" \
" srwi %0, %0, %4\n" \
" insrwi %0, %1, %4, 0\n" \
: "=&r"(mullo), "=r"(mulhi) \
: "r"(a), "r"(d), "i"(x) \
); \
return mullo; \
}
PRAGMA_FUNCS
#undef _scaler
static inline int32_t mulscale32(int32_t a, int32_t d)
{
int32_t mulhi;
__asm__(
" mulhw %0, %1, %2\n"
: "=r"(mulhi)
: "r"(a), "r"(d)
);
return mulhi;
}
static inline int32_t dmulscale(int32_t a, int32_t d, int32_t S, int32_t D, int32_t c)
{
int32_t mulhi, mullo, sumhi, sumlo;
__asm__(
" mullw %0, %4, %5\n"
" mulhw %1, %4, %5\n"
" mullw %2, %6, %7\n"
" mulhw %3, %6, %7\n"
" addc %0, %0, %2\n"
" adde %1, %1, %3\n"
" srw %0, %0, %8\n"
" slw %1, %1, %9\n"
" or %0, %0, %1\n"
: "=&r"(sumlo), "=&r"(sumhi), "=&r"(mullo), "=&r"(mulhi)
: "r"(a), "r"(d), "r"(S), "r"(D), "r"(c), "r"(32-c)
: "xer"
);
return sumlo;
}
#define _scaler(x) \
static inline int32_t dmulscale##x(int32_t a, int32_t d, int32_t S, int32_t D) \
{ \
int32_t mulhi, mullo, sumhi, sumlo; \
__asm__ ( \
" mullw %0, %4, %5\n" \
" mulhw %1, %4, %5\n" \
" mullw %2, %6, %7\n" \
" mulhw %3, %6, %7\n" \
" addc %0, %0, %2\n" \
" adde %1, %1, %3\n" \
" srwi %0, %0, %8\n" \
" insrwi %0, %1, %8, 0\n" \
: "=&r"(sumlo), "=&r"(sumhi), "=&r"(mullo), "=r"(mulhi) \
: "r"(a), "r"(d), "r"(S), "r"(D), "i"(x) \
: "xer" \
); \
return sumlo; \
}
PRAGMA_FUNCS
#undef _scaler
static inline int32_t dmulscale32(int32_t a, int32_t d, int32_t S, int32_t D)
{
int32_t mulhi, mullo, sumhi, sumlo;
__asm__(\
" mullw %0, %4, %5\n" \
" mulhw %1, %4, %5\n" \
" mullw %2, %6, %7\n" \
" mulhw %3, %6, %7\n" \
" addc %0, %0, %2\n" \
" adde %1, %1, %3\n" \
: "=&r"(sumlo), "=&r"(sumhi), "=&r"(mullo), "=r"(mulhi)
: "r"(a), "r"(d), "r"(S), "r"(D)
: "xer"
);
return sumhi;
}
// tmulscale only seems to be used in one place...
static inline int32_t tmulscale11(int32_t a, int32_t d, int32_t b, int32_t c, int32_t S, int32_t D)
{
int32_t mulhi, mullo, sumhi, sumlo;
__asm__(
" mullw %0, %4, %5\n" \
" mulhw %1, %4, %5\n" \
" mullw %2, %6, %7\n" \
" mulhw %3, %6, %7\n" \
" addc %0, %0, %2\n" \
" adde %1, %1, %3\n" \
" mullw %2, %8, %9\n" \
" mulhw %3, %8, %9\n" \
" addc %0, %0, %2\n" \
" adde %1, %1, %3\n" \
" srwi %0, %0, 11\n" \
" insrwi %0, %1, 11, 0\n" \
: "=&r"(sumlo), "=&r"(sumhi), "=&r"(mullo), "=&r"(mulhi)
: "r"(a), "r"(d), "r"(b), "r"(c), "r"(S), "r"(D)
: "xer"
);
return sumlo;
}
static inline char readpixel(void *d)
{
return *(char*) d;
}
static inline void drawpixel(void *d, char a)
{
*(char*) d = a;
}
static inline void drawpixels(void *d, int16_t a)
{
__asm__(
" sthbrx %0, 0, %1\n"
:
: "r"(&a), "r"(d)
: "memory"
);
}
static inline void drawpixelses(void *d, int32_t a)
{
__asm__(
" stwbrx %0, 0, %1\n"
:
: "r"(&a), "r"(d)
: "memory"
);
}
void clearbufbyte(void *d, int32_t c, int32_t a);
static inline void clearbuf(void *d, int32_t c, int32_t a)
{
int32_t *p = (int32_t*) d;
if (a==0) {
clearbufbyte(d, c<<2, 0);
return;
}
while (c--) {
*p++ = a;
}
}
static inline void copybuf(void *s, void *d, int32_t c)
{
int32_t *p = (int32_t*) s, *q = (int32_t*) d;
while (c--) {
*q++ = *p++;
}
}
static inline void copybufbyte(void *s, void *d, int32_t c)
{
uint8_t *src = (uint8_t*) s, *dst = (uint8_t*) d;
while (c--) {
*dst++ = *src++;
}
}
static inline void copybufreverse(void *s, void *d, int32_t c)
{
uint8_t *src = (uint8_t*) s, *dst = (uint8_t*) d;
while (c--) {
*dst++ = *src--;
}
}
static inline void qinterpolatedown16(intptr_t bufptr, int32_t num, int32_t val, int32_t add)
{
int i;
int32_t *lptr = (int32_t *) bufptr;
for (i=0; i<num; i++) {
lptr[i] = (val>>16);
val += add;
}
}
static inline void qinterpolatedown16short(intptr_t bufptr, int32_t num, int32_t val, int32_t add)
{
int i;
int16_t *sptr = (int16_t *) bufptr;
for (i=0; i<num; i++) {
sptr[i] = (val>>16);
val += add;
}
}
static inline int32_t mul3(int32_t a)
{
return (a<<1)+a;
}
static inline int32_t mul5(int32_t a)
{
return (a<<2)+a;
}
static inline int32_t mul9(int32_t a)
{
return (a<<3)+a;
}
static inline int32_t klabs(int32_t a)
{
int32_t mask;
__asm__(
" srawi %0, %1, 31\n"
" xor %1, %0, %1\n"
" subf %1, %0, %1\n"
: "=&r"(mask), "+r"(a)
:
: "xer"
);
return a;
}
static inline int32_t ksgn(int32_t a)
{
int32_t s, t;
__asm__(
" neg %1, %2\n"
" srawi %0, %2, 31\n"
" srwi %1, %1, 31\n"
" or %1, %1, %0\n"
: "=r"(t), "=&r"(s)
: "r"(a)
: "xer"
);
return s;
}
static inline void swapchar(void *a, void *b)
{
char t = *(char*) a;
*(char*) a = *(char*) b;
*(char*) b = t;
}
static inline void swapchar2(void *a, void *b, int32_t s)
{
swapchar(a, b);
swapchar((char*) a+1, (char*) b+s);
}
static inline void swapshort(void *a, void *b)
{
int16_t t = *(int16_t*) a;
*(int16_t*) a = *(int16_t*) b;
*(int16_t*) b = t;
}
static inline void swaplong(void *a, void *b)
{
int32_t t = *(int32_t*) a;
*(int32_t*) a = *(int32_t*) b;
*(int32_t*) b = t;
}
static inline void swap64bit(void *a, void *b)
{
double t = *(double*) a;
*(double*) a = *(double*) b;
*(double*) b = t;
}
static inline int32_t divmod(int32_t a, int32_t b)
{
int32_t div;
__asm__(
" divwu %0, %2, %3\n"
" mullw %1, %0, %3\n"
" subf %1, %1, %2\n"
: "=&r"(div), "=&r"(dmval)
: "r"(a), "r"(b)
);
return div;
}
static inline int32_t moddiv(int32_t a, int32_t b)
{
int32_t mod;
__asm__(
" divwu %0, %2, %3\n"
" mullw %1, %0, %3\n"
" subf %1, %1, %2\n"
: "=&r"(dmval), "=&r"(mod)
: "r"(a), "r"(b)
);
return mod;
}
static inline int32_t umin(int32_t a, int32_t b) { if ((uint32_t) a < (uint32_t) b) return a; return b; }
static inline int32_t umax(int32_t a, int32_t b) { if ((uint32_t) a < (uint32_t) b) return b; return a; }
static inline int32_t kmin(int32_t a, int32_t b) { if ((int32_t) a < (int32_t) b) return a; return b; }
static inline int32_t kmax(int32_t a, int32_t b) { if ((int32_t) a < (int32_t) b) return b; return a; }
#endif // __pragmas_ppc_h__
#endif // __pragmas_h__

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,690 @@
//
// Microsoft C inline assembler
//
//{{{
#ifdef __pragmas_h__
#ifndef __pragmas_x86_h__
#define __pragmas_x86_h__
static __inline int32_t sqr(int32_t a)
{
_asm {
mov eax, a
imul eax, eax
}
}
static __inline int32_t scale(int32_t a, int32_t d, int32_t c)
{
_asm {
mov eax, a
imul d
idiv c
}
}
static __inline int32_t mulscale(int32_t a, int32_t d, int32_t c)
{
_asm {
mov ecx, c
mov eax, a
imul d
shrd eax, edx, cl
}
}
#define MULSCALE(x) \
static __inline int32_t mulscale##x (int32_t a, int32_t d) \
{ \
_asm mov eax, a \
_asm imul d \
_asm shrd eax, edx, x \
}
MULSCALE(1) MULSCALE(2) MULSCALE(3) MULSCALE(4)
MULSCALE(5) MULSCALE(6) MULSCALE(7) MULSCALE(8)
MULSCALE(9) MULSCALE(10) MULSCALE(11) MULSCALE(12)
MULSCALE(13) MULSCALE(14) MULSCALE(15) MULSCALE(16)
MULSCALE(17) MULSCALE(18) MULSCALE(19) MULSCALE(20)
MULSCALE(21) MULSCALE(22) MULSCALE(23) MULSCALE(24)
MULSCALE(25) MULSCALE(26) MULSCALE(27) MULSCALE(28)
MULSCALE(29) MULSCALE(30) MULSCALE(31)
#undef MULSCALE
static __inline int32_t mulscale32(int32_t a, int32_t d)
{
_asm {
mov eax, a
imul d
mov eax, edx
}
}
static __inline int32_t dmulscale(int32_t a, int32_t d, int32_t S, int32_t D, int32_t c)
{
_asm {
mov ecx, c
mov eax, a
imul d
mov ebx, eax
mov eax, S
mov esi, edx
imul D
add eax, ebx
adc edx, esi
shrd eax, edx, cl
}
}
#define DMULSCALE(x) \
static __inline int32_t dmulscale##x (int32_t a, int32_t d, int32_t S, int32_t D) \
{ \
_asm mov eax, a \
_asm imul d \
_asm mov ebx, eax \
_asm mov eax, S \
_asm mov esi, edx \
_asm imul D \
_asm add eax, ebx \
_asm adc edx, esi \
_asm shrd eax, edx, x \
}
DMULSCALE(1) DMULSCALE(2) DMULSCALE(3) DMULSCALE(4)
DMULSCALE(5) DMULSCALE(6) DMULSCALE(7) DMULSCALE(8)
DMULSCALE(9) DMULSCALE(10) DMULSCALE(11) DMULSCALE(12)
DMULSCALE(13) DMULSCALE(14) DMULSCALE(15) DMULSCALE(16)
DMULSCALE(17) DMULSCALE(18) DMULSCALE(19) DMULSCALE(20)
DMULSCALE(21) DMULSCALE(22) DMULSCALE(23) DMULSCALE(24)
DMULSCALE(25) DMULSCALE(26) DMULSCALE(27) DMULSCALE(28)
DMULSCALE(29) DMULSCALE(30) DMULSCALE(31)
#undef DMULSCALE
static __inline int32_t dmulscale32(int32_t a, int32_t d, int32_t S, int32_t D)
{
_asm {
mov eax, a
imul d
mov ebx, eax
mov eax, S
mov esi, edx
imul D
add eax, ebx
adc edx, esi
mov eax, edx
}
}
#define TMULSCALE(x) \
static __inline int32_t tmulscale##x (int32_t a, int32_t d, int32_t b, int32_t c, int32_t S, int32_t D) \
{ \
_asm mov eax, a \
_asm mov ebx, b \
_asm imul d \
_asm xchg eax, ebx \
_asm mov ecx, c \
_asm xchg edx, ecx \
_asm imul edx \
_asm add ebx, eax \
_asm adc ecx, edx \
_asm mov eax, S \
_asm imul D \
_asm add eax, ebx \
_asm adc edx, ecx \
_asm shrd eax, edx, x \
}
TMULSCALE(1) TMULSCALE(2) TMULSCALE(3) TMULSCALE(4)
TMULSCALE(5) TMULSCALE(6) TMULSCALE(7) TMULSCALE(8)
TMULSCALE(9) TMULSCALE(10) TMULSCALE(11) TMULSCALE(12)
TMULSCALE(13) TMULSCALE(14) TMULSCALE(15) TMULSCALE(16)
TMULSCALE(17) TMULSCALE(18) TMULSCALE(19) TMULSCALE(20)
TMULSCALE(21) TMULSCALE(22) TMULSCALE(23) TMULSCALE(24)
TMULSCALE(25) TMULSCALE(26) TMULSCALE(27) TMULSCALE(28)
TMULSCALE(29) TMULSCALE(30) TMULSCALE(31)
#undef TMULSCALE
static __inline int32_t tmulscale32(int32_t a, int32_t d, int32_t b, int32_t c, int32_t S, int32_t D)
{
_asm {
mov eax, a
mov ebx, b
imul d
xchg eax, ebx
mov ecx, c
xchg edx, ecx
imul edx
add ebx, eax
adc ecx, edx
mov eax, S
imul D
add eax, ebx
adc edx, ecx
mov eax, edx
}
}
#ifdef USE_ASM_DIVSCALE
static __inline int32_t divscale(int32_t a, int32_t b, int32_t c)
{
_asm {
mov eax, a
mov ecx, c
mov edx, eax
shl eax, cl
neg cl
sar edx, cl
idiv b
}
}
static __inline int32_t divscale1(int32_t a, int32_t b)
{
_asm {
mov eax, a
add eax, eax
sbb edx, edx
idiv b
}
}
static __inline int32_t divscale2(int32_t a, int32_t b)
{
_asm {
mov eax, a
mov edx, eax
sar edx, 30
lea eax, [eax*4]
idiv b
}
}
static __inline int32_t divscale3(int32_t a, int32_t b)
{
_asm {
mov eax, a
mov edx, eax
sar edx, 29
lea eax, [eax*8]
idiv b
}
}
#define DIVSCALE(x,y) \
static __inline int32_t divscale##y(int32_t a, int32_t b) \
{ \
_asm mov eax, a \
_asm mov edx, eax \
_asm sar edx, x \
_asm shl eax, y \
_asm idiv b \
}
DIVSCALE(28, 4) DIVSCALE(27, 5) DIVSCALE(26, 6) DIVSCALE(25, 7)
DIVSCALE(24, 8) DIVSCALE(23, 9) DIVSCALE(22, 10) DIVSCALE(21, 11)
DIVSCALE(20, 12) DIVSCALE(19, 13) DIVSCALE(18, 14) DIVSCALE(17, 15)
DIVSCALE(16, 16) DIVSCALE(15, 17) DIVSCALE(14, 18) DIVSCALE(13, 19)
DIVSCALE(12, 20) DIVSCALE(11, 21) DIVSCALE(10, 22) DIVSCALE(9, 23)
DIVSCALE(8, 24) DIVSCALE(7, 25) DIVSCALE(6, 26) DIVSCALE(5, 27)
DIVSCALE(4, 28) DIVSCALE(3, 29) DIVSCALE(2, 30) DIVSCALE(1, 31)
static __inline int32_t divscale32(int32_t d, int32_t b)
{
_asm {
mov edx, d
xor eax, eax
idiv b
}
}
#endif // defined USE_ASM_DIVSCALE
static __inline char readpixel(void *d)
{
_asm {
mov edx, d
mov al, byte ptr[edx]
}
}
static __inline void drawpixel(void *d, char a)
{
_asm {
mov edx, d
mov al, a
mov byte ptr[edx], al
}
}
static __inline void drawpixels(void *d, int16_t a)
{
_asm {
mov edx, d
mov ax, a
mov word ptr[edx], ax
}
}
static __inline void drawpixelses(void *d, int32_t a)
{
_asm {
mov edx, d
mov eax, a
mov dword ptr[edx], eax
}
}
static __inline void clearbuf(void *d, int32_t c, int32_t a)
{
_asm {
mov edi, d
mov ecx, c
mov eax, a
rep stosd
}
}
static __inline void clearbufbyte(void *d, int32_t c, int32_t a)
{
_asm {
mov edi, d
mov ecx, c
mov eax, a
cmp ecx, 4
jae longcopy
test cl, 1
jz preskip
stosb
preskip :
shr ecx, 1
rep stosw
jmp endit
longcopy :
test edi, 1
jz skip1
stosb
dec ecx
skip1 :
test edi, 2
jz skip2
stosw
sub ecx, 2
skip2 :
mov ebx, ecx
shr ecx, 2
rep stosd
test bl, 2
jz skip3
stosw
skip3 :
test bl, 1
jz endit
stosb
endit :
}
}
static __inline void copybuf(const void *s, void *d, int32_t c)
{
_asm {
mov esi, s
mov edi, d
mov ecx, c
rep movsd
}
}
static __inline void copybufbyte(const void *s, void *d, int32_t c)
{
_asm {
mov esi, s
mov edi, d
mov ecx, c
cmp ecx, 4
jae longcopy
test cl, 1
jz preskip
movsb
preskip :
shr ecx, 1
rep movsw
jmp endit
longcopy :
test edi, 1
jz skip1
movsb
dec ecx
skip1 :
test edi, 2
jz skip2
movsw
sub ecx, 2
skip2 :
mov ebx, ecx
shr ecx, 2
rep movsd
test bl, 2
jz skip3
movsw
skip3 :
test bl, 1
jz endit
movsb
endit :
}
}
static __inline void copybufreverse(const void *s, void *d, int32_t c)
{
_asm {
mov esi, s
mov edi, d
mov ecx, c
shr ecx, 1
jnc skipit1
mov al, byte ptr[esi]
dec esi
mov byte ptr[edi], al
inc edi
skipit1 :
shr ecx, 1
jnc skipit2
mov ax, word ptr[esi-1]
sub esi, 2
ror ax, 8
mov word ptr[edi], ax
add edi, 2
skipit2:
test ecx, ecx
jz endloop
begloop :
mov eax, dword ptr[esi-3]
sub esi, 4
bswap eax
mov dword ptr[edi], eax
add edi, 4
dec ecx
jnz begloop
endloop :
}
}
static __inline void qinterpolatedown16(int32_t a, int32_t c, int32_t d, int32_t s)
{
_asm {
mov eax, a
mov ecx, c
mov edx, d
mov esi, s
mov ebx, ecx
shr ecx, 1
jz skipbegcalc
begqcalc :
lea edi, [edx+esi]
sar edx, 16
mov dword ptr[eax], edx
lea edx, [edi+esi]
sar edi, 16
mov dword ptr[eax+4], edi
add eax, 8
dec ecx
jnz begqcalc
test ebx, 1
jz skipbegqcalc2
skipbegcalc :
sar edx, 16
mov dword ptr[eax], edx
skipbegqcalc2 :
}
}
static __inline void qinterpolatedown16short(int32_t a, int32_t c, int32_t d, int32_t s)
{
_asm {
mov eax, a
mov ecx, c
mov edx, d
mov esi, s
test ecx, ecx
jz endit
test al, 2
jz skipalignit
mov ebx, edx
sar ebx, 16
mov word ptr[eax], bx
add edx, esi
add eax, 2
dec ecx
jz endit
skipalignit :
sub ecx, 2
jc finishit
begqcalc :
mov ebx, edx
add edx, esi
sar ebx, 16
mov edi, edx
and edi, 0ffff0000h
add edx, esi
add ebx, edi
mov dword ptr[eax], ebx
add eax, 4
sub ecx, 2
jnc begqcalc
test cl, 1
jz endit
finishit :
mov ebx, edx
sar ebx, 16
mov word ptr[eax], bx
endit :
}
}
static __inline int32_t mul3(int32_t a)
{
_asm {
mov eax, a
lea eax, [eax+eax*2]
}
}
static __inline int32_t mul5(int32_t a)
{
_asm {
mov eax, a
lea eax, [eax+eax*4]
}
}
static __inline int32_t mul9(int32_t a)
{
_asm {
mov eax, a
lea eax, [eax+eax*8]
}
}
//returns eax/ebx, dmval = eax%edx;
static __inline int32_t divmod(int32_t a, int32_t b)
{
_asm {
mov eax, a
xor edx, edx
div b
mov dmval, edx
}
}
//returns eax%ebx, dmval = eax/edx;
static __inline int32_t moddiv(int32_t a, int32_t b)
{
_asm {
mov eax, a
xor edx, edx
div b
mov dmval, eax
mov eax, edx
}
}
static __inline int32_t klabs(int32_t a)
{
_asm {
mov eax, a
test eax, eax
jns skipnegate
neg eax
skipnegate :
}
}
static __inline int32_t ksgn(int32_t b)
{
_asm {
mov ebx, b
add ebx, ebx
sbb eax, eax
cmp eax, ebx
adc al, 0
}
}
//eax = (unsigned min)umin(eax,ebx)
static __inline int32_t umin(int32_t a, int32_t b)
{
_asm {
mov eax, a
sub eax, b
sbb ecx, ecx
and eax, ecx
add eax, b
}
}
//eax = (unsigned max)umax(eax,ebx)
static __inline int32_t umax(int32_t a, int32_t b)
{
_asm {
mov eax, a
sub eax, b
sbb ecx, ecx
xor ecx, 0xffffffff
and eax, ecx
add eax, b
}
}
static __inline int32_t kmin(int32_t a, int32_t b)
{
_asm {
mov eax, a
mov ebx, b
cmp eax, ebx
jl skipit
mov eax, ebx
skipit :
}
}
static __inline int32_t kmax(int32_t a, int32_t b)
{
_asm {
mov eax, a
mov ebx, b
cmp eax, ebx
jg skipit
mov eax, ebx
skipit :
}
}
static __inline void swapchar(void *a, void *b)
{
_asm {
mov eax, a
mov ebx, b
mov cl, [eax]
mov ch, [ebx]
mov[ebx], cl
mov[eax], ch
}
}
static __inline void swapshort(void *a, void *b)
{
_asm {
mov eax, a
mov ebx, b
mov cx, [eax]
mov dx, [ebx]
mov[ebx], cx
mov[eax], dx
}
}
static __inline void swaplong(void *a, void *b)
{
_asm {
mov eax, a
mov ebx, b
mov ecx, [eax]
mov edx, [ebx]
mov[ebx], ecx
mov[eax], edx
}
}
static __inline void swapbuf4(void *a, void *b, int32_t c)
{
_asm {
mov eax, a
mov ebx, b
mov ecx, c
begswap :
mov esi, [eax]
mov edi, [ebx]
mov[ebx], esi
mov[eax], edi
add eax, 4
add ebx, 4
dec ecx
jnz short begswap
}
}
static __inline void swap64bit(void *a, void *b)
{
_asm {
mov eax, a
mov ebx, b
mov ecx, [eax]
mov edx, [ebx]
mov[ebx], ecx
mov ecx, [eax+4]
mov[eax], edx
mov edx, [ebx+4]
mov[ebx+4], ecx
mov[eax+4], edx
}
}
//swapchar2(ptr1,ptr2,xsiz); is the same as:
//swapchar(ptr1,ptr2); swapchar(ptr1+1,ptr2+xsiz);
static __inline void swapchar2(void *a, void *b, int32_t s)
{
_asm {
mov eax, a
mov ebx, b
mov esi, s
add esi, ebx
mov cx, [eax]
mov dl, [ebx]
mov[ebx], cl
mov dh, [esi]
mov[esi], ch
mov[eax], dx
}
}
//}}}
#endif // __pragmas_x86_h__
#endif // __pragmas_h__

View file

@ -171,33 +171,6 @@ void clearbufbyte(void *d, int32_t c, int32_t a)
#define ASM __asm__ __volatile__
int32_t boundmulscale(int32_t a, int32_t b, int32_t c)
{
ASM(
"imull %%ebx\n\t"
"movl %%edx, %%ebx\n\t" // mov ebx, edx
"shrdl %%cl, %%edx, %%eax\n\t" // mov eax, edx, cl
"sarl %%cl, %%edx\n\t" // sar edx, cl
"xorl %%eax, %%edx\n\t" // xor edx, eax
"js 0f\n\t" // js checkit
"xorl %%eax, %%edx\n\t" // xor edx, eax
"jz 1f\n\t" // js skipboundit
"cmpl $0xffffffff, %%edx\n\t" // cmp edx, 0xffffffff
"je 1f\n\t" // je skipboundit
"0:\n\t" // checkit:
"movl %%ebx, %%eax\n\t" // mov eax, ebx
"sarl $31, %%eax\n\t" // sar eax, 31
"xorl $0x7fffffff, %%eax\n\t" // xor eax, 0x7fffffff
"1:" // skipboundit:
: "+a"(a), "+b"(b), "+c"(c) // input eax ebx ecx
:
: "edx", "cc"
);
return a;
}
void clearbufbyte(void *D, int32_t c, int32_t a)
{
ASM(