在GNU GCC 4.5.3中,将int转换为short

在GNU GCC 4.5.3中,将int转换为short,gcc,compiler-theory,Gcc,Compiler Theory,我想知道,当两个整数相乘,结果被类型转换为short并分配给short时,编译器会将其解析为什么?下面是代码片段 int a=1,b=2,c; short x=3,y=4,z; int p; short q; int main() { c = a*b; /* Mul two ints and assign to int [compiler resolves this to __mulsi3()] */ z = x*y; /* Mul two short and a

我想知道,当两个整数相乘,结果被类型转换为short并分配给short时,编译器会将其解析为什么?下面是代码片段

int a=1,b=2,c;
short x=3,y=4,z;

int p;
short q;

int main()
{

c = a*b; /* Mul two ints and assign to int
            [compiler resolves this to __mulsi3()] */

z = x*y; /* Mul two short and assign to short
            [compiler resolves this to __mulhi3()] */

p = (x*y); /* Mul two short and assign to int
              [compiler resolves this to __mulsi3()] */

q =(short)(a*b); /* Mul two ints typecast to short and assign to short
                    [compiler resolves this to __mulhi3()] */

return 0;

} 
这里在
q=(短)(a*b)的情况下
,应执行前两个整数乘法(使用
\uuuu3()
),然后将其分配给short。但这里的情况并非如此,编译器类型将
a
b
都强制转换为short,然后调用
\uu mulhi3()


我想知道如何更改gcc源代码[哪个文件],以便实现上述要求。

编译器可以分析代码,并看到当您将结果立即转换为
short
时,复制可以作为
short
乘法进行,而不会影响结果。这与您示例中的案例二完全相同


结果是一样的,您不必担心使用哪个乘法函数。

为什么您关心它生成什么指令?它是否产生了错误的结果?编译器是特定于目标的,并且已经完成了移植。因此,我要求在gcc源代码中实现上述更改。