Hello,
The compiler is incorrectly sign-extending halfword operations at all optimization levels above O0. I hit this bug with XE 2013 edition, but I have confirmed the problem exists in the most recent 2016 edition as well. This is affecting a critical project, can you please investigate? A reduced test case is provided below.
Code:
#include <stdio.h>
typedef short size2s_t;
typedef int size4s_t;
typedef long long int size8s_t;
size8s_t vrmpyhacc(size8s_t Rxx, size8s_t Rss, size8s_t Rtt)
{
Rxx = Rxx +
(size2s_t)((Rss>>(0*16))&0xffff) * (size2s_t)((Rtt>>(0*16))&0xffff)
+ (size2s_t)((Rss>>(1*16))&0xffff) * (size2s_t)((Rtt>>(1*16))&0xffff)
+ (size2s_t)((Rss>>(2*16))&0xffff) * (size2s_t)((Rtt>>(2*16))&0xffff)
+ (size2s_t)((Rss>>(3*16))&0xffff) * (size2s_t)((Rtt>>(3*16))&0xffff);
return Rxx;
}
int main()
{
typedef union {
signed long long db;
signed short hw[4];
} newvar;
newvar Rxx, Rss, Rtt;
Rss.hw[0] = -5;
Rss.hw[1] = -10;
Rss.hw[2] = -1;
Rss.hw[3] = -9;
Rtt.hw[0] = -3;
Rtt.hw[1] = -8;
Rtt.hw[2] = -5;
Rtt.hw[3] = -1;
Rxx.db = 0;
printf("vrmpyhacc: 0x%llx\n", (long long unsigned int) vrmpyhacc(Rxx.db, Rss.db, Rtt.db));
return 0;
}
Build:
icl vector.c -O1
Run (observed output):
vrmpyhacc: 0xffffffffffde006d
Expected output:
vrmpyhacc: 0x6d