Changeset 69080 in webkit


Ignore:
Timestamp:
Oct 4, 2010 10:56:55 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-10-04 David Goodwin <david_goodwin@apple.com>

Reviewed by Oliver Hunt.

ARMv7 JIT should take advantage of 2-byte branches to reduce code size
https://bugs.webkit.org/show_bug.cgi?id=47007

  • assembler/ARMv7Assembler.cpp:
  • assembler/ARMv7Assembler.h: (JSC::ARMv7Assembler::computeJumpType): (JSC::ARMv7Assembler::link): (JSC::ARMv7Assembler::canBeJumpT2): (JSC::ARMv7Assembler::canBeJumpT4): (JSC::ARMv7Assembler::linkBX): (JSC::ARMv7Assembler::linkJumpT4): (JSC::ARMv7Assembler::linkJumpT2): (JSC::ARMv7Assembler::linkJumpAbsolute):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r69060 r69080  
     12010-10-04  David Goodwin  <david_goodwin@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        ARMv7 JIT should take advantage of 2-byte branches to reduce code size
     6        https://bugs.webkit.org/show_bug.cgi?id=47007
     7
     8        * assembler/ARMv7Assembler.cpp:
     9        * assembler/ARMv7Assembler.h:
     10        (JSC::ARMv7Assembler::computeJumpType):
     11        (JSC::ARMv7Assembler::link):
     12        (JSC::ARMv7Assembler::canBeJumpT2):
     13        (JSC::ARMv7Assembler::canBeJumpT4):
     14        (JSC::ARMv7Assembler::linkBX):
     15        (JSC::ARMv7Assembler::linkJumpT4):
     16        (JSC::ARMv7Assembler::linkJumpT2):
     17        (JSC::ARMv7Assembler::linkJumpAbsolute):
     18
    1192010-10-04  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    220
  • trunk/JavaScriptCore/assembler/ARMv7Assembler.cpp

    r65042 r69080  
    3232namespace JSC {
    3333
    34 const int ARMv7Assembler::JumpSizes[] = { 0xffffffff, 2 * sizeof(uint16_t), 2 * sizeof(uint16_t), 5 * sizeof(uint16_t) };
     34const int ARMv7Assembler::JumpSizes[] = { 0xffffffff, sizeof(uint16_t), sizeof(uint16_t),
     35    2 * sizeof(uint16_t), 2 * sizeof(uint16_t), 5 * sizeof(uint16_t) };
    3536
    3637}
  • trunk/JavaScriptCore/assembler/ARMv7Assembler.h

    r68764 r69080  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
    33 * Copyright (C) 2010 University of Szeged
    44 *
     
    480480
    481481    enum JumpType { JumpNoCondition, JumpCondition, JumpFullSize };
    482     enum JumpLinkType { LinkInvalid, LinkShortJump, LinkConditionalShortJump, LinkLongJump, JumpTypeCount };
     482    enum JumpLinkType { LinkInvalid, LinkJumpT2, LinkConditionalJumpT2,
     483        LinkJumpT4, LinkConditionalJumpT4, LinkBX, JumpTypeCount };
    483484    static const int JumpSizes[JumpTypeCount];
    484485    enum { JumpPaddingSize = 5 * sizeof(uint16_t) };
     
    629630
    630631    typedef enum {
     632        OP_B_T2         = 0xE000,
    631633        OP_AND_reg_T2   = 0xEA00,
    632634        OP_TST_reg_T2   = 0xEA10,
     
    16801682    {
    16811683        if (record.type() >= JumpFullSize) {
    1682             record.setLinkType(LinkLongJump);
    1683             return LinkLongJump;
     1684            record.setLinkType(LinkBX);
     1685            return LinkBX;
     1686        }
     1687        const uint16_t* jumpT2Location = reinterpret_cast<const uint16_t*>(from  - (JumpPaddingSize - JumpSizes[LinkJumpT2]));
     1688        if (canBeJumpT2(jumpT2Location, to)) {
     1689            if (record.type() == JumpCondition) {
     1690                record.setLinkType(LinkConditionalJumpT2);
     1691                return LinkConditionalJumpT2;
     1692            }
     1693            record.setLinkType(LinkJumpT2);
     1694            return LinkJumpT2;
    16841695        }
    16851696        bool mayTriggerErrata = false;
    1686         const uint16_t* shortJumpLocation = reinterpret_cast<const uint16_t*>(from  - (JumpPaddingSize - JumpSizes[LinkShortJump]));
    1687         if (!canBeShortJump(shortJumpLocation, to, mayTriggerErrata)) {
    1688             record.setLinkType(LinkLongJump);
    1689             return LinkLongJump;
     1697        const uint16_t* jumpT4Location = reinterpret_cast<const uint16_t*>(from  - (JumpPaddingSize - JumpSizes[LinkJumpT4]));
     1698        if (!canBeJumpT4(jumpT4Location, to, mayTriggerErrata)) {
     1699            record.setLinkType(LinkBX);
     1700            return LinkBX;
    16901701        }
    16911702        if (mayTriggerErrata) {
    1692             record.setLinkType(LinkLongJump);
    1693             return LinkLongJump;
     1703            record.setLinkType(LinkBX);
     1704            return LinkBX;
    16941705        }
    16951706        if (record.type() == JumpCondition) {
    1696             record.setLinkType(LinkConditionalShortJump);
    1697             return LinkConditionalShortJump;
    1698         }
    1699         record.setLinkType(LinkShortJump);
    1700         return LinkShortJump;
     1707            record.setLinkType(LinkConditionalJumpT4);
     1708            return LinkConditionalJumpT4;
     1709        }
     1710        record.setLinkType(LinkJumpT4);
     1711        return LinkJumpT4;
    17011712    }
    17021713
     
    17181729    void link(LinkRecord& record, uint8_t* from, uint8_t* to)
    17191730    {
    1720         uint16_t* itttLocation;
    1721         if (record.linkType() == LinkConditionalShortJump) {
    1722             itttLocation = reinterpret_cast<uint16_t*>(from - JumpSizes[LinkConditionalShortJump] - 2);
     1731        JumpLinkType linkType = record.linkType();
     1732        ASSERT(linkType != LinkInvalid);
     1733        if ((linkType == LinkConditionalJumpT2) || (linkType == LinkConditionalJumpT4)) {
     1734            uint16_t* itttLocation = reinterpret_cast<uint16_t*>(from - JumpSizes[linkType] - 2);
    17231735            itttLocation[0] = ifThenElse(record.condition()) | OP_IT;
    17241736        }
    1725         ASSERT(record.linkType() != LinkInvalid);
    1726         if (record.linkType() != LinkLongJump)
    1727             linkShortJump(reinterpret_cast<uint16_t*>(from), to);
    1728         else
    1729             linkLongJump(reinterpret_cast<uint16_t*>(from), to);
     1737        switch (linkType) {
     1738        case LinkJumpT2:
     1739        case LinkConditionalJumpT2:
     1740            linkJumpT2(reinterpret_cast<uint16_t*>(from), to);
     1741            break;
     1742        case LinkJumpT4:
     1743        case LinkConditionalJumpT4:
     1744            linkJumpT4(reinterpret_cast<uint16_t*>(from), to);
     1745            break;
     1746        case LinkBX:
     1747            linkBX(reinterpret_cast<uint16_t*>(from), to);
     1748            break;
     1749        default:
     1750            ASSERT_NOT_REACHED();
     1751            break;
     1752        }
    17301753    }
    17311754
     
    19471970    }
    19481971
    1949     static bool canBeShortJump(const uint16_t* instruction, const void* target, bool& mayTriggerErrata)
     1972    static bool canBeJumpT2(const uint16_t* instruction, const void* target)
     1973    {
     1974        ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
     1975        ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
     1976       
     1977        intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
     1978        // It does not appear to be documented in the ARM ARM (big surprise), but
     1979        // for OP_B_T2 the branch displacement encoded in the instruction is 2
     1980        // less than the actual displacement.
     1981        relative -= 2;
     1982        return ((relative << 20) >> 20) == relative;
     1983    }
     1984   
     1985    static bool canBeJumpT4(const uint16_t* instruction, const void* target, bool& mayTriggerErrata)
    19501986    {
    19511987        ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
     
    19682004    }
    19692005
    1970     static void linkLongJump(uint16_t* instruction, void* target)
     2006    static void linkBX(uint16_t* instruction, void* target)
    19712007    {
    19722008        linkJumpAbsolute(instruction, target);
    19732009    }
    19742010   
    1975     static void linkShortJump(uint16_t* instruction, void* target)
     2011    static void linkJumpT4(uint16_t* instruction, void* target)
    19762012    {
    19772013        // FIMXE: this should be up in the MacroAssembler layer. :-(       
     
    19822018        bool scratch;
    19832019        UNUSED_PARAM(scratch);
    1984         ASSERT(canBeShortJump(instruction, target, scratch));
     2020        ASSERT(canBeJumpT4(instruction, target, scratch));
    19852021        // ARM encoding for the top two bits below the sign bit is 'peculiar'.
    19862022        if (relative >= 0)
     
    19932029    }
    19942030
     2031    static void linkJumpT2(uint16_t* instruction, void* target)
     2032    {
     2033        // FIMXE: this should be up in the MacroAssembler layer. :-(       
     2034        ASSERT(!(reinterpret_cast<intptr_t>(instruction) & 1));
     2035        ASSERT(!(reinterpret_cast<intptr_t>(target) & 1));
     2036        ASSERT(canBeJumpT2(instruction, target));
     2037       
     2038        intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
     2039        // It does not appear to be documented in the ARM ARM (big surprise), but
     2040        // for OP_B_T2 the branch displacement encoded in the instruction is 2
     2041        // less than the actual displacement.
     2042        relative -= 2;
     2043       
     2044        // All branch offsets should be an even distance.
     2045        ASSERT(!(relative & 1));
     2046        instruction[-1] = OP_B_T2 | ((relative & 0xffe) >> 1);
     2047    }
     2048   
    19952049    static void linkJumpAbsolute(uint16_t* instruction, void* target)
    19962050    {
     
    20042058        intptr_t relative = reinterpret_cast<intptr_t>(target) - (reinterpret_cast<intptr_t>(instruction));
    20052059        bool scratch;
    2006         if (canBeShortJump(instruction, target, scratch)) {
     2060        if (canBeJumpT4(instruction, target, scratch)) {
    20072061            // ARM encoding for the top two bits below the sign bit is 'peculiar'.
    20082062            if (relative >= 0)
Note: See TracChangeset for help on using the changeset viewer.