sys/contrib/dev/acpica-unix/compiler/aslopcodes.c
UINT32
OpcSetOptimalIntegerSize (
    ACPI_PARSE_OBJECT       *Op)
{

#if 0
    /*
     * TBD: - we don't want to optimize integers in the block header, but the
     * code below does not work correctly.
     */
    if (Op->Asl.Parent &&
        Op->Asl.Parent->Asl.Parent &&
       (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK))
    {
        return 0;
    }
#endif

    /*
     * Check for the special AML integers first - Zero, One, Ones.
     * These are single-byte opcodes that are the smallest possible
     * representation of an integer.
     *
     * This optimization is optional.
     */
    if (Gbl_IntegerOptimizationFlag)
    {
        switch (Op->Asl.Value.Integer)
        {
        case 0:

            Op->Asl.AmlOpcode = AML_ZERO_OP;
            AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                Op, "Zero");
            return 1;

        case 1:

            Op->Asl.AmlOpcode = AML_ONE_OP;
            AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                Op, "One");
            return 1;

        case ACPI_UINT32_MAX:

            /* Check for table integer width (32 or 64) */

            if (AcpiGbl_IntegerByteWidth == 4)
            {
                Op->Asl.AmlOpcode = AML_ONES_OP;
                AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                    Op, "Ones");
                return 1;
            }
            break;

        case ACPI_UINT64_MAX:

            /* Check for table integer width (32 or 64) */

            if (AcpiGbl_IntegerByteWidth == 8)
            {
                Op->Asl.AmlOpcode = AML_ONES_OP;
                AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                    Op, "Ones");
                return 1;
            }
            break;

        default:
            break;
        }
    }

    /* Find the best fit using the various AML integer prefixes */

    if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
    {
        Op->Asl.AmlOpcode = AML_BYTE_OP;
        return 1;
    }
    if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
    {
        Op->Asl.AmlOpcode = AML_WORD_OP;
        return 2;
    }
    if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
    {
        Op->Asl.AmlOpcode = AML_DWORD_OP;
        return 4;
    }
    else
    {
        if (AcpiGbl_IntegerByteWidth == 4)
        {
            AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH,
                Op, NULL);

            if (!Gbl_IgnoreErrors)
            {
                /* Truncate the integer to 32-bit */
                Op->Asl.AmlOpcode = AML_DWORD_OP;
                return 4;
            }
        }

        Op->Asl.AmlOpcode = AML_QWORD_OP;
        return 8;
    }
}
/*******************************************************************************
 *
 * FUNCTION:    OpcSetOptimalIntegerSize
 *
 * PARAMETERS:  Op        - A parse tree node
 *
 * RETURN:      Integer width, in bytes.  Also sets the node AML opcode to the
 *              optimal integer AML prefix opcode.
 *
 * DESCRIPTION: Determine the optimal AML encoding of an integer.  All leading
 *              zeros can be truncated to squeeze the integer into the
 *              minimal number of AML bytes.
 *
 ******************************************************************************/
OpcSetOptimalIntegerSize
PARAMETERS:  Op        - A parse tree node

Integer width, in bytes.  Also sets the node AML opcode to the
optimal integer AML prefix opcode.

Determine the optimal AML encoding of an integer.  All leading
zeros can be truncated to squeeze the integer into the
minimal number of AML bytes.
OpcSetOptimalIntegerSize PARAMETERS : Op - A parse tree node Integer width in bytes . Also sets the node AML opcode to the optimal integer AML prefix opcode . Determine the optimal AML encoding of an integer . All leading zeros can be truncated to squeeze the integer into the minimal number of AML bytes .
UINT32
OpcSetOptimalIntegerSize (
    ACPI_PARSE_OBJECT       *Op)
{
#if 0
    if (Op->Asl.Parent &&
        Op->Asl.Parent->Asl.Parent &&
       (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK))
    {
        return 0;
    }
#endif
    if (Gbl_IntegerOptimizationFlag)
    {
        switch (Op->Asl.Value.Integer)
        {
        case 0:
            Op->Asl.AmlOpcode = AML_ZERO_OP;
            AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                Op, "Zero");
            return 1;
        case 1:
            Op->Asl.AmlOpcode = AML_ONE_OP;
            AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                Op, "One");
            return 1;
        case ACPI_UINT32_MAX:
            if (AcpiGbl_IntegerByteWidth == 4)
            {
                Op->Asl.AmlOpcode = AML_ONES_OP;
                AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                    Op, "Ones");
                return 1;
            }
            break;
        case ACPI_UINT64_MAX:
            if (AcpiGbl_IntegerByteWidth == 8)
            {
                Op->Asl.AmlOpcode = AML_ONES_OP;
                AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION,
                    Op, "Ones");
                return 1;
            }
            break;
        default:
            break;
        }
    }
    if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX)
    {
        Op->Asl.AmlOpcode = AML_BYTE_OP;
        return 1;
    }
    if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX)
    {
        Op->Asl.AmlOpcode = AML_WORD_OP;
        return 2;
    }
    if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX)
    {
        Op->Asl.AmlOpcode = AML_DWORD_OP;
        return 4;
    }
    else
    {
        if (AcpiGbl_IntegerByteWidth == 4)
        {
            AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH,
                Op, NULL);
            if (!Gbl_IgnoreErrors)
            {
                Op->Asl.AmlOpcode = AML_DWORD_OP;
                return 4;
            }
        }
        Op->Asl.AmlOpcode = AML_QWORD_OP;
        return 8;
    }
}
UINT32 OpcSetOptimalIntegerSize ( ACPI_PARSE_OBJECT * Op ) { #if 0 if ( Op -> Asl . Parent && Op -> Asl . Parent -> Asl . Parent && ( Op -> Asl . Parent -> Asl . Parent -> Asl . ParseOpcode == PARSEOP_DEFINITIONBLOCK ) ) { return 0 ; } #endif if ( Gbl_IntegerOptimizationFlag ) { switch ( Op -> Asl . Value . Integer ) { case 0 : Op -> Asl . AmlOpcode = AML_ZERO_OP ; AslError ( ASL_OPTIMIZATION , ASL_MSG_INTEGER_OPTIMIZATION , Op , " " ) ; return 1 ; case 1 : Op -> Asl . AmlOpcode = AML_ONE_OP ; AslError ( ASL_OPTIMIZATION , ASL_MSG_INTEGER_OPTIMIZATION , Op , " " ) ; return 1 ; case ACPI_UINT32_MAX : if ( AcpiGbl_IntegerByteWidth == 4 ) { Op -> Asl . AmlOpcode = AML_ONES_OP ; AslError ( ASL_OPTIMIZATION , ASL_MSG_INTEGER_OPTIMIZATION , Op , " " ) ; return 1 ; } break ; case ACPI_UINT64_MAX : if ( AcpiGbl_IntegerByteWidth == 8 ) { Op -> Asl . AmlOpcode = AML_ONES_OP ; AslError ( ASL_OPTIMIZATION , ASL_MSG_INTEGER_OPTIMIZATION , Op , " " ) ; return 1 ; } break ; default : break ; } } if ( Op -> Asl . Value . Integer <= ACPI_UINT8_MAX ) { Op -> Asl . AmlOpcode = AML_BYTE_OP ; return 1 ; } if ( Op -> Asl . Value . Integer <= ACPI_UINT16_MAX ) { Op -> Asl . AmlOpcode = AML_WORD_OP ; return 2 ; } if ( Op -> Asl . Value . Integer <= ACPI_UINT32_MAX ) { Op -> Asl . AmlOpcode = AML_DWORD_OP ; return 4 ; } else { if ( AcpiGbl_IntegerByteWidth == 4 ) { AslError ( ASL_WARNING , ASL_MSG_INTEGER_LENGTH , Op , NULL ) ; if ( ! Gbl_IgnoreErrors ) { Op -> Asl . AmlOpcode = AML_DWORD_OP ; return 4 ; } } Op -> Asl . AmlOpcode = AML_QWORD_OP ; return 8 ; } }
FUNCTION:    OpcSetOptimalIntegerSize
 PARAMETERS:  Op        - A parse tree node
FUNCTION : OpcSetOptimalIntegerSize PARAMETERS : Op - A parse tree node
/*
     * TBD: - we don't want to optimize integers in the block header, but the
     * code below does not work correctly.
     */ /*
     * Check for the special AML integers first - Zero, One, Ones.
     * These are single-byte opcodes that are the smallest possible
     * representation of an integer.
     *
     * This optimization is optional.
     */ /* Check for table integer width (32 or 64) */ /* Check for table integer width (32 or 64) */ /* Find the best fit using the various AML integer prefixes */ /* Truncate the integer to 32-bit */