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

Unexpected result when compiler optimizations were enabled. #4

Open
atlanswer opened this issue Dec 15, 2020 · 1 comment
Open

Unexpected result when compiler optimizations were enabled. #4

atlanswer opened this issue Dec 15, 2020 · 1 comment
Assignees
Labels
bug Something isn't working task 1 Related to task 1
Milestone

Comments

@atlanswer
Copy link
Owner

Description

The interpolation algorithm implemented in C works fine in debug configurations, but failed to generate the correct output when compiler optimizations were enabled with -O2.

Demo

Using lena32.bmp as input for simplicity, 2x magnification.

Debug
Debug

Release
Release

With -O2, only the last row, which is the first row to be generated, was correct. The rest of the image was blank.

Possible causes

It's clear that the optimizations introduced unexpected behaviors to the algorithm. After some searching, the absence of the volatile keyword might be to blame. Refer to How to Use C's volatile Keyword for more info.

@atlanswer atlanswer added bug Something isn't working task 1 Related to task 1 labels Dec 15, 2020
@atlanswer atlanswer added this to the Task 1 milestone Dec 15, 2020
@atlanswer atlanswer self-assigned this Dec 15, 2020
@atlanswer
Copy link
Owner Author

It's been verified that using volatile keyword in every declaration related to loops could fix the problem. Whether it is necessary or not is not tested yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working task 1 Related to task 1
Projects
None yet
Development

No branches or pull requests

1 participant