java怎样将乘法优化成位移乘法,编程中用移位运算替代乘除法会不会有问题?...

79

2018-07-12 14:37:20 +08:00 via Android

@yanaraika 其实我并不觉得写未定义行为的代码,就是问题,更谈不上是严重的问题。

我们这套代码用了十多年了,好多东西都是静态库直接分发的,能 O3 的部分早就 O3 了。

历史包袱有多重,你想不到的兄弟,就这样上边还嫌需求开发的慢呢,本来 O2 能跑,就为了一点虚无缥缈的性能,你非要换成 O3,线上炸了,这个责任谁接,炸了的这部分代码和你一点关系都没有? O2 加上特殊的代码写法,能达到我们要的性能,何必换呢?

再说 O3 又不是一定会带来性能提升,我贴一段话:

-O3 has several disadvantages:

First of all it often produces slower code than -O2 or -Os. Sometimes it produces longer code due to loop unrolling which may be in fact slower due to worse cache performance of code.

As it was said it sometimes produces wrong code. It may be either due to error in optimalization or error in code (like ignoring strict aliasing). As kernel code sometimes is and sometimes have to be 'smart' I'd say it is possible that some kernel developer made some error. I experienced various strange problems, like crashing of userspace utilities, when I compiled kernel with gcc 4.5 which at that point was stable. I still use gcc 4.4 for kernel and several selected userspace utilities due to various bugs. The same may apply for -O3.

I don't think it offers much benefit for the Linux kernel. The kernel does not do heavy computations and in places it does, it is optimized with assembly. -O3 flag will not change the cost of context switching or speed of I/O. I don't think something like <0.1% speedup of overall performance is worth it.

只要是能稳定,性能不差,O2 又能怎样。

招不到靠谱的人,兄弟,不是说这十几年里每个人都是会写 well-defined 的代码,要是人人都这样,那还要做什么测试,直接发布就得了。

理想很丰满啊哥们。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值