Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6860-inline-nonbigint-bitwise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**Codegen perf:** lower the six bitwise ops (`& | ^ << >> >>>`) inline (`ToInt32 <op> ToInt32`) instead of the BigInt-aware `js_dynamic_bit*` runtime helper whenever both operands are provably not a BigInt — including `Any`-typed accumulators proven non-BigInt by a new flow analysis (`collect_not_bigint_locals`). Kills the per-round runtime-call cascade in integer kernels such as bcryptjs's `_encipher` Feistel network (12 `js_dynamic_*` bitwise calls → 0 in the optimized function; ~1.98x faster on the reproduction). The BigInt bail is preserved: a mixed `bigint <op> number` still throws `TypeError` and `bigint <op> bigint` still computes a BigInt. Gated behind `PERRY_INLINE_NONBIGINT_BITWISE` (default on; `=0` reverts).
1 change: 1 addition & 0 deletions crates/perry-codegen/src/codegen/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ pub(super) fn compile_closure(
try_depth: 0,
pending_declares: Vec::new(),
integer_locals: native_facts.integer_locals(),
not_bigint_locals: native_facts.not_bigint_locals(),
unsigned_i32_locals: native_facts.unsigned_i32_locals(),
shadow_slot_map,
persistent_shadow_slots: std::collections::HashSet::new(),
Expand Down
2 changes: 2 additions & 0 deletions crates/perry-codegen/src/codegen/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ pub(super) fn compile_module_entry(
try_depth: 0,
pending_declares: Vec::new(),
integer_locals: main_native_facts.integer_locals(),
not_bigint_locals: main_native_facts.not_bigint_locals(),
unsigned_i32_locals: main_native_facts.unsigned_i32_locals(),
shadow_slot_map: main_shadow_slot_map,
persistent_shadow_slots: std::collections::HashSet::new(),
Expand Down Expand Up @@ -1351,6 +1352,7 @@ pub(super) fn compile_module_entry(
try_depth: 0,
pending_declares: Vec::new(),
integer_locals: init_native_facts.integer_locals(),
not_bigint_locals: init_native_facts.not_bigint_locals(),
unsigned_i32_locals: init_native_facts.unsigned_i32_locals(),
shadow_slot_map: init_shadow_slot_map,
persistent_shadow_slots: std::collections::HashSet::new(),
Expand Down
1 change: 1 addition & 0 deletions crates/perry-codegen/src/codegen/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ pub(super) fn compile_function(
try_depth: 0,
pending_declares: Vec::new(),
integer_locals: native_facts.integer_locals(),
not_bigint_locals: native_facts.not_bigint_locals(),
unsigned_i32_locals: native_facts.unsigned_i32_locals(),
shadow_slot_map,
persistent_shadow_slots: std::collections::HashSet::new(),
Expand Down
2 changes: 2 additions & 0 deletions crates/perry-codegen/src/codegen/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ pub(super) fn compile_method(
try_depth: 0,
pending_declares: Vec::new(),
integer_locals: native_facts.integer_locals(),
not_bigint_locals: native_facts.not_bigint_locals(),
unsigned_i32_locals: native_facts.unsigned_i32_locals(),
shadow_slot_map,
persistent_shadow_slots: std::collections::HashSet::new(),
Expand Down Expand Up @@ -1462,6 +1463,7 @@ pub(super) fn compile_static_method(
try_depth: 0,
pending_declares: Vec::new(),
integer_locals: native_facts.integer_locals(),
not_bigint_locals: native_facts.not_bigint_locals(),
unsigned_i32_locals: native_facts.unsigned_i32_locals(),
shadow_slot_map,
persistent_shadow_slots: std::collections::HashSet::new(),
Expand Down
11 changes: 11 additions & 0 deletions crates/perry-codegen/src/collectors/hir_facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub(crate) type NativeRegionFactGraph = TypeFacts;
pub(crate) struct RepresentationFacts {
pub integer_locals: HashSet<u32>,
pub unsigned_i32_locals: HashSet<u32>,
/// Locals whose runtime value provably can never be a BigInt (every write
/// is a non-BigInt expression). Seeds `is_provably_not_bigint`, which gates
/// the inline non-BigInt bitwise fast path. See `collect_not_bigint_locals`.
pub not_bigint_locals: HashSet<u32>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -125,6 +129,10 @@ impl TypeFacts {
&self.representation.unsigned_i32_locals
}

pub(crate) fn not_bigint_locals(&self) -> &HashSet<u32> {
&self.representation.not_bigint_locals
}

pub(crate) fn array_kind(&self, local_id: u32) -> ArrayKindFact {
self.arrays
.local_kinds
Expand Down Expand Up @@ -316,6 +324,8 @@ pub(crate) fn collect_type_facts(
arg_dependent_clamp_fn_ids,
);
let unsigned_i32_locals = super::i32_locals::collect_unsigned_i32_locals(stmts);
let not_bigint_locals =
super::not_bigint_locals::collect_not_bigint_locals(stmts, params, binding_types);
let (array_facts, effect_facts, materialization_hazards) =
collect_array_facts(stmts, params, module_globals, binding_types);
let index_used_locals = super::index_uses::collect_index_used_locals(stmts);
Expand Down Expand Up @@ -369,6 +379,7 @@ pub(crate) fn collect_type_facts(
representation: RepresentationFacts {
integer_locals: integer_locals.clone(),
unsigned_i32_locals,
not_bigint_locals,
},
arrays: array_facts,
effect: effect_facts,
Expand Down
1 change: 1 addition & 0 deletions crates/perry-codegen/src/collectors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod index_uses;
mod integer_locals;
mod local_refs;
mod mutation;
mod not_bigint_locals;
mod pointer_locals;
mod refs;
mod scalar_method_dispatch;
Expand Down
Loading
Loading