views:

82

answers:

4

Possible Duplicate:
Power Efficient Software Coding

Adobe announced at Google I/O that it's next version of Flash 10.1 is going to more efficient for devices where power consumption matters.

This got me to thinking: how do you write code that uses less power? Are there any helpful resources regarding this topic?

My guess would be that it is a combination of:

  • reducing the complexity of your application
  • writing efficient code that is executed quickly (presumably because processing time = power consumed)
+2  A: 

Seeing as though this is probably aimed towards embedded devices, I would venture to say that the best way to save power is to not be on, and to minimize how long the device is on. This means putting the processor to sleep and waking up only when work needs to be done. The best way I can think of to do this would to make an application entirely interrupt-driven.

Kevin
+1  A: 

In addition to Kevin's suggestion, I would think that minimizing Internet communications would help. This would include fetching data in bulk so more time can be spent asleep.

Steven Sudit
+1  A: 

Also keep in mind that accessing devices like drives and wifi increases power consumption. Try to minimize access to such devices.

Jim C
+2  A: 

There's actually one much bigger way to reduce power consumption that hasn't been touched on.

Let's take a computer and divide all functions into two basic groups. Those implemented in hardware and those implemented in software.

If a function is implemented in hardware (that is- there is circuitry for which you can put the inputs on one set of wires and the outputs come out another set of wires) then the power consumption is equal to the power consumed in the total number of gates. The clock ticks one time (draining a little power) and the bus goes hot for the output (draining a little power).

If a function is implemented in software (that is- there is no single circuit which is used to implement the function) then it requires the use of multiple circuits, multiple clock cycles, and often-times lots of memory calls. Keep in mind that SRAM (used for processor registers) is made of D flip-flops which are constantly draining power so long as they are in use.

As a simple example, let's look at the H.264 encoder. H.264 is a video encoding used by QuickTime videos. It's also used in MPEG videos, many AVIs, and it's used by Skype. Because it's so common someone sat down and found a way to make a chip in hardware to which you feed the encoded file on one end and the red, green, and blue video channels come out the other end.

Before this chip existed (and before Flash 10.1) you had to decode this using software. Decoding it involves lots of sines and cosines. Sine and cosine are transcendental functions (that is- there is no way to write them in the four basic math operations without an infinite series). This means that the best you could do what run a loop 32-64 times getting gradually more accurate, with each iteration of the loop adding, multiplying, and dividing. Each iteration of the loop also moves values in and out of registers (which- as you recall, uses power).

Flash used to decode video by mathematically decoding it in software. Now it just says "pass the video to the H.264 chip". Of course it also has to check for the existence of this chip and use software if it doesn't exist. This means Flash, as a whole, is now larger. But one any system (like HTC phones) with an H.264 chip, it now uses less power.

Apply this same logic for:

  • Multiplying (adding multiple times in software)
  • Modulus (an infinite series in software)
  • Comparing (subtracting and checking if negative in software)
  • Drawing (sines/cosines/nastiness in software. Easy to pass to a videocard)
steven_desu