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

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

aphorism

Member
Jun 26, 2010
41
0
0
i already did, in less than 10 lines. i didnt output to a .txt file b/c that's not necessary.

Code:
int main()
{
	int c, time = GetTickCount();
	for(int i=1; i<10000; i++)c = sqrt(i * i + i * i);
	time -= GetTickCount();
        cout << time;
        return 0;
}
 
Last edited:

bigpow

Platinum Member
Dec 10, 2000
2,372
2
81
Back in 1990, my micro prof told my class that all computers on the planet could be connected all together if everyone started using UNIX.
Of course, my buddies and I, despite our love for machine language, just laughed at him. We chose Wing Commander and Ultima, over UNIX.

I believe if we really want to save electricity, then we can't use any MULTIPURPOSE DEVICES, e.g., game consoles to play games, word processor or business computers for businesses, 1-2 seater car for carpool, ban SUV & minivans, ban any vehicles older than 10yrs or less than 20MPG combined, etc. Basically, only specific purpose devices to do specific tasks, and only efficient specific purpose devices are allowed.

Of course, this is not possible since it violates human rights and the spirit of freedom.
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
i already did, in less than 10 lines. i didnt output to a .txt file b/c that's not necessary.

Code:
int main()
{
    int c, time = GetTickCount();
    for(int i=1; i<10000; i++)c = sqrt(i * i + i * i);
    time -= GetTickCount();
        cout << time;
        return 0;
}

make it executable and output it to a text file so we can measure the speed.
gettickcount won't work.
 

aphorism

Member
Jun 26, 2010
41
0
0
meh. there are some libraries that will give you low level access to time but i dont really feel like taking it that far if the user cant even notice the difference.
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
Back in 1990, my micro prof told my class that all computers on the planet could be connected all together if everyone started using UNIX.
Of course, my buddies and I, despite our love for machine language, just laughed at him. We chose Wing Commander and Ultima, over UNIX.

I believe if we really want to save electricity, then we can't use any MULTIPURPOSE DEVICES, e.g., game consoles to play games, word processor or business computers for businesses, 1-2 seater car for carpool, ban SUV & minivans, ban any vehicles older than 10yrs or less than 20MPG combined, etc. Basically, only specific purpose devices to do specific tasks, and only efficient specific purpose devices are allowed.

Of course, this is not possible since it violates human rights and the spirit of freedom.

it is not just about saving electricity. it is more about efficiency. for someone who writes programs which are used by relatively few people and not so often, it does't make a differece what language is used. But window is used by so many people and it is runnig the moment you turn on the computer having faster code makes good sense.
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
it is not just about saving electricity. it is more about efficiency. for someone who writes programs which are used by relatively few people and not so often, it does't make a differece what language is used. But window is used by so many people and it is runnig the moment you turn on the computer having faster code makes good sense.

did you read this thread?

http://forums.anandtech.com/showthread.php?t=2080936
 

Any_Name_Does

Member
Jul 13, 2010
143
0
0
meh. there are some libraries that will give you low level access to time but i dont really feel like taking it that far if the user cant even notice the difference.

ok. compile that code. you don't need the gettickcount. I'll disassemble it. and look at the generated code. if I am convinced that my code is at least twice as fast as yours, I will come back here and tell you so. otherwise you win and I take back everything I said.
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
I just took a look at it. it would be good to know what point you want to make.

That even C/C++ is often not worth the trouble for developing some applications. The same can be said for ASM. Efficiency in writing code is more important 99&#37; of the time for businesses, including MS.

I could what? Where did I mention how much hardware we use? Hardware is dirt cheap. Cycles are dirt cheap. Disk space is dirt cheap. Bandwidth is dirt cheap. You know what isn't dirt cheap? Time and talent.



It's more than good enough. It's a perfect fit for what we needed to build. Your question of "how can we make this better/faster/more efficient" is not a bad question to ask, but you're creating the question to justify your preexisting answer. So I'll repeat myself: nothing about this system would have been "better/faster/more efficient" in any meaningful way if it had been written in an unmanaged language. Nothing. Yet, you would have decided to use the unmanaged language in the beginning, without even considering whether the project required it, because you assume it will be better.
 

aphorism

Member
Jun 26, 2010
41
0
0
cycles arent cheap for all applications. i really dont know about you but i need more compute power. hardware companies would not bother making faster hardware if it wasnt needed. they wouldnt spend time on things like avx or sse either.

i can give you more info about the source code if i disassemble it. i added a integer sqrt function. it's not the same code i posted.

do you want the .exe?
Code:
; Listing generated by Microsoft (R) Optimizing Compiler Version 16.00.30319.01 

	TITLE	c:\Users\aphorism\documents\visual studio 2010\Projects\....
	.686P
	.XMM
	include listing.inc
	.model	flat

INCLUDELIB OLDNAMES

PUBLIC	?isqrt@@YAHH@Z					; isqrt
PUBLIC	__real@3fc00000
PUBLIC	__real@3f000000
EXTRN	__fltused:DWORD
;	COMDAT __real@3fc00000
; File c:\users\aphorism\documents\visual studio 2010\projects\....
CONST	SEGMENT
__real@3fc00000 DD 03fc00000r			; 1.5
CONST	ENDS
;	COMDAT __real@3f000000
CONST	SEGMENT
__real@3f000000 DD 03f000000r			; 0.5
; Function compile flags: /Ogtp
CONST	ENDS
;	COMDAT ?isqrt@@YAHH@Z
_TEXT	SEGMENT
_x$ = -4						; size = 4
_rr$ = -4						; size = 4
?isqrt@@YAHH@Z PROC					; isqrt, COMDAT
; _r$ = edx
; Line 20
	push	ebp
	mov	ebp, esp
	push	ecx
; Line 25
	movss	xmm5, DWORD PTR __real@3f000000
; Line 28
	movss	xmm4, DWORD PTR __real@3fc00000
	xorps	xmm3, xmm3
	cvtsi2ss xmm3, edx
	movss	DWORD PTR _rr$[ebp], xmm3
	mov	eax, -1100021760			; be6f0000H
	sub	eax, DWORD PTR _rr$[ebp]
	movaps	xmm2, xmm3
	shr	eax, 1
	mov	DWORD PTR _x$[ebp], eax
	movss	xmm1, DWORD PTR _x$[ebp]
	movaps	xmm6, xmm1
	movaps	xmm0, xmm1
	mulss	xmm6, xmm1
	mulss	xmm2, xmm5
	mulss	xmm1, xmm2
	mulss	xmm0, xmm4
	mulss	xmm6, xmm1
	subss	xmm0, xmm6
; Line 29
	cmp	edx, 101123				; 00018b03H
	jle	SHORT $LN1@isqrt
	movaps	xmm1, xmm0
	mulss	xmm1, xmm4
	movaps	xmm4, xmm0
	mulss	xmm4, xmm0
	mulss	xmm0, xmm2
	mulss	xmm4, xmm0
	subss	xmm1, xmm4
	movaps	xmm0, xmm1
$LN1@isqrt:
; Line 30
	mulss	xmm0, xmm3
	addss	xmm0, xmm5
	cvttss2si ecx, xmm0
; Line 31
	mov	eax, 1
	sub	eax, ecx
	imul	eax, ecx
	add	eax, edx
	sar	eax, 31					; 0000001fH
; Line 32
	mov	esp, ebp
	pop	ebp
	ret	0
?isqrt@@YAHH@Z ENDP					; isqrt
_TEXT	ENDS
PUBLIC	_main
; Function compile flags: /Ogtp
;	COMDAT _main
_TEXT	SEGMENT
_main	PROC						; COMDAT
; Line 17
	xor	eax, eax
; Line 18
	ret	0
_main	ENDP
_TEXT	ENDS
END
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
cycles arent cheap for all applications. i really dont know about you but i need more compute power. hardware companies would not bother making faster hardware if it wasnt needed. they wouldnt spend time on things like avx or sse either.

that's not my point. i'm saying a financially sound company is not going to spend exponentially more money for minuscule gains in throughput. it's not smart business.

and the biggest bottleneck in applications is and will always be user interaction. who cares if you shave off a couple of ms if the user still has to spend 20 minutes using it?
 

jchu14

Senior member
Jul 5, 2001
613
0
0
3² + 4² = 5² = 25
4² + 3² = 5² = 25
5² + 12² = 13² = 169
6² + 8² = 10² = 100
7² + 24² = 25² = 625
and you go on until a and b reach 10000

ok?

So you want to find all of the Pythagorean triples such that a and b < 10,000? Is that right? and out put the results to a text file.

for the text file would for example, look like this:

3 4 5
4 3 5
5 12 13
6 8 10
... etc.

Then I don't see how aphorism's program does that?
 

ModestGamer

Banned
Jun 30, 2010
1,140
0
0
in reality the kernel is already fairly optimized. But it also should not be millions of lines of code. It should at best be a few thousand. We are talking about the kernel. Not the external compiles run at start up. The kernel handles the data delegation and handshake to the bios.

If you really want to look for a place with a potential for improvement. a virtual bios tat gets loaded at boot up as a feature of the kernel might not be a bad place to start.

but that would require compiling the code to run on the target machine directly on the target machin during instilation. a slow and lengthy process at the front end. But it would result in a very fast machine. Until you plugged in a USB joystick. you most likely have to recompile again.

I don't know that much about writing higher language stuff. I do know for a fact that assembler has a high efficiency if written by skilled coder and can by absolute shit when written by bad coders.

The truth is a good c compiler "if optimized for a particular architecture" can deliver code thats 99% as good as hand written assembler by competent coders.

The kernel is still going to be millions of lines isn't it?

If you change or optimise something there is always the possibility that it will break something else, which means it will take ages to implement.

That bit of redundant code you thought was redundant didn't turn out to be so redundant after all...

Edit: Yeah even linux kernels have surpassed 10 million lines of code... good luck with Win7!
 

EarthwormJim

Diamond Member
Oct 15, 2003
3,239
0
76
that's not my point. i'm saying a financially sound company is not going to spend exponentially more money for minuscule gains in throughput. it's not smart business.

and the biggest bottleneck in applications is and will always be user interaction. who cares if you shave off a couple of ms if the user still has to spend 20 minutes using it?

Here's the way I think of it. The OS is not the program anyone really wants to use. All the OS does is enable people to use the programs that they want to actually use. Who really just uses windows.

Ideally an OS is transparent to hardware, it doesn't suck any cycles. That's not possible so what we want is as efficient as possible of an OS, that doesn't get in the way of launching whatever program we want to use (crash or be incompatible). Since the OS is running 100&#37; of the time, any increase in efficiency will add up over time. 1ms saved every minute can add up.

At the same time, an OS needs to not get in the way of letting us do what we want with the computer. That's where the difficulty in using ASM comes in. Difficult to trouble-shoot, difficult to implement for large amounts of code, difficult to upgrade, difficult to use in the role that OS's play. The OS also needs to be compatible with whatever a user is expected to throw at it software or hardware wise.

You cannot measure efficiency in only power usage. We don't use computers just to see how much power they draw or could draw. We actually do work with them! What makes windows relatively easy to use and highly compatible is the fact that most of it was written in high level (or in C's case middle level?).

Wherever it is feasible to use asm in the OS, and the gains are substantial enough, I cannot fathom that Microsoft or Apple or Linux developers wouldn't use asm. So it seems like the majority of the work that any_name is proposing is already being done or has been done. You can't write an OS like Windows completely in asm, but the parts where gains can be had, asm is used.


Conversely lets be realistic, an OS written in mostly in asm will not be as reliable as an OS written in higher level languages (you cannot debug to the same degree with asm). Think about the wasted energy from users restarting their computers, restarting their programs and dealing with crashes.



Any_name_does are you a Compsci major or did you learn assembly on your own (oh God why learn asm on your own!!!)? You had mentioned you don't know C, yet you know assembly? I have yet to meet an EE or CE or Compsci Major who didn't know C.
 
Last edited:
Status
Not open for further replies.