Ignore:
Timestamp:
Mar 5, 2018, 10:31:40 AM (7 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Use WTF::ArithmeticOperations for CLoop overflow operations
https://bugs.webkit.org/show_bug.cgi?id=183324

Reviewed by JF Bastien.

We have WTF::ArithmeticOperations which has operations with overflow checking.
This is suitable for CLoop's overflow checking operations. This patch emits
WTF::ArithmeticOperations for CLoop's overflow checking operations. And it is
lowered to optimized code using CPU's overflow flag.

  • offlineasm/cloop.rb:
File:
1 edited

Legend:

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

    r228402 r229287  
    481481end
    482482
    483 def cloopAddOverflowTest(operands, type)
     483def cloopEmitOpAndBranchIfOverflow(operands, operator, type)
    484484    case type
    485485    when :int32
    486486        tempType = "int32_t"
    487         signBit = "SIGN_BIT32"
    488487    else
    489488        raise "Unimplemented type"
    490489    end
    491490
    492     $asm.putc "    #{tempType} a = #{operands[0].clValue(type)};"
    493     $asm.putc "    #{tempType} b = #{operands[1].clValue(type)};"
    494     $asm.putc "    // sign(b) sign(a) | Overflows if:"
    495     $asm.putc "    // 0       0       | sign(b+a) = 1 (pos + pos != neg)"
    496     $asm.putc "    // 0       1       | never"
    497     $asm.putc "    // 1       0       | never"
    498     $asm.putc "    // 1       1       | sign(b+a) = 0 (neg + neg != pos)"
    499     "((#{signBit}(b) == #{signBit}(a)) && (#{signBit}(b+a) != #{signBit}(a)))"
    500 end
    501 
    502 def cloopSubOverflowTest(operands, type)
    503     case type
    504     when :int32
    505         tempType = "int32_t"
    506         signBit = "SIGN_BIT32"
    507     else
    508         raise "Unimplemented type"
    509     end
    510 
    511     $asm.putc "    #{tempType} a = #{operands[0].clValue(type)};"
    512     $asm.putc "    #{tempType} b = #{operands[1].clValue(type)};"
    513     $asm.putc "    // sign(b) sign(a) | Overflows if:"
    514     $asm.putc "    // 0       0       | never"
    515     $asm.putc "    // 0       1       | sign(b-a) = 1 (pos - neg != pos)"
    516     $asm.putc "    // 1       0       | sign(b-a) = 0 (neg - pos != pos)"
    517     $asm.putc "    // 1       1       | never"
    518     "((#{signBit}(b) != #{signBit}(a)) && (#{signBit}(b-a) == #{signBit}(a)))"
    519 end
    520 
    521 def cloopMulOverflowTest(operands, type)
    522     case type
    523     when :int32
    524         tempType = "uint32_t"
    525     else
    526         raise "Unimplemented type"
    527     end
    528     $asm.putc "    #{tempType} a = #{operands[0].clValue(type)};"
    529     $asm.putc "    #{tempType} b = #{operands[1].clValue(type)};"
    530     "((b | a) >> 15)"
    531 end
    532 
    533 def cloopEmitOpAndBranchIfOverflow(operands, operator, type)
    534491    $asm.putc "{"
    535492
    536493    # Emit the overflow test based on the operands and the type:
    537494    case operator
    538     when "+"; overflowTest = cloopAddOverflowTest(operands, type)
    539     when "-"; overflowTest = cloopSubOverflowTest(operands, type)
    540     when "*"; overflowTest = cloopMulOverflowTest(operands, type)
     495    when "+"; operation = "add"
     496    when "-"; operation = "sub"
     497    when "*"; operation = "multiply"
    541498    else
    542499        raise "Unimplemented opeartor"
    543500    end
    544501
    545     $asm.putc "    bool didOverflow = #{overflowTest};"
    546     $asm.putc "    #{operands[1].clValue(type)} = #{operands[1].clValue(type)} #{operator} #{operands[0].clValue(type)};"
    547     $asm.putc "    if (didOverflow)"
     502    $asm.putc "    if (!WTF::ArithmeticOperations<#{tempType}, #{tempType}, #{tempType}>::#{operation}(#{operands[1].clValue(type)}, #{operands[0].clValue(type)}, #{operands[1].clValue(type)}))"
    548503    $asm.putc "        goto #{operands[2].cLabel};"
    549504    $asm.putc "}"
Note: See TracChangeset for help on using the changeset viewer.