asm for computer

Feel like posting Off Topic? Do it here.

Moderator: MaxCoderz Staff

User avatar
Batman
New Member
Posts: 71
Joined: Thu 29 May, 2008 1:44 pm
Location: Over the Rainbow

asm for computer

Post by Batman »

whats the big difference in asm for z80 and asm for any other computer?
like a del optiplex gx280...<- (is that a computer???)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: asm for computer

Post by King Harold »

What kind of computer are we talking about? The common x86 / AMD64 types?
The one you mentioned is more of a PC model - it's like, well, like saying "TI 84+ assembly" or something :)

You have to worry about helping the out-of-order core to do things in parallel, break dependacy chains, interleave chains that can not be broken, avoid partial read/write of any register including flags (so inc/dec is bad, use add/sub unless you absolutely need the C flag), avoid instructions that generate more than 1 µop if possible (complex instructions), always try to avoid instructions that need a microcode ROM lookup (even complexer instructions as well as rare and obsolete ones)
And I could go on..
It's quite a pain at first, but it's a challenge as well.

Branches are crazy: they are predicted - but not always the right way, be sure to use hinting prefixes when necessary and avoid branches if possible.
And memory latency is bad: 100 cycles for a cache miss is not uncommon, so be careful with the caches (use proper prefetches and temporality hints, avoid random access patterns)

For more information about current x86 implementations (PPro, P3, P4, PM, Core2, AMD K10) try these: http://www.agner.org/optimize/optimization_manuals.zip

Calculating how many cycles a piece of x86 code will take on say Core2 is a hell, there are too many things to keep in mind, it's so bad that no one has made a 100% correct calculator for it.
For z80 that's a piece of cake - so easy that you don't even need a calculator..

PS: isn't this a bit of a programming question?
User avatar
Batman
New Member
Posts: 71
Joined: Thu 29 May, 2008 1:44 pm
Location: Over the Rainbow

Re: asm for computer

Post by Batman »

ok, ok, wow ouch ----> pow ughhh..... i'm dead. sorry :o

point well made :crazy:

just wondering if people still program in it for computers...

i tryed starting learning c++ for windows programming and got just about the same shoot down... :(

oh well. thanks for the information!
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: asm for computer

Post by King Harold »

Almost no one writes complete programs in assembly for PC's anymore. It's too much work and most of the program doesn't need to be super fast - ok it shouldn't be super slow but compilers are generally good enough for that kind of job. But people certainly still use it for performance-critical code, many (perhaps most) games contain pieces of handwritten assembly for speed reasons, probably all video transcoders that are in use, and of course things that are used in high-performance area's a lot like FFT. There's more of course..

There are also those instructions that do not have an operator, such as rotate (would require bitmagic), "multiply and get the high half of the result" (would require upcasting and shifting) and "get sine and cosine at the same time", all those obsoleted decimal-math instructions and many more (don't use the bitscans though, they are slow). Many compilers offer intrinsic functions to do some of those things but usually not all instructions are covered that way.

Also in my opinion, for vector code, assembly is clearer than the intrinsic functions with names like _mm_cvttps_epi32, doesn't look too bad like that but some people like to nest them..
darkstone knight
New Member
Posts: 67
Joined: Sun 09 Nov, 2008 1:56 pm

Re: asm for computer

Post by darkstone knight »

people write 3d engines for it, beacause whit screen resolution of 1024*768 (= low) and 30 FPS, you need to calucate
1024*768*30=23 592 960 rays a second, that is more then the calucator has cycles in fast mode :shock:

you can image that shaving off 1 clock cycle saves alot of time
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Re: asm for computer

Post by CoBB »

darkstone knight wrote:people write 3d engines for it, beacause whit screen resolution of 1024*768 (= low) and 30 FPS, you need to calucate
1024*768*30=23 592 960 rays a second, that is more then the calucator has cycles in fast mode :shock:
Real-time 3D engines don’t work like that. You don’t shoot rays independently for each pixel, but reuse calculations for nearby pixels. That’s why polygons (well, triangles) are a big win: you can easily interpolate various characteristics over scanlines, so you don’t need to perform ray-tracing. Once I saw an ingenious texturing routine which needed only 2 (two!) clock cycles per textured pixel. Of course it wasn’t perspective corrected, but real-time software renderers never did the correction for every pixel anyway.

Of course that’s all history now, since nowadays everything happens on the GPU, and the high-end models have already entered the teraflops range...
darkstone knight
New Member
Posts: 67
Joined: Sun 09 Nov, 2008 1:56 pm

Re: asm for computer

Post by darkstone knight »

so... how does 3d on low-end machines work anyway?

you basely display an array of triangles?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: asm for computer

Post by King Harold »

Well there is this ray-tracing engine for Quake 4
Of course you need an octo-core to get a decent framerate but hey it's still cool..
It's a pity ray tracing has such a bad semi-random jumping behaviour otherwise GPU's could effectively accelerate it.

But yea games will be using rasterisation for some years to come - until the Really Badass CPU's take over or GPU's get a design makeover - in a way that would make them less good for rasterisation due to silicon wasted on executing different codepaths instead of the current "in groups of K (like 8) that must follow the same path" which is fine for rasterisation where you don't even need jumps at all unless you do something complicated (I won't bore you with more details)..
Won't be too soon. But it'll probably happen, some day..

Btw, 2 cc's, that's cool - did it texture more than 1 pixel at the same time?

Anyway, rasterisation:
You take a bunch of triangles, you multiply them with a projection matrix (see wikipedia) do some clipping around the edges of the screen, use a Z-buffer while filling pixels using the scanline algorithm to get the depth order right, each pixel has its texture coordinates interpolated from the vertices of the triangle it's on. This skips some details but basically this is how it works.
Oh and high-end works the same - just faster.
darkstone knight
New Member
Posts: 67
Joined: Sun 09 Nov, 2008 1:56 pm

Re: asm for computer

Post by darkstone knight »

so...

triangle:
(5,0,3)
(5,8,4)
(2,4,5)

you calucate the points on the screen:
x=x/z
y=y/z

you get these on-screen coordinates:
(5/3,0)
(5/4,2)
(2/5,4/5)

then you draw the lines of the triangle, and fill it using scanline algoritm...

that makes sense, thanks
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: asm for computer

Post by King Harold »

Well a projective projection is more than just dividing by the Z value and the scanline algorithm doesn't require the lines to be drawn (it only needs to know where they would be) but that's basically it..
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Re: asm for computer

Post by CoBB »

King Harold wrote:Btw, 2 cc's, that's cool - did it texture more than 1 pixel at the same time?
Sure, it used LUTs to advance four pixels at a time, and exploited the parallelisation capabilities of the good old Pentium 1 by arranging instructions in a highly pipeline efficient way. I think one iteration took 9 clock cycles.

Hey, I found it! The one I had in mind is in section 13.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: asm for computer

Post by King Harold »

Ah I almost forgot about the dual pipelining rules, good to see them back :)
User avatar
Batman
New Member
Posts: 71
Joined: Thu 29 May, 2008 1:44 pm
Location: Over the Rainbow

Re: asm for computer

Post by Batman »

ok, i have another one for yall...

its easy to access the area where ti stores the graph buffer... its just a memory address

but what about for the computer? I think that it has a buffer that will automatically update the monitor right??? so how do you change what is displayed for it? can you do it with C++? or do you have to go to a low level lang???
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: asm for computer

Post by King Harold »

It gets very scary there. In the good ol' times you would just write to the screenbuffer yes, but it all works completely different now. You'd have to interface with either the GPU (hard), the GPU driver (hard) or the OS (not hard, but not very powerful either, no full-screen (afaik) for example) or some graphics lib (there are lots of those, hardness depends on which one you choose)
But yes, you can do this.
User avatar
Batman
New Member
Posts: 71
Joined: Thu 29 May, 2008 1:44 pm
Location: Over the Rainbow

Re: asm for computer

Post by Batman »

So it would be better to just find my own kind of graphics program library and use their ruitines for c++?
you see, i am trying to learn to use c++ with microsoft visual and i wanted to make an intro thing that doesn't have the console app look, or a window...
Post Reply