Google
 

Trailing-Edge - PDP-10 Archives - BB-R775C-BM - sources/fields.bli
There are 21 other files named fields.bli in the archive. Click here to see a list.
%title 'Macros for field definition'

! THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY  BE  USED
! OR COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
!
! COPYRIGHT  (C)  DIGITAL  EQUIPMENT  CORPORATION 1983, 1985.
! ALL RIGHTS RESERVED.


!++
! .CHAPTER FIELDS -- Field Definitions assistance
!
!   FACILITY: DIX
!
!   Abstract:  This file defines macros to help in defining fields and
! working with field definitions made in terms of masks, positions and
! offsets, and etc.
!
! ENVIRONMENT: Transportable library
!
! AUTHOR: David Dyer-Bennet, Creation Date: 11-Jun-82
!--
%sbttl 'Edit History'                   ! [7] Add this entire subsection

!++
! .hl 1 Edit History
! 
!   The edit history/version number information in this file is 
! present only as comments.  Sinve VERSION uses FIELDS in setting
! up its version numbers, it seemed a lot safer that way.
!--

! ; .autotable

!++
! new_version (1, 0)
! 
! edit (7, '23-Aug-82', 'David Dyer-Bennet')
!  %( Change version and revision standards everywhere.
!     Files: All. )%
! 
! Edit (%O'30', '19-Jan-83', 'David Dyer-Bennet')
! %(  Update copyright notices, add mark at end of edit histories.
! )%
!
! Edit (%O'35', '8-June-83', 'Charlotte L. Richardson')
! %( Declare version 1 complete.  All modules.
! )%
! 
! new_version (1, 1)
!
! new_version (2, 0)
! 
! Edit (%O'36', '11-Apr-84', 'Sandy Clemens')
! %( Put all Version 2 DIX development files under edit control.  Some of
!    the files listed below have major code edits, or are new modules.  Others
!    have relatively minor changes, such as cleaning up a comment.
! )%
!
! Edit (%O'50', '8-Oct-84', 'Sandy Clemens')
!   %( Add new format of COPYRIGHT notice.  FILES:  ALL )%
! **EDIT**
! .autoparagraph
!-- 
!++
! .hl 1 Macros for field definition
!
!   These macros make it easy to work with fields defined by masks,
! positions, or etc.  Thanks to Scott Robinson and TENDEF for the algorithms
! used.
!--

MACRO
    make_mask                           ! \.hl 2 \
    !++
    !   Make a mask for a field given the bit position within the word, and
    ! the length of the field.
    !
    !   Formals:
    !--
        (                               ! ;.s 1.list 1
        pos,                            ! \.le;\: Bit position in normal
                                        ! ; BLISS notation
        lng                             ! \.le;\: Length in bits
        ) =                             ! ;.end list
        ((1^lng - 1)^pos)%,

    field_position                      ! \.hl 2\
    !++
    !   Given a mask, return the field position (bit number of the LO bit).
    !
    !   Formals:
    !--
        (                               ! ;.s 1.list 1
        mask                            ! \.le;\: The mask
        ) =                             ! ;.end list
        (%NBITSU (mask AND - mask) - 1) %,

    field_length                        ! \.hl 2\
!++
!   Given a mask, return the field length in bits.
!
!   Formals:
!--
        (                               ! ;.s 1.list 1
        mask                            ! \.le;\: The mask
        ) =                             ! ;.end list
! %BPVAL - %NBITSU ( NOT (mask^(%BPVAL - %NBITSU (MASK))))
! %NBITSU (mask) - (%NBITSU (mask AND - mask) - 1)
        (%NBITSU (mask) - field_position (mask)) % ,
    position_field                      ! \.hl 2 \
    !++
    !   Given a value and a mask, put the value in that position within the
    ! word (and restrict its size).
    !
    !   Formals:
    !--
        (                               ! ;.s 1.list 1
        mask,                           ! \.le;\: Mask
        val                             ! \.le;\: Value
        ) =                             ! ;.end list
        ((val^field_position(mask)) AND mask) % ;