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

Lots of warnings about precision conversion loss #369

Open
saghul opened this issue Apr 11, 2024 · 3 comments
Open

Lots of warnings about precision conversion loss #369

saghul opened this issue Apr 11, 2024 · 3 comments

Comments

@saghul
Copy link
Contributor

saghul commented Apr 11, 2024

Build output here since it's too big for a GH comment: https://gist.github.com/saghul/bc2aa4a4db058f4327ad1894bd360301

@bnoordhuis
Copy link
Contributor

A number of them can be fixed like this:

diff --git a/quickjs.h b/quickjs.h
index 6c538a8..fc5ac81 100644
--- a/quickjs.h
+++ b/quickjs.h
@@ -35,7 +35,7 @@ extern "C" {
 #endif
 
 #if defined(__GNUC__) || defined(__clang__)
-#define js_unlikely(x)        __builtin_expect(!!(x), 0)
+#define js_unlikely(x)        ((int)__builtin_expect(!!(x), 0))
 #define js_force_inline       inline __attribute__((always_inline))
 #define __js_printf_like(f, a)   __attribute__((format(printf, f, a)))
 #define JS_EXTERN __attribute__((visibility("default")))

@bnoordhuis
Copy link
Contributor

You know, having said that, maybe it's better to simply remove js_unlikely. It's hardly used and I'm somewhat skeptical it improves performance much, if at all.

bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Apr 11, 2024
It was a wrapper around gcc's __builtin_expect macro but it was only
used in three places and not in a way that suggests it really helps
branch prediction on modern (or even not so modern) CPUs.

Refs: quickjs-ng#369
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Apr 11, 2024
It was a wrapper around gcc's __builtin_expect macro but it was only
used in three places and not in a way that suggests it really helps
branch prediction on modern (or even not so modern) CPUs.

Refs: quickjs-ng#369
bnoordhuis added a commit that referenced this issue Apr 12, 2024
It was a wrapper around gcc's __builtin_expect macro but it was only
used in three places and not in a way that suggests it really helps
branch prediction on modern (or even not so modern) CPUs.

Refs: #369
@chqrlie chqrlie changed the title Lots of warnings about precission conversion loss Lots of warnings about precision conversion loss Apr 13, 2024
@neko-para
Copy link
Contributor

neko-para commented Jun 7, 2024

For reference, I've built quickjs by msvc, gcc and clang with some preset warning options. It generates a huge amount of warnings, and as my project enables Werror, I've added bunch of flags to disable them. Hope these flags could share some information.

if(MSVC)
    add_compile_options("/sdl-;/wd4146;/wd4820;/wd4100;/wd4267;/wd4018;/wd4242;/wd4244;/wd5250;/wd4295")
    add_compile_options("/wd4245;/wd5045;/wd5045;/wd4457;/wd4388;/wd4200;/wd4256;/wd4068;/wd4115;/wd4456")
    add_compile_options(
        "/wd4389;/wd4706;/wd4389;/wd4152;/wd4996;/wd4702;/wd4132;/wd4061;/wd4101;/wd4334;/wd4701;/wd4189;/wd4576;/wd4711;/wd4710;/wd4746"
    )
else()
    add_compile_options("-Wno-pedantic;-Wno-unused-parameter;-fPIC")
endif()

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

No branches or pull requests

3 participants