Skip to content

Promote big constants.#145

Merged
vext01 merged 1 commit intoykjit:mainfrom
ltratt:promote_big_consts
Mar 24, 2026
Merged

Promote big constants.#145
vext01 merged 1 commit intoykjit:mainfrom
ltratt:promote_big_consts

Conversation

@ltratt
Copy link
Copy Markdown
Contributor

@ltratt ltratt commented Mar 24, 2026

This commit promotes "big" constants i.e. those in the constant pool. This is possible thanks to 60c3e59, but still requires some work: in particular, we have to create different codepaths to ensure that whenever we load something out of the constant pool we do so via an idempotent function. Fortunately, by introducing "K" variants of some macros, we can do this in a way that doesn't cause much code corruption. Speeds up cd/json/storage by ~2%.

@vext01 You'll notice I've had to hack around idempotent_promote not supporting floats/doubles here. It's not a big deal, but is a bit icky. It also makes me realise that if we had yk_idempotent_promote(x) as a function we could do the same ABI "are we tracing" trick in a way that would remove a whole load of these idempotent_promote calls. Would it make much performance difference? Hard to say!

This commit promotes "big" constants i.e. those in the constant pool.
This is possible thanks to 60c3e59, but still requires some work: in
particular, we have to create different codepaths to ensure that
whenever we load something out of the constant pool we do so via an
idempotent function. Fortunately, by introducing "K" variants of some
macros, we can do this in a way that doesn't cause much code corruption.
Speeds up cd/json/storage by ~2%.
Comment thread src/lvm.c
NOOPT_VAL(o);
uint64_t x;
// FIXME: We currently have to use memcpy to bitcast from lua_Number to uint64_t
memcpy(&x, &o->value_.n, sizeof(lua_Number));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llvm will probably eliminate the memcpy anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It becomes a bitcast (but this is an ugly, and obsucatory, way to have to do it! But there's nothing better in C AFAIK).

@vext01 vext01 added this pull request to the merge queue Mar 24, 2026
Merged via the queue into ykjit:main with commit fbb4767 Mar 24, 2026
2 checks passed
@ltratt ltratt deleted the promote_big_consts branch March 24, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants