Skip to content

Commit

Permalink
Optimize generator creation
Browse files Browse the repository at this point in the history
Summary:
In `InitialYield`'s codegen, we were framing the `rep movsq` with
`std` and `cld`, to have the copy progress from higher to lower addresses. If
we start the pointers at the bottom of their respective buffers rather than the
top, we can leave `DF` alone and have the copy go from lower to higher
addresses (the System V ABI requires that DF be cleared on function entry/exit,
so it's safe to assume it's 0 coming into this code).

Reviewed By: jbower-fb

Differential Revision: D49653637

fbshipit-source-id: ea68e3ed83536fcb996d9478179cf82457e6818a
  • Loading branch information
swtaarrs authored and facebook-github-bot committed Oct 18, 2023
1 parent acbfee8 commit 8e269c0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Jit/codegen/autogen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,16 +447,15 @@ void translateYieldInitial(Environ* env, const Instruction* instr) {
emitStoreGenYieldPoint(as, env, instr, resume_label, x86::rdi, scratch_r);

// Store variables spilled by this point to generator.
// Point rsi at the top word of the current spill space.
as->lea(x86::rsi, x86::ptr(x86::rbp, -kPointerSize));
// Point rdi at the top word of the generator's spill space.
as->sub(x86::rdi, kPointerSize);
int current_spill_bytes = env->initial_yield_spill_size_;
JIT_CHECK(current_spill_bytes % kPointerSize == 0, "Bad spill alignment");
as->mov(x86::rcx, current_spill_bytes / kPointerSize);
as->std();
int spill_bytes = env->initial_yield_spill_size_;
JIT_CHECK(spill_bytes % kPointerSize == 0, "Bad spill alignment");

// Point rsi at the bottom word of the current spill space.
as->lea(x86::rsi, x86::ptr(x86::rbp, -spill_bytes));
// Point rdi at the bottom word of the generator's spill space.
as->sub(x86::rdi, spill_bytes);
as->mov(x86::rcx, spill_bytes / kPointerSize);
as->rep().movsq();
as->cld();

// Jump to bottom half of epilogue
as->jmp(env->hard_exit_label);
Expand Down

0 comments on commit 8e269c0

Please sign in to comment.