[MODS/VM]: Explain magic values in f32_abs and f64_abs
This commit is contained in:
parent
20ee18b85e
commit
f2fd7a3f1b
1 changed files with 6 additions and 0 deletions
|
|
@ -831,9 +831,11 @@ pub const Runtime = struct {
|
||||||
try self.stack.append(.{ .i64 = @intCast(std.math.rotr(u64, b, a)) });
|
try self.stack.append(.{ .i64 = @intCast(std.math.rotr(u64, b, a)) });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The value 0x7FFFFFFF here represents the bitmask that masks everything except for the IEEE754 32 bit precision sign bit
|
||||||
.f32_abs => {
|
.f32_abs => {
|
||||||
try self.stack.append(.{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) & 0x7FFFFFFF) });
|
try self.stack.append(.{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) & 0x7FFFFFFF) });
|
||||||
},
|
},
|
||||||
|
// The value 0x80000000 here represents the bitmask that only masks the IEEE754 32 bit precision sign bit
|
||||||
.f32_neg => {
|
.f32_neg => {
|
||||||
try self.stack.append(.{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) ^ 0x80000000) });
|
try self.stack.append(.{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) ^ 0x80000000) });
|
||||||
},
|
},
|
||||||
|
|
@ -885,15 +887,18 @@ pub const Runtime = struct {
|
||||||
const b = self.stack.pop().?.f32;
|
const b = self.stack.pop().?.f32;
|
||||||
try self.stack.append(.{ .f32 = @max(a, b) });
|
try self.stack.append(.{ .f32 = @max(a, b) });
|
||||||
},
|
},
|
||||||
|
// See f32_abs and f32_neg for explainations behind these magic values
|
||||||
.f32_copysign => {
|
.f32_copysign => {
|
||||||
const a = self.stack.pop().?.f32;
|
const a = self.stack.pop().?.f32;
|
||||||
const b = self.stack.pop().?.f32;
|
const b = self.stack.pop().?.f32;
|
||||||
try self.stack.append(.{ .f32 = @bitCast((@as(u32, @bitCast(b)) & 0x7FFFFFFF) | (@as(u32, @bitCast(a)) & 0x80000000)) });
|
try self.stack.append(.{ .f32 = @bitCast((@as(u32, @bitCast(b)) & 0x7FFFFFFF) | (@as(u32, @bitCast(a)) & 0x80000000)) });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The value 0x7FFFFFFFFFFFFFFF here represents the bitmask that masks everything except for the IEEE754 64 bit precision sign bit
|
||||||
.f64_abs => {
|
.f64_abs => {
|
||||||
try self.stack.append(.{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) & 0x7FFFFFFFFFFFFFFF) });
|
try self.stack.append(.{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) & 0x7FFFFFFFFFFFFFFF) });
|
||||||
},
|
},
|
||||||
|
// The value 0x8000000000000000 here represents the bitmask that only masks the IEEE754 64 bit precision sign bit
|
||||||
.f64_neg => {
|
.f64_neg => {
|
||||||
try self.stack.append(.{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) ^ 0x8000000000000000) });
|
try self.stack.append(.{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) ^ 0x8000000000000000) });
|
||||||
},
|
},
|
||||||
|
|
@ -942,6 +947,7 @@ pub const Runtime = struct {
|
||||||
const b = self.stack.pop().?.f64;
|
const b = self.stack.pop().?.f64;
|
||||||
try self.stack.append(.{ .f64 = @max(a, b) });
|
try self.stack.append(.{ .f64 = @max(a, b) });
|
||||||
},
|
},
|
||||||
|
// See f64_abs and f64_neg for explainations behind these magic values
|
||||||
.f64_copysign => {
|
.f64_copysign => {
|
||||||
const a = self.stack.pop().?.f64;
|
const a = self.stack.pop().?.f64;
|
||||||
const b = self.stack.pop().?.f64;
|
const b = self.stack.pop().?.f64;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue