test_multiple_if.c
#include <stdint.h>
struct In { int16_t flag; };
struct Out { int dummy; };
void u32_to_u8arr2(uint8_t *src, uint32_t v, int stride) {
src[0*stride] = v & 0xFF;
src[1*stride] = (v >> 8) & 0xFF;
src[2*stride] = (v >> 16) & 0xFF;
src[3*stride] = (v >> 24) & 0xFF;
}
void pred16x16_128_dc(uint8_t *res, uint32_t dcsplat, int stride)
{
u32_to_u8arr2(res+0, dcsplat, stride);
u32_to_u8arr2(res+4, dcsplat, stride);
}
void print_luma(uint8_t *luma) {
printf("%Zx %Zx %Zx %Zx", luma[0], luma[1], luma[2], luma[3]);
printf("%Zx %Zx %Zx %Zx", luma[4], luma[5], luma[6], luma[7]);
}
void compute(struct In *input, struct Out *output){
int prediction_mode = input->flag;
uint8_t res[8];
int scalar = 0;
if (prediction_mode == 1) {
pred16x16_128_dc(res, 0x10101010, 1);
scalar = 0x10101010;
}
if (prediction_mode == 2) {
pred16x16_128_dc(res, 0x20202020, 1);
scalar = 0x20202020;
}
printf("Mode %Zd", prediction_mode);
printf("Scalar %Zx", scalar);
print_luma(res);
}
input.txt
prints out:
PRINTF in computation_p 1:
"Mode 1"
PRINTF in computation_p 1:
"Scalar 10101010"
PRINTF in computation_p 8:
"0 0 0 0"
PRINTF in computation_p 8:
"0 0 0 0"
should print
PRINTF in computation_p 1:
"Mode 1"
PRINTF in computation_p 1:
"Scalar 10101010"
PRINTF in computation_p 8:
"10 10 10 10"
PRINTF in computation_p 8:
"10 10 10 10"
if you comment out
/* if (prediction_mode == 2) {
pred16x16_128_dc(res, 0x20202020, STRIDE);
scalar = 0x20202020;
}*/
you will get expected result.
Same thing with input value 2
Problem:
We have incorrect behavior if the code has more than one if statement which operates with array types.
Same thing if we replace it with if else if construction
As you can see, scalar types are ok.
test_multiple_if.c
input.txt
prints out:
should print
if you comment out
you will get expected result.
Same thing with input value
2Problem:
We have incorrect behavior if the code has more than one if statement which operates with array types.
Same thing if we replace it with
if else ifconstructionAs you can see, scalar types are ok.