aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-12 02:16:56 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-12-12 02:16:56 +0000
commit3d8930de5ce5d7c973977788ba593d236fa74145 (patch)
tree9b1ddd034103ed6ee665d4625b5c1a64e8d369a7
parent1771efed7401fd557a5bb6834c754a613bd241ff (diff)
parent5d52f45e3c8dde868a4b47e9efbf4eef89711bf6 (diff)
downloadbinary_translation-3d8930de5ce5d7c973977788ba593d236fa74145.tar.gz
Snap for 11206181 from 5d52f45e3c8dde868a4b47e9efbf4eef89711bf6 to 24Q1-release
Change-Id: I0c3387b7bd6655beb100e8bca0d645457e6ae68d
-rw-r--r--android_api/libjnigraphics/Android.bp30
-rw-r--r--berberis_config.mk1
-rw-r--r--calling_conventions/include/berberis/calling_conventions/calling_conventions_riscv64.h4
-rw-r--r--decoder/include/berberis/decoder/riscv64/decoder.h81
-rw-r--r--guest_abi/riscv64/include/berberis/guest_abi/guest_abi_arch.h6
-rw-r--r--guest_abi/riscv64/include/berberis/guest_abi/guest_params_arch.h7
6 files changed, 83 insertions, 46 deletions
diff --git a/android_api/libjnigraphics/Android.bp b/android_api/libjnigraphics/Android.bp
new file mode 100644
index 00000000..23ac99d8
--- /dev/null
+++ b/android_api/libjnigraphics/Android.bp
@@ -0,0 +1,30 @@
+//
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_library_shared {
+ name: "libberberis_proxy_libjnigraphics",
+ defaults: ["berberis_proxy_library_defaults"],
+ header_libs: ["jni_headers"],
+ srcs: ["//frameworks/libs/native_bridge_support/libjnigraphics:native_bridge_proxy_libjnigraphics_files"],
+ shared_libs: [
+ "libandroid",
+ "libjnigraphics",
+ ],
+}
diff --git a/berberis_config.mk b/berberis_config.mk
index ffb0e1f3..58f2558c 100644
--- a/berberis_config.mk
+++ b/berberis_config.mk
@@ -39,6 +39,7 @@ BERBERIS_PRODUCT_PACKAGES_RISCV64_TO_X86_64 := \
libberberis_proxy_libcamera2ndk \
libberberis_proxy_libmediandk \
libberberis_proxy_libnativehelper \
+ libberberis_proxy_libjnigraphics \
libberberis_proxy_libnativewindow \
libberberis_proxy_libneuralnetworks \
libberberis_proxy_libwebviewchromium_plat_support \
diff --git a/calling_conventions/include/berberis/calling_conventions/calling_conventions_riscv64.h b/calling_conventions/include/berberis/calling_conventions/calling_conventions_riscv64.h
index ec6f5d94..4297589d 100644
--- a/calling_conventions/include/berberis/calling_conventions/calling_conventions_riscv64.h
+++ b/calling_conventions/include/berberis/calling_conventions/calling_conventions_riscv64.h
@@ -81,8 +81,8 @@ class CallingConventions {
}
constexpr ArgLocation GetIntResLoc(unsigned size) {
- // Fundamental integer type - 1/1, 2/2, 4/4, 8/8.
- CHECK_LE(size, 8u);
+ // Fundamental integer type - 1/1, 2/2, 4/4, 8/8, 16/16.
+ CHECK_LE(size, 16u);
// Use x10/a0.
return {kArgLocationInt, 0u};
diff --git a/decoder/include/berberis/decoder/riscv64/decoder.h b/decoder/include/berberis/decoder/riscv64/decoder.h
index ff3929e8..f4c6021f 100644
--- a/decoder/include/berberis/decoder/riscv64/decoder.h
+++ b/decoder/include/berberis/decoder/riscv64/decoder.h
@@ -51,7 +51,7 @@ class Decoder {
// Note: that value is not used anywhere in the code, it exists solely to make conversion of not
// yet known to decoder RISC-V instructions robust.
- enum class AmoOpcode {
+ enum class AmoOpcode : uint8_t {
kLr = 0b00010,
kSc = 0b00011,
kAmoswap = 0b00001,
@@ -66,7 +66,7 @@ class Decoder {
kMaxValue = 0b11111,
};
- enum class BranchOpcode {
+ enum class BranchOpcode : uint8_t {
kBeq = 0b000,
kBne = 0b001,
kBlt = 0b100,
@@ -76,21 +76,21 @@ class Decoder {
kMaxValue = 0b111,
};
- enum class CsrOpcode {
+ enum class CsrOpcode : uint8_t {
kCsrrw = 0b01,
kCsrrs = 0b10,
kCsrrc = 0b11,
kMaxValue = 0b11,
};
- enum class CsrImmOpcode {
+ enum class CsrImmOpcode : uint8_t {
kCsrrwi = 0b01,
kCsrrsi = 0b10,
kCsrrci = 0b11,
kMaxValue = 0b11,
};
- enum class FmaOpcode {
+ enum class FmaOpcode : uint8_t {
kFmadd = 0b00,
kFmsub = 0b01,
kFnmsub = 0b10,
@@ -98,13 +98,13 @@ class Decoder {
kMaxValue = 0b11,
};
- enum class FenceOpcode {
+ enum class FenceOpcode : uint8_t {
kFence = 0b0000,
kFenceTso = 0b1000,
kMaxValue = 0b1111,
};
- enum class OpOpcode {
+ enum class OpOpcode : uint16_t {
kAdd = 0b0000'000'000,
kSub = 0b0100'000'000,
kSll = 0b0000'000'001,
@@ -142,7 +142,7 @@ class Decoder {
kMaxValue = 0b1111'111'111,
};
- enum class Op32Opcode {
+ enum class Op32Opcode : uint16_t {
kAddw = 0b0000'000'000,
kAdduw = 0b0000'100'000,
kSubw = 0b0100'000'000,
@@ -162,24 +162,24 @@ class Decoder {
kMaxValue = 0b1111'111'111,
};
- enum class OpSingleInputOpcode {
+ enum class OpSingleInputOpcode : uint16_t {
kZexth = 0b0000'100'100,
kMaxValue = 0b1111'111'111,
};
- enum class OpFpGpRegisterTargetNoRoundingOpcode {
+ enum class OpFpGpRegisterTargetNoRoundingOpcode : uint8_t {
kFle = 0b00'000,
kFlt = 0b00'001,
kFeq = 0b00'010,
kMaxValue = 0b11'111,
};
- enum class OpFpGpRegisterTargetSingleInputNoRoundingOpcode {
+ enum class OpFpGpRegisterTargetSingleInputNoRoundingOpcode : uint16_t {
kFclass = 0b00'00000'001,
kMaxValue = 0b11'11111'111,
};
- enum class OpFpNoRoundingOpcode {
+ enum class OpFpNoRoundingOpcode : uint8_t {
kFSgnj = 0b00'000,
kFSgnjn = 0b00'001,
kFSgnjx = 0b00'010,
@@ -188,7 +188,7 @@ class Decoder {
kMaxValue = 0b11'111,
};
- enum class OpFpOpcode {
+ enum class OpFpOpcode : uint8_t {
kFAdd = 0b00,
kFSub = 0b01,
kFMul = 0b10,
@@ -196,16 +196,16 @@ class Decoder {
kMaxValue = 0b11,
};
- enum class OpFpSingleInputOpcode {
+ enum class OpFpSingleInputOpcode : uint8_t {
kFSqrt = 0b11'00000,
kMaxValue = 0b11'11111,
};
- enum class OpFpSingleInputNoRoundingOpcode {
+ enum class OpFpSingleInputNoRoundingOpcode : uint8_t {
kFmv,
};
- enum class OpImmOpcode {
+ enum class OpImmOpcode : uint8_t {
kAddi = 0b000,
kSlti = 0b010,
kSltiu = 0b011,
@@ -215,26 +215,26 @@ class Decoder {
kMaxValue = 0b111,
};
- enum class OpImm32Opcode {
+ enum class OpImm32Opcode : uint8_t {
kAddiw = 0b000,
kMaxValue = 0b111,
};
- enum class ShiftImmOpcode {
+ enum class ShiftImmOpcode : uint8_t {
kSlli = 0b000000'001,
kSrli = 0b000000'101,
kSrai = 0b010000'101,
kMaxValue = 0b11111'111,
};
- enum class ShiftImm32Opcode {
+ enum class ShiftImm32Opcode : uint16_t {
kSlliw = 0b0000000'001,
kSrliw = 0b0000000'101,
kSraiw = 0b0100000'101,
kMaxValue = 0b111111'111,
};
- enum class BitmanipImmOpcode {
+ enum class BitmanipImmOpcode : uint16_t {
kClz = 0b0110000'00000'001,
kCpop = 0b0110000'00010'001,
kCtz = 0b0110000'00001'001,
@@ -250,7 +250,7 @@ class Decoder {
kMaxValue = 0b111111'111111'111,
};
- enum class BitmanipImm32Opcode {
+ enum class BitmanipImm32Opcode : uint16_t {
kClzw = 0b0110000'00000'001,
kCpopw = 0b0110000'00010'001,
kCtzw = 0b0110000'00001'001,
@@ -259,13 +259,13 @@ class Decoder {
kMaxValue = 0b1111111'111111'111,
};
- enum class SystemOpcode {
+ enum class SystemOpcode : uint32_t {
kEcall = 0b000000000000'00000'000'00000,
kEbreak = 0b000000000001'00000'000'00000,
kMaxValue = 0b111111111111'11111'111'11111,
};
- enum class VOpIViOpcode {
+ enum class VOpIViOpcode : uint8_t {
kVaddvi = 0b000000,
kVrsubvi = 0b000011,
kVandvi = 0b001001,
@@ -298,7 +298,7 @@ class Decoder {
kMaxValue = 0b111111,
};
- enum class VOpIVvOpcode {
+ enum class VOpIVvOpcode : uint8_t {
kVaddvv = 0b000000,
kVsubvv = 0b000010,
kVminuvv = 0b000100,
@@ -340,7 +340,7 @@ class Decoder {
kMaxValue = 0b111111
};
- enum class VOpIVxOpcode {
+ enum class VOpIVxOpcode : uint8_t {
kVaddvx = 0b000000,
kVsubvx = 0b000010,
kVrsubvx = 0b000011,
@@ -1058,7 +1058,7 @@ class Decoder {
.opcode = BranchOpcode(GetBits<uint8_t, 13, 1>()),
.src1 = uint8_t(8 + rs),
.src2 = 0,
- .offset = int16_t(SignExtend<9>(kBHigh[high_imm] + kBLow[low_imm])),
+ .offset = static_cast<int16_t>(SignExtend<9>(kBHigh[high_imm] + kBLow[low_imm])),
};
insn_consumer_->CompareAndBranch(args);
}
@@ -1306,9 +1306,9 @@ class Decoder {
template <typename OpcodeType>
void DecodeOp() {
- uint16_t low_opcode = GetBits<uint16_t, 12, 3>();
- uint16_t high_opcode = GetBits<uint16_t, 25, 7>();
- uint16_t opcode_bits = int16_t(low_opcode | (high_opcode << 3));
+ uint8_t low_opcode = GetBits<uint8_t, 12, 3>();
+ uint8_t high_opcode = GetBits<uint8_t, 25, 7>();
+ uint16_t opcode_bits = static_cast<int16_t>(low_opcode | (high_opcode << 3));
OpcodeType opcode{opcode_bits};
OpSingleInputOpcode single_input_opcode{opcode_bits};
@@ -1341,8 +1341,8 @@ class Decoder {
}
void DecodeAmo() {
- uint16_t low_opcode = GetBits<uint16_t, 12, 3>();
- uint16_t high_opcode = GetBits<uint16_t, 27, 5>();
+ uint8_t low_opcode = GetBits<uint8_t, 12, 3>();
+ uint8_t high_opcode = GetBits<uint8_t, 27, 5>();
// lr instruction must have rs2 == 0
if (high_opcode == 0b00010 && GetBits<uint8_t, 20, 5>() != 0) {
return Undefined();
@@ -1434,15 +1434,15 @@ class Decoder {
const StoreArgsTemplate<OperandTypeEnum> args = {
.operand_type = operand_type,
.src = GetBits<uint8_t, 15, 5>(),
- .offset = SignExtend<12>(int16_t(low_imm | (high_imm << 5))),
+ .offset = SignExtend<12>(static_cast<int16_t>(low_imm | (high_imm << 5))),
.data = GetBits<uint8_t, 20, 5>(),
};
insn_consumer_->Store(args);
}
template <typename OpOpcodeType,
- typename ShiftOcodeType,
- typename BitmanipOpCodeType,
+ typename ShiftOpcodeType,
+ typename BitmanipOpcodeType,
uint32_t kShiftFieldSize>
void DecodeOp() {
uint8_t low_opcode = GetBits<uint8_t, 12, 3>();
@@ -1463,9 +1463,10 @@ class Decoder {
0) { // For Canonical Shift Instructions from RV64G the opcode contains all
// zeros except for the 30th (second highest) bit.
uint16_t high_opcode = GetBits<uint16_t, 20 + kShiftFieldSize, 12 - kShiftFieldSize>();
- ShiftOcodeType opcode{int16_t(low_opcode | (high_opcode << 3))};
+ ShiftOpcodeType opcode{
+ static_cast<std::underlying_type_t<ShiftOpcodeType>>(low_opcode | (high_opcode << 3))};
- const ShiftImmArgsTemplate<ShiftOcodeType> args = {
+ const ShiftImmArgsTemplate<ShiftOpcodeType> args = {
.opcode = opcode,
.dst = GetBits<uint8_t, 7, 5>(),
.src = GetBits<uint8_t, 15, 5>(),
@@ -1475,7 +1476,7 @@ class Decoder {
} else {
uint8_t shamt = GetBits<uint8_t, 20, kShiftFieldSize>();
uint16_t high_opcode = GetBits<uint16_t, 20 + kShiftFieldSize, 12 - kShiftFieldSize>();
- BitmanipOpCodeType opcode{int16_t(low_opcode | (high_opcode << 3))};
+ BitmanipOpcodeType opcode{static_cast<uint16_t>(low_opcode | (high_opcode << 3))};
bool has_shamt = false;
switch ((BitmanipImmOpcode)opcode) {
@@ -1501,10 +1502,10 @@ class Decoder {
// TODO(b/291851792): Refactor instructions with shamt into ShiftImmArgs
if (!has_shamt) {
high_opcode = GetBits<uint16_t, 20, 12>();
- opcode = {low_opcode | (high_opcode << 3)};
+ opcode = BitmanipOpcodeType{static_cast<uint16_t>(low_opcode | (high_opcode << 3))};
shamt = 0;
}
- const BitmanipImmArgsTemplate<BitmanipOpCodeType> args = {
+ const BitmanipImmArgsTemplate<BitmanipOpcodeType> args = {
.opcode = opcode,
.dst = GetBits<uint8_t, 7, 5>(),
.src = GetBits<uint8_t, 15, 5>(),
@@ -1530,7 +1531,7 @@ class Decoder {
.src1 = GetBits<uint8_t, 15, 5>(),
.src2 = GetBits<uint8_t, 20, 5>(),
// The offset is encoded as 2-byte units, we need to multiply by 2.
- .offset = SignExtend<13>(int16_t(offset * 2)),
+ .offset = SignExtend<13>(static_cast<int16_t>(offset * 2)),
};
insn_consumer_->CompareAndBranch(args);
}
diff --git a/guest_abi/riscv64/include/berberis/guest_abi/guest_abi_arch.h b/guest_abi/riscv64/include/berberis/guest_abi/guest_abi_arch.h
index 8f46ada3..01c4d921 100644
--- a/guest_abi/riscv64/include/berberis/guest_abi/guest_abi_arch.h
+++ b/guest_abi/riscv64/include/berberis/guest_abi/guest_abi_arch.h
@@ -228,9 +228,9 @@ class GuestAbi {
struct GuestArgumentInfo<IntegerType,
kCallingConventionsVariant,
std::enable_if_t<std::is_integral_v<IntegerType>>> {
- // Integers wider than 8 bytes are not supported. They do not appear in the public Android API.
- // TODO: Remove this if 16-byte parameters are encountered.
- static_assert(sizeof(IntegerType) <= 8);
+ // Integers wider than 16 bytes are not supported. They do not appear in the public Android
+ // API.
+ static_assert(sizeof(IntegerType) <= 16);
constexpr static ArgumentClass kArgumentClass = ArgumentClass::kInteger;
constexpr static unsigned kSize = sizeof(IntegerType);
// Use sizeof, not alignof for kAlignment because all integer types are naturally aligned on
diff --git a/guest_abi/riscv64/include/berberis/guest_abi/guest_params_arch.h b/guest_abi/riscv64/include/berberis/guest_abi/guest_params_arch.h
index 31dd1bba..17c92416 100644
--- a/guest_abi/riscv64/include/berberis/guest_abi/guest_params_arch.h
+++ b/guest_abi/riscv64/include/berberis/guest_abi/guest_params_arch.h
@@ -133,6 +133,11 @@ class GuestParamsAndReturn<ReturnType(ParamType...) noexcept(kNoexcept), kCallin
return {conv, return_loc, param_locs};
}
+ constexpr static riscv64::ArgLocation ReturnInfoHelper() {
+ riscv64::CallingConventions conv;
+ return ReturnInfoHelper(conv);
+ }
+
constexpr static riscv64::ArgLocation ReturnInfoHelper(riscv64::CallingConventions& conv) {
using ReturnInfo = GuestArgumentInfo<ReturnType, kCallingConventionsVariant>;
if constexpr (std::is_same_v<ReturnType, void>) {
@@ -153,7 +158,7 @@ class GuestParamsAndReturn<ReturnType(ParamType...) noexcept(kNoexcept), kCallin
constexpr static riscv64::CallingConventions kVaStartBase = std::get<0>(ParamsInfoHelper());
- constexpr static riscv64::ArgLocation kReturnLocation = std::get<1>(ParamsInfoHelper());
+ constexpr static riscv64::ArgLocation kReturnLocation = ReturnInfoHelper();
constexpr static std::array<riscv64::ArgLocation, sizeof...(ParamType)> kParamsLocations =
std::get<2>(ParamsInfoHelper());