当前位置:网站首页>Risc-v instruction set explanation (7) instruction address alignment and addition and subtraction overflow processing
Risc-v instruction set explanation (7) instruction address alignment and addition and subtraction overflow processing
2022-06-24 05:51:00 【IC knowledge base】
1. Instruction address alignment
about load/store Instructions , The address of data in memory should be aligned .
If access storage 32 Bit data , The memory address should be the same as 32 Bit data alignment , in other words ,D_PC The lowest two digits of should be 0( If data is stored in memory, it will be 32 bit In units of , Indicates that the data is 4 Byte aligned );
If access storage 16 Bit data , The memory address should be the same as 16 Bit data alignment ,D_PC The lowest bit of should be 0( Indicates that the data is 2 Byte aligned );
If access storage 8 Bit data , Because the unit of memory is a byte , That is, no alignment is required . The details are as follows: CPU How to implement the design in hardware is shown in RISC-V LSU,SRAM,GPIO modular (2)D_sram The processing of address shift in the module .
Be careful :RISC-V Only the small end format is supported (little-endian). The comparison between the small end format and the large end format is shown in the figure 1 Shown . If different end sequences are used to store the same 32 digit 0x0A0B0C0D, The situation is shown in the picture .
The highest byte of the small end is 0x0A, The lowest byte is 0x0D;
The highest byte of the big end is 0x0D, The lowest byte is 0x0A.
If data is exchanged in systems with different end sequences , It is necessary to ensure that the transmitted data is in the form of 32 The number of digits is in . If the unit is one byte , Exchange data in different end sequence systems , There may be problems , For example, the small end here 0x0A The corresponding address (a + 3), In big end systems , The data stored in this address is 0x0D.
chart 1 Big end format , Small end format [1]
RISC-V The small end format is chosen as the end order because it is currently dominant in the business . be-all X86-32 Systems and Apple iOS, Google Android Operating system and Microsoft Windows for ARM They all use the small end format to sort addresses ( Low byte priority ) [2].
2. Add and subtract overflow treatment
As mentioned before ADD,ADDI and SUB Such instructions may overflow during calculation , Generally speaking , Hardware design ignores arithmetic overflow , therefore RISC-V Rely on software checks . The following is an example of how addition is handled ( Subtraction is similar ):
Unsigned number addition overflow ( hypothesis x6,x7 It's an unsigned number )
ADD x5,x6,x7
BLTU x5,x6,overflow ( Jump to Processing branches with incorrect results )
interpretative statement :x5 by x6 and x7 And , If the sum is smaller than the addend , This indicates that addition has overflowed , That is, you can go to the branch that handles the overflow ,overflow
Signed numbers are added , It is known that imm Is a positive number
ADDI x5,x6,+imm( Positive numbers )
BLT x5,x6,overflow ( Jump to Processing branches with incorrect results )
interpretative statement : No matter what x6 Is it a positive number or a negative number , It adds a positive number , The result should be bigger than itself . If the x5,x6 Make a signed comparison ,x5 Less than x6, It indicates that addition has overflowed , That is, you can go to the branch that handles the overflow ,overflow
Except for the above two special cases , For general addition , The treatment is as follows
(x7 < 0) && (x6 + x7 >= x6) || (x7 >= 0) && (x6 + x7 < x6)
ADD x5,x6,x7
SLTI x28,x7,0
SLT x29,x5,x6
BNE x28,x29,overflow ( Jump to Processing branches with incorrect results )
interpretative statement :
If x7 Less than 0, that x28 by 1, that x6 and x7 The sum of should be less than x6, Yes x5 and x6 Compare , If x5 Less than x6,x29 by 1, If x5 Not less than x6, That is to say, overflow , here x29 by 0.x28 It's not equal to x29, That is, you can go to the incorrect processing branch
If x7 Greater than or equal to 0, that x28 by 0, meanwhile x6 and x7 The sum of should not be less than x6, Same for x5 and x6 Compare , If x29 by 1, explain x5 Less than x6, That is to say, overflow ,x28 It's not equal to x29, It also goes to the incorrect processing branch
Or it can be understood as : if (x7 < 0) && (x6 + x7 >= x6) || (x7 >= 0) && (x6 + x7 < x6) Is an incorrect processing branch
remarks : Please search the search engine for the complete content “IC The knowledge base ” see .
边栏推荐
- Net domain name? Net domain name?
- Kubernetes configures two ways of hot update
- When we talk about zero trust, what are we talking about?
- 3D visualization of smart dam
- Oceanus practice - develop MySQL CDC to es SQL jobs from 0 to 1
- Material production tool manual
- How to resolve the domain name to IP? How long does it take for the domain name resolution to take effect?
- What happened to the JVM locking on Tencent ECS?
- Script updates CLB type ingress Certificate in tke cluster
- How to resolve Chinese domain names? What is domain name resolution?
猜你喜欢
随机推荐
Install and use juicefs storage on Tencent cloud
Kubernetes configures two ways of hot update
How to do domain name resolution? What does domain name resolution mean?
[experience sharing] 1.39 million problem solving report of Tencent's internal track
Interpretation of Cocos creator source code: siblingindex and zindex
Go's package management learning notes
Best practices for building a distributed Domain Driven Architecture Based on data mesh
What is a first level domain name? What are the steps to purchase a primary domain name?
Technical dry goods | multi modal classification and recognition of audio-visual scenes in the stage of Tencent cloud smart media AI
What functions can the IOT pole platform develop
Explain thoroughly and learn rotten binary tree (4): storage structure of binary tree - build heap - Search - sort
How to apply for a company domain name? What are the requirements for the applicant company?
Data warehouse data processing DB basic concept analysis and understanding OLAP OLTP hatp similarities and differences MPP architecture
How to build a website with a domain name? What steps need to be taken?
Analysis and summary of the packet capturing artifact tcpdump - covering major use scenarios and advanced usage
The development and construction of live broadcast app, and the source code of live broadcast app involves all aspects
What are the advantages of building a private cloud platform?
How do websites apply for domain names? How to select a website domain name?
How to set the secondary domain name of the website? What should I pay attention to when setting the domain name?
2021, how to select a programming language?