Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.Value


        int width = inputs[0].getWidth();
        Value[] ret = new Value[width];
        for (int i = 0; i < width; i++) {
            int count = 0;
            for (int j = 0; j < numInputs; j++) {
                Value v = inputs[j].get(i);
                if (v == Value.TRUE) {
                    count++;
                } else if (v == Value.FALSE) {
                    // do nothing
                    ;
View Full Code Here


    public void propagate(InstanceState state) {
        // get attributes
        BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

        // compute outputs
        Value a = state.getPort(IN0);
        Value b = state.getPort(IN1);
        Value upper = state.getPort(UPPER);
        Value[] outs = Divider.computeResult(dataWidth, a, b, upper);

        // propagate them
        int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
        state.setPort(OUT, outs[0], delay);
View Full Code Here

        int width = state.getAttributeValue(StdAttr.WIDTH).getWidth();
        int outWidth = computeOutputBits(width - 1);
        Object type = state.getAttributeValue(TYPE);

        Value[] bits = state.getPort(2).getAll();
        Value want;
        int i;
        if (type == HIGH_ZERO) {
            want = Value.FALSE;
            for (i = bits.length - 1; i >= 0 && bits[i] == Value.TRUE; i--) { }
        } else if (type == LOW_ZERO) {
            want = Value.FALSE;
            for (i = 0; i < bits.length && bits[i] == Value.TRUE; i++) { }
        } else if (type == HIGH_ONE) {
            want = Value.TRUE;
            for (i = bits.length - 1; i >= 0 && bits[i] == Value.FALSE; i--) { }
        } else {
            want = Value.TRUE;
            for (i = 0; i < bits.length && bits[i] == Value.FALSE; i++) { }
        }

        Value present;
        Value index;
        if (i < 0 || i >= bits.length) {
            present = Value.FALSE;
            index = Value.createKnown(BitWidth.create(outWidth), 0);
        } else if (bits[i] == want) {
            present = Value.TRUE;
View Full Code Here

        // number that are definitely 1
        int minCount = 0;
        // number that are definitely not 0 (incl X/Z)
        int maxCount = 0;
        for (int i = 1; i <= inputs; i++) {
            Value v = state.getPort(i);
            Value[] bits = v.getAll();
            for (int j = 0; j < bits.length; j++) {
                Value b = bits[j];
                if (b == Value.TRUE) {
                    minCount++;
                }

                if (b != Value.FALSE) {
View Full Code Here

        }

        BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
        Object triggerType = state.getAttributeValue(StdAttr.EDGE_TRIGGER);
        int max = state.getAttributeValue(ATTR_MAX).intValue();
        Value clock = state.getPort(CK);
        boolean triggered = data.updateClock(clock, triggerType);

        Value newValue;
        boolean carry;
        if (state.getPort(CLR) == Value.TRUE) {
            newValue = Value.createKnown(dataWidth, 0);
            carry = false;
        } else {
            boolean ld = state.getPort(LD) == Value.TRUE;
            boolean ct = state.getPort(CT) != Value.FALSE;
            int oldVal = data.value;
            int newVal;
            if (!triggered) {
                newVal = oldVal;
            // trigger, enable = 1: should increment or decrement
            } else if (ct) {
                int goal = ld ? 0 : max;
                if (oldVal == goal) {
                    Object onGoal = state.getAttributeValue(ATTR_ON_GOAL);
                    if (onGoal == ON_GOAL_WRAP) {
                        newVal = ld ? max : 0;
                    } else if (onGoal == ON_GOAL_STAY) {
                        newVal = oldVal;
                    } else if (onGoal == ON_GOAL_LOAD) {
                        Value in = state.getPort(IN);
                        newVal = in.isFullyDefined() ? in.toIntValue() : 0;
                        if (newVal > max) {
                            newVal &= max;
                        }

                    } else if (onGoal == ON_GOAL_CONT) {
                        newVal = ld ? oldVal - 1 : oldVal + 1;
                    } else {
                        //OK
                        System.err.println("Invalid goal attribute " + onGoal);
                        newVal = ld ? max : 0;
                    }
                } else {
                    newVal = ld ? oldVal - 1 : oldVal + 1;
                }
            // trigger, enable = 0, load = 1: should load
            } else if (ld) {
                Value in = state.getPort(IN);
                newVal = in.isFullyDefined() ? in.toIntValue() : 0;
                if (newVal > max) {
                    newVal &= max;
                }

            // trigger, enable = 0, load = 0: no change
View Full Code Here

    @Override
    public void propagate(InstanceState state) {
        // compute output
        BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
        int bits = dataWidth == null ? 32 : dataWidth.getWidth();
        Value vx = state.getPort(IN0);
        Value vd = state.getPort(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;
View Full Code Here

    public void propagate(InstanceState state) {
        // get attributes
        BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

        // compute outputs
        Value in = state.getPort(IN);
        Value out;
        if (in.isFullyDefined()) {
            out = Value.createKnown(in.getBitWidth(), -in.toIntValue());
        } else {
            Value[] bits = in.getAll();
            Value fill = Value.FALSE;
            int pos = 0;
            while (pos < bits.length) {
                if (bits[pos] == Value.FALSE) {
                    bits[pos] = fill;
                } else if (bits[pos] == Value.TRUE) {
View Full Code Here

    public void propagate(InstanceState state) {
        // get attributes
        BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

        // compute outputs
        Value gt = Value.FALSE;
        Value eq = Value.TRUE;
        Value lt = Value.FALSE;

        Value a = state.getPort(IN0);
        Value b = state.getPort(IN1);
        Value[] ax = a.getAll();
        Value[] bx = b.getAll();
        int maxlen = Math.max(ax.length, bx.length);
        for (int pos = maxlen - 1; pos >= 0; pos--) {
            Value ab = pos < ax.length ? ax[pos] : Value.ERROR;
            Value bb = pos < bx.length ? bx[pos] : Value.ERROR;
            if (pos == ax.length - 1 && ab != bb) {
                Object mode = state.getAttributeValue(MODE_ATTRIBUTE);
                if (mode != UNSIGNED_OPTION) {
                    Value t = ab;
                    ab = bb;
                    bb = t;
                }
            }
View Full Code Here

    public void propagate(InstanceState state) {
        // get attributes
        BitWidth data = state.getAttributeValue(StdAttr.WIDTH);

        // compute outputs
        Value a = state.getPort(IN0);
        Value b = state.getPort(IN1);
        Value b_in = state.getPort(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);
View Full Code Here

    public void propagate(InstanceState state) {
        // get attributes
        BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

        // compute outputs
        Value a = state.getPort(IN0);
        Value b = state.getPort(IN1);
        Value c_in = state.getPort(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);
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.