Path: utzoo!attcan!uunet!husc6!uwvax!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.arch Subject: Re: Semantics (was Software Distribution) Message-ID: <13898@mimsy.UUCP> Date: 7 Oct 88 13:08:58 GMT References: <13889@mimsy.UUCP> <2472@uhccux.uhcc.hawaii.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 67 >In article <13889@mimsy.UUCP> I wrote: >>... if we can improve the performance of a language on existing >>architectures by explicitly leaving certain semantics undefined, >>should we do so? In article <2472@uhccux.uhcc.hawaii.edu> lee@uhccux.uhcc.hawaii.edu (Greg Lee) argues with my arguments. Let me take the last first: >This appears to assume your conclusion -- that a proper version >of the language may leave syntactically correct constructions undefined. All nontrivial languages have this property. What is 1/0? 0/0? What sort of rounding modes does the hardware use for floating point? Ones complement or two? >Why would programs run any faster in a language with some undefined >semantics? Put it this way: if the language defines 0/0 as `runtime error, code = INDETERMINATE' while `1/0' is `runtime error, code = DIV BY ZERO', but some hardware has imprecise faults and makes all divide by zero errors a single code, then to implement the language correctly on this hardware, we must check every divide before dividing unless we can prove that neither the numerator nor the denominator are zero. >To make a comparison, the same programs would have to >run in both versions of the language, and so could not make any >use of the semantics undefined in one of the versions. This is the thrust behind the `argumentam con'. Recall that this whole discussion came up when someone said that the action of *(type *)NULL in C should be defined: it should do the same thing on every machine. The only reason to define it is because people use it. These people, and their programs, are wrong; but they do exist. And if you do not know that a program depends on strcmp((char *)0,"f(")==0, and sell this program without testing it on something other than a 3B first, then those who buy it and try to run it on a Sun or a Vax will lose out. (Assuming *(char *)0 == "f(" is a real example from a real program!) >So why then would the definition of semantics cause a program which does >not use it to run slower? It requires two assertions to hold. First, the machine's `native' semantics must not match---easily demonstrated for *(type *)NULL and for division by zero and for uninitialised local variables and so forth. Second, and more importantly, it must be sufficiently hard to predict whether a program does in fact use the `nonnative' semantics. Again, this is easily demonstrated for *(type *)NULL and for division by zero and so forth: f() { float a, b = g() ? 1. : 0.; a = 1./b; } Does this program depend on the semantics of 1.0/0.0? If the language defines it and your machine does not match the languages definition, will you have to insert runtime checks? And if you must insert runtime checks, will not the program run slower? -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris