Skip to content

Truly independent web browser

LibJS/Flap: Add a compressed cell pointer field representation

Andreas Klingaa8c60097768
diff --git a/Libraries/LibJS/Flap/src/frontend/layout.rs b/Libraries/LibJS/Flap/src/frontend/layout.rs
index 6dc6981026c..e0edd296e28 100644
--- a/Libraries/LibJS/Flap/src/frontend/layout.rs
+++ b/Libraries/LibJS/Flap/src/frontend/layout.rs
@@ -192,6 +192,9 @@ pub(crate) struct Field {
pub(crate) nonnull: bool,
pub(crate) embedded: bool,
pub(crate) cell_pointer: bool,
+ /// Whether the cell pointer is stored compressed, as the cell's offset into the heap region in units of 8 bytes in
+ /// a u32 (0 for null), which loads decode with the heap region base.
+ pub(crate) compressed: bool,
pub(crate) pair: Option<String>,
pub(crate) pinned_base: Option<String>,
pub(crate) pinned_offset: Option<LayoutValue>,
@@ -207,6 +210,7 @@ struct UnresolvedField {
nonnull: bool,
embedded: bool,
cell_pointer: bool,
+ compressed: bool,
pair: Option<String>,
pinned_base: Option<String>,
pinned_offset: Option<String>,
@@ -287,9 +291,10 @@ impl LayoutDatabase {
));
}
};
- let cell_pointer = match words[4] {
- "cell" => true,
- "scalar" => false,
+ let (cell_pointer, compressed) = match words[4] {
+ "cell" => (true, false),
+ "compressed" => (true, true),
+ "scalar" => (false, false),
representation => {
return Err(LayoutError::new(
line_number,
@@ -303,6 +308,12 @@ impl LayoutDatabase {
"embedded fields must use scalar representation",
));
}
+ if compressed && words.len() > 5 {
+ return Err(LayoutError::new(
+ line_number,
+ "compressed cell pointer fields take no modifiers",
+ ));
+ }
if cell_pointer && ty.width() != Some(8) {
return Err(LayoutError::new(
line_number,
@@ -357,6 +368,7 @@ impl LayoutDatabase {
nonnull,
embedded,
cell_pointer,
+ compressed,
pair,
pinned_base,
pinned_offset,
@@ -375,6 +387,7 @@ impl LayoutDatabase {
nonnull: field.nonnull,
embedded: field.embedded,
cell_pointer: field.cell_pointer,
+ compressed: field.compressed,
pair: field.pair,
pinned_base: field.pinned_base,
pinned_offset: field
@@ -480,6 +493,31 @@ mod tests {
assert_eq!(database.fields()[0].ty, Type::Shape);
assert!(database.fields()[0].nonnull);
assert!(database.fields()[0].cell_pointer);
+ assert!(!database.fields()[0].compressed);
+ }
+
+ #[test]
+ fn parses_compressed_cell_pointer_fields() {
+ let database = LayoutDatabase::parse(
+ "const ENVIRONMENT_OUTER = 16\nfield Environment.outer Environment ENVIRONMENT_OUTER nullable compressed\n",
+ )
+ .unwrap();
+
+ assert_eq!(database.fields()[0].ty, Type::Environment);
+ assert!(!database.fields()[0].nonnull);
+ assert!(database.fields()[0].cell_pointer);
+ assert!(database.fields()[0].compressed);
+
+ let error = LayoutDatabase::parse("field Environment.outer Environment 16 nullable compressed outer_pair\n")
+ .unwrap_err();
+ assert!(
+ error
+ .message
+ .contains("compressed cell pointer fields take no modifiers")
+ );
+
+ let error = LayoutDatabase::parse("field Environment.declarative u8 0 nullable compressed\n").unwrap_err();
+ assert!(error.message.contains("cell pointer field must be 64 bits"));
}
#[test]
diff --git a/Libraries/LibJS/Flap/src/hir/mod.rs b/Libraries/LibJS/Flap/src/hir/mod.rs
index f0672ce16d5..19632f7327e 100644
--- a/Libraries/LibJS/Flap/src/hir/mod.rs
+++ b/Libraries/LibJS/Flap/src/hir/mod.rs
@@ -91,6 +91,7 @@ struct LayoutField {
nonnull: bool,
embedded: bool,
cell_pointer: bool,
+ compressed: bool,
pair: Option<FieldPair>,
pinned_base: Option<String>,
pinned_offset: Option<layout::LayoutValue>,
@@ -1591,7 +1592,10 @@ impl<'a> Checker<'a> {
}
let width = field_width(&field.ty, false)
.ok_or_else(|| Diagnostic::new(self.filename, span, format!("cannot load field of type {}", field.ty)))?;
- let kind = if field.cell_pointer {
+ let kind = if field.compressed {
+ debug_assert_eq!(width, FieldWidth::U64);
+ FieldAccessKind::LoadCompressedCellPointer { nonzero: field.nonnull }
+ } else if field.cell_pointer {
debug_assert_eq!(width, FieldWidth::U64);
FieldAccessKind::LoadCellPointer { nonzero: field.nonnull }
} else {
@@ -1679,6 +1683,12 @@ impl<'a> Checker<'a> {
if field.embedded {
return self.error(span, format!("cannot assign embedded field '{}.{field_name}'", base.ty));
}
+ if field.compressed {
+ return self.error(
+ span,
+ format!("cannot store compressed cell pointer field '{}.{field_name}'", base.ty),
+ );
+ }
if field.nonnull && self.initializer_is_known_null_pointer(initializer, &field.ty) {
return self.error(
initializer.span,
@@ -3548,6 +3558,7 @@ pub(crate) fn check_with_layouts(
nonnull: field.nonnull,
embedded: field.embedded,
cell_pointer: field.cell_pointer,
+ compressed: field.compressed,
pair,
pinned_base: field.pinned_base.clone(),
pinned_offset: field.pinned_offset,
@@ -4615,6 +4626,65 @@ handler Read(address: u64) {
assert_eq!(field_access.kind, FieldAccessKind::LoadCellPointer { nonzero: true });
}
+ #[test]
+ fn routes_compressed_cell_pointer_fields_through_compressed_loads() {
+ let layouts = crate::frontend::layout::LayoutDatabase::parse(
+ "const OUTER = 16\nfield Environment.outer Environment OUTER nullable compressed\n",
+ )
+ .unwrap();
+ let ast = parser::parse(
+ "test.flap",
+ r#"
+handler Read(address: u64) {
+ let environment: Environment = alias(address);
+ let outer = environment.outer;
+ assert(outer != 0);
+ dispatch_next;
+}
+"#,
+ )
+ .unwrap();
+ let program = check_with_layouts("test.flap", &ast, layouts.fields()).unwrap();
+ let field_access = program.handlers[0]
+ .body
+ .statements
+ .iter()
+ .find_map(|statement| match &statement.kind {
+ StatementKindIr::Call(_, call) => call.field_access(),
+ _ => None,
+ })
+ .unwrap();
+
+ assert_eq!(
+ field_access.kind,
+ FieldAccessKind::LoadCompressedCellPointer { nonzero: false }
+ );
+ }
+
+ #[test]
+ fn rejects_stores_to_compressed_cell_pointer_fields() {
+ let layouts = crate::frontend::layout::LayoutDatabase::parse(
+ "const OUTER = 16\nfield Environment.outer Environment OUTER nullable compressed\n",
+ )
+ .unwrap();
+ let ast = parser::parse(
+ "test.flap",
+ r#"
+handler Write(address: u64) {
+ let environment: Environment = alias(address);
+ environment.outer = environment;
+ dispatch_next;
+}
+"#,
+ )
+ .unwrap();
+ let error = check_with_layouts("test.flap", &ast, layouts.fields()).unwrap_err();
+ assert!(
+ error.to_string().contains("cannot store compressed cell pointer field"),
+ "{error}"
+ );
+ }
+
accepts!(
explicitly_widens_refined_values,
r#"
diff --git a/Libraries/LibJS/Flap/src/intrinsic.rs b/Libraries/LibJS/Flap/src/intrinsic.rs
index eda648b9101..4962b5411e6 100644
--- a/Libraries/LibJS/Flap/src/intrinsic.rs
+++ b/Libraries/LibJS/Flap/src/intrinsic.rs
@@ -200,8 +200,17 @@ impl From<FieldWidth> for MemoryWidth {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum FieldAccessKind {
- Load { width: FieldWidth, nonzero: bool },
- LoadCellPointer { nonzero: bool },
+ Load {
+ width: FieldWidth,
+ nonzero: bool,
+ },
+ LoadCellPointer {
+ nonzero: bool,
+ },
+ /// A cell pointer stored compressed in 32 bits, which the load decodes.
+ LoadCompressedCellPointer {
+ nonzero: bool,
+ },
Store(FieldWidth),
}
@@ -210,6 +219,7 @@ impl FieldAccessKind {
match self {
Self::Load { width, .. } | Self::Store(width) => width,
Self::LoadCellPointer { .. } => FieldWidth::U64,
+ Self::LoadCompressedCellPointer { .. } => FieldWidth::U32,
}
}
@@ -220,7 +230,9 @@ impl FieldAccessKind {
pub(crate) fn nonzero(self) -> bool {
matches!(
self,
- Self::Load { nonzero: true, .. } | Self::LoadCellPointer { nonzero: true }
+ Self::Load { nonzero: true, .. }
+ | Self::LoadCellPointer { nonzero: true }
+ | Self::LoadCompressedCellPointer { nonzero: true }
)
}
@@ -232,6 +244,8 @@ impl FieldAccessKind {
} => MemoryOperation::Load64NonZero,
Self::LoadCellPointer { nonzero: true } => MemoryOperation::LoadNonnullCellPointer,
Self::LoadCellPointer { nonzero: false } => MemoryOperation::LoadCellPointer,
+ Self::LoadCompressedCellPointer { nonzero: true } => MemoryOperation::LoadNonnullCompressedCellPointer,
+ Self::LoadCompressedCellPointer { nonzero: false } => MemoryOperation::LoadCompressedCellPointer,
Self::Load { width, .. } => MemoryOperation::Load {
width: width.into(),
signed: false,
@@ -1441,6 +1455,8 @@ pub(crate) enum MemoryOperation {
Load64NonZero,
LoadCellPointer,
LoadNonnullCellPointer,
+ LoadCompressedCellPointer,
+ LoadNonnullCompressedCellPointer,
Store(MemoryWidth),
LoadPair(PairWidth),
StorePair(PairWidth),
@@ -1456,6 +1472,8 @@ intrinsic_names!(MemoryOperation {
Self::Load64NonZero => "load64_nonzero" signatures [signature!([Out AnyGpr, In Memory])];
Self::LoadCellPointer => "load_cell_ptr" signatures [signature!([Out AnyGpr, In Memory])];
Self::LoadNonnullCellPointer => "load_nonnull_cell_ptr" signatures [signature!([Out AnyGpr, In Memory])];
+ Self::LoadCompressedCellPointer => "load_compressed_cell_ptr" signatures [signature!([Out AnyGpr, In Memory])];
+ Self::LoadNonnullCompressedCellPointer => "load_nonnull_compressed_cell_ptr" signatures [signature!([Out AnyGpr, In Memory])];
Self::Load { width: MemoryWidth::Float, signed: false } => "loadf32" signatures [signature!([Out F32, In Memory])];
Self::Load { width: MemoryWidth::Double, signed: false } => "loadf64" signatures [signature!([Out F64, In Memory])];
Self::Load { width: MemoryWidth::Vector, signed: false } => "load128" signatures [signature!([Out V128, In Memory])];
@@ -1476,7 +1494,10 @@ impl MemoryOperation {
pub(crate) fn effects(self) -> IntrinsicEffects {
IntrinsicEffects {
memory: if self.writes() { ModRef::Write } else { ModRef::Read },
- may_trap: matches!(self, Self::Load64NonZero | Self::LoadNonnullCellPointer),
+ may_trap: matches!(
+ self,
+ Self::Load64NonZero | Self::LoadNonnullCellPointer | Self::LoadNonnullCompressedCellPointer
+ ),
..IntrinsicEffects::PURE
}
}
@@ -1495,6 +1516,7 @@ impl MemoryOperation {
match self {
Self::Load { width, .. } | Self::Store(width) => width,
Self::Load64NonZero | Self::LoadCellPointer | Self::LoadNonnullCellPointer => MemoryWidth::DoubleWord,
+ Self::LoadCompressedCellPointer | Self::LoadNonnullCompressedCellPointer => MemoryWidth::Word,
Self::LoadPair(PairWidth::Word) | Self::StorePair(PairWidth::Word) => MemoryWidth::Word,
Self::LoadPair(PairWidth::DoubleWord) | Self::StorePair(PairWidth::DoubleWord) => MemoryWidth::DoubleWord,
}
diff --git a/Libraries/LibJS/Flap/src/lib.rs b/Libraries/LibJS/Flap/src/lib.rs
index fc375071d18..86ccecc9b8c 100644
--- a/Libraries/LibJS/Flap/src/lib.rs
+++ b/Libraries/LibJS/Flap/src/lib.rs
@@ -928,6 +928,61 @@ handler Widen(dst: out Operand, src: in Operand) {
}
}
+ #[test]
+ fn decodes_compressed_cell_pointer_fields_with_the_heap_region_base() {
+ const LAYOUT: &str = r#"
+const ENVIRONMENT_OUTER = 16
+field Environment.outer Environment ENVIRONMENT_OUTER nullable compressed
+const ECMASCRIPT_FUNCTION_OBJECT_SHARED_DATA = 76
+field ECMAScriptFunctionObject.shared_data SharedFunctionInstanceData ECMASCRIPT_FUNCTION_OBJECT_SHARED_DATA nonnull compressed
+const EXECUTION_CONTEXT_LEXICAL_ENVIRONMENT = 24
+field ExecutionContext.lexical_environment Environment EXECUTION_CONTEXT_LEXICAL_ENVIRONMENT nullable cell
+const EXECUTION_CONTEXT_VARIABLE_ENVIRONMENT = 32
+field ExecutionContext.variable_environment Environment EXECUTION_CONTEXT_VARIABLE_ENVIRONMENT nullable cell
+"#;
+ let source = r#"
+handler Outer() {
+ let environment = exec_ctx.lexical_environment;
+ let outer = environment.outer;
+ exec_ctx.lexical_environment = outer;
+ let function: ECMAScriptFunctionObject = alias(environment);
+ let shared_data = function.shared_data;
+ let shared_data_environment: Environment = alias(shared_data);
+ exec_ctx.variable_environment = shared_data_environment;
+ dispatch_next;
+}
+"#;
+ let layout = format!("{REQUIRED_LAYOUT}{LAYOUT}");
+ for architecture in [Architecture::X86_64, Architecture::Aarch64] {
+ let assembly = compiler(architecture)
+ .compile(CompilationUnit {
+ source: SourceInput {
+ name: "test.flap",
+ contents: source,
+ },
+ constants: Some(SourceInput {
+ name: "layout.conf",
+ contents: &layout,
+ }),
+ })
+ .unwrap();
+ let assembly = assembly.as_str();
+ match architecture {
+ Architecture::X86_64 => {
+ assert!(assembly.contains("+ 16]"), "{assembly}");
+ assert!(assembly.contains("lea r11, [r15 + "), "{assembly}");
+ assert!(assembly.contains("cmovnz r"), "{assembly}");
+ assert!(assembly.contains("+ 76]"), "{assembly}");
+ }
+ Architecture::Aarch64 => {
+ assert!(assembly.contains("add x9, x24, w"), "{assembly}");
+ assert!(assembly.contains("uxtw #3"), "{assembly}");
+ assert!(assembly.contains(", x9, xzr, ne"), "{assembly}");
+ }
+ }
+ }
+ }
+
#[test]
fn compiles_from_in_memory_sources_for_each_target() {
for architecture in [Architecture::X86_64, Architecture::Aarch64] {
diff --git a/Libraries/LibJS/Flap/src/low_ir/lowering.rs b/Libraries/LibJS/Flap/src/low_ir/lowering.rs
index 107b028300f..abdef42e9e1 100644
--- a/Libraries/LibJS/Flap/src/low_ir/lowering.rs
+++ b/Libraries/LibJS/Flap/src/low_ir/lowering.rs
@@ -2132,6 +2132,19 @@ fn lower_memory_operation(
return Err("'load_cell_ptr' requires one result and one address".to_string());
};
emit!(output; MachineOperation::load(MemoryWidth::DoubleWord, false) => [destination.clone(), address.clone()];);
+ } else if matches!(
+ operation,
+ MemoryOperation::LoadCompressedCellPointer | MemoryOperation::LoadNonnullCompressedCellPointer
+ ) {
+ let ([destination], [address]) = (results, inputs) else {
+ return Err("'load_compressed_cell_ptr' requires one result and one address".to_string());
+ };
+ let nullable = operation == MemoryOperation::LoadCompressedCellPointer;
+ emit!(output; MachineOperation::load(MemoryWidth::Word, false) => [destination.clone(), address.clone()];);
+ if !nullable {
+ emit!(output; MachineOperation::AssertNonzero => [destination.clone()];);
+ }
+ emit!(output; MachineOperation::DecompressCellPointer { nullable } => [destination.clone(), destination.clone()];);
} else {
output.push(machine_instruction(
MachineOperation::Memory(operation),
diff --git a/Libraries/LibJS/Flap/src/target/aarch64.rs b/Libraries/LibJS/Flap/src/target/aarch64.rs
index cc6bd12a647..83fd952d24e 100644
--- a/Libraries/LibJS/Flap/src/target/aarch64.rs
+++ b/Libraries/LibJS/Flap/src/target/aarch64.rs
@@ -347,6 +347,8 @@ define_machine_opcodes! {
.is_some_and(|value| (0..=4095).contains(&value))
} printing simple!(add_subtract_mnemonic(operation, FlagUpdate::Set); word(0), word(0), SimpleOperand::HashImmediate(1, false));
[AddSubtract32RegisterWithFlags(AddSubtractOperation)] => Self::AddSubtract32RegisterWithFlags(operation) => [[R, R]] printing simple!(add_subtract_mnemonic(operation, FlagUpdate::Set); word(0), word(0), word(1));
+ [DecompressCellPointer] => Self::DecompressCellPointer => [[R, R]] printing simple!("add"; native(0), SimpleOperand::Literal("x24"), word(1), SimpleOperand::Literal("uxtw #3"));
+ [SelectNotEqualElseZero] => Self::SelectNotEqualElseZero => [[R, R]] printing simple!("csel"; native(0), native(1), SimpleOperand::Literal("xzr"), SimpleOperand::Literal("ne"));
[AddShiftedRegister { shift: AddressIndexShift }] => Self::AddShiftedRegister { shift } => [[R, R, R]] printing simple!("add"; native(0), native(1), native(2), SimpleOperand::ShiftValue(shift.amount()));
[MultiplyAdd64] => Self::MultiplyAdd64 => [[R, R, R, R]] printing simple!("madd"; native(0), native(1), native(2), native(3));
[LogicalImmediate { operation: LogicalOperation, width: IntegerWidth }] => Self::LogicalImmediate { operation, width } => [[R, R, I]] encoding {
diff --git a/Libraries/LibJS/Flap/src/target/aarch64/finalize.rs b/Libraries/LibJS/Flap/src/target/aarch64/finalize.rs
index b8ef6f77c2d..93fe365130c 100644
--- a/Libraries/LibJS/Flap/src/target/aarch64/finalize.rs
+++ b/Libraries/LibJS/Flap/src/target/aarch64/finalize.rs
@@ -33,7 +33,7 @@ use crate::target::ir::{
use crate::target::machine_verify::emit_machine_instructions as emit;
use crate::target::registers::{
PhysicalRegister,
- aarch64::{X21, X22, X23, X24, X25, X26, XZR},
+ aarch64::{X9, X21, X22, X23, X24, X25, X26, XZR},
};
use crate::{Architecture, CompileError, CompileStage, Target};
@@ -1630,6 +1630,24 @@ impl Backend for Aarch64Backend {
Ok(())
}
+ fn decompress_cell_pointer(
+ &self,
+ emit: &mut Emit<'_>,
+ destination: PhysicalRegister,
+ source: PhysicalRegister,
+ nullable: bool,
+ ) {
+ if !nullable {
+ emit!(emit.output, Aarch64; Opcode::DecompressCellPointer => [register destination, register source];);
+ return;
+ }
+ emit!(emit.output, Aarch64;
+ Opcode::DecompressCellPointer => [register X9, register source];
+ Opcode::CompareImmediate(IntegerWidth::U32) => [register source, immediate 0];
+ Opcode::SelectNotEqualElseZero => [register destination, register X9];
+ );
+ }
+
fn float_operation(
&self,
emit: &mut Emit<'_>,
diff --git a/Libraries/LibJS/Flap/src/target/backend.rs b/Libraries/LibJS/Flap/src/target/backend.rs
index ecfdb6a383c..0819fe3b00a 100644
--- a/Libraries/LibJS/Flap/src/target/backend.rs
+++ b/Libraries/LibJS/Flap/src/target/backend.rs
@@ -81,6 +81,16 @@ pub(crate) trait Backend: Sync {
source: PhysicalRegister,
) -> Result<(), CompileError>;
+ /// `destination = heap_region_base + (source << 3)`, with the base in its pinned register, and 0 if `nullable` and
+ /// `source` is 0. `source` holds a compressed cell pointer, zero-extended.
+ fn decompress_cell_pointer(
+ &self,
+ emit: &mut Emit<'_>,
+ destination: PhysicalRegister,
+ source: PhysicalRegister,
+ nullable: bool,
+ );
+
fn float_operation(
&self,
emit: &mut Emit<'_>,
diff --git a/Libraries/LibJS/Flap/src/target/description.rs b/Libraries/LibJS/Flap/src/target/description.rs
index 831b6529a48..2b87f6b02c2 100644
--- a/Libraries/LibJS/Flap/src/target/description.rs
+++ b/Libraries/LibJS/Flap/src/target/description.rs
@@ -173,6 +173,11 @@ pub(crate) enum Operation {
ExtractTag,
UnboxInt32,
UnboxObject,
+ /// The cell pointer a compressed cell pointer (zero-extended to 64 bits) names, in the heap region; 0 stays 0 if
+ /// `nullable`.
+ DecompressCellPointer {
+ nullable: bool,
+ },
BoxInt32 {
clean: bool,
},
@@ -954,6 +959,10 @@ fn lookup_operation(operation: Operation) -> &'static InstructionDescription {
&const { plain(&[GprOut, GprIn]).coalesces(&[(0, 1)]).scratches(&[R11], &[]) }
}
Operation::UnboxObject => &const { plain(&[GprOut, GprIn]).coalesces(&[(0, 1)]).scratches(&[R11], &[]) },
+ Operation::DecompressCellPointer { nullable: false } => &const { plain(&[GprOut, GprIn]).coalesces(&[(0, 1)]) },
+ Operation::DecompressCellPointer { nullable: true } => {
+ &const { plain(&[GprOut, GprIn]).coalesces(&[(0, 1)]).scratches(&[R11], &[X9]) }
+ }
Operation::UnboxInt32 => &const { plain(&[GprOut, GprIn]) },
Operation::BoxInt32 { clean: false } => &const { plain(&[GprOut, GprIn]).scratches(&[R11], &[]) },
Operation::IntegerBinary {
@@ -1156,7 +1165,11 @@ fn lookup_operation(operation: Operation) -> &'static InstructionDescription {
Operation::AssertNonzero => &const { plain(&[GprIn]) },
Operation::StorePairIndexed(PairWidth::Word) => unreachable!("indexed 32-bit pair stores are unsupported"),
Operation::Memory(
- MemoryOperation::Load64NonZero | MemoryOperation::LoadCellPointer | MemoryOperation::LoadNonnullCellPointer,
+ MemoryOperation::Load64NonZero
+ | MemoryOperation::LoadCellPointer
+ | MemoryOperation::LoadNonnullCellPointer
+ | MemoryOperation::LoadCompressedCellPointer
+ | MemoryOperation::LoadNonnullCompressedCellPointer,
) => {
unreachable!("specialized loads must be lowered before target selection")
}
diff --git a/Libraries/LibJS/Flap/src/target/finalize.rs b/Libraries/LibJS/Flap/src/target/finalize.rs
index c7fd6e99d24..2aa36c0d627 100644
--- a/Libraries/LibJS/Flap/src/target/finalize.rs
+++ b/Libraries/LibJS/Flap/src/target/finalize.rs
@@ -183,6 +183,10 @@ fn finalize_value_operation(
let [destination, source] = operands.physical_registers();
backend.unbox_object(emit, destination, source)?;
}
+ Operation::DecompressCellPointer { nullable } => {
+ let [destination, source] = operands.physical_registers();
+ backend.decompress_cell_pointer(emit, destination, source, nullable);
+ }
_ => unreachable!(),
}
Ok(())
@@ -448,7 +452,8 @@ fn finalize_instruction(
| Operation::ToggleBit
| Operation::ClearBit
| Operation::ExtractTag
- | Operation::UnboxObject => {
+ | Operation::UnboxObject
+ | Operation::DecompressCellPointer { .. } => {
finalize_value_operation(backend, emit, operation, operands)?;
}
Operation::Cold => {
diff --git a/Libraries/LibJS/Flap/src/target/x86_64.rs b/Libraries/LibJS/Flap/src/target/x86_64.rs
index 5ac6ca4da2d..894778050b4 100644
--- a/Libraries/LibJS/Flap/src/target/x86_64.rs
+++ b/Libraries/LibJS/Flap/src/target/x86_64.rs
@@ -189,6 +189,7 @@ define_machine_opcodes! {
} printing simple!("call"; SimpleOperand::Relocation(0));
[CallRegister] => Self::CallRegister => [[R]] printing simple!("call"; native(0));
[TestRegister(IntegerWidth)] => Self::TestRegister(width) => [[R]] printing simple!("test"; integer(0, width), integer(0, width));
+ [ConditionalMoveNonZero64] => Self::ConditionalMoveNonZero64 => [[R, R]] printing simple!("cmovnz"; native(0), native(1));
[JumpNegativeToExit] => Self::JumpNegativeToExit => [[]] printing simple!("js"; SimpleOperand::Literal(".Lexit"));
[LoadEffectiveAddress] => Self::LoadEffectiveAddress => [[R, A]] printing simple!("lea"; native(0), SimpleOperand::Resolved(1, ""));
[LoadValuesAddress] => Self::LoadValuesAddress => [[R, A]];
diff --git a/Libraries/LibJS/Flap/src/target/x86_64/finalize.rs b/Libraries/LibJS/Flap/src/target/x86_64/finalize.rs
index 47cafee7992..3ac0ca02731 100644
--- a/Libraries/LibJS/Flap/src/target/x86_64/finalize.rs
+++ b/Libraries/LibJS/Flap/src/target/x86_64/finalize.rs
@@ -1241,6 +1241,31 @@ impl Backend for X86_64Backend {
Ok(())
}
+ fn decompress_cell_pointer(
+ &self,
+ emit: &mut Emit<'_>,
+ destination: PhysicalRegister,
+ source: PhysicalRegister,
+ nullable: bool,
+ ) {
+ let address = MachineMemoryAddress {
+ scale: Some(8),
+ ..MachineMemoryAddress::indexed(R15, source)
+ };
+ if !nullable {
+ emit!(emit.output, X86_64; Opcode::LoadEffectiveAddress => [register destination, address address];);
+ return;
+ }
+ emit!(emit.output, X86_64;
+ Opcode::LoadEffectiveAddress => [register R11, address address];
+ Opcode::TestRegister(IntegerWidth::U32) => [register source];
+ );
+ if destination != source {
+ emit!(emit.output, X86_64; Opcode::Move64Register => [register destination, register source];);
+ }
+ emit!(emit.output, X86_64; Opcode::ConditionalMoveNonZero64 => [register destination, register R11];);
+ }
+
fn float_operation(
&self,
emit: &mut Emit<'_>,