Commit eb27388b authored by yangguo's avatar yangguo Committed by Commit bot

Use bit_cast for Runtime_Double{Hi,Lo}.

To avoid undefined behavior.

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/977923002

Cr-Commit-Position: refs/heads/master@{#26998}
parent c8f9d7ab
......@@ -34,9 +34,10 @@ RUNTIME_FUNCTION(Runtime_DoubleHi) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_DOUBLE_ARG_CHECKED(x, 0);
uint64_t integer = double_to_uint64(x);
integer = (integer >> 32) & 0xFFFFFFFFu;
return *isolate->factory()->NewNumber(static_cast<int32_t>(integer));
uint64_t unsigned64 = double_to_uint64(x);
uint32_t unsigned32 = static_cast<uint32_t>(unsigned64 >> 32);
int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32);
return *isolate->factory()->NewNumber(signed32);
}
......@@ -44,8 +45,10 @@ RUNTIME_FUNCTION(Runtime_DoubleLo) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_DOUBLE_ARG_CHECKED(x, 0);
return *isolate->factory()->NewNumber(
static_cast<int32_t>(double_to_uint64(x) & 0xFFFFFFFFu));
uint64_t unsigned64 = double_to_uint64(x);
uint32_t unsigned32 = static_cast<uint32_t>(unsigned64);
int32_t signed32 = bit_cast<int32_t, uint32_t>(unsigned32);
return *isolate->factory()->NewNumber(signed32);
}
......
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