Changeset 58317 in webkit


Ignore:
Timestamp:
Apr 27, 2010 11:17:35 AM (14 years ago)
Author:
oliver@apple.com
Message:

2010-04-26 Oliver Hunt <oliver@apple.com>

Reviewed by Maciej Stachowiak.

Add specialized thunks for a char code related string functions
https://bugs.webkit.org/show_bug.cgi?id=38177

This is a simple extension to my prior patch. Basically hoist the
existing character loading logic from the charCodeAt thunk and into
a helper function, then add a helper to load strings from the small
string cache. This allows trivial implementations of fromCharCode
and charAt.

  • create_hash_table:
  • jit/SpecializedThunkJIT.h: (JSC::SpecializedThunkJIT::returnJSCell): (JSC::SpecializedThunkJIT::tagReturnAsJSCell):
  • jit/ThunkGenerators.cpp: (JSC::stringCharLoad): (JSC::charToString): (JSC::charCodeAtThunkGenerator): (JSC::charAtThunkGenerator): (JSC::fromCharCodeThunkGenerator):
  • jit/ThunkGenerators.h:
  • runtime/SmallStrings.h: (JSC::SmallStrings::singleCharacterStrings):
  • runtime/StringConstructor.cpp: (JSC::StringConstructor::StringConstructor):
Location:
trunk/JavaScriptCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r58309 r58317  
     12010-04-26  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Maciej Stachowiak.
     4
     5        Add specialized thunks for a char code related string functions
     6        https://bugs.webkit.org/show_bug.cgi?id=38177
     7
     8        This is a simple extension to my prior patch.  Basically hoist the
     9        existing character loading logic from the charCodeAt thunk and into
     10        a helper function, then add a helper to load strings from the small
     11        string cache.  This allows trivial implementations of fromCharCode
     12        and charAt.
     13
     14        * create_hash_table:
     15        * jit/SpecializedThunkJIT.h:
     16        (JSC::SpecializedThunkJIT::returnJSCell):
     17        (JSC::SpecializedThunkJIT::tagReturnAsJSCell):
     18        * jit/ThunkGenerators.cpp:
     19        (JSC::stringCharLoad):
     20        (JSC::charToString):
     21        (JSC::charCodeAtThunkGenerator):
     22        (JSC::charAtThunkGenerator):
     23        (JSC::fromCharCodeThunkGenerator):
     24        * jit/ThunkGenerators.h:
     25        * runtime/SmallStrings.h:
     26        (JSC::SmallStrings::singleCharacterStrings):
     27        * runtime/StringConstructor.cpp:
     28        (JSC::StringConstructor::StringConstructor):
     29
    1302010-04-27  Thomas Zander <t.zander@nokia.com>
    231
  • trunk/JavaScriptCore/create_hash_table

    r58286 r58317  
    276276            $thunkGenerator = "charCodeAtThunkGenerator";
    277277        }
     278        if ($key eq "charAt") {
     279            $thunkGenerator = "charAtThunkGenerator";
     280        }
    278281        print "   { \"$key\", $attrs[$i], (intptr_t)" . $castStr . "($firstValue), (intptr_t)$secondValue THUNK_GENERATOR($thunkGenerator) },\n";
    279282        $i++;
  • trunk/JavaScriptCore/jit/SpecializedThunkJIT.h

    r58287 r58317  
    7979            ret();
    8080        }
     81
     82        void returnJSCell(RegisterID src)
     83        {
     84            if (src != regT0)
     85                move(src, regT0);
     86            tagReturnAsJSCell();
     87            loadPtr(Address(callFrameRegister, RegisterFile::CallerFrame * (int)sizeof(Register)), callFrameRegister);
     88            ret();
     89        }
    8190       
    8291        PassRefPtr<NativeExecutable> finalize()
     
    107116        }
    108117       
     118        void tagReturnAsJSCell()
     119        {
     120#if USE(JSVALUE32_64)
     121            move(Imm32(JSValue::CellTag), regT1);
     122#endif
     123        }
     124       
    109125        int m_expectedArgCount;
    110126        JSGlobalData* m_globalData;
  • trunk/JavaScriptCore/jit/ThunkGenerators.cpp

    r58286 r58317  
    3838    static unsigned jsStringValueOffset() { return OBJECT_OFFSETOF(JSString, m_value); }
    3939};
    40    
    41 PassRefPtr<NativeExecutable> charCodeAtThunkGenerator(JSGlobalData* globalData, ExecutablePool* pool)
     40
     41static void stringCharLoad(SpecializedThunkJIT& jit)
    4242{
    43     SpecializedThunkJIT jit(1, globalData, pool);
    44    
    4543    // load string
    4644    jit.loadJSStringArgument(SpecializedThunkJIT::ThisArgument, SpecializedThunkJIT::regT0);
     
    5149    jit.loadPtr(MacroAssembler::Address(SpecializedThunkJIT::regT0, ThunkHelpers::jsStringValueOffset()), SpecializedThunkJIT::regT0);
    5250    jit.loadPtr(MacroAssembler::Address(SpecializedThunkJIT::regT0, ThunkHelpers::stringImplDataOffset()), SpecializedThunkJIT::regT0);
    53    
     51
    5452    // load index
    5553    jit.loadInt32Argument(0, SpecializedThunkJIT::regT1); // regT1 contains the index
    56    
     54
    5755    // Do an unsigned compare to simultaneously filter negative indices as well as indices that are too large
    5856    jit.appendFailure(jit.branch32(MacroAssembler::AboveOrEqual, SpecializedThunkJIT::regT1, SpecializedThunkJIT::regT2));
    59    
     57
    6058    // Load the character
    6159    jit.load16(MacroAssembler::BaseIndex(SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1, MacroAssembler::TimesTwo, 0), SpecializedThunkJIT::regT0);
     60}
     61
     62static void charToString(SpecializedThunkJIT& jit, JSGlobalData* globalData, MacroAssembler::RegisterID src, MacroAssembler::RegisterID dst, MacroAssembler::RegisterID scratch)
     63{
     64    jit.appendFailure(jit.branch32(MacroAssembler::AboveOrEqual, src, MacroAssembler::Imm32(0x100)));
     65    jit.move(MacroAssembler::ImmPtr(globalData->smallStrings.singleCharacterStrings()), scratch);
     66    jit.loadPtr(MacroAssembler::BaseIndex(scratch, src, MacroAssembler::ScalePtr, 0), dst);
     67    jit.appendFailure(jit.branchTestPtr(MacroAssembler::Zero, dst));
     68}
     69
     70PassRefPtr<NativeExecutable> charCodeAtThunkGenerator(JSGlobalData* globalData, ExecutablePool* pool)
     71{
     72    SpecializedThunkJIT jit(1, globalData, pool);
     73    stringCharLoad(jit);
    6274    jit.returnInt32(SpecializedThunkJIT::regT0);
     75    return jit.finalize();
     76}
     77
     78PassRefPtr<NativeExecutable> charAtThunkGenerator(JSGlobalData* globalData, ExecutablePool* pool)
     79{
     80    SpecializedThunkJIT jit(1, globalData, pool);
     81    stringCharLoad(jit);
     82    charToString(jit, globalData, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
     83    jit.returnJSCell(SpecializedThunkJIT::regT0);
     84    return jit.finalize();
     85}
     86
     87PassRefPtr<NativeExecutable> fromCharCodeThunkGenerator(JSGlobalData* globalData, ExecutablePool* pool)
     88{
     89    SpecializedThunkJIT jit(1, globalData, pool);
     90    // load char code
     91    jit.loadInt32Argument(0, SpecializedThunkJIT::regT0);
     92    charToString(jit, globalData, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT0, SpecializedThunkJIT::regT1);
     93    jit.returnJSCell(SpecializedThunkJIT::regT0);
    6394    return jit.finalize();
    6495}
  • trunk/JavaScriptCore/jit/ThunkGenerators.h

    r58286 r58317  
    3737    typedef PassRefPtr<NativeExecutable> (*ThunkGenerator)(JSGlobalData*, ExecutablePool*);
    3838    PassRefPtr<NativeExecutable> charCodeAtThunkGenerator(JSGlobalData*, ExecutablePool*);
     39    PassRefPtr<NativeExecutable> charAtThunkGenerator(JSGlobalData*, ExecutablePool*);
     40    PassRefPtr<NativeExecutable> fromCharCodeThunkGenerator(JSGlobalData*, ExecutablePool*);
    3941}
    4042#endif
  • trunk/JavaScriptCore/runtime/SmallStrings.h

    r54574 r58317  
    6161
    6262        unsigned count() const;
    63 
     63#if ENABLE(JIT)
     64        JSString** singleCharacterStrings() { return m_singleCharacterStrings; }
     65#endif
    6466    private:
    6567        void createEmptyString(JSGlobalData*);
  • trunk/JavaScriptCore/runtime/StringConstructor.cpp

    r53320 r58317  
    5555
    5656    // ECMA 15.5.3.2 fromCharCode()
     57#if ENABLE(JIT)
     58    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().fromCharCode, exec->globalData().getThunk(fromCharCodeThunkGenerator), stringFromCharCode), DontEnum);
     59#else
    5760    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().fromCharCode, stringFromCharCode), DontEnum);
    58 
     61#endif
    5962    // no. of arguments for constructor
    6063    putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), ReadOnly | DontEnum | DontDelete);
Note: See TracChangeset for help on using the changeset viewer.