Basic SAT model of x86 instructions using Z3, autogenerated from Intel docs
github.com
github.com
It's well-known that the official docs have bugs; others have had success using AMD's to compare:
It goes all the way back to 1980, where a revision to the 8086 introduced this to prevent an exception or non-maskable interrupt from using an incorrect stack pointer (by making MOV SS / POP SS atomic with the next instruction, which must load SP).
Arguably it should no longer be necessary in ring 3 protected mode, since the stack will be switched automatically - unless the handler itself was in ring 3, but no current OS allows that?
0: https://xenproject.org/2012/06/13/the-intel-sysret-privilege...
https://pages.cs.wisc.edu/~markhill/restricted/cacm10_x86-TS...
It is relevant here because none of the documentation the authors found was correct, so they wrote this and confirmed it matched observed hardware behavior.
Now, I just need to find the equivalent for arm…
For anyone who hasn't encountered one, Sewell gives excellent talks, e.g. at CCC, most recently https://media.ccc.de/v/35c3-9647-taming_the_chaos_can_we_bui...
Ideally, it should pull from the same master repository of information, but given my limited experience with how documentation tends to get built, I would be not at all surprised to learn that it's copy-pasted between several different projects, so that bugs in one don't get reflected in others.
So, if your proof is correct, and your description of the (language/CPU) is correct, you can prove the code does what you think it does.
Formal proof systems are still growing up, though, and they are still pretty hard to use. See Coq for an introduction: https://coq.inria.fr/
https://en.wikipedia.org/wiki/Model_checking
Three of the pioneers of model checking won the Turing Award back in the noughties:
https://amturing.acm.org/award_winners/clarke_1167964.cfm
https://amturing.acm.org/award_winners/emerson_1671460.cfm
https://amturing.acm.org/award_winners/sifakis_1701095.cfm
Z3 is an amazing theorem prover, bordering on magic.
https://en.wikipedia.org/wiki/Z3_Theorem_Prover
Theorem proving is often used in model checking.
This guy's code produces Z3 theorems for a subset of the x86 instructions. By theorems, I mean "mathematical statements about how they work".
They can be combined so that a small(ish?) piece of x86 code can be turned into a model, which Z3 can prove (or disprove) statements about.
This is very useful for proving a piece of code right or wrong.
Model checking used to require a phd -- now it just requires a bit of effort and "mathematical maturity". We have come a long way towards making it a generally available tool for all/most programmers but there is still a long way to go.
For example, consider a function f(x) = x << 1.
A valid sat semantics for this function is: y == f(x) implies y == 2 * x.
if f(x) != g(x) is satisfiable, you get one value of x for which f(x) != g(x)
Both of these are useful in practice.
x is the set of inputs to an instruction.