Commit 69a77f65 authored by Milad Fa's avatar Milad Fa Committed by V8 LUCI CQ

PPC/S390: Use ByteReverse from utils

This CL removes the the usage of custom byte reversing functions from
the simulator and uses the one provided by V8 utils under:
```
src/utils/utils.h
```

Change-Id: I9a334a10d659b8a3315c34563eb3e6f84644a9e8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3714898
Commit-Queue: Milad Farazmand <mfarazma@redhat.com>
Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Cr-Commit-Position: refs/heads/main@{#81261}
parent 308a7e2f
...@@ -3189,7 +3189,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3189,7 +3189,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
int rb = instr->RBValue(); int rb = instr->RBValue();
intptr_t ra_val = ra == 0 ? 0 : get_register(ra); intptr_t ra_val = ra == 0 ? 0 : get_register(ra);
intptr_t rb_val = get_register(rb); intptr_t rb_val = get_register(rb);
intptr_t result = __builtin_bswap64(ReadDW(ra_val + rb_val)); intptr_t result = ByteReverse<int64_t>(ReadDW(ra_val + rb_val));
set_register(rt, result); set_register(rt, result);
break; break;
} }
...@@ -3199,7 +3199,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3199,7 +3199,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
int rb = instr->RBValue(); int rb = instr->RBValue();
intptr_t ra_val = ra == 0 ? 0 : get_register(ra); intptr_t ra_val = ra == 0 ? 0 : get_register(ra);
intptr_t rb_val = get_register(rb); intptr_t rb_val = get_register(rb);
intptr_t result = __builtin_bswap32(ReadW(ra_val + rb_val)); intptr_t result = ByteReverse<int32_t>(ReadW(ra_val + rb_val));
set_register(rt, result); set_register(rt, result);
break; break;
} }
...@@ -3210,7 +3210,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3210,7 +3210,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
intptr_t ra_val = ra == 0 ? 0 : get_register(ra); intptr_t ra_val = ra == 0 ? 0 : get_register(ra);
intptr_t rs_val = get_register(rs); intptr_t rs_val = get_register(rs);
intptr_t rb_val = get_register(rb); intptr_t rb_val = get_register(rb);
WriteDW(ra_val + rb_val, __builtin_bswap64(rs_val)); WriteDW(ra_val + rb_val, ByteReverse<int64_t>(rs_val));
break; break;
} }
case STWBRX: { case STWBRX: {
...@@ -3220,7 +3220,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3220,7 +3220,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
intptr_t ra_val = ra == 0 ? 0 : get_register(ra); intptr_t ra_val = ra == 0 ? 0 : get_register(ra);
intptr_t rs_val = get_register(rs); intptr_t rs_val = get_register(rs);
intptr_t rb_val = get_register(rb); intptr_t rb_val = get_register(rb);
WriteW(ra_val + rb_val, __builtin_bswap32(rs_val)); WriteW(ra_val + rb_val, ByteReverse<int32_t>(rs_val));
break; break;
} }
case STHBRX: { case STHBRX: {
...@@ -3230,7 +3230,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3230,7 +3230,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
intptr_t ra_val = ra == 0 ? 0 : get_register(ra); intptr_t ra_val = ra == 0 ? 0 : get_register(ra);
intptr_t rs_val = get_register(rs); intptr_t rs_val = get_register(rs);
intptr_t rb_val = get_register(rb); intptr_t rb_val = get_register(rb);
WriteH(ra_val + rb_val, __builtin_bswap16(rs_val)); WriteH(ra_val + rb_val, ByteReverse<int16_t>(rs_val));
break; break;
} }
case STDX: case STDX:
...@@ -3496,8 +3496,8 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3496,8 +3496,8 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
uint64_t rs_val = get_register(rs); uint64_t rs_val = get_register(rs);
uint32_t rs_high = rs_val >> kBitsPerWord; uint32_t rs_high = rs_val >> kBitsPerWord;
uint32_t rs_low = (rs_val << kBitsPerWord) >> kBitsPerWord; uint32_t rs_low = (rs_val << kBitsPerWord) >> kBitsPerWord;
uint64_t result = __builtin_bswap32(rs_high); uint64_t result = ByteReverse<int32_t>(rs_high);
result = (result << kBitsPerWord) | __builtin_bswap32(rs_low); result = (result << kBitsPerWord) | ByteReverse<int32_t>(rs_low);
set_register(ra, result); set_register(ra, result);
break; break;
} }
...@@ -3505,7 +3505,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) { ...@@ -3505,7 +3505,7 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
int rs = instr->RSValue(); int rs = instr->RSValue();
int ra = instr->RAValue(); int ra = instr->RAValue();
uint64_t rs_val = get_register(rs); uint64_t rs_val = get_register(rs);
set_register(ra, __builtin_bswap64(rs_val)); set_register(ra, ByteReverse<int64_t>(rs_val));
break; break;
} }
case FCFIDS: { case FCFIDS: {
......
...@@ -328,8 +328,8 @@ class Simulator : public SimulatorBase { ...@@ -328,8 +328,8 @@ class Simulator : public SimulatorBase {
__uint128_t u128; __uint128_t u128;
} res, val; } res, val;
val.u128 = v; val.u128 = v;
res.u64[0] = __builtin_bswap64(val.u64[1]); res.u64[0] = ByteReverse<int64_t>(val.u64[1]);
res.u64[1] = __builtin_bswap64(val.u64[0]); res.u64[1] = ByteReverse<int64_t>(val.u64[0]);
return res.u128; return res.u128;
} }
......
...@@ -8372,7 +8372,7 @@ EVALUATE(LRVGR) { ...@@ -8372,7 +8372,7 @@ EVALUATE(LRVGR) {
DCHECK_OPCODE(LRVGR); DCHECK_OPCODE(LRVGR);
DECODE_RRE_INSTRUCTION(r1, r2); DECODE_RRE_INSTRUCTION(r1, r2);
int64_t r2_val = get_register(r2); int64_t r2_val = get_register(r2);
int64_t r1_val = ByteReverse(r2_val); int64_t r1_val = ByteReverse<int64_t>(r2_val);
set_register(r1, r1_val); set_register(r1, r1_val);
return length; return length;
...@@ -8508,7 +8508,7 @@ EVALUATE(LRVR) { ...@@ -8508,7 +8508,7 @@ EVALUATE(LRVR) {
DCHECK_OPCODE(LRVR); DCHECK_OPCODE(LRVR);
DECODE_RRE_INSTRUCTION(r1, r2); DECODE_RRE_INSTRUCTION(r1, r2);
int32_t r2_val = get_low_register<int32_t>(r2); int32_t r2_val = get_low_register<int32_t>(r2);
int32_t r1_val = ByteReverse(r2_val); int32_t r1_val = ByteReverse<int32_t>(r2_val);
set_low_register(r1, r1_val); set_low_register(r1, r1_val);
return length; return length;
...@@ -9471,7 +9471,7 @@ EVALUATE(LRVG) { ...@@ -9471,7 +9471,7 @@ EVALUATE(LRVG) {
int64_t b2_val = (b2 == 0) ? 0 : get_register(b2); int64_t b2_val = (b2 == 0) ? 0 : get_register(b2);
intptr_t mem_addr = b2_val + x2_val + d2; intptr_t mem_addr = b2_val + x2_val + d2;
int64_t mem_val = ReadW64(mem_addr); int64_t mem_val = ReadW64(mem_addr);
set_register(r1, ByteReverse(mem_val)); set_register(r1, ByteReverse<int64_t>(mem_val));
return length; return length;
} }
...@@ -9482,7 +9482,7 @@ EVALUATE(LRV) { ...@@ -9482,7 +9482,7 @@ EVALUATE(LRV) {
int64_t b2_val = (b2 == 0) ? 0 : get_register(b2); int64_t b2_val = (b2 == 0) ? 0 : get_register(b2);
intptr_t mem_addr = b2_val + x2_val + d2; intptr_t mem_addr = b2_val + x2_val + d2;
int32_t mem_val = ReadW(mem_addr); int32_t mem_val = ReadW(mem_addr);
set_low_register(r1, ByteReverse(mem_val)); set_low_register(r1, ByteReverse<int32_t>(mem_val));
return length; return length;
} }
...@@ -9494,7 +9494,7 @@ EVALUATE(LRVH) { ...@@ -9494,7 +9494,7 @@ EVALUATE(LRVH) {
int64_t b2_val = (b2 == 0) ? 0 : get_register(b2); int64_t b2_val = (b2 == 0) ? 0 : get_register(b2);
intptr_t mem_addr = b2_val + x2_val + d2; intptr_t mem_addr = b2_val + x2_val + d2;
int16_t mem_val = ReadH(mem_addr); int16_t mem_val = ReadH(mem_addr);
int32_t result = ByteReverse(mem_val) & 0x0000FFFF; int32_t result = ByteReverse<int16_t>(mem_val) & 0x0000FFFF;
result |= r1_val & 0xFFFF0000; result |= r1_val & 0xFFFF0000;
set_low_register(r1, result); set_low_register(r1, result);
return length; return length;
...@@ -9579,7 +9579,7 @@ EVALUATE(STRV) { ...@@ -9579,7 +9579,7 @@ EVALUATE(STRV) {
int64_t x2_val = (x2 == 0) ? 0 : get_register(x2); int64_t x2_val = (x2 == 0) ? 0 : get_register(x2);
int64_t b2_val = (b2 == 0) ? 0 : get_register(b2); int64_t b2_val = (b2 == 0) ? 0 : get_register(b2);
intptr_t mem_addr = b2_val + x2_val + d2; intptr_t mem_addr = b2_val + x2_val + d2;
WriteW(mem_addr, ByteReverse(r1_val)); WriteW(mem_addr, ByteReverse<int32_t>(r1_val));
return length; return length;
} }
...@@ -9590,7 +9590,7 @@ EVALUATE(STRVG) { ...@@ -9590,7 +9590,7 @@ EVALUATE(STRVG) {
int64_t x2_val = (x2 == 0) ? 0 : get_register(x2); int64_t x2_val = (x2 == 0) ? 0 : get_register(x2);
int64_t b2_val = (b2 == 0) ? 0 : get_register(b2); int64_t b2_val = (b2 == 0) ? 0 : get_register(b2);
intptr_t mem_addr = b2_val + x2_val + d2; intptr_t mem_addr = b2_val + x2_val + d2;
WriteDW(mem_addr, ByteReverse(r1_val)); WriteDW(mem_addr, ByteReverse<int64_t>(r1_val));
return length; return length;
} }
...@@ -9602,7 +9602,7 @@ EVALUATE(STRVH) { ...@@ -9602,7 +9602,7 @@ EVALUATE(STRVH) {
int64_t b2_val = (b2 == 0) ? 0 : get_register(b2); int64_t b2_val = (b2 == 0) ? 0 : get_register(b2);
intptr_t mem_addr = b2_val + x2_val + d2; intptr_t mem_addr = b2_val + x2_val + d2;
int16_t result = static_cast<int16_t>(r1_val >> 16); int16_t result = static_cast<int16_t>(r1_val >> 16);
WriteH(mem_addr, ByteReverse(result)); WriteH(mem_addr, ByteReverse<int16_t>(result));
return length; return length;
} }
......
...@@ -240,40 +240,6 @@ class Simulator : public SimulatorBase { ...@@ -240,40 +240,6 @@ class Simulator : public SimulatorBase {
inline void IncreaseStopCounter(uint32_t bkpt_code); inline void IncreaseStopCounter(uint32_t bkpt_code);
void PrintStopInfo(uint32_t code); void PrintStopInfo(uint32_t code);
// Byte Reverse
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. // Read and write memory.
inline uint8_t ReadBU(intptr_t addr); inline uint8_t ReadBU(intptr_t addr);
inline int8_t ReadB(intptr_t addr); inline int8_t ReadB(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