STP Main PageSTP PapersTools Using STP
|
Input Language of STPIntroductionSTP is an efficient decision procedure for the validity (or
satisfiability) of formulas from a quantifier-free many-sorted theory
of fixed-width bitvectors and (non-extensional) one-dimensional arrays.
The functions in STP's input language include concatenation,
extraction, left/right shift, sign-extension, unary minus, addition,
multiplication, (signed) modulo/division, bitwise Boolean operations,
if-then-else terms, and array reads and writes. The predicates in the
language include equality and (signed) comparators between bitvector
terms. The Input Langauge
|
Name |
Symbol |
Example |
Concatenation |
@ |
t1@t2@...@tm |
Extraction |
[i:j] |
x[31:26] |
left shift |
<< |
0bin0011 << 3 =
0bin0011000 |
right shift |
>> |
x[24:17] >> 5, another example: 0bin1000 >> 3 = 0bin0001 |
sign extension |
BVSX(bv,n) |
BVSX(0bin100, 5) = 0bin11100 |
Array READ |
[index] |
x_arr[t1] |
Array WRITE |
WITH |
x_arr WITH [index] := value |
Name |
Symbol |
Example |
Bitwise AND |
& |
t1 & t2 & ...
& tm |
Bitwise OR |
| |
t1 | t2 | t3 | ... | tm |
Bitwise NOT |
~ |
~t1 |
Bitwise XOR |
BVXOR |
BVXOR(t1,t2) |
Bitwise NAND |
BVNAND |
BVNAND(t1,t2) |
Bitwise NOR |
BVNOR |
BVNOR(t1,t2) |
Bitwise XNOR |
BVXNOR |
BVXNOR(t1,t2) |
Name |
Symbol |
Example |
Bitvector Add |
BVPLUS |
BVPLUS(n,t1,t2,...,tm) |
Bitvector Mult |
BVMULT |
BVMULT(n,t1,t2) |
Bitvector subtract |
BVSUB |
BVSUB(n,t1,t2) |
Bitvector Unary Minus |
BVUMINUS |
BVUMINUS(t1) |
Bitvector Div |
BVDIV |
BVDIV(n,t1,t2), where t1
is the
dividend and t2 is the divisor |
Signed Bitvector Div |
SBVDIV |
SBVDIV(n,t1,t2), where t1 is the dividend and t2 is the divisor |
Bitvector Modulo |
BVMOD |
BVMOD(n,t1,t2), where t1 is the dividend and t2 is the divisor |
Signed Bitvector Modulo |
SBVMOD |
SBVMOD(n,t1,t2), where t1 is the dividend and t2 is the divisor |
STP also supports conditional terms (IF cond THEN t1 ELSE t2 ENDIF), where cond is boolean term, t1 and t2 can be bitvector terms. This allows us to simulate multiplexors. An example is:
x,y : BITVECTOR(1);
QUERY(x = IF 0bin0=x THEN y ELSE BVUMINUS(y));
Name |
Symbol |
Example |
Equality |
= |
t1=t2 |
Less Than |
BVLT |
BVLT(t1,t2) |
Greater Than |
BVGT |
BVGT(t1,t2) |
Less Than Or Equal To |
BVLE |
BVLE(t1,t2) |
Greater Than Or Equal To |
BVGE |
BVGE(t1,t2) |
Signed Less Than |
SBVLT |
SBVLT(t1,t2) |
Signed Greater Than |
SBVGT |
SBVGT(t1,t2) |
Signed Less Than Or Equal
To |
SBVLE |
SBVLE(t1,t2) |
Signed Greater Than Or
Equal To |
SBVGE |
SBVGE(t1,t2) |
Example 1 illustrates the use of arithmetic, word-level and bitwise NOT operations:
x : BITVECTOR(5);
y : BITVECTOR(4);
yy : BITVECTOR(3);
QUERY(
BVPLUS(9, x@0bin0000, (0bin000@(~y)@0bin11))[8:4] = BVPLUS(5, x, ~(y[3:2]))
);
Example 2 illustrates the use of arithmetic, word-level and multiplexor terms:
bv : BITVECTOR(10);
a : BOOLEAN;
QUERY(
0bin01100000[5:3]=(0bin1111001@bv[0:0])[4:2]
AND
0bin1@(IF a THEN 0bin0 ELSE 0bin1 ENDIF)=(IF a THEN 0bin110 ELSE 0bin011 ENDIF)[1:0]
);
Example 3 illustrates the use of bitwise operations:
x, y, z, t, q : BITVECTOR(1024);
ASSERT(x=~x);
ASSERT(x&y&t&z&q = x);
ASSERT(x|y = t);
ASSERT(BVXOR(x,~x)=t);
QUERY(FALSE);
Example 4 illustrates the use of predicates and all the arithmetic operations:
x, y : BITVECTOR(4);
ASSERT(x=0hex5);
ASSERT(y = 0bin0101);
QUERY(
BVMULT(8,x,y)=BVMULT(8,y,x)
AND
NOT(BVLT(x,y))
AND
BVLE(BVSUB(8,x,y), BVPLUS(8, x, BVUMINUS(x)))
AND
x = BVSUB(4, BVUMINUS(x), BVPLUS(4, x,0hex1))
);
Example 5 illustrates the use of shift functions
x, y : BITVECTOR(8);
z, t : BITVECTOR(12);
ASSERT(x=0hexff);
ASSERT(z=0hexff0);
QUERY(z = x << 4);
QUERY((z >> 4)[7:0] = x);
For invalid inputs, the COUNTEREXAMPLE command can be used to generate appropriate counterexamples. The generated counter example is essentially a bitwise assignment to the variables in the input.