Search in sources :

Example 46 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Multiplier method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    // compute outputs
    Value a = state.getPortValue(IN0);
    Value b = state.getPortValue(IN1);
    Value c_in = state.getPortValue(C_IN);
    Value[] outs = Multiplier.computeProduct(dataWidth, a, b, c_in);
    // propagate them
    int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
    state.setPort(OUT, outs[0], delay);
    state.setPort(C_OUT, outs[1], delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 47 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Shifter method propagate.

@Override
public void propagate(InstanceState state) {
    // compute output
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    int bits = dataWidth == null ? 32 : dataWidth.getWidth();
    Value vx = state.getPortValue(IN0);
    Value vd = state.getPortValue(IN1);
    // y will by x shifted by d
    Value vy;
    if (vd.isFullyDefined() && vx.getWidth() == bits) {
        int d = vd.toIntValue();
        Object shift = state.getAttributeValue(ATTR_SHIFT);
        if (d == 0) {
            vy = vx;
        } else if (vx.isFullyDefined()) {
            int x = vx.toIntValue();
            int y;
            if (shift == SHIFT_LOGICAL_RIGHT) {
                y = x >>> d;
            } else if (shift == SHIFT_ARITHMETIC_RIGHT) {
                if (d >= bits)
                    d = bits - 1;
                y = x >> d | ((x << (32 - bits)) >> (32 - bits + d));
            } else if (shift == SHIFT_ROLL_RIGHT) {
                if (d >= bits)
                    d -= bits;
                y = (x >>> d) | (x << (bits - d));
            } else if (shift == SHIFT_ROLL_LEFT) {
                if (d >= bits)
                    d -= bits;
                y = (x << d) | (x >>> (bits - d));
            } else {
                // SHIFT_LOGICAL_LEFT
                y = x << d;
            }
            vy = Value.createKnown(dataWidth, y);
        } else {
            Value[] x = vx.getAll();
            Value[] y = new Value[bits];
            if (shift == SHIFT_LOGICAL_RIGHT) {
                if (d >= bits)
                    d = bits;
                System.arraycopy(x, d, y, 0, bits - d);
                Arrays.fill(y, bits - d, bits, Value.FALSE);
            } else if (shift == SHIFT_ARITHMETIC_RIGHT) {
                if (d >= bits)
                    d = bits;
                System.arraycopy(x, d, y, 0, x.length - d);
                Arrays.fill(y, bits - d, y.length, x[bits - 1]);
            } else if (shift == SHIFT_ROLL_RIGHT) {
                if (d >= bits)
                    d -= bits;
                System.arraycopy(x, d, y, 0, bits - d);
                System.arraycopy(x, 0, y, bits - d, d);
            } else if (shift == SHIFT_ROLL_LEFT) {
                if (d >= bits)
                    d -= bits;
                System.arraycopy(x, x.length - d, y, 0, d);
                System.arraycopy(x, 0, y, d, bits - d);
            } else {
                // SHIFT_LOGICAL_LEFT
                if (d >= bits)
                    d = bits;
                Arrays.fill(y, 0, d, Value.FALSE);
                System.arraycopy(x, 0, y, d, bits - d);
            }
            vy = Value.create(y);
        }
    } else {
        vy = Value.createError(dataWidth);
    }
    // propagate them
    int delay = dataWidth.getWidth() * (3 * Adder.PER_DELAY);
    state.setPort(OUT, vy, delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 48 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class Subtractor method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    // compute outputs
    Value a = state.getPortValue(IN0);
    Value b = state.getPortValue(IN1);
    Value b_in = state.getPortValue(B_IN);
    if (b_in == Value.UNKNOWN || b_in == Value.NIL)
        b_in = Value.FALSE;
    Value[] outs = Adder.computeSum(data, a, b.not(), b_in.not());
    // propagate them
    int delay = (data.getWidth() + 4) * Adder.PER_DELAY;
    state.setPort(OUT, outs[0], delay);
    state.setPort(B_OUT, outs[1].not(), delay);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 49 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class bin2bcd method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    BitWidth nrofbits = attrs.getValue(bin2bcd.ATTR_BinBits);
    int NrOfPorts = (int) (Math.log10(1 << nrofbits.getWidth()) + 1.0);
    return Bounds.create((int) (-0.5 * InnerDistance), -20, NrOfPorts * InnerDistance, 40);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 50 with BitWidth

use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.

the class bin2bcd method propagate.

@Override
public void propagate(InstanceState state) {
    int bin_value = (state.getPortValue(BINin).isFullyDefined() & !state.getPortValue(BINin).isUnknown() & !state.getPortValue(BINin).isErrorValue() ? state.getPortValue(BINin).toIntValue() : -1);
    BitWidth NrOfBits = state.getAttributeValue(bin2bcd.ATTR_BinBits);
    int NrOfPorts = (int) (Math.log10(Math.pow(2.0, NrOfBits.getWidth())) + 1.0);
    for (int i = NrOfPorts; i > 0; i--) {
        int value = (int) (Math.pow(10, i - 1));
        int number = bin_value / value;
        state.setPort(i, Value.createKnown(BitWidth.create(4), number), PER_DELAY);
        bin_value -= number * value;
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Aggregations

BitWidth (com.cburch.logisim.data.BitWidth)106 Value (com.cburch.logisim.data.Value)30 Bounds (com.cburch.logisim.data.Bounds)21 Direction (com.cburch.logisim.data.Direction)20 Location (com.cburch.logisim.data.Location)16 Graphics (java.awt.Graphics)15 Port (com.cburch.logisim.instance.Port)12 EndData (com.cburch.logisim.comp.EndData)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 AttributeOption (com.cburch.logisim.data.AttributeOption)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)1 Attribute (com.cburch.logisim.data.Attribute)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Dimension (java.awt.Dimension)1