• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
          • Syntax-for-tools
          • Atc
          • Language
            • Abstract-syntax
            • Integer-ranges
            • Implementation-environments
            • Dynamic-semantics
            • Static-semantics
            • Grammar
            • Integer-formats
              • Short-bits
              • Long-bits
              • Int-bits
              • Def-integer-bits-linear-rule
              • Llong-bits
              • Def-integer-bits
                • Char-bits
              • Types
              • Portable-ascii-identifiers
              • Values
              • Integer-operations
              • Computation-states
              • Object-designators
              • Operations
              • Errors
              • Tag-environments
              • Function-environments
              • Character-sets
              • Flexible-array-member-removal
              • Arithmetic-operations
              • Pointer-operations
              • Bytes
              • Keywords
              • Real-operations
              • Array-operations
              • Scalar-operations
              • Structure-operations
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Integer-formats

    Def-integer-bits

    Macro to generate the nullary functions, and some theorems about them, for the size in bits of the C integer types.

    Macro: def-integer-bits

    (defmacro def-integer-bits (type bits minbits)
     (declare
        (xargs :guard (and (member-eq type '(char short int long llong))
                           (posp bits)
                           (posp minbits)
                           (>= bits minbits))))
     (b* ((type-bits (pack type '-bits))
          (type-bits-bound (pack type-bits '-bound))
          (type-bits-multiple-of-char-bits
               (pack type '-bits-multiple-of-char-bits))
          (short-substring (if (eq type 'char)
                               "signed, unsigned, and plain"
                             "signed and unsigned")))
      (cons
       'define
       (cons
        type-bits
        (cons
         'nil
         (cons
          ':returns
          (cons
           (cons type-bits
                 '(posp :rule-classes :type-prescription))
           (cons
            ':short
            (cons
             (str::cat "Size of " short-substring " @('"
                       (str::downcase-string (symbol-name type))
                       "') values, in bits.")
             (cons
              bits
              (cons
               '///
               (append
                (and
                 (not (eq type 'char))
                 (cons
                  (cons
                   'defrule
                   (cons
                     type-bits-multiple-of-char-bits
                     (cons (cons 'integerp
                                 (cons (cons '/
                                             (cons (cons type-bits 'nil)
                                                   '((char-bits))))
                                       'nil))
                           '(:rule-classes :type-prescription
                                           :enable char-bits))))
                  'nil))
                (cons
                 (cons
                      'in-theory
                      (cons (cons 'disable
                                  (cons (cons ':e (cons type-bits 'nil))
                                        'nil))
                            'nil))
                 (cons
                  (cons
                   'defret
                   (cons
                       type-bits-bound
                       (cons (cons '>=
                                   (cons type-bits (cons minbits 'nil)))
                             '(:rule-classes :linear))))
                  'nil))))))))))))))