Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.questions Subject: Re: HELP needed with inline expansions!!! Message-ID: <566@cresswell.quintus.UUCP> Date: 23 Jan 88 04:58:34 GMT References: <563@tuvie> Organization: Quintus Computer Systems, Mountain View, CA Lines: 65 Keywords: inline expansions Summary: check your manuals In article <563@tuvie>, rcvie@tuvie (ELIN Forsch.z.) writes: > Please help me .. use .. in-line expansion template files. This is a BSD-ism. It should be described somewhere in your manual set. If you are using SUNs, check the "Floating-Point Programmer's Guide for the Sun Workstation". Whatever you are using, look in /usr/lib/ for examples (e.g. /usr/lib/pc2.il). I learned how to use .il files from reading these examples. Basically, a .il file is a collection of definitions .inline ,<#bytes popped from stack> ^ this may be different on a VAX .end What this thing does is to take function calls which have already been compiled as function calls and replace them by your in-line expansions. The is the full thing, e.g. for C it is _{C name} and for Fortran it is _{lower cased Fortran name}_ Within the you should assume that the arguments have already been pushed on the stack. You can use the registers that function calls do not preserve (on a 680x0, d0..d2, a0..a1, and maybe some others). Your expansion should pop the arguments from the stack. This will probably be optimised away. For example, suppose that the IEEE function copysign(x,y) did not exist, and you wanted to implement it as an in-line function. | copysign.il | Implement double copysign(double x, double y) .inline _copysign,16 movl sp@+,d0 | d0 := x.highbits bclr #31,d0 | d0 := abs(x).highbits movl sp@+,d1 | d1 := x.lowbits tstl sp@+ | test y.sign bges 1f | if y.sign == 1 then bset #31,d0 | d0.sign := 1 1: | endif addql #4,sp | discard y.lowbits .end The SUN 3.2 C compiler, presented with x = copysign(x, y); this inline file, and the -O option, produced movl a6@(-12),sp@- {low bits of y} movl a6@(-8),d0 {high bits of x} bclr #31,d0 movl a6@(-4),d1 {low bits of x} tstl a6@(-16) {high bits of y} bges LX1000000 bset #31,d0 LX1000000: addql #4,sp movl d0,a6@(-8) {set high bits of x} movl d1,a6@(-4) {set low bits of x} This is particularly useful for things like overflow-checked arithmetic. For example, .inline _ov_add,8 movl sp@+,d0 addl sp@+,d0 trapv .end