Commit 93148da7 authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

s390x: simply ByteReverse using templates

Change-Id: I8ec751f578e2d7a790852670690797f19aba74e4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2570220Reviewed-by: 's avatarMilad Fa <mfarazma@redhat.com>
Commit-Queue: Junliang Yan <junyan@redhat.com>
Cr-Commit-Position: refs/heads/master@{#71578}
parent 736e7144
......@@ -2347,34 +2347,6 @@ void Simulator::PrintStopInfo(uint32_t code) {
#define CheckOverflowForShiftLeft(src1, src2) \
(((src1) << (src2)) >> (src2) != (src1))
int16_t Simulator::ByteReverse(int16_t hword) {
#if defined(__GNUC__)
return __builtin_bswap16(hword);
#else
return (hword << 8) | ((hword >> 8) & 0x00FF);
#endif
}
int32_t Simulator::ByteReverse(int32_t word) {
#if defined(__GNUC__)
return __builtin_bswap32(word);
#else
int32_t result = word << 24;
result |= (word << 8) & 0x00FF0000;
result |= (word >> 8) & 0x0000FF00;
result |= (word >> 24) & 0x00000FF;
return result;
#endif
}
int64_t Simulator::ByteReverse(int64_t dword) {
#if defined(__GNUC__)
return __builtin_bswap64(dword);
#else
#error unsupport __builtin_bswap64
#endif
}
int Simulator::DecodeInstruction(Instruction* instr) {
Opcode op = instr->S390OpcodeValue();
DCHECK_NOT_NULL(EvalTable[op]);
......
......@@ -246,9 +246,38 @@ class Simulator : public SimulatorBase {
void PrintStopInfo(uint32_t code);
// Byte Reverse
inline int16_t ByteReverse(int16_t hword);
inline int32_t ByteReverse(int32_t word);
inline int64_t ByteReverse(int64_t dword);
static inline __uint128_t __builtin_bswap128(__uint128_t v) {
union {
uint64_t u64[2];
__uint128_t u128;
} res, val;
val.u128 = v;
res.u64[0] = __builtin_bswap64(val.u64[1]);
res.u64[1] = __builtin_bswap64(val.u64[0]);
return res.u128;
}
template <class T>
static inline T ByteReverse(T val) {
constexpr int size = sizeof(T);
#define CASE(type, size_in_bits) \
case sizeof(type): { \
type res = __builtin_bswap##size_in_bits(*reinterpret_cast<type*>(&val)); \
return *reinterpret_cast<T*>(&res); \
}
switch (size) {
case 1:
return val;
CASE(uint16_t, 16);
CASE(uint32_t, 32);
CASE(uint64_t, 64);
CASE(__uint128_t, 128);
default:
UNREACHABLE();
}
#undef CASE
return val;
}
// Read and write memory.
inline uint8_t ReadBU(intptr_t addr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment