jeff@unh.UUCP (Jeffrey E. F. Friedl) (07/28/88)
Hi... I'm having problems with the actions of a compiler I'm using ("cc" on the CalComp 7500), and am wondering if it's me or the compiler that's acting up. This is strictly a pre-X3J11 matter, but post K&R-I (i.e. C with "common extensions"). I have a situation where I need to multiply doubles with unsigned chars. There is a definite compiler bug in that I get different results between: double_result = double_var * ((int)uchar_var); and double_result = double_var * (temp_int_var = uchar_var, temp_int_var); The difference is that the first one "sign-extends" and the 2nd doesn't (which is what I desire). As was discussed several weeks ago, the problem is not the matter of sign extending or not, but simply that the assign to a temp acts differently than a cast. So, because of this bug, I was forced to change my code (which has several such multiplies in one expression) from something natural like (where D == Double, UC == unsigned char): result = D1 * UC1 + D2 * UC2 + D3 * UC3; to the kludge like: result = D1 * (TEMP_INT = UC1, TEMP_INT) + D2 * (TEMP_INT = UC2, TEMP_INT) + D3 * (TEMP_INT = UC3, TEMP_INT); The problem is this: the compiler generates assembler as if the latter had been written: TEMP_INT = UC1; /* side effects notwithstanding, worthless */ TEMP_INT = UC2; /* side effects notwithstanding, worthless */ TEMP_INT = UC3; /* this value gets used throughout...(agh!) */ result = D1 * TEMP_INT + D2 * TEMP_INT + D3 * TEMP_INT; Not quite what I intended. As a general case, I've checked that it generates code for: x = (ExpA_1, ..., ExpA_N-1, ExpA_N) + (ExpB_1, ..., ExpB_N-1, ExpB_N); as: ExpA_1; ...; ExpA_N-1; ExpB_1; ...; ExpB_N-1; x = ExpA_N + ExpB_N; Is this correct? It most certainly is not to my intuition. However, K&R-I says that the expressions are to be executed sequentially; does that (or other quotes -- I've been to perturbed to look this one up carefully) absolutely imply that they must be done together (i.e. not interleaved as this compiler does)? Could the compiler's actions be considered correct by any stretch of the rules? One one of us is brain damaged -- which?. (what friedl!vsi says [(-:] notwithstanding, I think it's the compiler). Any thoughts out there on this? How about in a context of compilation to parallel code -- could this be a way of specifying parallelism? (I hope not). As an aside: in checking the assembly listing, I noticed a *lot* of comments in the listing. Not the type that I would have loved to see -- "this register has that variable" -- but those cryptic kind (such as I have in my compiler under construction) obviously there for the compiler writer's benefit. So shocked at the number of such comments (in a released compiler) that I stripped all comments away to see just how much was there. The size of the file shrank from 63K to 34K. 47% of the "code" was tied up in comments. This is a *slow* system as it is .. they most certainly don't need the 47% overhead in I/O. Is this a normal and acceptable thing (by the tone of my question, my feeling should be quite obvious)? To end with one nice word about CalComp: the strawberries are impressive (if you know what I'm talking about, then you.. uh... well, *know* what I'm talking about [(-:]). *jeff* ------------------------------------------------------------------------------- Jeffrey Eric Francis Friedl, Box 2146 Babcock House, Durham New Hampshire 03824 ..!{uunet,decvax}!unh!jeff BITNET%"j_friedl@unhh" ..!ucbvax!kentvax!jfriedl I hope I'm not around Jan 18, 2038 at 10:14:08PM