Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/perl5Public

Perl_leave_adjust_stacks: additional efficiency for mortal copies#22163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

richardleach
Copy link
Contributor

The existing code has a fast path for copying aSVt_NULL orSVt_IV. For all
other types, a newSVt_NULL is passed intosv_setsv_flags, where it will
be upgraded into the required type bysv_upgrade().

This commit makes two changes:

  1. Special case copying aSVt_NV where possible, assv_setsv_flags does.
  2. It's safe and more efficient to directly create a new type ofSVt_PVNV
    or below, rather than upgrade it later, so do that.

@richardleach
Copy link
ContributorAuthor

This can be defer-next-dev.

@tonycoztonycoz added the defer-next-devThis PR should not be merged yet, but await the next development cycle labelApr 21, 2024
pp_hot.c Outdated
Comment on lines 6007 to 6011
#if NVSIZE <= IVSIZE
if (SvTYPE(sv) <= SVt_NV) {
#else
if (SvTYPE(sv) <= SVt_IV) {
/* arg must be one of undef, IV/UV, or RV: skip
* sv_setsv_flags() and do the copy directly */
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know what our policy on preprocessor use is, but this could be written more compactly as

if (SvTYPE(sv) <= (NVSIZE <=IVSIZE ?SVt_NV :SVt_IV)) {

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I'm certainly happy to write it like that. The current form is just mirroring what's already been in use inPerl_sv_setsv_flags.

Anyone else want to weigh in on preprocessor policy?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the only concern would be C compilers which can't do simple constant folding, which I'm assuming would be rare these days.

Copy link
Contributor

Choose a reason for hiding this comment

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

The C standard requires constant folding.

A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be.

In particular, you can use constant expressions as array sizes,case labels, bit-field sizes, and null pointer constants. If it doesn't constant fold, it's not a C compiler. :-)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok, making those changes as suggested.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Er, stuff has gone awry in tests, will have to look into it later.

@richardleachrichardleachforce-pushed thehydahy/leave_adjust_copies branch fromc717a64 to8e27883CompareMay 13, 2024 20:59
pp_hot.c Outdated
Comment on lines 6038 to 6051
else if (NVSIZE <= IVSIZE && (srcflags & SVf_NOK)) {
SET_SVANY_FOR_BODYLESS_NV(newsv);
dstflags = (SVt_NV|SVf_NOK|SVp_NOK|SVs_TEMP);

/* both src and dst are <= SVt_MV, so sv_any points to the
* head; so access the head directly
*/
assert( &(sv->sv_u.svu_nv)
== &(((XPVNV*) SvANY(sv))->xnv_u.xnv_nv));
assert( &(newsv->sv_u.svu_nv)
== &(((XPVNV*) SvANY(newsv))->xnv_u.xnv_nv));
newsv->sv_u.svu_nv = sv->sv_u.svu_nv;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Alas, this needs to use the preprocessor, since for long double or quadmath builds NV is 12-16 bytes and IV is 8 bytes on 64-bit platforms.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks Tony. I'll revert to the original PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The SvTYPE() comparison that mauke suggested is still fine, it just doesn't work for this block.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok, I had been thinking about keeping the two changes consistent, but have just reverted this second one.

@iabyn
Copy link
Contributor

Apart from the issue of the macros, I approve of this PR.

The existing code has a fast path for copying a SVt_NULL or SVt_IV. For allother types, a new SVt_NULL is passed into sv_setsv_flags, where it willbe upgraded into the required type by sv_upgrade().This commit makes two changes:1) Special case copying a SVt_NV where possible, as sv_setsv_flags does.2) It's safe and more efficient to directly create a new type of SVt_PVNV   or below, rather than upgrade it later, so do that.
@richardleachrichardleachforce-pushed thehydahy/leave_adjust_copies branch from8e27883 tof40ea39CompareMay 22, 2024 22:24
@jkeenanjkeenan removed the defer-next-devThis PR should not be merged yet, but await the next development cycle labelJun 10, 2024
@richardleach
Copy link
ContributorAuthor

I'll merge this soon if there are no further comments/suggestions.

@richardleachrichardleach merged commit8456431 intoPerl:bleadJun 11, 2024
@richardleachrichardleach deleted the hydahy/leave_adjust_copies branchJune 11, 2024 08:32
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@maukemaukemauke left review comments

@iabyniabyniabyn left review comments

@tonycoztonycoztonycoz approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@richardleach@iabyn@tonycoz@mauke@jkeenan

[8]ページ先頭

©2009-2025 Movatter.jp