migrated Splitter to Bits helper class

This commit is contained in:
hneemann 2018-03-05 21:21:31 +01:00
parent e6120e7b27
commit 298d2890a0
2 changed files with 10 additions and 11 deletions

View File

@ -32,8 +32,8 @@ public class ObservableValue extends Observable implements PinDescription {
/**
* Creates a new instance.
*
* @param name the name of this value
* @param bits the number of bits
* @param name the name of this value
* @param bits the number of bits
*/
public ObservableValue(String name, int bits) {
this.name = name;
@ -58,15 +58,14 @@ public class ObservableValue extends Observable implements PinDescription {
}
/**
* Sets the value and fires an event if value has changed.
* Also sets this value to low Z
* Sets the value and fires an event if the value has changed.
* Also sets all bits to low Z.
*
* @param value the new value
* @return this for chained calls
*/
public ObservableValue setValue(long value) {
set(value, 0);
return this;
return set(value, 0);
}
/**

View File

@ -129,7 +129,7 @@ public class Splitter implements Element {
inValue.addObserverToValue(new NodeWithoutDelay(outValue) {
@Override
public void hasChanged() {
outValue.set(inValue.getValue() >> bitPos, inValue.getHighZ() >> bitPos);
outValue.set(inValue.getValue() >>> bitPos, inValue.getHighZ() >>> bitPos);
}
});
break; // done!! out is completely filled!
@ -138,7 +138,7 @@ public class Splitter implements Element {
// complete in value needs to be copied to a part of the output
if (out.getPos() <= in.getPos() && in.getPos() + in.getBits() <= out.getPos() + out.getBits()) {
final int bitPos = in.getPos() - out.getPos();
final long mask = ~(((1L << in.bits) - 1) << bitPos);
final long mask = ~Bits.up(Bits.mask(in.bits), bitPos);
final ObservableValue inValue = inputs.get(in.number);
final ObservableValue outValue = outputs.get(out.number);
inputs.get(in.number).addObserverToValue(new NodeWithoutDelay(outValue) {
@ -159,7 +159,7 @@ public class Splitter implements Element {
// upper part of input needs to be copied to the lower part of the output
if (in.getPos() < out.getPos()) {
final int bitsToCopy = in.getPos() + in.getBits() - out.getPos();
final long mask = ~((1L << bitsToCopy) - 1);
final long mask = ~Bits.mask(bitsToCopy);
final int shift = out.getPos() - in.getPos();
final ObservableValue inValue = inputs.get(in.number);
final ObservableValue outValue = outputs.get(out.number);
@ -170,7 +170,7 @@ public class Splitter implements Element {
long out12 = outValue.getValue();
long inz12 = inValue.getHighZ();
long outz12 = outValue.getHighZ();
outValue.set((out12 & mask) | (in12 >> shift), (outz12 & mask) | (inz12 >> shift));
outValue.set((out12 & mask) | (in12 >>> shift), (outz12 & mask) | (inz12 >>> shift));
}
});
continue;
@ -179,7 +179,7 @@ public class Splitter implements Element {
// lower part of input needs to be copied to the upper part of the output
final int bitsToCopy = out.getPos() + out.getBits() - in.getPos();
final int shift = in.getPos() - out.getPos();
final long mask = ~(((1L << bitsToCopy) - 1) << shift);
final long mask = ~Bits.up(Bits.mask(bitsToCopy), shift);
final ObservableValue inValue = inputs.get(in.number);
final ObservableValue outValue = outputs.get(out.number);
inputs.get(in.number).addObserverToValue(new NodeWithoutDelay(outValue) {