1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_COMPILER_OPTIMIZING_NODES_RISCV64_H_
18 #define ART_COMPILER_OPTIMIZING_NODES_RISCV64_H_
19 
20 namespace art HIDDEN {
21 
22 class HRiscv64ShiftAdd final : public HBinaryOperation {
23  public:
24   HRiscv64ShiftAdd(HInstruction* left,
25                    HInstruction* right,
26                    uint32_t distance,
27                    uint32_t dex_pc = kNoDexPc)
HBinaryOperation(kRiscv64ShiftAdd,DataType::Type::kInt64,left,right,SideEffects::None (),dex_pc)28       : HBinaryOperation(
29             kRiscv64ShiftAdd, DataType::Type::kInt64, left, right, SideEffects::None(), dex_pc) {
30     DCHECK_GE(distance, 1u);
31     DCHECK_LE(distance, 3u);
32 
33     SetPackedField<DistanceField>(distance);
34   }
35 
GetDistance()36   uint32_t GetDistance() const { return GetPackedField<DistanceField>(); }
37 
IsCommutative()38   bool IsCommutative() const override { return false; }
InstructionDataEquals(const HInstruction * other)39   bool InstructionDataEquals(const HInstruction* other) const override {
40     return GetPackedFields() == other->AsRiscv64ShiftAdd()->GetPackedFields();
41   }
42 
Evaluate(HLongConstant * x,HLongConstant * y)43   HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override {
44     const int64_t value = y->GetValue() + (x->GetValue() << GetDistance());
45     return GetBlock()->GetGraph()->GetLongConstant(value, GetDexPc());
46   }
47 
48   DECLARE_INSTRUCTION(Riscv64ShiftAdd);
49 
50  protected:
51   DEFAULT_COPY_CONSTRUCTOR(Riscv64ShiftAdd);
52 
53  private:
54   static constexpr size_t kFieldDistance = kNumberOfGenericPackedBits;
55   static constexpr size_t kFieldDistanceSize = MinimumBitsToStore(3u);
56   static constexpr size_t kNumberOfRiscv64ShiftAddPackedBits =
57       kFieldDistance + kFieldDistanceSize;
58   static_assert(kNumberOfRiscv64ShiftAddPackedBits <= kMaxNumberOfPackedBits,
59                 "Too many packed fields.");
60   using DistanceField = BitField<uint32_t, kFieldDistance, kFieldDistanceSize>;
61 };
62 
63 }  // namespace art
64 
65 #endif  // ART_COMPILER_OPTIMIZING_NODES_RISCV64_H_
66