Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,7 @@ perfetto_filegroup(
srcs = [
"include/perfetto/base/build_config.h",
"include/perfetto/base/compiler.h",
"include/perfetto/base/endian.h",
"include/perfetto/base/export.h",
"include/perfetto/base/flat_set.h",
"include/perfetto/base/logging.h",
Expand Down Expand Up @@ -1415,7 +1416,6 @@ perfetto_filegroup(
"include/perfetto/ext/base/crash_keys.h",
"include/perfetto/ext/base/ctrl_c_handler.h",
"include/perfetto/ext/base/dynamic_string_writer.h",
"include/perfetto/ext/base/endian.h",
"include/perfetto/ext/base/event_fd.h",
"include/perfetto/ext/base/file_utils.h",
"include/perfetto/ext/base/flags.h",
Expand Down
7 changes: 5 additions & 2 deletions gn/standalone/android.gni
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ declare_args() {
android_abi_target = "aarch64-linux-android"
android_llvm_arch = "aarch64"
} else {
assert(false, "Need android libgcc support for this arch.")
assert(target_os != "android", "Need android libgcc support for this arch.")
android_abi_target = ""
android_llvm_arch = ""
}

if (current_cpu == "x86") {
Expand All @@ -56,6 +58,7 @@ declare_args() {
} else if (current_cpu == "arm64") {
android_app_abi = "arm64-v8a"
} else {
assert(false, "Unknown ABI: " + current_cpu)
assert(target_os != "android", "Unknown ABI: " + current_cpu)
Comment thread
miladfarca marked this conversation as resolved.
android_app_abi = ""
}
}
1 change: 1 addition & 0 deletions include/perfetto/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ source_set("base") {
sources = [
"build_config.h",
"compiler.h",
"endian.h",
"export.h",
"flat_set.h",
"logging.h",
Expand Down
2 changes: 1 addition & 1 deletion include/perfetto/base/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extern "C" void __msan_unpoison(void const volatile*, size_t);
#endif // __clang__

#if defined(__GNUC__) || defined(__clang__)
#define PERFETTO_IS_LITTLE_ENDIAN() __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define PERFETTO_IS_LITTLE_ENDIAN() (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#else
// Assume all MSVC targets are little endian.
#define PERFETTO_IS_LITTLE_ENDIAN() 1
Expand Down
249 changes: 249 additions & 0 deletions include/perfetto/base/endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
/*
* Copyright (C) 2020 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.
*/

#ifndef INCLUDE_PERFETTO_BASE_ENDIAN_H_
#define INCLUDE_PERFETTO_BASE_ENDIAN_H_

#include <stdint.h>
#include <stdlib.h> // For MSVC
#include <string.h>

#include "perfetto/base/build_config.h"
#include "perfetto/base/compiler.h"

namespace perfetto {
namespace base {

#if PERFETTO_BUILDFLAG(PERFETTO_COMPILER_MSVC)
inline uint16_t ByteSwap16(uint16_t x) {
return _byteswap_ushort(x);
}
inline uint32_t ByteSwap32(uint32_t x) {
return _byteswap_ulong(x);
}
inline uint64_t ByteSwap64(uint64_t x) {
return _byteswap_uint64(x);
}
#else
inline uint16_t ByteSwap16(uint16_t x) {
return __builtin_bswap16(x);
}
inline uint32_t ByteSwap32(uint32_t x) {
return __builtin_bswap32(x);
}
inline uint64_t ByteSwap64(uint64_t x) {
return __builtin_bswap64(x);
}
#endif

#if PERFETTO_IS_LITTLE_ENDIAN()
inline uint16_t HostToLE16(uint16_t x) {
return x;
}
inline uint32_t HostToLE32(uint32_t x) {
return x;
}
inline uint64_t HostToLE64(uint64_t x) {
return x;
}
inline uint16_t LE16ToHost(uint16_t x) {
return x;
}
inline uint32_t LE32ToHost(uint32_t x) {
return x;
}
inline uint64_t LE64ToHost(uint64_t x) {
return x;
}
inline uint16_t HostToBE16(uint16_t x) {
return ByteSwap16(x);
}
inline uint32_t HostToBE32(uint32_t x) {
return ByteSwap32(x);
}
inline uint64_t HostToBE64(uint64_t x) {
return ByteSwap64(x);
}
inline uint16_t BE16ToHost(uint16_t x) {
return ByteSwap16(x);
}
inline uint32_t BE32ToHost(uint32_t x) {
return ByteSwap32(x);
}
inline uint64_t BE64ToHost(uint64_t x) {
return ByteSwap64(x);
}
inline float HostToLEFloat(float x) {
return x;
}
inline double HostToLEDouble(double x) {
return x;
}
inline float LEFloatToHost(float x) {
return x;
}
inline double LEDoubleToHost(double x) {
return x;
}
inline float HostToBEFloat(float x) {
uint32_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap32(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline double HostToBEDouble(double x) {
uint64_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap64(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline float BEFloatToHost(float x) {
uint32_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap32(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline double BEDoubleToHost(double x) {
uint64_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap64(u);
memcpy(&x, &u, sizeof(u));
return x;
}
#else
inline uint16_t HostToLE16(uint16_t x) {
return ByteSwap16(x);
}
inline uint32_t HostToLE32(uint32_t x) {
return ByteSwap32(x);
}
inline uint64_t HostToLE64(uint64_t x) {
return ByteSwap64(x);
}
inline uint16_t LE16ToHost(uint16_t x) {
return ByteSwap16(x);
}
inline uint32_t LE32ToHost(uint32_t x) {
return ByteSwap32(x);
}
inline uint64_t LE64ToHost(uint64_t x) {
return ByteSwap64(x);
}
inline uint16_t HostToBE16(uint16_t x) {
return x;
}
inline uint32_t HostToBE32(uint32_t x) {
return x;
}
inline uint64_t HostToBE64(uint64_t x) {
return x;
}
inline uint16_t BE16ToHost(uint16_t x) {
return x;
}
inline uint32_t BE32ToHost(uint32_t x) {
return x;
}
inline uint64_t BE64ToHost(uint64_t x) {
return x;
}
inline float HostToLEFloat(float x) {
uint32_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap32(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline double HostToLEDouble(double x) {
uint64_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap64(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline float LEFloatToHost(float x) {
uint32_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap32(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline double LEDoubleToHost(double x) {
uint64_t u;
memcpy(&u, &x, sizeof(u));
u = ByteSwap64(u);
memcpy(&x, &u, sizeof(u));
return x;
}
inline float HostToBEFloat(float x) {
return x;
}
inline double HostToBEDouble(double x) {
return x;
}
inline float BEFloatToHost(float x) {
return x;
}
inline double BEDoubleToHost(double x) {
return x;
}
#endif

inline uint32_t HostToLE(uint32_t x) {
return HostToLE32(x);
}
inline int32_t HostToLE(int32_t x) {
return static_cast<int32_t>(HostToLE32(static_cast<uint32_t>(x)));
}
inline uint64_t HostToLE(uint64_t x) {
return HostToLE64(x);
}
inline int64_t HostToLE(int64_t x) {
return static_cast<int64_t>(HostToLE64(static_cast<uint64_t>(x)));
}
inline float HostToLE(float x) {
return HostToLEFloat(x);
}
inline double HostToLE(double x) {
return HostToLEDouble(x);
}

inline uint32_t LEToHost(uint32_t x) {
return LE32ToHost(x);
}
inline int32_t LEToHost(int32_t x) {
return static_cast<int32_t>(LE32ToHost(static_cast<uint32_t>(x)));
}
inline uint64_t LEToHost(uint64_t x) {
return LE64ToHost(x);
}
inline int64_t LEToHost(int64_t x) {
return static_cast<int64_t>(LE64ToHost(static_cast<uint64_t>(x)));
}
inline float LEToHost(float x) {
return LEFloatToHost(x);
}
inline double LEToHost(double x) {
return LEDoubleToHost(x);
}

} // namespace base
} // namespace perfetto

#endif // INCLUDE_PERFETTO_BASE_ENDIAN_H_
1 change: 0 additions & 1 deletion include/perfetto/ext/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ source_set("base") {
"crash_keys.h",
"ctrl_c_handler.h",
"dynamic_string_writer.h",
"endian.h",
"event_fd.h",
"file_utils.h",
"flags.h",
Expand Down
76 changes: 0 additions & 76 deletions include/perfetto/ext/base/endian.h

This file was deleted.

Loading
Loading