Line 49... |
Line 49... |
#include <assert.h>
|
#include <assert.h>
|
|
|
#include "zparser.h"
|
#include "zparser.h"
|
#include "zopcodes.h"
|
#include "zopcodes.h"
|
|
|
typedef ZPARSER::ZIPI ZIPI; // A Zip Instruction (i.e. uint32)
|
|
|
|
#define IMMOP(OP,CND,IMM,A) (((OP&0x01f)<<22)|((A&0x0f)<<27)|((CND&0x07)<<19) \
|
#define IMMOP(OP,CND,IMM,A) (((OP&0x01f)<<22)|((A&0x0f)<<27)|((CND&0x07)<<19) \
|
| (IMM & 0x03ffff))
|
| (IMM & 0x03ffff))
|
|
|
#define DBLREGOP(OP,CND,IMM,B,A) (((OP&0x01f)<<22)|((A&0x0f)<<27) \
|
#define DBLREGOP(OP,CND,IMM,B,A) (((OP&0x01f)<<22)|((A&0x0f)<<27) \
|
|((CND&0x07)<<19)|(1<<18)|((B&0x0f)<<14) \
|
|((CND&0x07)<<19)|(1<<18)|((B&0x0f)<<14) \
|
Line 132... |
Line 130... |
#ifdef LONG_MPY
|
#ifdef LONG_MPY
|
ZIPI ZPARSER::op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
ZIPI ZPARSER::op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
return DBLREGOP(ZIPO_MPY, cnd, imm, b, a);
|
return DBLREGOP(ZIPO_MPY, cnd, imm, b, a);
|
} ZIPI ZPARSER::op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
} ZIPI ZPARSER::op_mpy(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
return IMMOP(ZIPO_MPY, cnd, imm, a);
|
return IMMOP(ZIPO_MPY, cnd, imm, a);
|
} ZIPI ZPARSER::op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
|
ZIPI in = IMMOP(ZIPO_BREV, cnd, brev(imm)&0x0ffff, a);
|
|
return in;
|
|
}
|
}
|
#else
|
#else
|
ZIPI ZPARSER::op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
ZIPI ZPARSER::op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
ZIPI in = IMMOP(ZIPO_LDIHI, cnd, (imm & 0x0ffff), a);
|
ZIPI in = IMMOP(ZIPO_LDIHI, cnd, (imm & 0x0ffff), a);
|
return in;
|
return in;
|
Line 147... |
Line 142... |
ZIPI ZPARSER::op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
ZIPI ZPARSER::op_ldilo(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
ZIPI in = IMMOP(ZIPO_LDILO, cnd, (imm & 0x0ffff), a);
|
ZIPI in = IMMOP(ZIPO_LDILO, cnd, (imm & 0x0ffff), a);
|
return in;
|
return in;
|
}
|
}
|
|
|
|
#ifdef LONG_MPY
|
|
ZIPI ZPARSER::op_mpyuhi(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
|
return DBLREGOP(ZIPO_MPYUHI, cnd, imm, b, a);
|
|
} ZIPI ZPARSER::op_mpyuhi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
|
return IMMOP(ZIPO_MPYUHI, cnd, imm & 0x0ffff, a);
|
|
}
|
|
|
|
ZIPI ZPARSER::op_mpyshi(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
|
return DBLREGOP(ZIPO_MPYSHI, cnd, imm, b, a);
|
|
} ZIPI ZPARSER::op_mpyshi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
|
return IMMOP(ZIPO_MPYSHI, cnd, imm & 0x0ffff, a);
|
|
}
|
|
#else
|
ZIPI ZPARSER::op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
ZIPI ZPARSER::op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
return DBLREGOP(ZIPO_MPYU, cnd, imm, b, a);
|
return DBLREGOP(ZIPO_MPYU, cnd, imm, b, a);
|
} ZIPI ZPARSER::op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
} ZIPI ZPARSER::op_mpyu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
return IMMOP(ZIPO_MPYU, cnd, imm & 0x0ffff, a);
|
return IMMOP(ZIPO_MPYU, cnd, imm & 0x0ffff, a);
|
}
|
}
|
Line 158... |
Line 166... |
ZIPI ZPARSER::op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
ZIPI ZPARSER::op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
return DBLREGOP(ZIPO_MPYS, cnd, imm, b, a);
|
return DBLREGOP(ZIPO_MPYS, cnd, imm, b, a);
|
} ZIPI ZPARSER::op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
} ZIPI ZPARSER::op_mpys(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
return IMMOP(ZIPO_MPYS, cnd, imm & 0x0ffff, a);
|
return IMMOP(ZIPO_MPYS, cnd, imm & 0x0ffff, a);
|
}
|
}
|
|
#endif
|
|
|
ZIPI ZPARSER::op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
ZIPI ZPARSER::op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
|
return DBLREGOP(ZIPO_ROL, cnd, imm, b, a);
|
return DBLREGOP(ZIPO_ROL, cnd, imm, b, a);
|
} ZIPI ZPARSER::op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
} ZIPI ZPARSER::op_rol(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
|
return IMMOP(ZIPO_ROL, cnd, imm, a);
|
return IMMOP(ZIPO_ROL, cnd, imm, a);
|
Line 269... |
Line 278... |
imm = (a & 0x0fff); if (a&0x1fff) imm |= -0x1000; break;
|
imm = (a & 0x0fff); if (a&0x1fff) imm |= -0x1000; break;
|
case ZIPO_LDI:
|
case ZIPO_LDI:
|
imm = (a & 0x03fffff); break;
|
imm = (a & 0x03fffff); break;
|
case ZIPO_LDIn:
|
case ZIPO_LDIn:
|
imm = (a & 0x03fffff); imm |= -0x200000; break;
|
imm = (a & 0x03fffff); imm |= -0x200000; break;
|
case ZIPO_LDILO: case ZIPO_LDIHI:
|
case ZIPO_LDILO:
|
|
#ifndef LONG_MPY
|
|
case ZIPO_LDIHI:
|
|
#endif
|
imm = (a & 0x0ffff); break;
|
imm = (a & 0x0ffff); break;
|
default:
|
default:
|
if (a & 0x040000) {
|
if (a & 0x040000) {
|
imm = (a&0x3fff);
|
imm = (a&0x3fff);
|
if (a&0x2000) imm |= -0x02000;
|
if (a&0x2000) imm |= -0x02000;
|
Line 323... |
Line 335... |
ZIPIMM imma, immb;
|
ZIPIMM imma, immb;
|
switch(opa) {
|
switch(opa) {
|
case ZIPO_MOV:
|
case ZIPO_MOV:
|
imma = (a & 0x03fff); if (a) return false; break;
|
imma = (a & 0x03fff); if (a) return false; break;
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDILO: case ZIPO_LDIHI:
|
case ZIPO_LDILO:
|
|
#ifndef LONG_MPY
|
|
case ZIPO_LDIHI:
|
|
#endif
|
imma = immediate(a); break;
|
imma = immediate(a); break;
|
default:
|
default:
|
if (a & 0x040000) {
|
if (a & 0x040000) {
|
imma = (a&0x3ffff);
|
imma = (a&0x3ffff);
|
// if (a&0x20000) a |= -0x20000;
|
// if (a&0x20000) a |= -0x20000;
|
Line 340... |
Line 355... |
}
|
}
|
} switch(opb) {
|
} switch(opb) {
|
case ZIPO_MOV:
|
case ZIPO_MOV:
|
immb = (b & 0x0fff); if (b) return false; break;
|
immb = (b & 0x0fff); if (b) return false; break;
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDILO: case ZIPO_LDIHI:
|
case ZIPO_LDILO:
|
|
#ifndef LONG_MPY
|
|
case ZIPO_LDIHI:
|
|
#endif
|
immb = immediate(b); break;
|
immb = immediate(b); break;
|
default:
|
default:
|
if (b & 0x040000) {
|
if (b & 0x040000) {
|
immb = (b&0x3fff);
|
immb = (b&0x3fff);
|
// if (b&0x2000) b |= -0x02000;
|
// if (b&0x2000) b |= -0x02000;
|
Line 355... |
Line 373... |
if (b&0x20000)
|
if (b&0x20000)
|
immb |= -0x20000;
|
immb |= -0x20000;
|
}
|
}
|
}
|
}
|
|
|
if ((opa == ZIPO_LDI)||(opa == ZIPO_LDIn)||(opa == ZIPO_LDILO)||(opa == ZIPO_LDIHI)) {
|
if ((opa == ZIPO_LDI)||(opa == ZIPO_LDIn)
|
|
#ifndef LONG_MPY
|
|
||(opa == ZIPO_LDIHI)
|
|
#endif
|
|
||(opa == ZIPO_LDILO)) {
|
if ((imma > 15)||(imma < -16))
|
if ((imma > 15)||(imma < -16))
|
return false;
|
return false;
|
} else if ((imma > 7)||(imma < -8))
|
} else if ((imma > 7)||(imma < -8))
|
return false;
|
return false;
|
if ((opb == ZIPO_LDI)||(opb == ZIPO_LDIn)||(opb == ZIPO_LDILO)||(opb == ZIPO_LDIHI)) {
|
if ((opb == ZIPO_LDI)||(opb == ZIPO_LDIn)
|
|
#ifndef LONG_MPY
|
|
||(opb == ZIPO_LDIHI)
|
|
#endif
|
|
||(opb == ZIPO_LDILO)) {
|
if ((immb > 15)||(immb < -16))
|
if ((immb > 15)||(immb < -16))
|
return false;
|
return false;
|
} else if ((immb > 7)||(immb < -8))
|
} else if ((immb > 7)||(immb < -8))
|
return false;
|
return false;
|
|
|
Line 400... |
Line 426... |
|
|
// Are we using the register form of opB?
|
// Are we using the register form of opB?
|
switch(opa) {
|
switch(opa) {
|
case ZIPO_MOV: ni |= (a&0x078000); break; // Always a register
|
case ZIPO_MOV: ni |= (a&0x078000); break; // Always a register
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDILO: case ZIPO_LDIHI:
|
case ZIPO_LDILO:
|
|
#ifndef LONG_MPY
|
|
case ZIPO_LDIHI:
|
|
#endif
|
ni |= (imma & 0x01f)<<14;
|
ni |= (imma & 0x01f)<<14;
|
break;
|
break;
|
default:
|
default:
|
if (a & 0x040000) {
|
if (a & 0x040000) {
|
ni |= (a&0x078000);
|
ni |= (a&0x078000);
|
Line 414... |
Line 443... |
|
|
switch(opb) {
|
switch(opb) {
|
case ZIPO_MOV:
|
case ZIPO_MOV:
|
ni |= ((b>>14)&0x0f)|0x10; break;
|
ni |= ((b>>14)&0x0f)|0x10; break;
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDI: case ZIPO_LDIn:
|
case ZIPO_LDILO: case ZIPO_LDIHI:
|
case ZIPO_LDILO:
|
|
#ifndef LONG_MPY
|
|
case ZIPO_LDIHI:
|
|
#endif
|
ni |= (immb & 0x01f);
|
ni |= (immb & 0x01f);
|
break;
|
break;
|
default:
|
default:
|
if (b & 0x040000) {
|
if (b & 0x040000) {
|
ni |= ((b>>14)&0x0f)|0x10;
|
ni |= ((b>>14)&0x0f)|0x10;
|