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

Core/Movie: Use fmt where applicable #8180

Merged
merged 2 commits into from Jun 20, 2019
Merged

Core/Movie: Use fmt where applicable #8180

merged 2 commits into from Jun 20, 2019

Conversation

@lioncash
Copy link
Member

lioncash commented Jun 14, 2019

This is split into its own PR, as it makes mild changes to some of the internal functions in Movie.cpp (namely changing u8 parameters to u32), and not purely replacing StringFromFormat calls.

While u8 may have been OK with printf-style formatting, which promotes most smaller types back to int internally, this won't work with fmt. fmt preserves the type of the passed in arguments, meaning that u8, being an alias of uint8_t (itself being an alias of unsigned char on all the platforms we support), will print out as a character, not a numeric value.

Because of that, we amend some functions to operate on u32 values for two reasons:

  1. We actually want said parameters to print out as a value, not a character, and casts are gross.

  2. Arithmetic on unsigned types smaller than unsigned int will actually promote to an int, not unsigned int. This is very non-obvious to some and makes for error-prone code. < sizeof(int) types are great for storage, not so much for performing unsigned arithmetic, despite the unsignedness of the type.

lioncash added 2 commits Jun 14, 2019
While we do have this library as part of the public linkage interface in
the common library target, which will be used in the future for the
logging macros, we should still be explicit that we're using this
library. Therefore, we privately link it in to be explicit about it.
In a few cases we needed to alter... less than ideal parameter types.
While u8 may have been OK with printf-style formatting, which promotes
most smaller types back to int, this won't work with fmt. fmt preserves
the type of the passed in arguments, meaning that u8, being an alias of
uint8_t (itself being an alias of unsigned char on all the platforms we
support), will print out as a character, not a numeric value.

As such, we amend some functions to operate on u32 values for two
reasons:

1. We actually want it to print out as a value
2. Arithmetic on unsigned types smaller than unsigned int will actually promote to an int,
   not unsigned int. This is very non-obvious to some and makes for
   error-prone code. < sizeof(int) types are great for storage, not so
   much for performing unsigned arithmetic, despite the signedness of
   the type.
@leoetlino

This comment has been minimized.

Copy link
Member

leoetlino commented Jun 15, 2019

Hmm, doesn't fmt explicitly print unsigned char and uint8_t as a number, and not a character? fmtlib/fmt#217

@lioncash

This comment has been minimized.

Copy link
Member Author

lioncash commented Jun 15, 2019

Ah good, I didn't know that was fixed. That'll make future changes less concerning :)

I'll keep the change as is though, since we're still implicitly truncating from int to u8 in our current code.

@Warepire

This comment has been minimized.

Copy link

Warepire commented Jun 15, 2019

Additionally at least on some arches unnecessarily restricting memory usage will generate more complex assembly to access those variables, increasing the size of the binary. ARM64 is one example.

(Just one more reason to get rid of pointless u8's)

@leoetlino leoetlino merged commit 4edf174 into dolphin-emu:master Jun 20, 2019
10 checks passed
10 checks passed
default Very basic checks passed, handed off to Buildbot.
Details
lint Build succeeded on builder lint
Details
pr-android Build succeeded on builder pr-android
Details
pr-deb-dbg-x64 Build succeeded on builder pr-deb-dbg-x64
Details
pr-deb-x64 Build succeeded on builder pr-deb-x64
Details
pr-freebsd-x64 Build succeeded on builder pr-freebsd-x64
Details
pr-osx-x64 Build succeeded on builder pr-osx-x64
Details
pr-ubu-x64 Build succeeded on builder pr-ubu-x64
Details
pr-win-dbg-x64 Build succeeded on builder pr-win-dbg-x64
Details
pr-win-x64 Build succeeded on builder pr-win-x64
Details
@lioncash lioncash deleted the lioncash:fmt branch Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.