Faster and stronger 64-bit programming of military rules

Source: Internet
Author: User
Tags integer numbers

Even if you haven't compiled advanced applications for nanoelectronics, aerodynamic, Molecular static, cell lifecycle modeling, and so on, maybe the following 32 rules are as follows, it will help you port programs to a higher-level processor.

Recently, it seems that everyone has been talking about 64-bit computing, such as amd athlon 64 processor laptops, Apple G5 using IBM PowerPC 970 chips, or whether the Intel itanium architecture will be canceled, in this regard, the IT industry and the press seem to have not enjoyed themselves. The impact of the new round of processors is not only manifested in improving database execution efficiency, improving the speed of graphics programs, but also paving the way for the compilation of applications to solve the world's most complex scientific problems.

In any case, the benefits of a 64-bit processor are not just as simple as copying a program to a new computer. At least, the application needs to be re-compiled with a 64-bit library, the worst case is that the entire program needs to be rewritten to remove other troubles such as non-portable pointer algorithms. Even so, new applications may not run better than the old 32-bit platform.

Fortunately, it is easier to figure out what needs to be done before you start, especially the performance and limitations of related processors. Similarly, as long as you follow certain rules, you can get the expected results with the minimal changes. In order to give everyone a good start, the following 32 military rules are proposed, including the technologies and information required to develop 64-bit applications.

First, there are small adverse factors

1. 64-bit processors have not been invented in recent years. Almost a decade ago, DEC and Sun launched 64-bit processors for high-end servers, motorola also launched its PowerPC 1996 processor in 620, and even in the same year, Nintendo also launched its Nintendo 64 game system. It was not until the advent of AMD athlon 64 and IBM PowerPC 970 processors in the last two years that people began to pay attention to the arrival of 64-bit computing. With these processors applied to desktop systems, analysts have begun to predict that 32-bit computing is about to kill (may be a little too early ).

2. 64-bit architecture processors, in itself, will not speed twice as much as 32-bit equivalent processors. Why? Because the 64-bit term simply describes the size of General registers of the processor, although this size determines the amount of data that can be processed at a time, it does not represent the speed of data processing.

3. Some applications run on 64-bit processors, which may be slower than 32-bit processors, mainly because the 64-bit address occupies more space in the cache, this reduces the cache hit rate. According to Tony Bourke's independent survey of Sun ultra 5 workstations, programs that do not execute a large number of data operations may reduce the cache hit rate by 20% on 64-bit platforms. "The expansion of data types, such as pointers, means that more memory is needed, and the memory becomes a bottleneck," said Andreas Jaeger, SuSE Linux project manager. "On a 64-bit platform, as the memory overhead increases, pointer tracking may be slower ". Next we have good news.

4. Why do we still need a 64-bit processor? One of the reasons is that a wider register bit can process larger numeric values at a time. In a 32-bit system, adding 1 to the power of 2 will cause overflow, because no more bit can store this value on 32-bit registers. In many programming languages, due to the provision of a special 64-bit structure, programmers who develop 32-bit programs generally rely on this to solve the problem of numerical overflow. In fact, these structs require the processor to perform two operations on two 32-bit registers, which is inefficient for programs that frequently execute complex mathematical operations. The 64-bit processor does not need two registers. In this way, in the field of scientific computing, programmers can write programs that solve more complex problems in a shorter period of time, one of the most obvious examples is virginiatech x supercomputer, which consists of 1100 Apple's double G5 processors, which is now the third-ranked supercomputer in the world. According to Apple, G5 processors are designed to run advanced applications such as nano electronics, Chemistry, Biochemistry, aerodynamic, Molecular static, cell life cycle modeling, and computational acoustics.

5. Another benefit of 64-bit computing is video editing (and rendering ). The powerful computing power brought by the 64-bit system is undoubtedly good news for video program developers. In the past, those programs that need to decode large videos can now be faster and more complex. This is even more true for the video game industry. game developers are always looking for new methods to show more realistic scenarios.

6. Some 64-bit processors have some special functions, which allow them to completely surpass 32-bit processors in terms of speed. For example, the amd x84-64 processor has 16 General registers-eight more than its 32-bit predecessors, the PowerPC processor has 32 General registers, and the itanium) there are 128 (although only 8 of them are visible to programmers, and the other 120 are allocated as needed by processors ). As mentioned above, applications can store more data inside the processor for convenient access, which is much better than loading data from the memory when data is needed.

"The Apple G5 processor contains two 64-bit floating point units, which are essential for Audio creation, 3D rendering, and scientific computing ." Anuj Nayar, spokesman of the apple developer Relations Association, said: "It also contains two 64-bit integer units, which greatly improves efficiency when calculating large integer numbers ."

7. On amd opteron and athlon 64 processors, if you want to perform byte operations, there is an additional advantage here, you can use the low byte bit of 16 general-purpose registers, this means that the application no longer needs to move data in some special registers.

8. Another benefit of the amd x86-64 processor architecture is the ability to allow applications to use directive pointers to help compute the addresses of functions and variables in the shared library. Without this rip (related instruction pointer), the application must use an additional register, so that it takes some time to set this register before each function call.

9. If you use the square root function built in G5 when compiling a program for the Apple G5 (PowerPC 970) processor, the performance will be greatly improved. Just like most of the optimizations for the processor, you must make the correct settings when compiling the program so that the compiler can use these new features as much as possible. Of course, if the program does not use the square root function, or is rarely used, it does not provide much help for the speed of the program. In addition, using these functions may increase the size of executable files.

10. 64-bit systems allow applications to access more than 4 GB of memory directly at a time, while 32-bit programs are limited to less than 4 GB, the reason is that the 32-bit register can only store the power 32-1 of the value 2. Once a 64-bit register is used, the program can address 264. Theoretically, it can access 18 Pb (18 Gigabit bytes) of memory, this is almost 4 billion times the size of 32-Bit Memory (the actual number of addressable memory depends on the operating system and related physical limits ).

11. addressable access to 18 Pb memory means that the database, complex 3D environment, and even the entire operating system can be stored in the memory, which is several times faster than they are on the hard disk. Of course, at present, computers in the world do not have 18 Pb of memory, but some itanium-based servers have as much memory as GB. Based on the current development trend, in the near future, both programs and computers will push the demand for memory to exceed this number.

12. At present, applications are also likely to boost demand for disk space, while the 64-bit architecture can address larger disk space, this makes managing a larger disk much easier. Just like how much memory can be accessed by an application, there are some restrictions on the disk, such as how many files can be stored on the disk and how large each file is.

13. Don't worry about y2k38 any more. Due to the UNIX system's time management method, many 32-bit applications that use the time_t data type will encounter problems similar to those of the millennium in January 19, 2038, because there are no more, it can be used to continue counting the number of seconds since January 1, 1970 (some procedures for mortgage and pension management may encounter such problems earlier, if these programs require Date Processing for many future events ). Fortunately, on a 64-bit system, no clock error occurred before the arrival of 292,000,000,000 a.m. It is important to note that the 64-bit library should be used to recompile the entire application to avoid this small "fault ".

Things to think about

14. A 64-bit operating system is required to fully utilize the performance of the 64-bit processor. Various variants of Linux/UNIX operating systems are emerging, including red hat, Suse, sun, turbolinux, and even Apple (Mac OS X, for Windows users, their selection is very limited. So far, Microsoft has released only English versions of Windows XP Professional x64 Edition and Windows Server 2003x64 Edition.

15. Contrary to the public opinion, 64-bit processors are not very helpful for encryption programs. According to Bruce Schneier, a security expert at secrets and lies, today's encryption methods are fast enough. "What is the significance of reducing from two milliseconds to one millisecond? The 64-bit processor will not bring a qualitative change to most encryption methods ."

16. For 32-bit and 64-bit systems, whether to send different binary files to users depends entirely on your code optimization method. For example, the simple re-compilation code for Apple G5 does not work well on the G4 of the old version. However, for the specific features of the G5 processor, if you modify the code, you have to provide a separate binary file. The best way to solve this problem is to make a judgment before executing code specific to a certain processor to check whether the current processor matches, but this also has disadvantages, because the generated binary file will be larger.

17. You can use only one system to develop programs on multiple platforms. For example, with GCC, you can generate a 32-bit x86 application and a 64-bit amd64 application on a 64-bit amd64 platform. When a 32-bit program is generated, you only need to include "-M32" in the compiler ".

Related Compilers

18. When optimizing program speed, you often have to sacrifice portability. This usually means that the hardware manufacturer provides a compiler that can generate faster executable code than the GNU Compiler. "GCC is an excellent compiler product, but the quality of code generation relies heavily on minor adjustments to specific processors," said Jaeger of Suse. "For example, intel compilers generally generate better code on the itanium processor. However, on the amd64 processor, the Code with the highest SPECint value is still generated by the GCC compiler."

19. In terms of code optimization for G5 processors, Apple provides its xcode tools suite for free for each OS X 10.3 operating system. This development kit includes an integrated development environment (IDE), a user interface generator, a debugger, and a GCC 3.3 compiler optimized for G5.

20. If it is developed for the athon 64 and opteron series, amd recommends Microsoft compiler. Linux users can achieve satisfactory results by using gcc.

21. On the itanium system, you can use the Intel C ++ compiler to generate highly optimized 64-bit executable code for those C/C ++ source codes. Intel has different compiler versions for Linux and Windows operating systems, both of which are priced at $399. There are also some third-party compiler products, including Microsoft, HP, IBM, and even SGI. If Linux users want to use the GCC compiler, it is best to take a look at Article 18th.

22. If you want to develop and optimize code on the ultrasparc processor, Sun provides the Sun ONE Studio development kit for about $ one thousand.

23. On Unix systems, the ilp32 (integer int, long, and pointer) data model is no longer applicable to 64-bit applications. If you have assumed that all int, long, and pointer lengths are 32 bits before writing a program, you must drop the transpose header to rewrite it, because the length of long and pointer is already 64 bits (lp64 ). Note that you should carefully check all the values and comparison statements related to int, long, and pointer.

24. In 64-bit windows, the length of long is still 32 bits, but the pointer and long are 64 bits, which are called llp64 models.

25. Converting a 64-bit pointer value to a 32-bit int (or a 32-bit long in Windows) will cause serious consequences. This problem can be avoided if you use a common data type when writing different code for 32-bit and 64-bit platforms. For example, if you are using C/C ++ on Windows, int_ptr is better than int if you want to store a pointer value. In Linux, this type is intptr_t. Using this generic data type ensures that the variable has enough bits to put down the pointer address, regardless of the processor.

26. Specify the data type in the constant expression. If you want to make a constant long, you must follow L or L after the value. Otherwise, the compiler may treat it as an int.

27. pay more attention to the device drivers. If your application is distributed along with the device driver or interacts with a third-party driver, remember that the Code must be re-compiled for a 64-bit object. Of course, if you or a third-party developer uses the ilp32 data model when writing a driver, you must update it in time to use the lp64 or llp64 model. For details, see articles 23rd and 24.

28. Be careful with the symbol extension in C language. For example, to convert an unsigned int to a 64-bit unsigned long, it must first be converted into a signed int, then signed long, and finally be converted to an unsigned long. During this period, any 31 Power int value that exceeds 2 will be treated as a negative number by the system, the negative signs will also be extended to the 32 new bits added for the conversion to long, And the unsigned long value converted to will be much larger than the original value.

29. The Data Alignment mode also changes from 32-bit to 64-bit. For example, a variable is 4-byte alignment in one architecture, and an octal alignment is formed on the other. Some programmers simply use some structures to avoid this problem. However, for those operations that require creating dynamic structures or performing one operation, it is very important to know how to handle the variable alignment mode at this time. One solution is to avoid coding the data size and offset into a constant. Instead, use the sizeof operator in the C language to determine the data size.

30. If your 64-bit program runs on Linux, the system must have a 64-bit library installed in the path ending with/lib64, it can be separated from the 32-bit reservoir. (Note that there is no 32-bit library on the DEC Alpha and itanium processors, and the 64-bit library is in the/lib directory .)

31. Windows XP Professional x64 Edition and Windows Server 2003x64 Edition allow 32-bit and 64-bit applications; however, they only have 64-bit libraries. All 32-bit commands are passed through the x86 simulation layer called wow64, which is responsible for converting the corresponding commands into calls to 64-bit libraries.

Please try again!

32. It is not difficult to optimize software for a 64-bit processor. You only need to know what to pay attention to and what to avoid. The only thing to remember is that after a program is transplanted to a 64-bit platform, there will be no performance improvement, but it will always be better than nothing.


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: 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.