Skip to content

buffer.distance

← buffer dialect

Return lhs_offset minus rhs_offset as a signed byte distance. Both positions must derive from the same buffer byte origin, proven before target lowering; otherwise compilation fails. Sharing an allocation without a common byte origin is insufficient. Nonnull positions must be live and in bounds or one-past. Two null positions at offset zero have distance zero. Positions may be signed index displacements from an interior origin or nonnegative offsets. Their mathematical difference must fit the signed result type. No address or payload bytes are observed.

Operation contract

Property Value
Semantic phase source structure
Traits Pure
Ownership effects borrow lhs (by_value), borrow rhs (by_value)

Signature

Kind Name Type Cardinality Description
Operand lhs buffer required Left storage root.
Operand lhs_offset address required Left root-relative byte position.
Operand rhs buffer required Right storage root.
Operand rhs_offset address required Right root-relative byte position.
Result result integer required Signed left-minus-right byte distance.

Examples

%bytes = buffer.distance %buffer[%end], %buffer[%begin] : i64