Ignore:
Timestamp:
May 24, 2013, 9:46:10 AM (12 years ago)
Author:
[email protected]
Message:

[sh4] Optimize LLINT generated code and fix few bugs in baseline JIT.
https://bugs.webkit.org/show_bug.cgi?id=116716

Patch by Julien Brianceau <[email protected]> on 2013-05-24
Reviewed by Geoffrey Garen.

  • assembler/MacroAssemblerSH4.h:

(JSC::MacroAssemblerSH4::mul32): Cosmetic changes.
(JSC::MacroAssemblerSH4::convertInt32ToDouble): Absolute address was not dereferenced.
(JSC::MacroAssemblerSH4::branch32): Absolute address was not dereferenced.
(JSC::MacroAssemblerSH4::revertJumpReplacementToBranchPtrWithPatch): Use all 32 bits of pointer for revertJump call.

  • assembler/SH4Assembler.h:

(JSC::SH4Assembler::revertJump): Use changePCrelativeAddress to patch the whole pointer.
(JSC::SH4Assembler::linkJump): Cosmetic change.

  • offlineasm/sh4.rb: Optimize LLINT generated code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/offlineasm/sh4.rb

    r149403 r150644  
    319319        if node.is_a? Instruction
    320320            case node.opcode
    321             when "bdnequn", "bdgtequn", "bdltun", "bdltequn", "bdgtun"
    322                 # Handle floating point unordered opcodes.
     321            when "bdltun", "bdgtun"
     322                # Handle specific floating point unordered opcodes.
    323323                tmp1 = Tmp.new(codeOrigin, :gpr)
    324324                tmp2 = Tmp.new(codeOrigin, :gpr)
     
    326326                newList << Instruction.new(codeOrigin, "bdnan", [node.operands[1], node.operands[2], tmp1, tmp2])
    327327                newList << Instruction.new(codeOrigin, node.opcode[0..-3], node.operands)
     328            when "bdnequn", "bdgtequn", "bdltequn"
     329                newList << Instruction.new(codeOrigin, node.opcode[0..-3], node.operands)
     330            when "bdneq", "bdgteq", "bdlteq"
     331                # Handle specific floating point ordered opcodes.
     332                tmp1 = Tmp.new(codeOrigin, :gpr)
     333                tmp2 = Tmp.new(codeOrigin, :gpr)
     334                outlabel = LocalLabel.unique("out_#{node.opcode}")
     335                outref = LocalLabelReference.new(codeOrigin, outlabel)
     336                newList << Instruction.new(codeOrigin, "bdnan", [node.operands[0], outref, tmp1, tmp2])
     337                newList << Instruction.new(codeOrigin, "bdnan", [node.operands[1], outref, tmp1, tmp2])
     338                newList << Instruction.new(codeOrigin, node.opcode, node.operands)
     339                newList << outlabel
    328340            else
    329341                newList << node
     
    430442end
    431443
    432 def emitSH4LoadConstant(constant, operand)
    433     if constant == 0x40000000
     444def emitSH4Load32(constant, dest)
     445    outlabel = LocalLabel.unique("load32out")
     446    constlabel = LocalLabel.unique("load32const")
     447    $asm.puts "mov.l #{LocalLabelReference.new(codeOrigin, constlabel).asmLabel}, #{dest.sh4Operand}"
     448    $asm.puts "bra #{LocalLabelReference.new(codeOrigin, outlabel).asmLabel}"
     449    $asm.puts "nop"
     450    $asm.puts ".balign 4"
     451    constlabel.lower("SH4")
     452    $asm.puts ".long #{constant}"
     453    outlabel.lower("SH4")
     454end
     455
     456def emitSH4Load32AndJump(constant, scratch)
     457    constlabel = LocalLabel.unique("load32const")
     458    $asm.puts "mov.l #{LocalLabelReference.new(codeOrigin, constlabel).asmLabel}, #{scratch.sh4Operand}"
     459    $asm.puts "jmp @#{scratch.sh4Operand}"
     460    $asm.puts "nop"
     461    $asm.puts ".balign 4"
     462    constlabel.lower("SH4")
     463    $asm.puts ".long #{constant}"
     464end
     465
     466def emitSH4LoadImm(operands)
     467    if operands[0].value == 0x40000000
    434468        # FirstConstantRegisterIndex const is often used (0x40000000).
    435469        # It's more efficient to "build" the value with 3 opcodes without branch.
    436         $asm.puts "mov #64, #{operand.sh4Operand}"
    437         $asm.puts "shll16 #{operand.sh4Operand}"
    438         $asm.puts "shll8 #{operand.sh4Operand}"
    439     else
     470        $asm.puts "mov #64, #{operands[1].sh4Operand}"
     471        $asm.puts "shll16 #{operands[1].sh4Operand}"
     472        $asm.puts "shll8 #{operands[1].sh4Operand}"
     473    elsif (-128..127).include? operands[0].value
     474        $asm.puts "mov #{sh4Operands(operands)}"
     475    elsif (-32768..32767).include? operands[0].value
    440476        constlabel = LocalLabel.unique("loadconstant")
    441         $asm.puts ".balign 4"
    442         $asm.puts "mov.l @(8, PC), #{operand.sh4Operand}"
     477        $asm.puts "mov.w @(6, PC), #{operands[1].sh4Operand}"
    443478        $asm.puts "bra #{LocalLabelReference.new(codeOrigin, constlabel).asmLabel}"
    444479        $asm.puts "nop"
    445         $asm.puts "nop"
    446         $asm.puts ".long #{constant}"
     480        $asm.puts ".word #{operands[0].value}"
    447481        constlabel.lower("SH4")
     482    else
     483        emitSH4Load32(operands[0].value, operands[1])
    448484    end
    449485end
     
    481517        $asm.puts "nop"
    482518    else
    483         $asm.puts ".balign 4"
    484         $asm.puts "mov.l @(8, PC), #{SH4_TMP_GPRS[0].sh4Operand}"
    485         $asm.puts "jmp @#{SH4_TMP_GPRS[0].sh4Operand}"
    486         $asm.puts "nop"
    487         $asm.puts "nop"
    488         $asm.puts ".long #{label.asmLabel}"
     519        emitSH4Load32AndJump(label.asmLabel, SH4_TMP_GPRS[0])
    489520    end
    490521    outlabel.lower("SH4")
     
    520551    scrint = operands[3]
    521552
     553    notNaNlabel = LocalLabel.unique("notnan")
     554    notNaNref = LocalLabelReference.new(codeOrigin, notNaNlabel)
     555    constlabel1 = LocalLabel.unique("notnanConst1")
     556    constlabel2 = LocalLabel.unique("notnanConst2")
     557
    522558    # If we don't have "E = Emax + 1", it's not a NaN.
    523     notNaNlabel = LocalLabel.unique("notnan")
    524559    $asm.puts "fcnvds #{dblop.sh4Operand}, fpul"
    525560    $asm.puts "sts fpul, #{scrint.sh4Operand}"
    526     emitSH4LoadConstant(0x7f800000, scrmask)
     561    $asm.puts "mov.l #{LocalLabelReference.new(codeOrigin, constlabel1).asmLabel}, #{scrmask.sh4Operand}"
    527562    $asm.puts "and #{sh4Operands([scrmask, scrint])}"
    528563    $asm.puts "cmp/eq #{sh4Operands([scrmask, scrint])}"
    529     $asm.puts "bf #{LocalLabelReference.new(codeOrigin, notNaNlabel).asmLabel}"
     564    $asm.puts "bf #{notNaNref.asmLabel}"
    530565
    531566    # If we have "E = Emax + 1" and "f != 0", then it's a NaN.
    532567    $asm.puts "sts fpul, #{scrint.sh4Operand}"
    533     emitSH4LoadConstant(0x003fffff, scrmask)
     568    $asm.puts "mov.l #{LocalLabelReference.new(codeOrigin, constlabel2).asmLabel}, #{scrmask.sh4Operand}"
    534569    $asm.puts "tst #{sh4Operands([scrmask, scrint])}"
    535     $asm.puts "bf #{labelop.asmLabel}"
     570    $asm.puts "bt #{notNaNref.asmLabel}"
     571    $asm.puts "bra #{labelop.asmLabel}"
     572    $asm.puts "nop"
     573
     574    $asm.puts ".balign 4"
     575    constlabel1.lower("SH4")
     576    $asm.puts ".long 0x7f800000"
     577    constlabel2.lower("SH4")
     578    $asm.puts ".long 0x003fffff"
    536579
    537580    notNaNlabel.lower("SH4")
     
    540583def emitSH4DoubleCondBranch(cmpOpcode, neg, operands)
    541584    if cmpOpcode == "lt"
    542         if !neg
    543             outlabel = LocalLabel.unique("dcbout")
    544             $asm.puts "fcmp/gt #{sh4Operands([operands[1], operands[0]])}"
    545             $asm.puts "bt #{LocalLabelReference.new(codeOrigin, outlabel).asmLabel}"
    546             $asm.puts "fcmp/eq #{sh4Operands([operands[1], operands[0]])}"
    547             $asm.puts "bf #{operands[2].asmLabel}"
    548             outlabel.lower("SH4")
    549         else
    550             $asm.puts "fcmp/gt #{sh4Operands([operands[1], operands[0]])}"
    551             $asm.puts "bt #{operands[2].asmLabel}"
    552             $asm.puts "fcmp/eq #{sh4Operands([operands[1], operands[0]])}"
    553             $asm.puts "bt #{operands[2].asmLabel}"
    554         end
     585        $asm.puts "fcmp/gt #{sh4Operands([operands[0], operands[1]])}"
    555586    else
    556587        $asm.puts "fcmp/#{cmpOpcode} #{sh4Operands([operands[1], operands[0]])}"
    557         emitSH4BranchIfT(operands[2], neg)
    558     end
     588    end
     589    emitSH4BranchIfT(operands[2], neg)
    559590end
    560591
     
    729760            end
    730761        when "jmpf"
    731             $asm.puts ".balign 4"
    732             $asm.puts "mov.l @(8, PC), #{operands[0].sh4Operand}"
    733             $asm.puts "jmp @#{operands[0].sh4Operand}"
    734             $asm.puts "nop"
    735             $asm.puts "nop"
    736             $asm.puts ".long #{operands[1].asmLabel}"
     762            emitSH4Load32AndJump(operands[1].asmLabel, operands[0])
    737763        when "ret"
    738764            $asm.puts "rts"
     
    747773            $asm.puts "mov.l #{sh4Operands(operands)}"
    748774        when "move"
    749             if operands[0].is_a? Immediate and (operands[0].value < -128 or operands[0].value > 127)
    750                 emitSH4LoadConstant(operands[0].value, operands[1])
    751             elsif operands[0].is_a? LabelReference
    752                 emitSH4LoadConstant(operands[0].asmLabel, operands[1])
     775            if operands[0].is_a? LabelReference
     776                emitSH4Load32(operands[0].asmLabel, operands[1])
     777            elsif operands[0].is_a? Immediate
     778                emitSH4LoadImm(operands)
    753779            else
    754780                $asm.puts "mov #{sh4Operands(operands)}"
Note: See TracChangeset for help on using the changeset viewer.