当前位置:网站首页>Register keyword
Register keyword
2022-07-03 07:49:00 【It's Beichen not too PI acridine】
register keyword
Preface
Compiler optimization is largely through data flow analysis 、 Adjust the order of reading memory , Reduce CPU Read and write to memory . Because the running speed of memory is relative to CPU Is very slow , Add cache Just to solve it CPU And memory running speed is too different . In terms of running speed : register >cache> Memory > External storage ; In terms of price, it's just the opposite : register >cache> Memory > External storage . This is also register and cache Is the fastest to read , But in the computer, registers and cache The reason why the capacity of is very small , You can buy 1T But I can't buy it 1T Memory module of , The price is too high , I can't afford it . The number and function of registers are Soc It's fixed , It cannot be expanded later , Register resources are scarce , Be careful with register operation .
register The role of keywords
register: This keyword asks the compiler to make variables exist as much as possible CPU Internal registers instead of memory addressing access to improve efficiency . Note that as much as possible , Not absolute . Do you think , One CPU There are only a few or dozens of registers , If you define a lot register Variable , It's too tired to put all these variables into registers , It may not be your turn .
register Keyword application scenarios
When a variable is called frequently , It can be used register To modify variables , Save variables in registers , It can improve the speed of accessing variables .
register Key words
1.register Variables must be able to be CPU The type accepted . Variables are stored in registers , That means that the degree of variables cannot exceed the number of bits of the register and the type should be consistent with the data type accepted by the register . General situation register The decorated variable must be a single value , And the length should be less than or equal to the length of an integer . If the register allows floating point numbers , that register Decorated variables can also be floating-point numbers .
2. because register Variables may not be stored in memory , So it can't be used “&” To get register The address of the variable . use register Decorated variables are not necessarily stored in registers , use register Decoration just suggests saving the variable to a register , It's not mandatory .
3.register Keywords can only be used for local variables ( That is, the variables in the code block ), Cannot be used to decorate global variables .
4. Local static variables cannot be defined as register variables . Can not write :register static int a, b, c. I guess the reason is : The life cycle of static variables is the same as that of the whole program , You can't always allocate a register to be occupied by a variable , Register resources are very valuable , It's too wasteful .
5. Cannot define any number of register variables , The reason is simple Soc There are too few registers in . Even if you use register Embellishments are not necessarily placed in registers , Let alone define multiple . Personally feel , These special keywords , Don't use it without full confidence , Now the compiler is very intelligent , The compiler knows how to optimize the code . For ordinary people like me , Know the meaning of these keywords , See Linux Kernel code , Just know what these keyword modifiers do .
边栏推荐
- 技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
- Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
- Redis查看客户端连接
- 【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
- Go language foundation ----- 07 ----- method
- Pat grade a 1029 median
- Go language foundation ----- 08 ----- interface
- Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
- opensips与对方tls sip trunk对接注意事项
- PDO and SDO concepts
猜你喜欢

技术干货|昇思MindSpore NLP模型迁移之LUKE模型——阅读理解任务

Pat class a 1030 travel plan

Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!

技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估

Go language foundation ----- 13 ----- file

技术干货|AI框架动静态图统一的思考

Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
![[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)](/img/38/3435d353e50b19fe09c8ab9db52204.png)
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)

Pat class a 1031 Hello world for u
![[mindspire paper presentation] summary of training skills in AAAI long tail problem](/img/34/9c9ec1b94edeecd4a3e7f20fdd8356.png)
[mindspire paper presentation] summary of training skills in AAAI long tail problem
随机推荐
Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
Structure of golang
【MySQL 14】使用DBeaver工具远程备份及恢复MySQL数据库(Linux 环境)
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
How does yarn link help developers debug NPM packages?
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Pat class a 1032 sharing
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
Redis查看客户端连接
PAT甲级 1030 Travel Plan
Analysis of the problems of the 7th Blue Bridge Cup single chip microcomputer provincial competition
华为交换机Console密码重置、设备初始化、默认密码
Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
Pat grade a 1029 median
Go language foundation ----- 05 ----- structure
C2-关于VCF文件合并的几种方法
PAT甲级 1028 List Sorting
哪一刻你才发现青春结束了