DSP-HW icon indicating copy to clipboard operation
DSP-HW copied to clipboard

Unexpected result when compiler optimizations were enabled.

Open atlanswer opened this issue 4 years ago • 1 comments

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 avatar Dec 15 '20 11:12 atlanswer

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.

atlanswer avatar Dec 25 '20 15:12 atlanswer