XMLWordPrintable

Details

    • Sub-task
    • Resolution: Fixed
    • P3
    • 9
    • 8u40
    • core-libs
    • b37
    • generic
    • generic

    Backports

      Description

        asm.js uses the "x|0" idiom to coerce the argument to int32, and the "x>>>0" idiom to coerce the argument to uint32. Currently, nashorn compiles these to

        <load x as int>
        ICONST_0
        IOR

        and

        <load x as int>
        ICONST_0
        IUSHR
        <convert to uint>

        the ICONST_0, IOR|IUSHR are unnecessary. In case "x" is already an int local variable, "x|0" nicely just becomes an ILOAD.

        Further, <convert to uint> is currently implemented by emitting
        I2L
        LDC 0xFFFF_FFFFL
        LAND
        which is 5 bytes long. Encapsulating it in "long JSType.uint32(int)" would result in it needing only 3 bytes for INVOKESTATIC.

        Using both these optimizations, we can translate x>>>0 for an already int variable from

        ILOAD x
        ICONST_0
        IUSHR
        I2L
        LDC 0xFFFF_FFFFL
        LAND

        to much nicer:

        ILOAD x
        INVOKESTATIC JSType.toUint32(I)J

        For large asm.js-compliant, emscripten/mandreel generated code the savings in bytecode size for emitted methods can be quite significant, e.g. "function a8" in zlib got reduced from ~6400 bytes to ~6000.

        Attachments

          Issue Links

            Activity

              People

                attila Attila Szegedi
                attila Attila Szegedi
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: