Class BitVectorMath
- java.lang.Object
-
- ru.ispras.fortress.data.types.bitvector.BitVectorMath
-
public final class BitVectorMath extends java.lang.Object
TheBitVectorMath
class contains utility methods and classes to perform operations with bit vectors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BitVectorMath.Operands
Describes the number of arguments accepted by the bit vector operations.static class
BitVectorMath.Operations
Provides singleton objects that allow performing operations with bit vectors in a unified way (i.e.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BitVector
add(BitVector lhs, BitVector rhs)
Returns the result of "add" operation on the specified values.static BitVector
and(BitVector lhs, BitVector rhs)
Returns the result of "AND" operation on the specified values.static BitVector
andr(BitVector bv)
Returns the result of "reduced AND" operation on the specified value.static BitVector
ashr(BitVector bitVector, int to)
Performs arithmetical right shift of the specified bit vector by the specified shift amount.static BitVector
ashr(BitVector bitVector, java.math.BigInteger to)
Performs arithmetical right shift of the specified bit vector by the specified shift amount.static BitVector
ashr(BitVector bitVector, BitVector to)
Performs arithmetical right shift of the specified bit vector by the specified shift amount.static boolean
eq(BitVector lhs, BitVector rhs)
Returns the result of "equal" operation on the specified values.static BitVector
lshr(BitVector bitVector, int to)
Performs logical right shift of the specified bit vector by the specified shift amount.static BitVector
lshr(BitVector bitVector, java.math.BigInteger to)
Performs logical right shift of the specified bit vector by the specified shift amount.static BitVector
lshr(BitVector bitVector, BitVector to)
Performs logical right shift of the specified bit vector by the specified shift amount.static BitVector
mul(BitVector lhs, BitVector rhs)
Returns the result of "multiply" operation on the specified values.static BitVector
nand(BitVector lhs, BitVector rhs)
Returns the result of "negation of AND" operation on the specified values.static BitVector
nandr(BitVector bv)
Returns the result of "negation of reduced AND" operation on the specified value.static BitVector
neg(BitVector bitVector)
Returns the result of "negation" operation on the specified value.static boolean
neq(BitVector lhs, BitVector rhs)
Returns the result of "not equal" operation on the specified values.static BitVector
nor(BitVector lhs, BitVector rhs)
Returns the result of "negation of OR" operation on the specified values.static BitVector
norr(BitVector bv)
Returns the result of "negation of reduced OR" operation on the specified value.static BitVector
not(BitVector bitVector)
Returns the result of "not" operation on the specified value.static BitVector
or(BitVector lhs, BitVector rhs)
Returns the result of "OR" operation on the specified values.static BitVector
orr(BitVector bv)
Returns the result of "reduced OR" operation on the specified value.static BitVector
plus(BitVector bitVector)
Returns the result of "unary plus" operation on the specified value.static BitVector
rotl(BitVector bitVector, int to)
Performs rotation to the left of the specified bit vector by the specified shift amount.static BitVector
rotl(BitVector bitVector, java.math.BigInteger to)
Performs rotation to the left of the specified bit vector by the specified shift amount.static BitVector
rotl(BitVector bitVector, BitVector to)
Performs rotation to the left of the specified bit vector by the specified shift amount.static BitVector
rotr(BitVector bitVector, int to)
Performs rotation to the right of the specified bit vector by the specified shift amount.static BitVector
rotr(BitVector bitVector, java.math.BigInteger to)
Performs rotation to the right of the specified bit vector by the specified shift amount.static BitVector
rotr(BitVector bitVector, BitVector to)
Performs rotation to the right of the specified bit vector by the specified shift amount.static BitVector
sdiv(BitVector lhs, BitVector rhs)
Returns the result of "signed divide" operation on the specified values.static boolean
sge(BitVector lhs, BitVector rhs)
Returns the result of "signed greater or equal" operation on the specified values.static boolean
sgt(BitVector lhs, BitVector rhs)
Returns the result of "signed greater than" operation on the specified values.static BitVector
shl(BitVector bitVector, int to)
Performs logical left shift of the specified bit vector by the specified shift amount.static BitVector
shl(BitVector bitVector, java.math.BigInteger to)
Performs logical left shift of the specified bit vector by the specified shift amount.static BitVector
shl(BitVector bitVector, BitVector to)
Performs logical left shift of the specified bit vector by the specified shift amount.static boolean
sle(BitVector lhs, BitVector rhs)
Returns the result of "signed less or equal" operation on the specified values.static boolean
slt(BitVector lhs, BitVector rhs)
Returns the result of "signed less than" operation on the specified values.static BitVector
smod(BitVector lhs, BitVector rhs)
Returns the result of "signed modulo" operation on the specified values.static BitVector
srem(BitVector lhs, BitVector rhs)
Returns the result of "signed remainder" operation on the specified values.static BitVector
sub(BitVector lhs, BitVector rhs)
Returns the result of "subtract" operation on the specified values.static BitVector
udiv(BitVector lhs, BitVector rhs)
Returns the result of "unsigned divide" operation on the specified values.static boolean
uge(BitVector lhs, BitVector rhs)
Returns the result of "unsigned greater or equal" operation on the specified values.static boolean
ugt(BitVector lhs, BitVector rhs)
Returns the result of "unsigned greater than" operation on the specified values.static boolean
ule(BitVector lhs, BitVector rhs)
Returns the result of "unsigned less or equal" operation on the specified values.static boolean
ult(BitVector lhs, BitVector rhs)
Returns the result of "unsigned less than" operation on the specified values.static BitVector
urem(BitVector lhs, BitVector rhs)
Returns the result of "unsigned remainder" operation on the specified values.static BitVector
xnor(BitVector lhs, BitVector rhs)
Returns the result of "negation of exclusive OR" operation on the specified values.static BitVector
xnorr(BitVector bv)
Returns the result of "negation of reduced exclusive OR" operation on the specified value.static BitVector
xor(BitVector lhs, BitVector rhs)
Returns the result of "exclusive OR" operation on the specified values.static BitVector
xorr(BitVector bv)
Returns the result of "reduced exclusive OR" operation on the specified value.
-
-
-
Method Detail
-
and
public static BitVector and(BitVector lhs, BitVector rhs)
Returns the result of "AND" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "AND" on the specified values.
-
or
public static BitVector or(BitVector lhs, BitVector rhs)
Returns the result of "OR" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "OR" on the specified values.
-
xor
public static BitVector xor(BitVector lhs, BitVector rhs)
Returns the result of "exclusive OR" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "exclusive OR" on the specified values.
-
not
public static BitVector not(BitVector bitVector)
Returns the result of "not" operation on the specified value.- Parameters:
bitVector
- The operation argument.- Returns:
- The result of "not" on the specified value.
-
nand
public static BitVector nand(BitVector lhs, BitVector rhs)
Returns the result of "negation of AND" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "negation of AND" on the specified values.
-
nor
public static BitVector nor(BitVector lhs, BitVector rhs)
Returns the result of "negation of OR" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "negation of OR" on the specified values.
-
xnor
public static BitVector xnor(BitVector lhs, BitVector rhs)
Returns the result of "negation of exclusive OR" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "negation of exclusive OR" on the specified values.
-
shl
public static BitVector shl(BitVector bitVector, BitVector to)
Performs logical left shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Logical left shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
shl
public static BitVector shl(BitVector bitVector, java.math.BigInteger to)
Performs logical left shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Logical left shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
shl
public static BitVector shl(BitVector bitVector, int to)
Performs logical left shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Logical left shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
lshr
public static BitVector lshr(BitVector bitVector, BitVector to)
Performs logical right shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Logical right shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
lshr
public static BitVector lshr(BitVector bitVector, java.math.BigInteger to)
Performs logical right shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Logical right shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
lshr
public static BitVector lshr(BitVector bitVector, int to)
Performs logical right shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Logical right shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
ashr
public static BitVector ashr(BitVector bitVector, BitVector to)
Performs arithmetical right shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Arithmetical right shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
ashr
public static BitVector ashr(BitVector bitVector, java.math.BigInteger to)
Performs arithmetical right shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Arithmetical right shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
ashr
public static BitVector ashr(BitVector bitVector, int to)
Performs arithmetical right shift of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Arithmetical right shift result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
rotl
public static BitVector rotl(BitVector bitVector, BitVector to)
Performs rotation to the left of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Left rotation result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
rotl
public static BitVector rotl(BitVector bitVector, java.math.BigInteger to)
Performs rotation to the left of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Left rotation result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
rotl
public static BitVector rotl(BitVector bitVector, int to)
Performs rotation to the left of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asbitVector.getBitSize()
minus (to
modulobitVector.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Left rotation result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
rotr
public static BitVector rotr(BitVector bitVector, BitVector to)
Performs rotation to the right of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asv.getBitSize()
minus (to
modulov.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Right rotation result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
rotr
public static BitVector rotr(BitVector bitVector, java.math.BigInteger to)
Performs rotation to the right of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asv.getBitSize()
minus (to
modulov.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Right rotation result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
rotr
public static BitVector rotr(BitVector bitVector, int to)
Performs rotation to the right of the specified bit vector by the specified shift amount. The actual shift amount is calculated asto
modulobitVector.getBitSize()
. If the actual shift amount equals0
, no shift is performed and the initial bit vector is returned. Otherwise, a new copy of data is created and returned. If the shift amount is negative, the actual shift amount is calculated asv.getBitSize()
minus (to
modulov.getBitSize()
).- Parameters:
bitVector
- Bit vector to be shifted.to
- Shift amount.- Returns:
- Right rotation result.
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters isnull
.
-
add
public static BitVector add(BitVector lhs, BitVector rhs)
Returns the result of "add" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "add" on the specified values.
-
sub
public static BitVector sub(BitVector lhs, BitVector rhs)
Returns the result of "subtract" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "subtract" on the specified values.
-
mul
public static BitVector mul(BitVector lhs, BitVector rhs)
Returns the result of "multiply" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "multiply" on the specified values.
-
udiv
public static BitVector udiv(BitVector lhs, BitVector rhs)
Returns the result of "unsigned divide" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "unsigned divide" on the specified values.
-
sdiv
public static BitVector sdiv(BitVector lhs, BitVector rhs)
Returns the result of "signed divide" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed divide" on the specified values.
-
urem
public static BitVector urem(BitVector lhs, BitVector rhs)
Returns the result of "unsigned remainder" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "unsigned remainder" on the specified values.
-
srem
public static BitVector srem(BitVector lhs, BitVector rhs)
Returns the result of "signed remainder" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed remainder" on the specified values.
-
smod
public static BitVector smod(BitVector lhs, BitVector rhs)
Returns the result of "signed modulo" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed modulo" on the specified values.
-
plus
public static BitVector plus(BitVector bitVector)
Returns the result of "unary plus" operation on the specified value.- Parameters:
bitVector
- The operation argument.- Returns:
- The result of "unary plus" on the specified value.
-
neg
public static BitVector neg(BitVector bitVector)
Returns the result of "negation" operation on the specified value.- Parameters:
bitVector
- The operation argument.- Returns:
- The result of "negation" on the specified value.
-
ule
public static boolean ule(BitVector lhs, BitVector rhs)
Returns the result of "unsigned less or equal" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "unsigned less or equal" operation on the specified values.
-
ult
public static boolean ult(BitVector lhs, BitVector rhs)
Returns the result of "unsigned less than" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "unsigned less than" operation on the specified values.
-
uge
public static boolean uge(BitVector lhs, BitVector rhs)
Returns the result of "unsigned greater or equal" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "unsigned greater or equal" operation on the specified values.
-
ugt
public static boolean ugt(BitVector lhs, BitVector rhs)
Returns the result of "unsigned greater than" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "unsigned greater than" operation on the specified values.
-
sle
public static boolean sle(BitVector lhs, BitVector rhs)
Returns the result of "signed less or equal" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed less or equal" operation on the specified values.
-
slt
public static boolean slt(BitVector lhs, BitVector rhs)
Returns the result of "signed less than" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed less than" operation on the specified values.
-
sge
public static boolean sge(BitVector lhs, BitVector rhs)
Returns the result of "signed greater or equal" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed greater or equal" operation on the specified values.
-
sgt
public static boolean sgt(BitVector lhs, BitVector rhs)
Returns the result of "signed greater than" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "signed greater than" operation on the specified values.
-
eq
public static boolean eq(BitVector lhs, BitVector rhs)
Returns the result of "equal" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "equal" operation on the specified values.
-
neq
public static boolean neq(BitVector lhs, BitVector rhs)
Returns the result of "not equal" operation on the specified values.- Parameters:
lhs
- The left hand-side argument.rhs
- The right hand-side argument.- Returns:
- The result of "not equal" operation on the specified values.
-
andr
public static BitVector andr(BitVector bv)
Returns the result of "reduced AND" operation on the specified value.- Parameters:
bv
- The operation argument.- Returns:
- The result of "reduced AND" operation on the specified value.
-
nandr
public static BitVector nandr(BitVector bv)
Returns the result of "negation of reduced AND" operation on the specified value.- Parameters:
bv
- The operation argument.- Returns:
- The result of "negation of reduced AND" operation on the specified value.
-
orr
public static BitVector orr(BitVector bv)
Returns the result of "reduced OR" operation on the specified value.- Parameters:
bv
- The operation argument.- Returns:
- The result of "reduced OR" operation on the specified value.
-
norr
public static BitVector norr(BitVector bv)
Returns the result of "negation of reduced OR" operation on the specified value.- Parameters:
bv
- The operation argument.- Returns:
- The result of "negation of reduced OR" operation on the specified value.
-
xorr
public static BitVector xorr(BitVector bv)
Returns the result of "reduced exclusive OR" operation on the specified value.- Parameters:
bv
- The operation argument.- Returns:
- The result of "reduced exclusive OR" operation on the specified value.
-
-