Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace __forceinline with zend_always_inline in win32/ #17482

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 15, 2025

__forceinline is MSVC specific (and also understood by Clang on Windows), but the code in win32/ should not be constrained to these compilers. Since we already have zend_always_inline, we use this instead.


The motivation is to make the win32/ more portable, since there are other relevant compilers than MSVC and Clang on Windows (e.g. MinGW GCC). While this commit doesn't really change anything in this regard, it makes it simpler to do so.

Note that I have deliberately not touched some bundled libraries using __forceinline, because it may make updating these a bit harder, and more importantly, because they already use __forceinline only if _MSC_VER is defined.

Also note that I consider the use of zend_always_inline generally doubtful, because it (a) does not necessarily enforce inlining (what might easily be overlooked), and (b) the programmer doesn't know better than the compiler (maybe for some tiny amount of time, but the next commit/compiler version may make that moot; profile guided optimization is likely the better judge).

We should probably have a look at our uses of __inline which appear to be outdated.

`__forceinline` is MSVC specific (and also understood by Clang on
Windows), but the code in win32/ should not be constrained to these
compilers.  Since we already have `zend_always_inline`, we use this
instead.
@cmb69
Copy link
Member Author

cmb69 commented Jan 16, 2025

See also #15075.

Copy link
Member

@devnexen devnexen left a comment

Choose a reason for hiding this comment

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

LGTM

@Girgias
Copy link
Member

Girgias commented Jan 16, 2025

We should probably have a look at our uses of __inline which appear to be outdated.

I feel there was a bit of a discussion somewhere by @nielsdos and @arnaud-lb (and probably others) about this IIRC.

@cmb69
Copy link
Member Author

cmb69 commented Jan 16, 2025

We should probably have a look at our uses of __inline which appear to be outdated.

I feel there was a bit of a discussion somewhere by @nielsdos and @arnaud-lb (and probably others) about this IIRC.

I found #13429, which removed AC_C_INLINE.

Anyhow, relevant code using __inline:

#ifdef PHP_WIN32
static __inline __int64 php_date_llabs( __int64 i ) { return i >= 0? i: -i; }
#elif defined(__GNUC__) && __GNUC__ < 3
static __inline __int64_t php_date_llabs( __int64_t i ) { return i >= 0 ? i : -i; }
#else
static inline long long php_date_llabs( long long i ) { return i >= 0 ? i : -i; }
#endif

inline should be supported by MSVC and Clang (also) in C mode (required feature of C99), and I don't think we still support GCC < 3 anyway.

@Girgias
Copy link
Member

Girgias commented Jan 16, 2025

I think I was more referring to the discussion that happened in #15075 (I just realized you already mentioned this PR... ignore the noise)

@cmb69
Copy link
Member Author

cmb69 commented Jan 16, 2025

I think I was more referring to the discussion that happened in #15075

Ah. I was actually referring to the out-dated __inline alias. :)

@cmb69 cmb69 merged commit 5c39a46 into php:master Jan 16, 2025
10 checks passed
@cmb69 cmb69 deleted the cmb/forceinline branch January 16, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants