Changeset 191983 in webkit


Ignore:
Timestamp:
Nov 3, 2015 3:24:50 PM (8 years ago)
Author:
benjamin@webkit.org
Message:

[JSC] Add Air lowering for BitOr and impove BitAnd
https://bugs.webkit.org/show_bug.cgi?id=150827

Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-11-03
Reviewed by Filip Pizlo.

In this patch:
-B3 to Air lowering for BirOr.
-Codegen for BitOr.
-Strength reduction for BitOr and BitAnd.
-Tests for BitAnd and BitOr.
-Bug fix: Move64 with a negative value was destroying the top bits.

  • b3/B3Const32Value.cpp:

(JSC::B3::Const32Value::bitAndConstant):
(JSC::B3::Const32Value::bitOrConstant):

  • b3/B3Const32Value.h:
  • b3/B3Const64Value.cpp:

(JSC::B3::Const64Value::bitAndConstant):
(JSC::B3::Const64Value::bitOrConstant):

  • b3/B3Const64Value.h:
  • b3/B3LowerToAir.cpp:

(JSC::B3::Air::LowerToAir::immForMove):
(JSC::B3::Air::LowerToAir::immOrTmpForMove):
(JSC::B3::Air::LowerToAir::tryOr):
(JSC::B3::Air::LowerToAir::tryConst64):
(JSC::B3::Air::LowerToAir::tryUpsilon):
(JSC::B3::Air::LowerToAir::tryIdentity):
(JSC::B3::Air::LowerToAir::tryReturn):
(JSC::B3::Air::LowerToAir::immOrTmp): Deleted.

  • b3/B3LoweringMatcher.patterns:
  • b3/B3ReduceStrength.cpp:
  • b3/B3Value.cpp:

(JSC::B3::Value::bitAndConstant):
(JSC::B3::Value::bitOrConstant):

  • b3/B3Value.h:
  • b3/air/AirOpcode.opcodes:
  • b3/testb3.cpp:

(JSC::B3::testReturnConst64):
(JSC::B3::testBitAndArgs):
(JSC::B3::testBitAndSameArg):
(JSC::B3::testBitAndImms):
(JSC::B3::testBitAndArgImm):
(JSC::B3::testBitAndImmArg):
(JSC::B3::testBitAndBitAndArgImmImm):
(JSC::B3::testBitAndImmBitAndArgImm):
(JSC::B3::testBitAndArgs32):
(JSC::B3::testBitAndSameArg32):
(JSC::B3::testBitAndImms32):
(JSC::B3::testBitAndArgImm32):
(JSC::B3::testBitAndImmArg32):
(JSC::B3::testBitAndBitAndArgImmImm32):
(JSC::B3::testBitAndImmBitAndArgImm32):
(JSC::B3::testBitOrArgs):
(JSC::B3::testBitOrSameArg):
(JSC::B3::testBitOrImms):
(JSC::B3::testBitOrArgImm):
(JSC::B3::testBitOrImmArg):
(JSC::B3::testBitOrBitOrArgImmImm):
(JSC::B3::testBitOrImmBitOrArgImm):
(JSC::B3::testBitOrArgs32):
(JSC::B3::testBitOrSameArg32):
(JSC::B3::testBitOrImms32):
(JSC::B3::testBitOrArgImm32):
(JSC::B3::testBitOrImmArg32):
(JSC::B3::testBitOrBitOrArgImmImm32):
(JSC::B3::testBitOrImmBitOrArgImm32):
(JSC::B3::run):

Location:
trunk/Source/JavaScriptCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r191982 r191983  
     12015-11-03  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [JSC] Add Air lowering for BitOr and impove BitAnd
     4        https://bugs.webkit.org/show_bug.cgi?id=150827
     5
     6        Reviewed by Filip Pizlo.
     7
     8        In this patch:
     9        -B3 to Air lowering for BirOr.
     10        -Codegen for BitOr.
     11        -Strength reduction for BitOr and BitAnd.
     12        -Tests for BitAnd and BitOr.
     13        -Bug fix: Move64 with a negative value was destroying the top bits.
     14
     15        * b3/B3Const32Value.cpp:
     16        (JSC::B3::Const32Value::bitAndConstant):
     17        (JSC::B3::Const32Value::bitOrConstant):
     18        * b3/B3Const32Value.h:
     19        * b3/B3Const64Value.cpp:
     20        (JSC::B3::Const64Value::bitAndConstant):
     21        (JSC::B3::Const64Value::bitOrConstant):
     22        * b3/B3Const64Value.h:
     23        * b3/B3LowerToAir.cpp:
     24        (JSC::B3::Air::LowerToAir::immForMove):
     25        (JSC::B3::Air::LowerToAir::immOrTmpForMove):
     26        (JSC::B3::Air::LowerToAir::tryOr):
     27        (JSC::B3::Air::LowerToAir::tryConst64):
     28        (JSC::B3::Air::LowerToAir::tryUpsilon):
     29        (JSC::B3::Air::LowerToAir::tryIdentity):
     30        (JSC::B3::Air::LowerToAir::tryReturn):
     31        (JSC::B3::Air::LowerToAir::immOrTmp): Deleted.
     32        * b3/B3LoweringMatcher.patterns:
     33        * b3/B3ReduceStrength.cpp:
     34        * b3/B3Value.cpp:
     35        (JSC::B3::Value::bitAndConstant):
     36        (JSC::B3::Value::bitOrConstant):
     37        * b3/B3Value.h:
     38        * b3/air/AirOpcode.opcodes:
     39        * b3/testb3.cpp:
     40        (JSC::B3::testReturnConst64):
     41        (JSC::B3::testBitAndArgs):
     42        (JSC::B3::testBitAndSameArg):
     43        (JSC::B3::testBitAndImms):
     44        (JSC::B3::testBitAndArgImm):
     45        (JSC::B3::testBitAndImmArg):
     46        (JSC::B3::testBitAndBitAndArgImmImm):
     47        (JSC::B3::testBitAndImmBitAndArgImm):
     48        (JSC::B3::testBitAndArgs32):
     49        (JSC::B3::testBitAndSameArg32):
     50        (JSC::B3::testBitAndImms32):
     51        (JSC::B3::testBitAndArgImm32):
     52        (JSC::B3::testBitAndImmArg32):
     53        (JSC::B3::testBitAndBitAndArgImmImm32):
     54        (JSC::B3::testBitAndImmBitAndArgImm32):
     55        (JSC::B3::testBitOrArgs):
     56        (JSC::B3::testBitOrSameArg):
     57        (JSC::B3::testBitOrImms):
     58        (JSC::B3::testBitOrArgImm):
     59        (JSC::B3::testBitOrImmArg):
     60        (JSC::B3::testBitOrBitOrArgImmImm):
     61        (JSC::B3::testBitOrImmBitOrArgImm):
     62        (JSC::B3::testBitOrArgs32):
     63        (JSC::B3::testBitOrSameArg32):
     64        (JSC::B3::testBitOrImms32):
     65        (JSC::B3::testBitOrArgImm32):
     66        (JSC::B3::testBitOrImmArg32):
     67        (JSC::B3::testBitOrBitOrArgImmImm32):
     68        (JSC::B3::testBitOrImmBitOrArgImm32):
     69        (JSC::B3::run):
     70
    1712015-11-03  Saam barati  <sbarati@apple.com>
    272
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h

    r191700 r191983  
    10511051        if (reg1 != reg2)
    10521052            m_assembler.xchgq_rr(reg1, reg2);
     1053    }
     1054
     1055    void signExtend32ToPtr(TrustedImm32 imm, RegisterID dest)
     1056    {
     1057        m_assembler.mov_i32r(imm.m_value, dest);
    10531058    }
    10541059
  • trunk/Source/JavaScriptCore/assembler/X86Assembler.h

    r191865 r191983  
    14931493        m_formatter.immediate64(imm);
    14941494    }
     1495
     1496    void mov_i32r(int32_t imm, RegisterID dst)
     1497    {
     1498        m_formatter.oneByteOp64(OP_GROUP11_EvIz, GROUP11_MOV, dst);
     1499        m_formatter.immediate32(imm);
     1500    }
    14951501   
    14961502    void movsxd_rr(RegisterID src, RegisterID dst)
  • trunk/Source/JavaScriptCore/b3/B3Const32Value.cpp

    r191816 r191983  
    6262}
    6363
     64Value* Const32Value::bitAndConstant(Procedure& proc, Value* other) const
     65{
     66    if (!other->hasInt32())
     67        return nullptr;
     68    return proc.add<Const32Value>(origin(), m_value & other->asInt32());
     69}
     70
     71Value* Const32Value::bitOrConstant(Procedure& proc, Value* other) const
     72{
     73    if (!other->hasInt32())
     74        return nullptr;
     75    return proc.add<Const32Value>(origin(), m_value | other->asInt32());
     76}
     77
    6478Value* Const32Value::equalConstant(Procedure& proc, Value* other) const
    6579{
  • trunk/Source/JavaScriptCore/b3/B3Const32Value.h

    r191816 r191983  
    4545    Value* addConstant(Procedure&, Value* other) const override;
    4646    Value* subConstant(Procedure&, Value* other) const override;
     47    Value* bitAndConstant(Procedure&, Value* other) const override;
     48    Value* bitOrConstant(Procedure&, Value* other) const override;
    4749    Value* equalConstant(Procedure&, Value* other) const override;
    4850    Value* notEqualConstant(Procedure&, Value* other) const override;
  • trunk/Source/JavaScriptCore/b3/B3Const64Value.cpp

    r191816 r191983  
    6262}
    6363
     64Value* Const64Value::bitAndConstant(Procedure& proc, Value* other) const
     65{
     66    if (!other->hasInt64())
     67        return nullptr;
     68    return proc.add<Const64Value>(origin(), m_value & other->asInt64());
     69}
     70
     71Value* Const64Value::bitOrConstant(Procedure& proc, Value* other) const
     72{
     73    if (!other->hasInt64())
     74        return nullptr;
     75    return proc.add<Const64Value>(origin(), m_value | other->asInt64());
     76}
     77
    6478Value* Const64Value::equalConstant(Procedure& proc, Value* other) const
    6579{
  • trunk/Source/JavaScriptCore/b3/B3Const64Value.h

    r191816 r191983  
    4545    Value* addConstant(Procedure&, Value* other) const override;
    4646    Value* subConstant(Procedure&, Value* other) const override;
     47    Value* bitAndConstant(Procedure&, Value* other) const override;
     48    Value* bitOrConstant(Procedure&, Value* other) const override;
    4749    Value* equalConstant(Procedure&, Value* other) const override;
    4850    Value* notEqualConstant(Procedure&, Value* other) const override;
  • trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp

    r191977 r191983  
    655655    }
    656656
     657    bool tryOr(Value* left, Value* right)
     658    {
     659        switch (left->type()) {
     660        case Int32:
     661            appendBinOp<Or32, Commutative>(left, right);
     662            return true;
     663        case Int64:
     664            appendBinOp<Or64, Commutative>(left, right);
     665            return true;
     666        default:
     667            // FIXME: Implement more types!
     668            return false;
     669        }
     670    }
     671
    657672    bool tryShl(Value* value, Value* amount)
    658673    {
  • trunk/Source/JavaScriptCore/b3/B3LoweringMatcher.patterns

    r191977 r191983  
    3434Sub = Sub(left, right)
    3535And = BitAnd(left, right)
     36Or = BitOr(left, right)
    3637
    3738Shl = Shl(value, amount)
  • trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp

    r191865 r191983  
    138138            break;
    139139
     140        case BitAnd:
     141            handleCommutativity();
     142
     143            // Turn this: BitAnd(constant1, constant2)
     144            // Into this: constant1 & constant2
     145            if (Value* constantBitAnd = m_value->child(0)->bitAndConstant(m_proc, m_value->child(1))) {
     146                replaceWithNewValue(constantBitAnd);
     147                break;
     148            }
     149
     150            // Turn this: BitAnd(BitAnd(value, constant1), constant2)
     151            // Into this: BitAnd(value, constant1 & constant2).
     152            if (m_value->child(0)->opcode() == BitAnd) {
     153                Value* newConstant = m_value->child(1)->bitAndConstant(m_proc, m_value->child(0)->child(1));
     154                if (newConstant) {
     155                    m_insertionSet.insertValue(m_index, newConstant);
     156                    m_value->child(0) = m_value->child(0)->child(0);
     157                    m_value->child(1) = newConstant;
     158                    m_changed = true;
     159                }
     160            }
     161
     162            // Turn this: BitAnd(valueX, valueX)
     163            // Into this: valueX.
     164            if (m_value->child(0) == m_value->child(1)) {
     165                m_value->replaceWithIdentity(m_value->child(0));
     166                m_changed = true;
     167                break;
     168            }
     169
     170            // Turn this: BitAnd(value, zero-constant)
     171            // Into this: zero-constant.
     172            if (m_value->child(1)->isInt(0)) {
     173                m_value->replaceWithIdentity(m_value->child(1));
     174                m_changed = true;
     175                break;
     176            }
     177
     178            // Turn this: BitAnd(value, all-ones)
     179            // Into this: value.
     180            if ((m_value->type() == Int64 && m_value->child(1)->isInt(0xffffffffffffffff))
     181                || (m_value->type() == Int32 && m_value->child(1)->isInt(0xffffffff))) {
     182                m_value->replaceWithIdentity(m_value->child(0));
     183                m_changed = true;
     184                break;
     185            }
     186
     187            break;
     188
     189        case BitOr:
     190            handleCommutativity();
     191
     192            // Turn this: BitOr(constant1, constant2)
     193            // Into this: constant1 | constant2
     194            if (Value* constantBitAnd = m_value->child(0)->bitOrConstant(m_proc, m_value->child(1))) {
     195                replaceWithNewValue(constantBitAnd);
     196                break;
     197            }
     198
     199            // Turn this: BitAnd(BitAnd(value, constant1), constant2)
     200            // Into this: BitAnd(value, constant1 & constant2).
     201            if (m_value->child(0)->opcode() == BitOr) {
     202                Value* newConstant = m_value->child(1)->bitOrConstant(m_proc, m_value->child(0)->child(1));
     203                if (newConstant) {
     204                    m_insertionSet.insertValue(m_index, newConstant);
     205                    m_value->child(0) = m_value->child(0)->child(0);
     206                    m_value->child(1) = newConstant;
     207                    m_changed = true;
     208                }
     209            }
     210
     211            // Turn this: BitOr(valueX, valueX)
     212            // Into this: valueX.
     213            if (m_value->child(0) == m_value->child(1)) {
     214                m_value->replaceWithIdentity(m_value->child(0));
     215                m_changed = true;
     216                break;
     217            }
     218
     219            // Turn this: BitOr(value, zero-constant)
     220            // Into this: value.
     221            if (m_value->child(1)->isInt(0)) {
     222                m_value->replaceWithIdentity(m_value->child(0));
     223                m_changed = true;
     224                break;
     225            }
     226
     227            // Turn this: BitOr(value, all-ones)
     228            // Into this: all-ones.
     229            if ((m_value->type() == Int64 && m_value->child(1)->isInt(0xffffffffffffffff))
     230                || (m_value->type() == Int32 && m_value->child(1)->isInt(0xffffffff))) {
     231                m_value->replaceWithIdentity(m_value->child(1));
     232                m_changed = true;
     233                break;
     234            }
     235
     236            break;
     237
    140238        case Load8Z:
    141239        case Load8S:
  • trunk/Source/JavaScriptCore/b3/B3Value.cpp

    r191816 r191983  
    124124
    125125Value* Value::subConstant(Procedure&, Value*) const
     126{
     127    return nullptr;
     128}
     129
     130Value* Value::bitAndConstant(Procedure&, Value*) const
     131{
     132    return nullptr;
     133}
     134
     135Value* Value::bitOrConstant(Procedure&, Value*) const
    126136{
    127137    return nullptr;
  • trunk/Source/JavaScriptCore/b3/B3Value.h

    r191913 r191983  
    113113    virtual Value* addConstant(Procedure&, Value* other) const;
    114114    virtual Value* subConstant(Procedure&, Value* other) const;
     115    virtual Value* bitAndConstant(Procedure&, Value* other) const;
     116    virtual Value* bitOrConstant(Procedure&, Value* other) const;
    115117    virtual Value* equalConstant(Procedure&, Value* other) const;
    116118    virtual Value* notEqualConstant(Procedure&, Value* other) const;
  • trunk/Source/JavaScriptCore/b3/air/AirOpcode.opcodes

    r191865 r191983  
    108108    Imm, Tmp
    109109
     110Or32 U:G, UD:G
     111    Tmp, Tmp
     112    Imm, Tmp
     113    Tmp, Addr
     114    Addr, Tmp
     115    Imm, Addr
     116
     117Or64 U:G, UD:G
     118    Tmp, Tmp
     119    Imm, Tmp
     120
    110121Lshift64 U:G, UD:G
    111122    Tmp*, Tmp
     
    122133Move U:G, D:G
    123134    Tmp, Tmp
    124     Imm, Tmp
     135    Imm, Tmp as signExtend32ToPtr
    125136    Imm64, Tmp
    126137    Addr, Tmp as loadPtr # This means that "Move Addr, Tmp" is code-generated as "load" not "move".
  • trunk/Source/JavaScriptCore/b3/testb3.cpp

    r191913 r191983  
    121121}
    122122
     123void testReturnConst64(int64_t value)
     124{
     125    Procedure proc;
     126    BasicBlock* root = proc.addBlock();
     127    root->appendNew<ControlValue>(
     128        proc, Return, Origin(),
     129        root->appendNew<Const64Value>(proc, Origin(), value));
     130
     131    CHECK(compileAndRun<int64_t>(proc) == value);
     132}
     133
    123134void testAddArgs(int a, int b)
    124135{
     
    271282
    272283    CHECK(compileAndRun<int>(proc, b) == a - b);
     284}
     285
     286void testBitAndArgs(int64_t a, int64_t b)
     287{
     288    Procedure proc;
     289    BasicBlock* root = proc.addBlock();
     290    root->appendNew<ControlValue>(
     291        proc, Return, Origin(),
     292        root->appendNew<Value>(
     293            proc, BitAnd, Origin(),
     294            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     295            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)));
     296
     297    CHECK(compileAndRun<int64_t>(proc, a, b) == (a & b));
     298}
     299
     300void testBitAndSameArg(int64_t a)
     301{
     302    Procedure proc;
     303    BasicBlock* root = proc.addBlock();
     304    Value* argument = root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0);
     305    root->appendNew<ControlValue>(
     306        proc, Return, Origin(),
     307        root->appendNew<Value>(
     308            proc, BitAnd, Origin(),
     309            argument,
     310            argument));
     311
     312    CHECK(compileAndRun<int64_t>(proc, a) == a);
     313}
     314
     315void testBitAndImms(int64_t a, int64_t b)
     316{
     317    Procedure proc;
     318    BasicBlock* root = proc.addBlock();
     319    root->appendNew<ControlValue>(
     320        proc, Return, Origin(),
     321        root->appendNew<Value>(
     322            proc, BitAnd, Origin(),
     323            root->appendNew<Const64Value>(proc, Origin(), a),
     324            root->appendNew<Const64Value>(proc, Origin(), b)));
     325
     326    CHECK(compileAndRun<int64_t>(proc) == (a & b));
     327}
     328
     329void testBitAndArgImm(int64_t a, int64_t b)
     330{
     331    Procedure proc;
     332    BasicBlock* root = proc.addBlock();
     333    root->appendNew<ControlValue>(
     334        proc, Return, Origin(),
     335        root->appendNew<Value>(
     336            proc, BitAnd, Origin(),
     337            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     338            root->appendNew<Const64Value>(proc, Origin(), b)));
     339
     340    CHECK(compileAndRun<int64_t>(proc, a) == (a & b));
     341}
     342
     343void testBitAndImmArg(int64_t a, int64_t b)
     344{
     345    Procedure proc;
     346    BasicBlock* root = proc.addBlock();
     347    root->appendNew<ControlValue>(
     348        proc, Return, Origin(),
     349        root->appendNew<Value>(
     350            proc, BitAnd, Origin(),
     351            root->appendNew<Const64Value>(proc, Origin(), a),
     352            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)));
     353
     354    CHECK(compileAndRun<int64_t>(proc, b) == (a & b));
     355}
     356
     357void testBitAndBitAndArgImmImm(int64_t a, int64_t b, int64_t c)
     358{
     359    Procedure proc;
     360    BasicBlock* root = proc.addBlock();
     361    Value* innerBitAnd = root->appendNew<Value>(
     362        proc, BitAnd, Origin(),
     363        root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     364        root->appendNew<Const64Value>(proc, Origin(), b));
     365    root->appendNew<ControlValue>(
     366        proc, Return, Origin(),
     367        root->appendNew<Value>(
     368            proc, BitAnd, Origin(),
     369            innerBitAnd,
     370            root->appendNew<Const64Value>(proc, Origin(), c)));
     371
     372    CHECK(compileAndRun<int64_t>(proc, a) == ((a & b) & c));
     373}
     374
     375void testBitAndImmBitAndArgImm(int64_t a, int64_t b, int64_t c)
     376{
     377    Procedure proc;
     378    BasicBlock* root = proc.addBlock();
     379    Value* innerBitAnd = root->appendNew<Value>(
     380        proc, BitAnd, Origin(),
     381        root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     382        root->appendNew<Const64Value>(proc, Origin(), c));
     383    root->appendNew<ControlValue>(
     384        proc, Return, Origin(),
     385        root->appendNew<Value>(
     386            proc, BitAnd, Origin(),
     387            root->appendNew<Const64Value>(proc, Origin(), a),
     388            innerBitAnd));
     389
     390    CHECK(compileAndRun<int64_t>(proc, b) == (a & (b & c)));
     391}
     392
     393void testBitAndArgs32(int a, int b)
     394{
     395    Procedure proc;
     396    BasicBlock* root = proc.addBlock();
     397    root->appendNew<ControlValue>(
     398        proc, Return, Origin(),
     399        root->appendNew<Value>(
     400            proc, BitAnd, Origin(),
     401            root->appendNew<Value>(
     402                proc, Trunc, Origin(),
     403                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     404            root->appendNew<Value>(
     405                proc, Trunc, Origin(),
     406                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1))));
     407
     408    CHECK(compileAndRun<int>(proc, a, b) == (a & b));
     409}
     410
     411void testBitAndSameArg32(int a)
     412{
     413    Procedure proc;
     414    BasicBlock* root = proc.addBlock();
     415    Value* argument = root->appendNew<Value>(proc, Trunc, Origin(),
     416        root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0));
     417    root->appendNew<ControlValue>(
     418        proc, Return, Origin(),
     419        root->appendNew<Value>(
     420            proc, BitAnd, Origin(),
     421            argument,
     422            argument));
     423
     424    CHECK(compileAndRun<int>(proc, a) == a);
     425}
     426
     427void testBitAndImms32(int a, int b)
     428{
     429    Procedure proc;
     430    BasicBlock* root = proc.addBlock();
     431    root->appendNew<ControlValue>(
     432        proc, Return, Origin(),
     433        root->appendNew<Value>(
     434            proc, BitAnd, Origin(),
     435            root->appendNew<Const32Value>(proc, Origin(), a),
     436            root->appendNew<Const32Value>(proc, Origin(), b)));
     437
     438    CHECK(compileAndRun<int>(proc) == (a & b));
     439}
     440
     441void testBitAndArgImm32(int a, int b)
     442{
     443    Procedure proc;
     444    BasicBlock* root = proc.addBlock();
     445    root->appendNew<ControlValue>(
     446        proc, Return, Origin(),
     447        root->appendNew<Value>(
     448            proc, BitAnd, Origin(),
     449            root->appendNew<Value>(
     450                proc, Trunc, Origin(),
     451                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     452            root->appendNew<Const32Value>(proc, Origin(), b)));
     453
     454    CHECK(compileAndRun<int>(proc, a) == (a & b));
     455}
     456
     457void testBitAndImmArg32(int a, int b)
     458{
     459    Procedure proc;
     460    BasicBlock* root = proc.addBlock();
     461    root->appendNew<ControlValue>(
     462        proc, Return, Origin(),
     463        root->appendNew<Value>(
     464            proc, BitAnd, Origin(),
     465            root->appendNew<Const32Value>(proc, Origin(), a),
     466            root->appendNew<Value>(
     467                proc, Trunc, Origin(),
     468                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0))));
     469
     470    CHECK(compileAndRun<int>(proc, b) == (a & b));
     471}
     472
     473void testBitAndBitAndArgImmImm32(int a, int b, int c)
     474{
     475    Procedure proc;
     476    BasicBlock* root = proc.addBlock();
     477    Value* innerBitAnd = root->appendNew<Value>(
     478        proc, BitAnd, Origin(),
     479        root->appendNew<Value>(
     480            proc, Trunc, Origin(),
     481            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     482        root->appendNew<Const32Value>(proc, Origin(), b));
     483    root->appendNew<ControlValue>(
     484        proc, Return, Origin(),
     485        root->appendNew<Value>(
     486            proc, BitAnd, Origin(),
     487            innerBitAnd,
     488            root->appendNew<Const32Value>(proc, Origin(), c)));
     489
     490    CHECK(compileAndRun<int>(proc, a) == ((a & b) & c));
     491}
     492
     493void testBitAndImmBitAndArgImm32(int a, int b, int c)
     494{
     495    Procedure proc;
     496    BasicBlock* root = proc.addBlock();
     497    Value* innerBitAnd = root->appendNew<Value>(
     498        proc, BitAnd, Origin(),
     499        root->appendNew<Value>(
     500            proc, Trunc, Origin(),
     501            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     502        root->appendNew<Const32Value>(proc, Origin(), c));
     503    root->appendNew<ControlValue>(
     504        proc, Return, Origin(),
     505        root->appendNew<Value>(
     506            proc, BitAnd, Origin(),
     507            root->appendNew<Const32Value>(proc, Origin(), a),
     508            innerBitAnd));
     509
     510    CHECK(compileAndRun<int>(proc, b) == (a & (b & c)));
     511}
     512
     513void testBitOrArgs(int64_t a, int64_t b)
     514{
     515    Procedure proc;
     516    BasicBlock* root = proc.addBlock();
     517    root->appendNew<ControlValue>(
     518        proc, Return, Origin(),
     519        root->appendNew<Value>(
     520            proc, BitOr, Origin(),
     521            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     522            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)));
     523
     524    CHECK(compileAndRun<int64_t>(proc, a, b) == (a | b));
     525}
     526
     527void testBitOrSameArg(int64_t a)
     528{
     529    Procedure proc;
     530    BasicBlock* root = proc.addBlock();
     531    Value* argument = root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0);
     532    root->appendNew<ControlValue>(
     533        proc, Return, Origin(),
     534        root->appendNew<Value>(
     535            proc, BitOr, Origin(),
     536            argument,
     537            argument));
     538
     539    CHECK(compileAndRun<int64_t>(proc, a) == a);
     540}
     541
     542void testBitOrImms(int64_t a, int64_t b)
     543{
     544    Procedure proc;
     545    BasicBlock* root = proc.addBlock();
     546    root->appendNew<ControlValue>(
     547        proc, Return, Origin(),
     548        root->appendNew<Value>(
     549            proc, BitOr, Origin(),
     550            root->appendNew<Const64Value>(proc, Origin(), a),
     551            root->appendNew<Const64Value>(proc, Origin(), b)));
     552
     553    CHECK(compileAndRun<int64_t>(proc) == (a | b));
     554}
     555
     556void testBitOrArgImm(int64_t a, int64_t b)
     557{
     558    Procedure proc;
     559    BasicBlock* root = proc.addBlock();
     560    root->appendNew<ControlValue>(
     561        proc, Return, Origin(),
     562        root->appendNew<Value>(
     563            proc, BitOr, Origin(),
     564            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     565            root->appendNew<Const64Value>(proc, Origin(), b)));
     566
     567    CHECK(compileAndRun<int64_t>(proc, a) == (a | b));
     568}
     569
     570void testBitOrImmArg(int64_t a, int64_t b)
     571{
     572    Procedure proc;
     573    BasicBlock* root = proc.addBlock();
     574    root->appendNew<ControlValue>(
     575        proc, Return, Origin(),
     576        root->appendNew<Value>(
     577            proc, BitOr, Origin(),
     578            root->appendNew<Const64Value>(proc, Origin(), a),
     579            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)));
     580
     581    CHECK(compileAndRun<int64_t>(proc, b) == (a | b));
     582}
     583
     584void testBitOrBitOrArgImmImm(int64_t a, int64_t b, int64_t c)
     585{
     586    Procedure proc;
     587    BasicBlock* root = proc.addBlock();
     588    Value* innerBitOr = root->appendNew<Value>(
     589        proc, BitOr, Origin(),
     590        root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     591        root->appendNew<Const64Value>(proc, Origin(), b));
     592    root->appendNew<ControlValue>(
     593        proc, Return, Origin(),
     594        root->appendNew<Value>(
     595            proc, BitOr, Origin(),
     596            innerBitOr,
     597            root->appendNew<Const64Value>(proc, Origin(), c)));
     598
     599    CHECK(compileAndRun<int64_t>(proc, a) == ((a | b) | c));
     600}
     601
     602void testBitOrImmBitOrArgImm(int64_t a, int64_t b, int64_t c)
     603{
     604    Procedure proc;
     605    BasicBlock* root = proc.addBlock();
     606    Value* innerBitOr = root->appendNew<Value>(
     607        proc, BitOr, Origin(),
     608        root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     609        root->appendNew<Const64Value>(proc, Origin(), c));
     610    root->appendNew<ControlValue>(
     611        proc, Return, Origin(),
     612        root->appendNew<Value>(
     613            proc, BitOr, Origin(),
     614            root->appendNew<Const64Value>(proc, Origin(), a),
     615            innerBitOr));
     616
     617    CHECK(compileAndRun<int64_t>(proc, b) == (a | (b | c)));
     618}
     619
     620void testBitOrArgs32(int a, int b)
     621{
     622    Procedure proc;
     623    BasicBlock* root = proc.addBlock();
     624    root->appendNew<ControlValue>(
     625        proc, Return, Origin(),
     626        root->appendNew<Value>(
     627            proc, BitOr, Origin(),
     628            root->appendNew<Value>(
     629                proc, Trunc, Origin(),
     630                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     631            root->appendNew<Value>(
     632                proc, Trunc, Origin(),
     633                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1))));
     634
     635    CHECK(compileAndRun<int>(proc, a, b) == (a | b));
     636}
     637
     638void testBitOrSameArg32(int a)
     639{
     640    Procedure proc;
     641    BasicBlock* root = proc.addBlock();
     642    Value* argument = root->appendNew<Value>(
     643        proc, Trunc, Origin(),
     644            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0));
     645    root->appendNew<ControlValue>(
     646        proc, Return, Origin(),
     647        root->appendNew<Value>(
     648            proc, BitOr, Origin(),
     649            argument,
     650            argument));
     651
     652    CHECK(compileAndRun<int>(proc, a) == a);
     653}
     654
     655void testBitOrImms32(int a, int b)
     656{
     657    Procedure proc;
     658    BasicBlock* root = proc.addBlock();
     659    root->appendNew<ControlValue>(
     660        proc, Return, Origin(),
     661        root->appendNew<Value>(
     662            proc, BitOr, Origin(),
     663            root->appendNew<Const32Value>(proc, Origin(), a),
     664            root->appendNew<Const32Value>(proc, Origin(), b)));
     665
     666    CHECK(compileAndRun<int>(proc) == (a | b));
     667}
     668
     669void testBitOrArgImm32(int a, int b)
     670{
     671    Procedure proc;
     672    BasicBlock* root = proc.addBlock();
     673    root->appendNew<ControlValue>(
     674        proc, Return, Origin(),
     675        root->appendNew<Value>(
     676            proc, BitOr, Origin(),
     677            root->appendNew<Value>(
     678                proc, Trunc, Origin(),
     679                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     680            root->appendNew<Const32Value>(proc, Origin(), b)));
     681
     682    CHECK(compileAndRun<int>(proc, a) == (a | b));
     683}
     684
     685void testBitOrImmArg32(int a, int b)
     686{
     687    Procedure proc;
     688    BasicBlock* root = proc.addBlock();
     689    root->appendNew<ControlValue>(
     690        proc, Return, Origin(),
     691        root->appendNew<Value>(
     692            proc, BitOr, Origin(),
     693            root->appendNew<Const32Value>(proc, Origin(), a),
     694            root->appendNew<Value>(
     695                proc, Trunc, Origin(),
     696                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0))));
     697
     698    CHECK(compileAndRun<int>(proc, b) == (a | b));
     699}
     700
     701void testBitOrBitOrArgImmImm32(int a, int b, int c)
     702{
     703    Procedure proc;
     704    BasicBlock* root = proc.addBlock();
     705    Value* innerBitOr = root->appendNew<Value>(
     706        proc, BitOr, Origin(),
     707        root->appendNew<Value>(
     708            proc, Trunc, Origin(),
     709            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     710        root->appendNew<Const32Value>(proc, Origin(), b));
     711    root->appendNew<ControlValue>(
     712        proc, Return, Origin(),
     713        root->appendNew<Value>(
     714            proc, BitOr, Origin(),
     715            innerBitOr,
     716            root->appendNew<Const32Value>(proc, Origin(), c)));
     717
     718    CHECK(compileAndRun<int>(proc, a) == ((a | b) | c));
     719}
     720
     721void testBitOrImmBitOrArgImm32(int a, int b, int c)
     722{
     723    Procedure proc;
     724    BasicBlock* root = proc.addBlock();
     725    Value* innerBitOr = root->appendNew<Value>(
     726        proc, BitOr, Origin(),
     727        root->appendNew<Value>(
     728            proc, Trunc, Origin(),
     729            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     730        root->appendNew<Const32Value>(proc, Origin(), c));
     731    root->appendNew<ControlValue>(
     732        proc, Return, Origin(),
     733        root->appendNew<Value>(
     734            proc, BitOr, Origin(),
     735            root->appendNew<Const32Value>(proc, Origin(), a),
     736            innerBitOr));
     737
     738    CHECK(compileAndRun<int>(proc, b) == (a | (b | c)));
    273739}
    274740
     
    12511717    RUN(testLoad42());
    12521718    RUN(testArg(43));
     1719    RUN(testReturnConst64(5));
     1720    RUN(testReturnConst64(-42));
    12531721
    12541722    RUN(testAddArgs(1, 1));
     
    12891757    RUN(testSubImmArg32(13, -42));
    12901758    RUN(testSubImmArg32(-13, 42));
     1759
     1760    RUN(testBitAndArgs(43, 43));
     1761    RUN(testBitAndArgs(43, 0));
     1762    RUN(testBitAndArgs(10, 3));
     1763    RUN(testBitAndArgs(42, 0xffffffffffffffff));
     1764    RUN(testBitAndSameArg(43));
     1765    RUN(testBitAndSameArg(0));
     1766    RUN(testBitAndSameArg(3));
     1767    RUN(testBitAndSameArg(0xffffffffffffffff));
     1768    RUN(testBitAndImms(43, 43));
     1769    RUN(testBitAndImms(43, 0));
     1770    RUN(testBitAndImms(10, 3));
     1771    RUN(testBitAndImms(42, 0xffffffffffffffff));
     1772    RUN(testBitAndArgImm(43, 43));
     1773    RUN(testBitAndArgImm(43, 0));
     1774    RUN(testBitAndArgImm(10, 3));
     1775    RUN(testBitAndArgImm(42, 0xffffffffffffffff));
     1776    RUN(testBitAndImmArg(43, 43));
     1777    RUN(testBitAndImmArg(43, 0));
     1778    RUN(testBitAndImmArg(10, 3));
     1779    RUN(testBitAndImmArg(42, 0xffffffffffffffff));
     1780    RUN(testBitAndBitAndArgImmImm(2, 7, 3));
     1781    RUN(testBitAndBitAndArgImmImm(1, 6, 6));
     1782    RUN(testBitAndBitAndArgImmImm(0xffff, 24, 7));
     1783    RUN(testBitAndImmBitAndArgImm(7, 2, 3));
     1784    RUN(testBitAndImmBitAndArgImm(6, 1, 6));
     1785    RUN(testBitAndImmBitAndArgImm(24, 0xffff, 7));
     1786    RUN(testBitAndArgs32(43, 43));
     1787    RUN(testBitAndArgs32(43, 0));
     1788    RUN(testBitAndArgs32(10, 3));
     1789    RUN(testBitAndArgs32(42, 0xffffffff));
     1790    RUN(testBitAndSameArg32(43));
     1791    RUN(testBitAndSameArg32(0));
     1792    RUN(testBitAndSameArg32(3));
     1793    RUN(testBitAndSameArg32(0xffffffff));
     1794    RUN(testBitAndImms32(43, 43));
     1795    RUN(testBitAndImms32(43, 0));
     1796    RUN(testBitAndImms32(10, 3));
     1797    RUN(testBitAndImms32(42, 0xffffffff));
     1798    RUN(testBitAndArgImm32(43, 43));
     1799    RUN(testBitAndArgImm32(43, 0));
     1800    RUN(testBitAndArgImm32(10, 3));
     1801    RUN(testBitAndArgImm32(42, 0xffffffff));
     1802    RUN(testBitAndImmArg32(43, 43));
     1803    RUN(testBitAndImmArg32(43, 0));
     1804    RUN(testBitAndImmArg32(10, 3));
     1805    RUN(testBitAndImmArg32(42, 0xffffffff));
     1806    RUN(testBitAndBitAndArgImmImm32(2, 7, 3));
     1807    RUN(testBitAndBitAndArgImmImm32(1, 6, 6));
     1808    RUN(testBitAndBitAndArgImmImm32(0xffff, 24, 7));
     1809    RUN(testBitAndImmBitAndArgImm32(7, 2, 3));
     1810    RUN(testBitAndImmBitAndArgImm32(6, 1, 6));
     1811    RUN(testBitAndImmBitAndArgImm32(24, 0xffff, 7));
     1812
     1813    RUN(testBitOrArgs(43, 43));
     1814    RUN(testBitOrArgs(43, 0));
     1815    RUN(testBitOrArgs(10, 3));
     1816    RUN(testBitOrArgs(42, 0xffffffffffffffff));
     1817    RUN(testBitOrSameArg(43));
     1818    RUN(testBitOrSameArg(0));
     1819    RUN(testBitOrSameArg(3));
     1820    RUN(testBitOrSameArg(0xffffffffffffffff));
     1821    RUN(testBitOrImms(43, 43));
     1822    RUN(testBitOrImms(43, 0));
     1823    RUN(testBitOrImms(10, 3));
     1824    RUN(testBitOrImms(42, 0xffffffffffffffff));
     1825    RUN(testBitOrArgImm(43, 43));
     1826    RUN(testBitOrArgImm(43, 0));
     1827    RUN(testBitOrArgImm(10, 3));
     1828    RUN(testBitOrArgImm(42, 0xffffffffffffffff));
     1829    RUN(testBitOrImmArg(43, 43));
     1830    RUN(testBitOrImmArg(43, 0));
     1831    RUN(testBitOrImmArg(10, 3));
     1832    RUN(testBitOrImmArg(42, 0xffffffffffffffff));
     1833    RUN(testBitOrBitOrArgImmImm(2, 7, 3));
     1834    RUN(testBitOrBitOrArgImmImm(1, 6, 6));
     1835    RUN(testBitOrBitOrArgImmImm(0xffff, 24, 7));
     1836    RUN(testBitOrImmBitOrArgImm(7, 2, 3));
     1837    RUN(testBitOrImmBitOrArgImm(6, 1, 6));
     1838    RUN(testBitOrImmBitOrArgImm(24, 0xffff, 7));
     1839    RUN(testBitOrArgs32(43, 43));
     1840    RUN(testBitOrArgs32(43, 0));
     1841    RUN(testBitOrArgs32(10, 3));
     1842    RUN(testBitOrArgs32(42, 0xffffffff));
     1843    RUN(testBitOrSameArg32(43));
     1844    RUN(testBitOrSameArg32(0));
     1845    RUN(testBitOrSameArg32(3));
     1846    RUN(testBitOrSameArg32(0xffffffff));
     1847    RUN(testBitOrImms32(43, 43));
     1848    RUN(testBitOrImms32(43, 0));
     1849    RUN(testBitOrImms32(10, 3));
     1850    RUN(testBitOrImms32(42, 0xffffffff));
     1851    RUN(testBitOrArgImm32(43, 43));
     1852    RUN(testBitOrArgImm32(43, 0));
     1853    RUN(testBitOrArgImm32(10, 3));
     1854    RUN(testBitOrArgImm32(42, 0xffffffff));
     1855    RUN(testBitOrImmArg32(43, 43));
     1856    RUN(testBitOrImmArg32(43, 0));
     1857    RUN(testBitOrImmArg32(10, 3));
     1858    RUN(testBitOrImmArg32(42, 0xffffffff));
     1859    RUN(testBitOrBitOrArgImmImm32(2, 7, 3));
     1860    RUN(testBitOrBitOrArgImmImm32(1, 6, 6));
     1861    RUN(testBitOrBitOrArgImmImm32(0xffff, 24, 7));
     1862    RUN(testBitOrImmBitOrArgImm32(7, 2, 3));
     1863    RUN(testBitOrImmBitOrArgImm32(6, 1, 6));
     1864    RUN(testBitOrImmBitOrArgImm32(24, 0xffff, 7));
    12911865
    12921866    RUN(testStore(44));
Note: See TracChangeset for help on using the changeset viewer.