summaryrefslogtreecommitdiff
path: root/yjit/src/utils.rs
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2023-10-16 18:35:26 -0400
committerAlan Wu <[email protected]>2023-11-07 17:43:43 -0500
commita1c61f0ae5f5ecaa7d8289942b78e6b0c77118fe (patch)
tree34ce4467e77196c9e6fc842f39b7bae0d8cd62c5 /yjit/src/utils.rs
parentaa6642de630cfc10063154d84e45a7bff30e9103 (diff)
YJIT: Use u32 for CodePtr to save 4 bytes each
We've long had a size restriction on the code memory region such that a u32 could refer to everything. This commit capitalizes on this restriction by shrinking the size of `CodePtr` to be 4 bytes from 8. To derive a full raw pointer from a `CodePtr`, one needs a base pointer. Both `CodeBlock` and `VirtualMemory` can be used for this purpose. The base pointer is readily available everywhere, except for in the case of the `jit_return` "branch". Generalize lea_label() to lea_jump_target() in the IR to delay deriving the `jit_return` address until `compile()`, when the base pointer is available. On railsbench, this yields roughly a 1% reduction to `yjit_alloc_size` (58,397,765 to 57,742,248).
Diffstat (limited to 'yjit/src/utils.rs')
-rw-r--r--yjit/src/utils.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/yjit/src/utils.rs b/yjit/src/utils.rs
index 58415e279f..6bc66ee33e 100644
--- a/yjit/src/utils.rs
+++ b/yjit/src/utils.rs
@@ -51,6 +51,20 @@ impl IntoUsize for u8 {
}
}
+/// The [Into<u64>] Rust does not provide.
+/// Convert to u64 with assurance that the value is preserved.
+/// Currently, `usize::BITS == 64` holds for all platforms we support.
+pub(crate) trait IntoU64 {
+ fn as_u64(self) -> u64;
+}
+
+#[cfg(target_pointer_width = "64")]
+impl IntoU64 for usize {
+ fn as_u64(self) -> u64 {
+ self as u64
+ }
+}
+
/// Compute an offset in bytes of a given struct field
#[allow(unused)]
macro_rules! offset_of {
@@ -219,7 +233,7 @@ pub fn print_str(asm: &mut Assembler, str: &str) {
asm.bake_string(str);
asm.write_label(after_string);
- let opnd = asm.lea_label(string_data);
+ let opnd = asm.lea_jump_target(string_data);
asm.ccall(print_str_cfun as *const u8, vec![opnd, Opnd::UImm(str.len() as u64)]);
asm.cpop_all();