From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,45b50f14dadfce5b X-Google-Attributes: gid1164f8,public X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public From: jhallen@world.std.com (Joseph H Allen) Subject: Re: Final kick at the "Merced Guessing Game" Date: 1997/10/02 Message-ID: #1/1 X-Deja-AN: 277203449 References: <3431A2DB.4273@EasyInternet.net> <60ui2q$33a$1@cdn-news.telecom.com.au> <60ujk7$i58$1@lyra.csx.cam.ac.uk> <3432F896.7FD2@HousemarqueREM.fi> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec In article <3432F896.7FD2@HousemarqueREM.fi>, Vesa Karvonen wrote: >Nick Maclaren wrote: >> Yes. And, if you can code C without implying aliasing, I take my hat >> off to you! The biggest problem with attempting this is that you can >> only 'const qualify' at the top level and, for efficient code-generation, >> you need to do it at other levels. I believe that the new 'restrict' in >> C9X is a sort of recursive 'const', but have not seen a specification. More complicated key words. Yuck, that's just what C needs. >Being an assembly language programmer before learning C, I used >to think a bit like you are thinking after seeing the bad code >produced by aliasing problems and the like in C. I'm still waiting for someone to try a hardware fix for the aliasing problem. One way is to make the internal registers more like a cache than they are now. Then when you load a word into a register, you also load the memory address where the word came from into some auxiliary part of the register. The register snoops the bus at this point: if a subroutine modifies the memory at that address, a bit in the register is set. If the caller then accesses that register you get a trap or delay and a reload occurs. Using this, you can have your compiler safely assume that there are no aliases, and avoid doing tons of reloads after every subroutine call. Of course this only solves the problem of aliases which depend on a single memory location as their source, not complicated values which depend on multiple memory locations. But in a language like C++, I would guess that most of the aliases are like this anyway (like the base addresses of objects, or whatever). I suppose you could even have more general alias detection hardware which would allow you to detect if any of the sources of a derived value were modified- it would just cost more. Other hardware could conceivably solve more general alias and dependancy problems than those caused by non-local subroutine calls. For example: if a==z then x=5 y=x+3 causes a pipeline stall of some sort, because y is an alias for x, but 'y=x+3' can not occur until it is known whether the previous conditional is going to modify x. The compiler can't do this because a and z could be arbitrary non-constant values. But with extra hardware, there are possibilities. Maybe you do y=x+3 at the same time that you do the if(a==z), but also have a 'y=8' on standby, in case the x=5 ended up happening. A branchless version of the above code could be done with a few extra interesting flag bits, instructions which occur only conditionally as on the ARM and a compiler which is aware of the processor's pipeline structure. -- /* jhallen@world.std.com (192.74.137.5) */ /* Joseph H. Allen */ int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0) +r*57)/7,q=q?q-1?q-2?1-p%79?-1:0:p%79-77?1:0:p<1659?79:0:p>158?-79:0,q?!a[p+q*2 ]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}