advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Do you have code where you think this type of inlining operation would provide a meaningful performance improvement? Given the ever-increasing speed of processors on both desktops and mobile devices, how important do you think such optimizations are? Should inlining remain the province of game programmers or should compilers take advantage of such features automatically, without programmer involvement? Let us know in the Wireless discussion group on DevX.
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.5/5 | Rate this item | 4 users have rated this item.
 

Optimizing Fixed Point (FP) Math with J2ME

Although hard-core code optimization on modern fast desktop and server machines is an arcane and disappearing art, there's still a need for such optimization when targeting the less powerful processors used in the handheld and mobile devices, particularly for game programming. 


advertisement
nce upon a time, game programmers had to write code in assembler and make many other optimizations to deliver games that ran well even with the slow processors and small memory address spaces available then. Today, processors running at gigahertz speed and hundreds of megabytes of RAM help programmers climb out of the Black Programming Art Tower—a place where only a few could survive.


In fact, the power unleashed by modern PCs is so huge, even compared to computers only ten years ago, that programmers began ignoring the optimizations and creating high-quality games that require increasing amounts of processor power, memory, and disk space. These less-optimized games have proven at least as addictive as the earlier games. In other words, the massive increase in computing power simplified game programming by removing the need for the very knowledge and optimizations that once made game programming an arcane art. For a while it seemed as if the Black Programming Art Tower was closed for good. Only a small number of game companies still push our desktop computers to the edge.

But history repeats itself. The handhelds and mobile devices gaining devotees today have characteristics very similar to the less-powerful desktop computers of the past. Small-footprint devices are back—but if you want great games-to-go, they bring with them the need to master obscure optimization techniques. One such optimization involves fixed-point math.

Fixed-point Math
FP math is a great optimization technique, particularly for math-intensive applications such as 3-D games; but instead of showing you how to perform arithmetic operations on FP numbers, a topic already covered in many other places, this article focuses on how to optimize FP operations to achieve a greater performance.

FP Libraries
One of the easiest ways to implement FP math in your program is to use one of the free FP libraries available. You substitute standard arithmetic operations with calls to the FP library. While this works well in most cases and lets you use fractions in your program, making large numbers of calls to methods in another class, the FP class, eats precious CPU cycles.

This is a direct consequence of the way the Java Virtual Machine works. For every method call, the JVM builds a new stack frame and copies method parameters to that newly created stack frame. Upon completion, it must copy the method's return value to the previous stack frame. Finally, it must destroy the current stack frame. That's a lot of work!

To reduce that workload, you have to remove the calls to the FP class methods in your code.

  Next Page: Eliminating FP Method Calls


Page 1: IntroductionPage 3: Inlining FP Arithmetic Automatically
Page 2: Eliminating FP Method Calls 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Help  |   Site Map  |   Network Map  |   About


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers