当前位置:网站首页>Compiler remainder optimization
Compiler remainder optimization
2022-07-20 08:01:00 【Sili who can't write code】
Preface
We know that the remainder also needs to be called div Assembly instruction , however div If the instruction cycle is too long, compilers often perform arithmetic optimization , To avoid calling div Instructions .
The divisor is 2 Multiple
int main(int argc, char* args[])
{
return argc%8;
}
In order to understand this formula, we first understand some basic logic :
We divide by 2 The displacement can be calculated , So for the remainder, it is also the same as the theoretical optimization thought .
We use 58 % 8 = 2
For example
Binary system :
58 -> 0011 1010
8 -> 0000 1000
2 -> 0000 0010
This formula is correct in unsigned, such as the following assembly code
Corresponding source code
We just need to do the shift number and The result can be obtained by calculation .
For negative division, we need to do the following optimization :
tip: The above figure 58>>3 error Change it to -15>>3
The above formula can be used when the remainder is not , If 0 Front complement 1 Obviously, it will lead to mistakes .
The compiler uses a trick to avoid branch judgment , Subtract one from the moved binary , Then complete the front 1, Finally, add 1.
The two extra steps above are for the remainder 0 Quite useful as follows :
According to the previous theory, we should now be able to understand the following compilation meaning
Non divisor is 2 Seeking remainder
int main( int argc, char* args[])
{
return argc % 7;
}
边栏推荐
- Finite element method for seepage problems in geotechnical engineering: theory, modular programming implementation, hands-on application of open source programs
- Flask framework - database operation commands (add, delete, modify and query)
- 为什么IT行业还是那么多人的首选?
- 中国黄芪行业市场预测与投资战略报告(2022版)
- TCP与UDP的区别
- Spiderpi convenient operation manual
- What are the main aspects of interface testing? What skills are needed? How to learn?
- 第五周复习
- What is the server SSL certificate? Is it an SSL encryption certificate or a code signing certificate
- Astgo SMS plug-in installation instructions
猜你喜欢
Mecol Studio - Huawei 14 day Hongmeng equipment development practical notes II
上班后很迷茫,到底该如何做一个合格的测试?
Nodejs学习
酷早报:7月18日Web3加密行业新闻大汇总
nodejs面经
A decorrelation sub domain adaptive framework based on weak pseudo supervision for cross domain land use classification
Ar beauty platform youcam supports real-time preview of male beard
【玩物立志-scratch少儿编程】骑上小摩托(动态背景+摄像头控制操作)
开发提测标准(简易版)
SpiderPi便捷操作手册
随机推荐
Super practical basic knowledge of geotechnical engineering
Don't know how to learn MySQL? It's enough to finish the 50 questions of Niuke! (Part II)
无重叠区间[贪心练习]
Read double_ data. Write CSV file to redis
Winform布局与控件自适应分辨率以及防止错位
Applet container technology is added to the mixed app development queue, and the cross end development efficiency is improved by 100%
Rllib学习[2] --env定义 + env rollout
This week's big news | Elbit pushes the exclusive ar helmet for pilots, and Apple's second generation Mr will be divided into high and low configurations
编译器除法优化
一篇文章让你彻底搞懂关于性能测试常见术语的定义
CnosDB 涅槃重生:弃用Go, 全面拥抱Rust
Use Wireshark's common filtering commands
Review in the fifth week
第五周复习
Unable to detect release version problem solving
Mysql 面向企业级开发(一)
selnium 获取js内容
js 九九乘法表
UnityVR-机械臂场景3-手爪
Regression - logical regression