How much electricity would be saved worldwide if Windows was writen in Assembly?

Page 4 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
Status
Not open for further replies.

Any_Name_Does

Member
Jul 13, 2010
143
0
0
You're accusing the entire Windows developmen team of incompetence? Wow, naive AND arrogant.

Using assembler is all well and good until you have to delay Win7 until 2020 so that you can optimize it properly. And then you find that a prima donna has used that new Intel instruction not supported by AMD, so anyone running an AMD machine gets a hard crash. So you try to debug, only thats so much harder than doing so in C/C++/C#, so that adds 2 weeks to your development time.

Really, theres a reason people dont use assembler for large projects. Until you have worked in dev, and you obviously havent, you just wouldnt have a clue. Its nice to want to improve the world, but really, this just isnt feasible or even a good idea.

You are playing aren't you? I am not accusing anyone. What I am saying is that at this time code optimization could help windows and it's users. Just like Intel moving to 22 nm process costs them a lot of money, but they still have to do it, otherwise their sales would start tanking.
 

Ancalagon44

Diamond Member
Feb 17, 2010
3,274
202
106
You are playing aren't you? I am not accusing anyone. What I am saying is that at this time code optimization could help windows and it's users. Just like Intel moving to 22 nm process costs them a lot of money, but they still have to do it, otherwise their sales would start tanking.

And you really, honestly and truly believe that the MS team havent thought of that? Or done optimization where they thought it was needed? Or conceded that the current level of optimization is good enough considering the hardware target and performance levels? And that spending another 2 years optimizing it would be a waste of other resources?
 

FishAk

Senior member
Jun 13, 2010
987
0
0
Come now, the number is not zero.

Due to the simple fact that the Op's proposal would slow development, the amount of energy saved would be significantly negative. The extra amount of time computers would have to work because of retarded evolution would mean a net increase in energy consumption.

Because development is exponential, allowing it's evolution by the most expedient way, has been decreases the energy demand for a given task exponentially.
 
Last edited:

Voo

Golden Member
Feb 27, 2009
1,684
0
76
Okay if you're that fixed on asm code, let's make a small game:

We both write a nice small boyer-moore string search - trivial algorithm that every decent programmer should be able to write in less than half an hour.. at least in C or any other higher level language that is (but still something I could imagine given students in a ASM course, not that hard)

Let's see how long it takes you in asm and how much performance you gain compared to my C version.

And really don't forget that that's a trivial algorithm, nothing anywhere near what the kernel of a modern OS would look like. So if you want something a little bit more demanding how about a multi threaded (after all multi threading is the way to go in this time and age) 3d stencil computation? Cache oblivious if we're at it.
If you get THAT right in assembly and get a measureable performance improvement compared to a optimized Cilk programm I'll applaud you and you should be able to get a job whereever you want.. honestly I don't think I could write that efficient even in something like MPI.

Optimizing a program written in C to get more performance out of it? For some applications, especially in HPC, sure that's worth it. Manual register allocation, making sure that the FMAs are maximized, yep.
And I'm also sure that some parts in windows is heavily optimized, but writting complex programs completely in asm? Never, just not worth the cost. Also you seem to forget that if you're using asm you've got to write every program half a dozen times. Itanium, x86, x86-64, or even so trivial things like SSE available or not.
And at that level, even the architecture itself starts to play an important role, I've seen PowerPCs that used parts of the fp pipe for ld/st ops.. meant you just couldn't more than ~90% of peak performance out of it.

No there are many better ways to optimize programs today, you can probably speed up 50% of all matrix multiplications by rewriting them as cache oblivious for example - that's something no compiler can do for you.

Engineering is always about tradeoffs, at google for example lots of new code is written in python (well c++ is still dominant, but that has historic reasons) and you really need a case before something will be rewritten in c++. The performance improvements have to be large enough to warrant all that invested time, testing and - extremely important but somehow completely ignored here - maintainability.
Some parts of the inner search loop surely are asm, since that's where it matters, but that's the exception and can be compared to the inner loops of the scheduler in windows that are surely optimized as well.
 
Last edited:

Edrick

Golden Member
Feb 18, 2010
1,939
230
106
MS could continue as usual, but also employ some opimizers, who work on finished code and shave off clock cycles here and there.

How do you know they do not already?

I used to work for a software development company. We wrote all our applications in C/C++. But we had one ASM developer who would work on some optimizations in ASM. It was never advertised and Im certain no one outside the company knew we did that.

I agree that in a perfect world, Windows written in ASM would be more efficient. But this is not a perfect world and the cons outweigh the pros by a large scale, as most people replying already pointed out.
 

A_Dying_Wren

Member
Apr 30, 2010
98
0
0
Come now, the number is not zero.

Due to the simple fact that the Op's proposal would slow development, the amount of energy saved would be significantly negative. The extra amount of time computers would have to work because of retarded evolution would mean a net increase in energy consumption.

Because development is exponential, allowing it's evolution by the most expedient way, has been decreases the energy demand for a given task exponentially.

From a hardware perspective you'd be right but in software I don't think so. Each version of windows seems to need more and more resources to run optimally (maybe except vista --> 7). If anything, having to slow down the pace of OS development to allow for greater efficiencies within the next iteration would decrease power both now and in the future.

Not that I'm suggesting that the above is in any way what microsoft are going/want to do.
 

DrPizza

Administrator Elite Member Goat Whisperer
Mar 5, 2001
49,601
167
111
www.slatebrookfarm.com
I agree with the OP that because of the number of computers using different Windows operating systems, the overall amount of energy that could be saved is a huge amount.

However, that "huge amount" only *seems* huge. When compared to the overall energy consumption on the planet, it's probably a pretty insignificant amount. I haven't seen any real numbers tossed about, but the OP himself did toss out a 10 million dollar figure. That amount is fairly laughable. In fact, an extra couple months delay in releasing a new OS probably costs Microsoft significantly more than that.

However, for a simpler example, let's move away from the operating system and just look at browsers. IE, Firefox, Opera, etc. They're significantly different in size, and there's quite a difference in efficiency. Is this because one is written in C and the other is written in ASM? I don't think so. It comes down to the actual coding.

So the OP wrote an algorithm that optimizes for time alone in a search. Great. But, does your algorithm do what the code you're comparing it to does? Does that code do a lot of other things - little spinning clocks or whatever so the idiot user (there are plenty of consumers fitting that description) doesn't reboot their computer after waiting 5 seconds? Are you operating on the assumption that all code is written to optimize time?
 

SunnyD

Belgian Waffler
Jan 2, 2001
32,675
146
106
www.neftastic.com
There will be so little to optimize that the argument is pointless. 98% of the inefficiency of Windows, or any of the operating system for that matter resides with the user. No amount of code in any language will fix that.
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
Okay if you're that fixed on asm code, let's make a small game:

We both write a nice small boyer-moore string search - trivial algorithm that every decent programmer should be able to write in less than half an hour.. at least in C or any other higher level language that is (but still something I could imagine given students in a ASM course, not that hard)

Let's see how long it takes you in asm and how much performance you gain compared to my C version.

And really don't forget that that's a trivial algorithm, nothing anywhere near what the kernel of a modern OS would look like. So if you want something a little bit more demanding how about a multi threaded (after all multi threading is the way to go in this time and age) 3d stencil computation? Cache oblivious if we're at it.
If you get THAT right in assembly and get a measureable performance improvement compared to a optimized Cilk programm I'll applaud you and you should be able to get a job whereever you want.. honestly I don't think I could write that efficient even in something like MPI.

Optimizing a program written in C to get more performance out of it? For some applications, especially in HPC, sure that's worth it. Manual register allocation, making sure that the FMAs are maximized, yep.
And I'm also sure that some parts in windows is heavily optimized, but writting complex programs completely in asm? Never, just not worth the cost. Also you seem to forget that if you're using asm you've got to write every program half a dozen times. Itanium, x86, x86-64, or even so trivial things like SSE available or not.
And at that level, even the architecture itself starts to play an important role, I've seen PowerPCs that used parts of the fp pipe for ld/st ops.. meant you just couldn't more than ~90% of peak performance out of it.

No there are many better ways to optimize programs today, you can probably speed up 50% of all matrix multiplications by rewriting them as cache oblivious for example - that's something no compiler can do for you.

Engineering is always about tradeoffs, at google for example lots of new code is written in python (well c++ is still dominant, but that has historic reasons) and you really need a case before something will be rewritten in c++. The performance improvements have to be large enough to warrant all that invested time, testing and - extremely important but somehow completely ignored here - maintainability.
Some parts of the inner search loop surely are asm, since that's where it matters, but that's the exception and can be compared to the inner loops of the scheduler in windows that are surely optimized as well.

Another game. You write the code and I'll optimize it. But you'll have to heavily comment your code, as asm is the only language I know. of course if I was doing it professionally I could learn a c syntax in matter of months or even weeks. It is not about asm competing c, rather improving the code. Yes it takes time and money. but so does sandy bridge, and people in these forums are eagerly awaiting it.
Also considering that mobile OSes are taking off, every clock cycle saved is valuable.
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
How do you know they do not already?

I used to work for a software development company. We wrote all our applications in C/C++. But we had one ASM developer who would work on some optimizations in ASM. It was never advertised and Im certain no one outside the company knew we did that.

I agree that in a perfect world, Windows written in ASM would be more efficient. But this is not a perfect world and the cons outweigh the pros by a large scale, as most people replying already pointed out.

How I know it? I think somewhere in this thread I pointed out that I have done some benchmarking Windows API against some optimized asm code.
 

aphorism

Member
Jun 26, 2010
41
0
0
the cost of software development vastly exceeds the cost of hardware development. comparing the costs of intel's manufacturing to microsofts development teams is not fair.
 

Wizlem

Member
Jun 2, 2010
94
0
66
I wondered into this thread simply because I thought the original question(based on an assumption of improved efficiency from assembly) was atleast somewhat interesting from a theoretical standpoint. I have just spent an overly large amount of time going through 4 pages of crap about practicality and not a single answer which looked past that and gave even some semblance of an answer so here goes. If we ignore all practicality and say 25% efficiency could be gained on 1 billion computers running 8 hours per day using 100 watts on average and energy costs $0.10 per kilowatt hour we get a savings of 0.25*1,000,000,000computers*8hours/day*0.1kilowatts/computer*$0.1/kilowatt = $20,000,000/day. If you compare this number to just US GDP/day its only like 0.06%. Interesting question but there are better and easier ways to save energy.
 

Voo

Golden Member
Feb 27, 2009
1,684
0
76
Another game. You write the code and I'll optimize it. But you'll have to heavily comment your code, as asm is the only language I know. of course if I was doing it professionally I could learn a c syntax in matter of months or even weeks. It is not about asm competing c, rather improving the code. Yes it takes time and money. but so does sandy bridge, and people in these forums are eagerly awaiting it.
Also considering that mobile OSes are taking off, every clock cycle saved is valuable.
That's something completely different. Now we're from "writing code in asm" to "optimizing some important parts" - something which is already done (note the "important" - that's most probably only internal parts of the Kernel and not some public APIs)
Also how do you check that your implementations are equivalent if you don't know C? I wouldn't claim that without some test cases and probably a fuzztester.

And mobile OSes? There the problem with portability is way more problematic than on the desktop, you want to write a different OS for every mobile plattform out there? Sounds fun.

Also you said you optimized a string concatenation lib - I'd love to see what exactly you did there, since I don't see a lot of optimization potential there. And about your search api.. how well does it handle hard links, different filesystems, localisation (oh I bet you ignored that) and so on?
Assembly is nice in a few selected parts, but most of the time you can optimize the code in the high level language as well - with the right datastructures and algorithms you can optimize much more than shaving off a few instructions here and there. If you've done that and still think that the 5% performance improvement is worth 300hours of engineering time than you may look at the asm code and look what the compiler did.

@aphorism: Actually I'm not sure about that, HDLs aren't that different to programming languages to begin with and Intel is already employing more sw than hw engineers. Both things are large and horribly complex (though I admit writing a minimal Kernel is much more complex than a small RISC machine).
Verilog or VHDL code does not look that different to pascal..
 

A_Dying_Wren

Member
Apr 30, 2010
98
0
0
I wondered into this thread simply because I thought the original question(based on an assumption of improved efficiency from assembly) was atleast somewhat interesting from a theoretical standpoint. I have just spent an overly large amount of time going through 4 pages of crap about practicality and not a single answer which looked past that and gave even some semblance of an answer so here goes. If we ignore all practicality and say 25% efficiency could be gained on 1 billion computers running 8 hours per day using 100 watts on average and energy costs $0.10 per kilowatt hour we get a savings of 0.25*1,000,000,000computers*8hours/day*0.1kilowatts/computer*$0.1/kilowatt = $20,000,000/day. If you compare this number to just US GDP/day its only like 0.06%. Interesting question but there are better and easier ways to save energy.

+1

Of course it's more than just the US we'd be looking at but I'd say its fairly representative of developed nations in general.

Plugging in some data from wiki, assuming 4157 terawatt hours of energy a year, 3% of which is spent on computing (figure found by the Lawrence Berkeley Labs) and assuming you can actually genuinely get 25% efficiencies from which which I extremely doubt, you'd save 31.1775 terawatt hours a year which I would solidly place as a best case scenario which is 3,559 megawatts. Its a fair bit to save if you can really extract such efficiencies which I doubt.

I think 10% would be extremely generous especially given that the OS really doesn't take up that much resources in comparison to the software written on it. There wouldn't be a substantial increase in efficiency of programs running on the OS if it were rewritten in assembly right? If there isn't such an increase in efficiency, perhaps 1% is as far as you'll get.
 
Last edited:

Any_Name_Does

Member
Jul 13, 2010
143
0
0
From a hardware perspective you'd be right but in software I don't think so. Each version of windows seems to need more and more resources to run optimally (maybe except vista --> 7). If anything, having to slow down the pace of OS development to allow for greater efficiencies within the next iteration would decrease power both now and in the future.

Not that I'm suggesting that the above is in any way what microsoft are going/want to do.

Thanks :D
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
I agree with the OP that because of the number of computers using different Windows operating systems, the overall amount of energy that could be saved is a huge amount.

However, that "huge amount" only *seems* huge. When compared to the overall energy consumption on the planet, it's probably a pretty insignificant amount. I haven't seen any real numbers tossed about, but the OP himself did toss out a 10 million dollar figure. That amount is fairly laughable. In fact, an extra couple months delay in releasing a new OS probably costs Microsoft significantly more than that.

However, for a simpler example, let's move away from the operating system and just look at browsers. IE, Firefox, Opera, etc. They're significantly different in size, and there's quite a difference in efficiency. Is this because one is written in C and the other is written in ASM? I don't think so. It comes down to the actual coding.

So the OP wrote an algorithm that optimizes for time alone in a search. Great. But, does your algorithm do what the code you're comparing it to does? Does that code do a lot of other things - little spinning clocks or whatever so the idiot user (there are plenty of consumers fitting that description) doesn't reboot their computer after waiting 5 seconds? Are you operating on the assumption that all code is written to optimize time?

That 10 000000 dollar saving is every month. besides I assumed 1 cent savings a month per computer. In reality those savings would be far mor than 1 cent.
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
That's something completely different. Now we're from "writing code in asm" to "optimizing some important parts" - something which is already done (note the "important" - that's most probably only internal parts of the Kernel and not some public APIs)
Also how do you check that your implementations are equivalent if you don't know C? I wouldn't claim that without some test cases and probably a fuzztester.

And mobile OSes? There the problem with portability is way more problematic than on the desktop, you want to write a different OS for every mobile plattform out there? Sounds fun.

Also you said you optimized a string concatenation lib - I'd love to see what exactly you did there, since I don't see a lot of optimization potential there. And about your search api.. how well does it handle hard links, different filesystems, localisation (oh I bet you ignored that) and so on?
Assembly is nice in a few selected parts, but most of the time you can optimize the code in the high level language as well - with the right datastructures and algorithms you can optimize much more than shaving off a few instructions here and there. If you've done that and still think that the 5% performance improvement is worth 300hours of engineering time than you may look at the asm code and look what the compiler did.

@aphorism: Actually I'm not sure about that, HDLs aren't that different to programming languages to begin with and Intel is already employing more sw than hw engineers. Both things are large and horribly complex (though I admit writing a minimal Kernel is much more complex than a small RISC machine).
Verilog or VHDL code does not look that different to pascal..

I think the best is that someone writes the code in c where the mind has more free room for better algorythm, and someone else optimizes the loops.
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
+1

Of course it's more than just the US we'd be looking at but I'd say its fairly representative of developed nations in general.

Plugging in some data from wiki, assuming 4157 terawatt hours of energy a year, 3% of which is spent on computing (figure found by the Lawrence Berkeley Labs) and assuming you can actually genuinely get 25% efficiencies from which which I extremely doubt, you'd save 31.1775 terawatt hours a year which I would solidly place as a best case scenario which is 3,559 megawatts. Its a fair bit to save if you can really extract such efficiencies which I doubt.

I think 10% would be extremely generous especially given that the OS really doesn't take up that much resources in comparison to the software written on it. There wouldn't be a substantial increase in efficiency of programs running on the OS if it were rewritten in assembly right? If there isn't such an increase in efficiency, perhaps 1% is as far as you'll get.

I want to be cooperative with your staterment. lets say 1 percent gain. we are talking about 1 percent which is accumulating every day.
 

cschill1290

Member
Feb 26, 2008
189
0
76
Not to try and start another arguement, but here goes. If rewriting the windows OS in ASM would yield such power savings and more speed/optimization, why hasn't microsoft done it yet? After all they are one of the most successful corporations in the U.S., so obviously they tend to make pretty sound business decisions. I'm sure you (OP) aren't the first person to have this thought. They have most likely explored it with their greatest minds and come to the same conclusions that others in this thread have. There are no substantial gains to changing over to ASM coding. Otherwise they would have explored it if it were worth their while.
 

taltamir

Lifer
Mar 21, 2004
13,576
6
76
If we ignore all practicality and say 25% efficiency
Here is the problem, even if you completely ignore practically, saying that "programming in assembly will increase power efficiency by 25%" is completely off the hook. I would actually say that programming all in assembly will give you WORSE power efficiency... even if you totally ignored practicality... to quote myself:

1. If MS was writing windows in assembly, it wouldn't be popular (due to lack of features) and people will use something else, no change there. Assembly = Nobody use it.
2. If forced to program in assembly, programmers are not automatically creating better code. The compiler can create better code then a programmer if the compiler has been optimized for efficiency, and the programmer doesn't know every little thing about coding efficient code. So, Assembly =! better code.
3. If forced to write it in assembly, MS would be too busy implementing basic features to get around to program all those nice power saving features they have created. As a result PCs would be less efficient, since they would be lacking the power saving features they currently have. So, Assembly = Less power saving features.

Reason 1 deals with practicality.
Reason 2 and 3 are why even if you ignored practicality, I SUSPECT (it is too impractical to confirm) that we will end up with worse overall power efficiency, rather then better power efficiency.

Not to try and start another arguement, but here goes. If rewriting the windows OS in ASM would yield such power savings and more speed/optimization, why hasn't microsoft done it yet?

AFAIK Microsoft already codes specific parts of the OS in assembly. (and assigns their best programmers and software engineers to those projects... ones who are experts in engineering and writing efficient code)

I guess you could always make the assumption that only the world's best programmers and software engineers would work on this "pure assembly windows" project, and will also take the time to perfectly optimize every single piece of code. since you are already tossing out any other semblance of feasibility.
 
Last edited:

bryanl

Golden Member
Oct 15, 2006
1,157
8
81
How large is Windows compared to the Nike-X/Spartan anti-ballistic missile system control program, which was perhaps the largest computer program written in the 1960s or early 1970s and was written in assembly language?
 

Voo

Golden Member
Feb 27, 2009
1,684
0
76
How large is Windows compared to the Nike-X/Spartan anti-ballistic missile system control program, which was perhaps the largest computer program written in the 1960s or early 1970s and was written in assembly language?
Even Win3.1 - something embarassingly small compared to Vista or Win7 - had over 3 million LoC. Modern Linux kernels are somewhere above 13million (that's the kernel only, Windows is much more than the OS kernel).

No idea how large that program was, but I doubt that it's anywhere near that size and complexity.. probably had lots of redundancy built in for apparant reasons.
 

Munky

Diamond Member
Feb 5, 2005
9,372
0
76
Smaller code does not mean more efficient code. With modern CPUs capable of decoding and issuing multiple instructions at once, efficiency comes from utilizing clever algorithms and well-designed compilers to maximize performance. The old rules from decades ago simply do not apply these days.
 
Status
Not open for further replies.