OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zparser.cpp] - Diff between revs 26 and 69

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 26 Rev 69
Line 12... Line 12...
//              In particular, all of the routines used to build instructions
//              In particular, all of the routines used to build instructions
//              from the appropriate fields are kept in this file.  For example,
//              from the appropriate fields are kept in this file.  For example,
//              op_noop() returns the instruction code for a NOOP  instruction.
//              op_noop() returns the instruction code for a NOOP  instruction.
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Tecnology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015, Gisselquist Technology, LLC
// Copyright (C) 2015, Gisselquist Technology, LLC
//
//
Line 44... Line 44...
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include <strings.h>
#include <strings.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)
typedef ZPARSER::ZIPI ZIPI;     // A Zip Instruction (i.e. uint32)
 
 
#define IMMOP(OP,CND,IMM,A) (((OP&0x0f)<<28)|((A&0x0f)<<24)|((CND&0x07)<<21) \
#define IMMOP(OP,CND,IMM,A) (((OP&0x01f)<<22)|((A&0x0f)<<27)|((CND&0x07)<<19) \
                        | (IMM & 0x0fffff))
                        | (IMM & 0x03ffff))
 
 
#define DBLREGOP(OP,CND,IMM,B,A) (((OP&0x0f)<<28)|((A&0x0f)<<24)        \
#define DBLREGOP(OP,CND,IMM,B,A) (((OP&0x01f)<<22)|((A&0x0f)<<27)       \
                        |((CND&0x07)<<21)|(1<<20)|((B&0x0f)<<16)         \
                        |((CND&0x07)<<19)|(1<<18)|((B&0x0f)<<14)         \
                        | (IMM & 0x0ffff))
                        | (IMM & 0x03fff))
 
 
ZIPI    ZPARSER::op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0x0, cnd, imm, b, a);
        return DBLREGOP(ZIPO_CMP, cnd, imm, b, a);
}
}
 
 
ZIPI    ZPARSER::op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
ZIPI    ZPARSER::op_cmp(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0x0, cnd, imm, a);
        return IMMOP(ZIPO_CMP, cnd, imm, a);
}
}
 
 
 
 
ZIPI    ZPARSER::op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0x1, cnd, imm, b, a);
        return DBLREGOP(ZIPO_TST, cnd, imm, b, a);
} ZIPI  ZPARSER::op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_tst(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0x1, cnd, imm, a);
        return IMMOP(ZIPO_TST, cnd, imm, a);
}
}
 
 
ZIPI    ZPARSER::op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_mov(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        ZIPI    in;
        ZIPI    in;
        in = (0x02 << 28)|((a&0x0f)<<24)|((cnd&0x07)<<21);
 
        in |= (a&0x10)<<16;
        in = (ZIPO_MOV)<<22;
        in |= (b&0x0f)<<16;
        in |= ((a  &0x0f)<<27);
        in |= (b&0x10)<<11;
        in |= ((cnd&0x07)<<19);
        in |= imm & 0x07fff;
        in |= ((b  &0x0f)<<14);
 
        in |= ( imm&0x01fff);
 
 
 
 
 
        if (b & 0x10)
 
                in |= (1<<13);
 
        if (a & 0x10)
 
                in |= (1<<18);
        return in;
        return in;
}
}
 
 
 
 
ZIPI    ZPARSER::op_ldi(ZIPIMM imm, ZIPREG a) const {
ZIPI    ZPARSER::op_ldi(ZIPIMM imm, ZIPREG a) const {
        ZIPI    in;
        ZIPI    in;
        in = ((0x03)<<28) | ((a&0x0f)<<24) | (imm & ((1<<24)-1));
        in = ((a&0x0f)<<27) | (ZIPO_LDI << 22) | (imm & ((1<<23)-1));
        return in;
        return in;
}
}
 
 
ZIPI    ZPARSER::op_trap(ZIPCOND cnd, ZIPIMM imm) const {
ZIPI    ZPARSER::op_trap(ZIPCOND cnd, ZIPIMM imm) const {
        ZIPI    in;
        ZIPI    in;
Line 101... Line 109...
        // in |= (imm & 0x0ffff);
        // in |= (imm & 0x0ffff);
        return in;
        return in;
}
}
 
 
ZIPI    ZPARSER::op_noop(void) const {
ZIPI    ZPARSER::op_noop(void) const {
        return 0x4e000000;
        return 0x76000000;
}
} ZIPI  ZPARSER::op_break(void) const {
ZIPI    ZPARSER::op_break(void) const {
        return 0x76400000;
        return 0x4e000001;
} ZIPI  ZPARSER::op_lock(void) const {
 
        return 0x76800000;
}
}
 
 
ZIPI    ZPARSER::op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
ZIPI    ZPARSER::op_ldihi(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        ZIPI    in;
        ZIPI    in = IMMOP(ZIPO_LDIHI, cnd, (imm & 0x0ffff), a);
        in  = ((0x4f)<<24)|((cnd&0x07)<<21)|(1<<20)|((a&0x0f)<<16);
 
        in |= (imm & 0x0ffff);
 
        return in;
        return in;
}
} 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;
 
        in  = ((0x4f)<<24)|((cnd&0x07)<<21)|(0<<20)|((a&0x0f)<<16);
 
        in |= (imm & 0x0ffff);
 
        return in;
        return in;
}
}
 
 
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 (0x04<<28)|((a&0x0f)<<24)|((cnd&0x7)<<21)|(0<<20)|((b&0x0f)<<16)|(imm & 0x0ffff);
        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 (0x04<<28)|((a&0x0f)<<24)|((cnd&0x7)<<21)|(0<<20)|((0x0f)<<16)|(imm & 0x0ffff);
        return IMMOP(ZIPO_MPYU, cnd, imm & 0x0ffff, a);
}
}
 
 
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 (0x04<<28)|((a&0x0f)<<24)|((cnd&0x7)<<21)|(1<<20)|((b&0x0f)<<16)|(imm & 0x0ffff);
        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 (0x04<<28)|((a&0x0f)<<24)|((cnd&0x7)<<21)|(1<<20)|((0x0f)<<16)|(imm & 0x0ffff);
        return IMMOP(ZIPO_MPYS, cnd, imm & 0x0ffff, a);
}
}
 
 
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(0x5, 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(0x5, cnd, imm, a);
        return IMMOP(ZIPO_ROL, cnd, imm, a);
 
}
 
 
 
ZIPI    ZPARSER::op_popc(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
 
        return DBLREGOP(ZIPO_POPC, cnd, imm, b, a);
 
} ZIPI  ZPARSER::op_popc(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
 
        return IMMOP(ZIPO_POPC, cnd, imm, a);
 
}
 
 
 
ZIPI    ZPARSER::op_brev(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
 
        return DBLREGOP(ZIPO_BREV, cnd, imm, b, a);
 
} ZIPI  ZPARSER::op_brev(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
 
        return IMMOP(ZIPO_BREV, cnd, imm, a);
}
}
 
 
ZIPI    ZPARSER::op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0x6, cnd, imm, b, a);
        return DBLREGOP(ZIPO_LOD, cnd, imm, b, a);
} ZIPI  ZPARSER::op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_lod(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0x6, cnd, imm, a);
        return IMMOP(ZIPO_LOD, cnd, imm, a);
}
}
 
 
 
 
ZIPI    ZPARSER::op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const {
ZIPI    ZPARSER::op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm, ZIPREG b) const {
        return DBLREGOP(0x7, cnd, imm, b, v);
        return DBLREGOP(ZIPO_STO, cnd, imm, b, v);
} ZIPI  ZPARSER::op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const {
} ZIPI  ZPARSER::op_sto(ZIPCOND cnd, ZIPREG v, ZIPIMM imm) const {
        return IMMOP(0x7, cnd, imm, v);
        return IMMOP(ZIPO_STO, cnd, imm, v);
}
}
 
 
 
 
ZIPI    ZPARSER::op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0x8, cnd, imm, b, a);
        return DBLREGOP(ZIPO_SUB, cnd, imm, b, a);
} ZIPI  ZPARSER::op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_sub(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        // While it seems like we might do well replacing a subtract immediate
        // While it seems like we might do well replacing a subtract immediate
        // with an add of the negative same, the conditions aren't the same
        // with an add of the negative same, the conditions aren't the same
        // when doing so.  Hence this is an invalid substitution.
        // when doing so.  Hence this is an invalid substitution.
        // return IMMOP(0xa, cnd, -imm, a); // Do an add of the negative of imm
        // return IMMOP(0xa, cnd, -imm, a); // Do an add of the negative of imm
        return IMMOP(0x8, cnd, imm, a);
        return IMMOP(ZIPO_SUB, cnd, imm, a);
}
}
 
 
 
 
ZIPI    ZPARSER::op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0x9, cnd, imm, b, a);
        return DBLREGOP(ZIPO_AND, cnd, imm, b, a);
} ZIPI  ZPARSER::op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_and(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0x9, cnd, imm, a);
        return IMMOP(ZIPO_AND, cnd, imm, a);
}
}
 
 
 
 
ZIPI    ZPARSER::op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0xa, cnd, imm, b, a);
        return DBLREGOP(ZIPO_ADD, cnd, imm, b, a);
} ZIPI  ZPARSER::op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_add(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0xa, cnd, imm, a);
        return IMMOP(ZIPO_ADD, cnd, imm, a);
}
}
 
 
 
 
ZIPI    ZPARSER::op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0xb, cnd, imm, b, a);
        return DBLREGOP(ZIPO_OR, cnd, imm, b, a);
} ZIPI  ZPARSER::op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_or(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0xb, cnd, imm, a);
        return IMMOP(ZIPO_OR, cnd, imm, a);
}
}
 
 
ZIPI    ZPARSER::op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0xc, cnd, imm, b, a);
        return DBLREGOP(ZIPO_XOR, cnd, imm, b, a);
} ZIPI  ZPARSER::op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_xor(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0xc, cnd, imm, a);
        return IMMOP(ZIPO_XOR, cnd, imm, a);
}
}
 
 
ZIPI    ZPARSER::op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0xd, cnd, imm, b, a);
        return DBLREGOP(ZIPO_LSL, cnd, imm, b, a);
} ZIPI  ZPARSER::op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_lsl(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0xd, cnd, imm, a);
        return IMMOP(ZIPO_LSL, cnd, imm, a);
}
}
 
 
ZIPI    ZPARSER::op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0xe, cnd, imm, b, a);
        return DBLREGOP(ZIPO_ASR, cnd, imm, b, a);
} ZIPI  ZPARSER::op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_asr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0xe, cnd, imm, a);
        return IMMOP(ZIPO_ASR, cnd, imm, a);
}
}
 
 
ZIPI    ZPARSER::op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
ZIPI    ZPARSER::op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
        return DBLREGOP(0xf, cnd, imm, b, a);
        return DBLREGOP(ZIPO_LSR, cnd, imm, b, a);
} ZIPI  ZPARSER::op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
} ZIPI  ZPARSER::op_lsr(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
        return IMMOP(0xf, cnd, imm, a);
        return IMMOP(ZIPO_LSR, cnd, imm, a);
}
}
 
 
 
ZIPI    ZPARSER::op_divu(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
 
        return DBLREGOP(ZIPO_DIVU, cnd, imm, b, a);
 
} ZIPI  ZPARSER::op_divu(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
 
        return IMMOP(ZIPO_DIVU, cnd, imm, a);
 
}
 
 
 
ZIPI    ZPARSER::op_divs(ZIPCOND cnd, ZIPIMM imm, ZIPREG b, ZIPREG a) const {
 
        return DBLREGOP(ZIPO_DIVS, cnd, imm, b, a);
 
} ZIPI  ZPARSER::op_divs(ZIPCOND cnd, ZIPIMM imm, ZIPREG a) const {
 
        return IMMOP(ZIPO_DIVS, cnd, imm, a);
 
}
 
 
 
ZPARSER::ZIPIMM ZPARSER::immediate(const ZIPI a) {
 
        ZIPOP   op((ZIPOP)((a>>25)&0x012));
 
        ZIPIMM  imm;
 
 
 
        switch(op) {
 
                case ZIPO_MOV:
 
                        imm = (a & 0x0fff); if (a&0x1fff) imm |= -0x1000; break;
 
                case ZIPO_LDI:
 
                        imm = (a & 0x03fffff); break;
 
                case ZIPO_LDIn:
 
                        imm = (a & 0x03fffff); imm |= -0x200000; break;
 
                case ZIPO_LDILO: case ZIPO_LDIHI:
 
                        imm = (a & 0x0ffff);   break;
 
                default:
 
                        if (a & 0x040000) {
 
                                imm = (a&0x3fff);
 
                                if (a&0x2000) imm |= -0x02000;
 
                                if (imm != 0)
 
                                        return false;
 
                        } else {
 
                                imm = (a&0x3ffff);
 
                                if (a&0x20000)
 
                                        imm |= -0x20000;
 
                        }
 
        }
 
 
 
        return imm;
 
}
 
 
 
bool    ZPARSER::can_merge(const ZIPI a, const ZIPI b) {
 
        // 1. Can't merge anything that's already merged
 
        if ((a|b) & 0x80000000)
 
                return false;
 
 
 
        ZIPOP   opa((ZIPOP)((a>>25)&0x012)), opb((ZIPOP)((b>>22)&0x01f));
 
        // 2. Conditions
 
        {
 
                ZIPCOND ca((ZIPCOND)((a>>19)&0x07)),cb((ZIPCOND)((b>>19)&0x07));
 
 
 
                if ((opa == ZIPO_LDI)||(opa == ZIPO_LDIn))
 
                        ca = ZIPC_ALWAYS;
 
                if ((opb == ZIPO_LDI)||(opb == ZIPO_LDIn))
 
                        cb = ZIPC_ALWAYS;
 
 
 
                if ((ca == ZIPC_ALWAYS)&&(cb != ZIPC_ALWAYS))
 
                        return false;
 
                if ((ca|cb) &0x04)
 
                        return false;
 
                if ((ca != ZIPC_ALWAYS)&&((cb != ca)&&(cb != ZIPC_ALWAYS)))
 
                        return false;
 
                // if ((ca != ZIPC_ALWAYS)||(cb != ZIPC_ALWAYS))
 
                        // return false;
 
        }
 
 
 
        // 3. Moves ... only move if the move doesn't address user registers
 
 
 
        if ((opa == ZIPO_MOV)&&(a & ((1<<18)|(1<<13))))
 
                return false;
 
        if ((opb == ZIPO_MOV)&&(b & ((1<<18)|(1<<13))))
 
                return false;
 
 
 
        // 4. Immediates.  If Register + Immediate, the answer is No.
 
        ZIPIMM imma, immb;
 
        switch(opa) {
 
                case ZIPO_MOV:
 
                        imma = (a & 0x0fff); if (a) return false; break;
 
                case ZIPO_LDI: case ZIPO_LDIn:
 
                case ZIPO_LDILO: case ZIPO_LDIHI:
 
                        imma = immediate(a);   break;
 
                default:
 
                        if (a & 0x040000) {
 
                                imma = (a&0x3ffff);
 
                                // if (a&0x20000) a |= -0x20000;
 
                                if (imma != 0)
 
                                        return false;
 
                        } else {
 
                                imma = (a&0x3fff);
 
                                if (a&0x2000) // Sign extension?
 
                                        imma |= -0x02000;
 
                        }
 
        } switch(opb) {
 
                case ZIPO_MOV:
 
                        immb = (b & 0x0fff); if (b) return false; break;
 
                case ZIPO_LDI: case ZIPO_LDIn:
 
                case ZIPO_LDILO: case ZIPO_LDIHI:
 
                        immb = immediate(b);   break;
 
                default:
 
                        if (b & 0x040000) {
 
                                immb = (b&0x3fff);
 
                                // if (b&0x2000) b |= -0x02000;
 
                                if (immb != 0)
 
                                        return false;
 
                        } else {
 
                                immb = (b&0x3ffff);
 
                                if (b&0x20000)
 
                                        immb |= -0x20000;
 
                        }
 
        }
 
 
 
        if ((opa == ZIPO_LDI)||(opa == ZIPO_LDIn)||(opa == ZIPO_LDILO)||(opa == ZIPO_LDIHI)) {
 
                if ((imma > 15)||(imma < -16))
 
                        return false;
 
        } else if ((imma > 7)||(imma < -8))
 
                        return false;
 
        if ((opb == ZIPO_LDI)||(opb == ZIPO_LDIn)||(opb == ZIPO_LDILO)||(opb == ZIPO_LDIHI)) {
 
                if ((immb > 15)||(immb < -16))
 
                        return false;
 
        } else if ((immb > 7)||(immb < -8))
 
                        return false;
 
 
 
        return true;
 
}
 
 
 
ZIPI    ZPARSER::merge(const ZIPI a, const ZIPI b) {
 
        assert(can_merge(a, b));
 
        ZIPI    ni;
 
 
 
        ZIPCOND ca( (ZIPCOND)((a>>19)&0x007)), cb( (ZIPCOND)((b>>19)&0x007));
 
        ZIPOP   opa((ZIPOP)((a>>25)&0x012)), opb((ZIPOP)((b>>22)&0x01f));
 
 
 
        if ((opa == ZIPO_LDI)||(opa == ZIPO_LDIn))
 
                ca = ZIPC_ALWAYS;
 
        if ((opb == ZIPO_LDI)||(opb == ZIPO_LDIn))
 
                cb = ZIPC_ALWAYS;
 
 
 
        ZIPIMM imma, immb;
 
        imma = immediate(a);
 
        immb = immediate(b);
 
 
 
        ni = (opa << 26)|(opb<<9)|0x80000000;
 
        if (ca != ZIPC_ALWAYS) {
 
                ni |= (ca << 19);
 
                if (cb == ca)
 
                        ni |= (1<<21);
 
        }
 
 
 
        // The result register(s)
 
        ni |= (a & 0x78000000);
 
        ni |= ((b>>27)&0x0f)<<5;
 
 
 
        // Are we using the register form of opB?
 
        switch(opa) {
 
                case ZIPO_MOV: ni |= (a&0x078000); break; // Always a register
 
                case ZIPO_LDI: case ZIPO_LDIn:
 
                case ZIPO_LDILO: case ZIPO_LDIHI:
 
                        ni |= (imma & 0x01f)<<14;
 
                        break;
 
                default:
 
                        if (a & 0x040000) {
 
                                ni |= (a&0x078000);
 
                        } else
 
                                ni |= (imma & 0x0f)<<14;
 
        }
 
 
 
        switch(opb) {
 
                case ZIPO_MOV:
 
                        ni |= ((b>>14)&0x0f)|0x10; break;
 
                case ZIPO_LDI: case ZIPO_LDIn:
 
                case ZIPO_LDILO: case ZIPO_LDIHI:
 
                        ni |= (immb & 0x01f);
 
                        break;
 
                default:
 
                        if (b & 0x040000) {
 
                                ni |= ((b>>14)&0x0f)|0x10;
 
                        } else
 
                                ni |= (immb & 0x0f);
 
        }
 
 
 
        return ni;
 
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.