Implementation of the
The SystemVerilog spec (20.8.1, page 567) says that
This almost lines up with integer-length but not quite, so to
avoid problems at the border cases we just need to subtract one from
n (integer-length n) (integer-length (- n 1)) $clog2 ----------------------------------------------------------------------- 0 0 0 0 1 1 0 0 2 2 1 1 3 2 2 2 4 3 2 2 5 3 3 3 6 3 3 3 7 3 3 3 8 4 3 3 9 4 4 4 10 4 4 4 -----------------------------------------------------------------------
Function:
(defun vl-clog2 (n) (declare (xargs :guard (natp n))) (let ((__function__ 'vl-clog2)) (declare (ignorable __function__)) (integer-length (- (lnfix n) 1))))
Theorem:
(defthm natp-of-vl-clog2 (b* ((ans (vl-clog2 n))) (natp ans)) :rule-classes :type-prescription)
Theorem:
(defthm vl-clog2-of-nfix-n (equal (vl-clog2 (nfix n)) (vl-clog2 n)))
Theorem:
(defthm vl-clog2-nat-equiv-congruence-on-n (implies (acl2::nat-equiv n n-equiv) (equal (vl-clog2 n) (vl-clog2 n-equiv))) :rule-classes :congruence)