Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!decvax!yale-com!leichter From: leichter@yale-com.UUCP (Jerry Leichter) Newsgroups: net.lang Subject: Re: Self-modifying code - (nf) Message-ID: <2681@yale-com.UUCP> Date: Sun, 8-Jan-84 17:02:16 EST Article-I.D.: yale-com.2681 Posted: Sun Jan 8 17:02:16 1984 Date-Received: Mon, 9-Jan-84 04:40:00 EST References: pur-ee.1322 Lines: 23 On modifying programs for speed: On the CDC 6000 (now CYBER 7x) machines, a call to a function, as generated by the FORTRAN compiler, always took up a full word. (The 6000 series has 60-bit words, and 15 and 30-bit instructions. A function call is 30 bits, and a return always goes to the NEXT word, so you can't put any code after it. The typical convention is to always put the call in the top 30 bits, and put something like traceback info in the bottom 30 bits.) Now, a full word can hold 4 instructions, and the call/return are relatively expensive (ANY control transfer costs a lot - on the 6600, a 48-bit (mantissa) floating multiply took 800 nanoseconds, while branch took at least 1200 nanoseconds, and could take more). There thus arose the idea of short functions that OVERWROTE CALLS TO THEMSELVES. A typical example was a pair of functions, callable from FORTRAN, to do shifting. When first called, they replaced the function call with a shift instruction. This was eventually gene- ralized to a function that received as an argument the code it was to overlay its calling instruction by. This is the Unix "modify the assembler's output to insert machine-specific code" done at run-time. Another example: The original SPITBOL on the IBM 360 was a true compiler, generating executable code. It implemented SNOBOL's tracing facilities by modifying the code to insert trace calls - i.e. it acted much like many debuggers today. -- Jerry decvax!yale-comix!leichter leichter@yale