[Switch] how to compile 64-bit applications for iPhone 5S.

Source: Internet
Author: User
Transferred from: http://blog.csdn.net/keyboardota/article/details/11993883with the release of iPhone 5S, we are concerned about the 64-bit CPU A7 used on 5s. In addition to the performance of A7, you will also be concerned about whether the 64-bit System Using A7 has any requirements for applications. Especially for application developers, we are all concerned about how our applications can be migrated to 64-bit systems to make full use of A7. In fact, these questions can be found in Apple's official documentation 64-bit transition guide for cocoa touch. For your convenience, I have sorted out some key points in 64-bit transition guide for cocoa touch, hoping to save you some time to read the documents in detail, if I understand something wrong, please correct it. First, A7 uses the arm V8 architecture. In addition to the 64-bit address bus and 64-bit registers, it also increases the number of registers, currently, the integer and floating-point register in A7 are twice that of A6. It should be emphasized that the increase of registers greatly increases the running speed of the program. The CPU is increased from 32-bit to 64-bit. The major change increases the addressing capability, and the 32-bit system can only access 3G memory (thanks to wanglang3081 for pointing out the problem here, in theory, the 32-bit system can access 4G memory because the power of 2 is about 4 290 000, many 32-bit systems can only access about 3 GB of memory because most of the addresses are allocated to the I/O system, so the total available memory is less than 4 GB .), However, the 32-bit to 64-bit change does not necessarily mean that the program runs faster. In some cases, the program runs slower because the data in the 64-bit system occupies larger memory. The increase in the number of registers directly increases the program running speed. Of course, the premise is that your application needs to re-compile the 64-bit system so that the program can fully use all the registers. Using xcode 5 can easily compile previous applications into 64-bit programs. The basic process is as follows: 1. Use xcode 5 to open the original project. 2. Change the supported devices to "iOS 7 ". 3. In "build setting", change "ubuntures" to "Standard ubuntures (including 64-bit )". 4. Run the test program to solve problems in the compilation process. Step 1 is the key. The specific problems may be related to the design of the original program, including whether the data type is used as a standard. Further details will be discussed later, in fact, the book 64-bit transition guide for cocoa touch mainly talks about these details. Before discussing the details, you can take a look at some macro content. The iOS 7 program compiled by xcode 5 contains two sets of binary code: 32-bit and 64-bit. The 32-bit binary code is called on the 32-bit IOS system, the 64-bit system calls 64-bit binary code to solve the problem of backward compatibility. At the same time, considering that many 32-bit programs may be deployed to 64-bit systems without re-compilation, the 64-bit IOS system has two sets of frameworks, one of which is 32-bit, one set is 64-bit. When the 64-bit IOS system runs the original 32-bit program, the system calls the 32-bit framework as the underlying support. When the system runs the 64-bit program, the system calls the 64-bit framework as the underlying support. That is to say, when an iPhone 5S runs both 32-bit and 64-bit programs, the system loads both the 32-bit and 64-bit frameworks into the memory, therefore, the memory consumption is also large. If all the programs running on a 64-bit iOS device are compiled by a 64-bit system, the IOS system will only load the 64-bit framework, which saves a lot of memory. Therefore, if you can quickly change the program to 64-bit, IOS will run faster. It is really "Hello everyone is really good ". Next let's take a look at some technical details for the 64-bit System Adjustment Program. There are two major differences between a 32-bit IOS system and a 64-bit IOS system: Data TypeThe difference is that Process callMethod Differences. In Data TypeThe main changes are the length changes of the pointer type and long integer type and the memory alignment mode, which also leads to changes in the data types at a higher level, for example, the length of nsinteger also changes. In Procedure Call MethodBecause arm V8 and arm V7 have different numbers of registers and have different process call conventions, the 32-bit and 64-bit systems are different at the Assembly level. Based on the changes in the above two aspects, the book summarizes the following points. developers can check the original 32-bit code based on the following points and port the application to a 64-bit system: 1. Do not assign long data (long) to an integer (INT)This code is fine in 32-bit systems, because the length of long and INT in 32-bit systems is the same, but there may be problems in 64-bit systems, in a 64-bit system, long is longer than Int. If you assign the long value to int, data loss will occur. 2. Do not assign the pointer type (pointer) to an integer (INT)To facilitate address computing, Programmers sometimes assign the pointer type to an integer. This code is fine in 32-bit systems, because in 32-bit systems, the length of pointer and INT is the same, however, there will be problems in 64-bit systems, because the pointer is longer than the int in 64-bit systems, assigning the pointer value to the int will lead to address data loss and eventually lead to serious problems. 3. Pay attention to numerical calculations related to digits.For example, if a long-type mask is used and the value is 0 at the top of the 64-bit system, the calculated result may not meet the expectation. There are also unsigned integers and mixed signed integers. 4. Pay attention to the changes in alignment ModeIf a 32-bit system defines a structure that contains two long types and the offset address of the second long value is 4, it can be obtained through the structure address + 4, however, in a 64-bit system, the offset of the second long value in a 64-bit system is 8. 5. fully consider data exchange between 32-bit applications and 64-bit applicationsBecause the user will exchange data through the network, and the data stored by the user may also be switched between the 32-bit system and the 64-bit system through backup, therefore, the application must fully consider when saving and sending stream data. For example, if the data is saved in a 32-bit system, can the data be opened normally in a 64-bit system, or, in turn, saved in a 64-bit system, and enabled in a 32-bit system. 6. rewrite all assembly codeThis does not need to be explained. If you embed assembly code in the code, you need to refer to the 64-bit system instruction set to rewrite assembly code. 7. Do not forcibly convert a variable parameter process to a variable parameter process, or convert a variable parameter process to a variable parameter process.In this case, the 32-bit system and 64-bit system have different processing methods for the two process calling methods. Check the program according to the above several key points. Of course, there are still a lot of details. You need to analyze the code and debugging results in actual work. In short, it is recommended that developers responsible for application migration fully read the 64-bit transition guide for cocoa touch.

[Switch] how to compile 64-bit applications for iPhone 5S.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.