-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix round_coordinate behavior for arm64 (fixes Namco System 22 video issues on arm64) #14369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f4b640c
Fix round_coordinate behavior for arm64
seleuco 30719fa
Modernize code and fix indentation
seleuco 1905330
poly.h: Safer
cuavas f47958e
video/poly.h: Dumb syntax error.
cuavas b6f6fcc
video/poly.h: Remove another stray tab.
cuavas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,9 @@ | |
|
||
#pragma once | ||
|
||
#include <climits> | ||
#include <atomic> | ||
#include <climits> | ||
#include <limits> | ||
|
||
|
||
#define KEEP_POLY_STATISTICS 0 | ||
|
@@ -365,12 +366,19 @@ class poly_manager | |
using unit_array = poly_array<work_unit, 0>; | ||
|
||
// round in a cross-platform consistent manner | ||
inline int32_t round_coordinate(BaseType value) | ||
static int32_t round_coordinate(BaseType value) | ||
{ | ||
int32_t result = int32_t(std::floor(value)); | ||
if (value > 0 && result < 0) | ||
return INT_MAX - 1; | ||
return result + (value - BaseType(result) > BaseType(0.5)); | ||
// saturate (avoid overflow/underflow) | ||
if (value >= BaseType(std::numeric_limits<int32_t>::max())) | ||
return std::numeric_limits<int32_t>::max(); | ||
const BaseType ipart = std::floor(value); | ||
if (ipart < BaseType(std::numeric_limits<int32_t>::min())) | ||
return std::numeric_limits<int32_t>::min(); | ||
Comment on lines
+374
to
+376
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be |
||
|
||
// round | ||
// TODO: this rounds the midpoint towards negative infinity - should it use more standard behaviour? | ||
const BaseType fpart = value - ipart; | ||
return int32_t(ipart) + ((fpart > BaseType(0.5)) ? 1 : 0); | ||
} | ||
|
||
// internal helpers | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know that if it doesn’t hit this test,
int32_t(ipart)
will never givestd::numeric_limits<int32_t>::max()
, becausestd::floor
always produces a lesser or equal value, and converting to integer rounds towards zero.In cases where
BaseType
can't representstd::numeric_limits<int32_t>::max()
precisely,BaseType(std::numeric_limits<int32_t>::max())
gets rounded away from zero so the test should still be safe.