codetable.c 8.7 KB
#include "assert.h"
#include "globals.h"
#include "opcodes.h"
#include "externs.h"

void
BuildOpcodeTable()
{
#include "codetablesetup.h"
}

unsigned int
BuildOpcode2(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    assert(leftMostFree == 0);
    return instruction;
}
    
unsigned int
BuildOpcode4(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    assert(leftMostFree == 0);
    return instruction;
}
    
unsigned int
BuildOpcode5(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3,
    unsigned int width4,
    unsigned int field4) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3 + width4) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    instruction |= (field4 << (leftMostFree-width4));
    leftMostFree -= width4;
    assert(leftMostFree == 0);
    return instruction;
}
    
unsigned int
BuildOpcode6(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3,
    unsigned int width4,
    unsigned int field4,
    unsigned int width5,
    unsigned int field5) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3 + width4 + width5) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    instruction |= (field4 << (leftMostFree-width4));
    leftMostFree -= width4;
    instruction |= (field5 << (leftMostFree-width5));
    leftMostFree -= width5;
    assert(leftMostFree == 0);
    return instruction;
}
    
unsigned int
BuildOpcode7(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3,
    unsigned int width4,
    unsigned int field4,
    unsigned int width5,
    unsigned int field5,
    unsigned int width6,
    unsigned int field6) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3 + width4 + width5 + width6) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    instruction |= (field4 << (leftMostFree-width4));
    leftMostFree -= width4;
    instruction |= (field5 << (leftMostFree-width5));
    leftMostFree -= width5;
    instruction |= (field6 << (leftMostFree-width6));
    leftMostFree -= width6;
    assert(leftMostFree == 0);
    return instruction;
}
    
    
unsigned int
BuildOpcode8(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3,
    unsigned int width4,
    unsigned int field4,
    unsigned int width5,
    unsigned int field5,
    unsigned int width6,
    unsigned int field6,
    unsigned int width7,
    unsigned int field7) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3 + width4 + width5 + width6 + width7) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    instruction |= (field4 << (leftMostFree-width4));
    leftMostFree -= width4;
    instruction |= (field5 << (leftMostFree-width5));
    leftMostFree -= width5;
    instruction |= (field6 << (leftMostFree-width6));
    leftMostFree -= width6;
    instruction |= (field7 << (leftMostFree-width7));
    leftMostFree -= width7;
    assert(leftMostFree == 0);
    return instruction;
}
    
unsigned int
BuildOpcode9(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3,
    unsigned int width4,
    unsigned int field4,
    unsigned int width5,
    unsigned int field5,
    unsigned int width6,
    unsigned int field6,
    unsigned int width7,
    unsigned int field7,
    unsigned int width8,
    unsigned int field8) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3 + width4 + width5 + width6 + width7 + width8) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    instruction |= (field4 << (leftMostFree-width4));
    leftMostFree -= width4;
    instruction |= (field5 << (leftMostFree-width5));
    leftMostFree -= width5;
    instruction |= (field6 << (leftMostFree-width6));
    leftMostFree -= width6;
    instruction |= (field7 << (leftMostFree-width7));
    leftMostFree -= width7;
    instruction |= (field8 << (leftMostFree-width8));
    leftMostFree -= width8;
    assert(leftMostFree == 0);
    return instruction;
}
    
    
unsigned int
BuildOpcode10(
    unsigned int width0, 
    unsigned int field0, 
    unsigned int width1,
    unsigned int field1,
    unsigned int width2,
    unsigned int field2,
    unsigned int width3,
    unsigned int field3,
    unsigned int width4,
    unsigned int field4,
    unsigned int width5,
    unsigned int field5,
    unsigned int width6,
    unsigned int field6,
    unsigned int width7,
    unsigned int field7,
    unsigned int width8,
    unsigned int field8,
    unsigned int width9, 
    unsigned int field9) {
    
    int leftMostFree;
    unsigned int instruction;
    
    assert((width0 + width1 + width2 + width3 + width4 + width5 + width6 + width7 + width8 + width9) == 32);
    leftMostFree = 32;
    instruction = (field0 << (leftMostFree-width0));
    leftMostFree -= width0;
    instruction |= (field1 << (leftMostFree-width1));
    leftMostFree -= width1;
    instruction |= (field2 << (leftMostFree-width2));
    leftMostFree -= width2;
    instruction |= (field3 << (leftMostFree-width3));
    leftMostFree -= width3;
    instruction |= (field4 << (leftMostFree-width4));
    leftMostFree -= width4;
    instruction |= (field5 << (leftMostFree-width5));
    leftMostFree -= width5;
    instruction |= (field6 << (leftMostFree-width6));
    leftMostFree -= width6;
    instruction |= (field7 << (leftMostFree-width7));
    leftMostFree -= width7;
    instruction |= (field8 << (leftMostFree-width8));
    leftMostFree -= width8;
    instruction |= (field9 << (leftMostFree-width9));
    leftMostFree -= width9;
    assert(leftMostFree == 0);
    return instruction;
}