In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "what are the tips for improving code execution efficiency in C language?" interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the tips for improving code execution efficiency in C language?"
I. limitation of method parameters
ARM64 has 34 registers, including 31 general registers (x0-x30), SP, PC, CPSR.
X0-x30 are 31 general integer registers. Each register can access a 64-bit number. When using R0-R30 access, it is a 64-bit number. When using W0-W30 access, the lower 32 bits of these registers are accessed.
Register bits describe x0-x3064bit general registers, which can be used as 32bit if necessary: WO-W30FP (x29) 64bit save stack frame address (stack bottom pointer) LR (x30) 64bit is usually called X30 as the program link register, saving the next instruction that needs to be executed after the end of the subroutine SP64bit saves the stack pointer, uses SP/WSP to access the SP register PC64bit program counter, commonly known as PC pointer Always points to the next instruction to be executed. In arm64, the software is the CPSR64bit status register that cannot overwrite the PC register.
Xcode runs the project in the real machine, adding breakpoints to LLDB to see the status of each register register read.
CPU consists of register, arithmetic unit and controller, in which the main function of register is to store information. It can be understood as a kind of memory, but it is much more efficient than memory. The X0-X7 register in ARM64 is mainly used to pass parameters when the subroutine is called. If the method passes too many parameters and the registers are not used enough, the extra parameters will be directly stored in the function call stack. The stack mainly exists in memory, which is much slower than registers, so the actual development of iOS should pay attention to the number of parameters passed, too many parameters, to a certain extent, will reduce the speed of code execution. Different platforms are different. Registers such as% rdi,% rsi,% rdx,% rcx,% R8,% R9,% R10 and other registers in 64-bit AT&T assembly are used to store function parameters, and some platforms may directly use stacks to save function parameters. In this case, in theory, too many parameters do not have much impact on code execution efficiency.
Int sum (int arecinint bjint c, int djint ePowerint fjint gpenint hreint inint jreint int k) {return a + b + c + d + e + f + g + h;} int main (int argc, const char * argv []) {@ autoreleasepool {int num = sum (1) NSLog (@ "% d", num);} return 0;}
The 64-bit AT&T assembly code corresponding to the above code is as follows. Take a closer look at the assembly code below, starting at line 13, which involves the addition and subtraction of rsp pointers, indicating that subsequent parameters exist in the stack area. (the memory address number for reading and writing to the stack is managed by the rsp register. After the push instruction and the pop instruction are run, the value of the esp register is automatically updated, the push instruction rsp decreases, and the pop command rsp increases. That is, the first seven parameters exist in the register (% rdi,% rsi,% rdx,% rcx,% R8,% R9,% R10), and the last four parameters are stored in the stack.
0x100000eb2: movl $0x1,% edi 0x100000eb7: movl $0x2,% esi 0x100000ebc: movl $0x3,% edx 0x100000ec1: movl $0x4,% ecx 0x100000ec6: movl $0x5,% R8d 0x100000ecc: movl $0x6,% r9d 0x100000ed2: movl $0x7,% r10d 0x100000ed8: movl $0x8,% r11d 0x100000ede: movl $0x9,% ebx 0x100000ee3: movl $0xa,% r14d 0x100000ee9: movl $0xb,% r15d 0x100000eef: movl $0x7 (% rsp) 0x100000ef6: movl $0x8, 0x8 (% rsp) / / Line 13 0x100000efe: movl $0x9, 0x10 (% rsp) 0x100000f06: movl $0xa, 0x18 (% rsp) 0x100000f0e: movl $0xb, 0x20 (% rsp) 0x100000f16: movq% rax,-0x40 (% rbp) 0x100000f1a: movl% r15d,-0x44 (% rbp) 0x100000f1e: movl% r14d,-0x48 (% rbp) 0x100000f22: movl% movl -0x4c (% rbp) 0x100000f25: movl% r11d,-0x50 (% rbp) 0x100000f29: movl% r10d,-0x54 (% rbp) 0x100000f2d: callq 0x100000e30 Sum at main.m:11 II. Switch case & if else2.1 disassembly if elseint a = 1; if (a > 1) {NSLog (@ "a > 1");} else if (a > 2) {NSLog (@ "a > 2");} else {NSLog (@ "a 1" 7, 0x100000f07: movq% rax,% rdi 8, 0x100000f0a: movb $0x0,% al 9, 0x100000f0c: callq 0x100000f5e Symbol stub for: NSLog 10, 0x100000f11: jmp 0x100000f4c; at main.m:21 11, 0x100000f16: cmpl $0x2,-0x14 (% rbp) 12, 0x100000f1a: jle 0x100000f36; at main.m 13, 0x100000f20: leaq 0x121 (% rip),% rax @ "a > 2" 14, 0x100000f27: movq% rax,% rdi 15, 0x100000f2a: movb $0x0,% al 16, 0x100000f2c: callq 0x100000f5e; symbol stub for: NSLog 17, 0x100000f31: jmp 0x100000f47; at main.m 18, 0x100000f36: leaq 0x12b (% rip),% rax; @ "a
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.