(read-16sbe channel state) reads a 16-bit, signed, big-endian value from the input channel.
Function:
(defun read-16sbe (channel state) (declare (xargs :guard (and (state-p state) (symbolp channel) (open-input-channel-p channel :byte state)))) (b* (((mv x1 state) (read-byte$ channel state)) ((mv x2 state) (read-byte$ channel state)) ((unless x1) (mv nil state)) ((unless x2) (mv 'fail state))) (mv (combine16s x1 x2) state)))
Theorem:
(defthm read-16sbe-signed-byte (implies (and (force (state-p1 state)) (force (open-input-channel-p1 channel :byte state)) (force (symbolp channel)) (mv-nth 0 (read-16sbe channel state)) (not (equal (mv-nth 0 (read-16sbe channel state)) 'fail))) (signed-byte-p 16 (mv-nth 0 (read-16sbe channel state)))))
Theorem:
(defthm read-16sbe-integer (implies (and (mv-nth 0 (read-16sbe channel state)) (not (equal (mv-nth 0 (read-16sbe channel state)) 'fail))) (integerp (mv-nth 0 (read-16sbe channel state)))))
Theorem:
(defthm read-16sbe-range (implies (and (force (state-p1 state)) (force (open-input-channel-p1 channel :byte state)) (force (symbolp channel)) (mv-nth 0 (read-16sbe channel state)) (not (equal (mv-nth 0 (read-16sbe channel state)) 'fail))) (and (<= -32768 (mv-nth 0 (read-16sbe channel state))) (<= (- (expt 2 15)) (mv-nth 0 (read-16sbe channel state))) (< (mv-nth 0 (read-16sbe channel state)) 32768) (< (mv-nth 0 (read-16sbe channel state)) (expt 2 15)))) :rule-classes :linear)
Theorem:
(defthm read-16sbe-state (implies (and (force (state-p1 state)) (force (open-input-channel-p1 channel :byte state)) (force (symbolp channel))) (state-p1 (mv-nth 1 (read-16sbe channel state)))))
Theorem:
(defthm read-16sbe-open-input-channel-p1 (implies (and (force (state-p1 state)) (force (open-input-channel-p1 channel :byte state)) (force (symbolp channel))) (open-input-channel-p1 channel :byte (mv-nth 1 (read-16sbe channel state)))))