🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #49971

variable length array

#49971
From: Giuseppe Attardi
Date: Wed, 01 Dec 1993 20:59
44 lines
1945 bytes
I need to implement an APPLY function for a Lisp interpreter/compiler.
APPLY takes a function, an array of arguments and their count, and
must call the function with those arguments.

I implemented it like this:

APPLY(int n, int (*fn)(), int *x)
{ int i; CSTACK(n);
  for (i = 0; i < n; i++)
    CPUSH(*x++);
  return(CCALL(fn));
}

where CSTACK is a macro which allocates a variable length array,
CPUSH fills it, and CCALL issues the appropriate assembler instruction.

This works fairly easily on I386, but on the Sparc GCC-2.4.5 puts
6 extra words on the stack.
To get around this I shift the args by that OFFSET:

#define OFFSET -6
#define CSTACK(size)     	register int *_stack_top; \
  				object _stack_bot[size]; \
  				_stack_top = _stack_bot+OFFSET

#define CPUSH(val)		*_stack_top++ = (val);

#define CCALL(fun)	  ({ register int _res asm("%o0"); \
			     asm("ld [%%sp+68],%%o0"); \
			     asm("ld [%%sp+72],%%o1"); \
			     asm("ld [%%sp+76],%%o2"); \
			     asm("ld [%%sp+80],%%o3"); \
			     asm("ld [%%sp+84],%%o4"); \
			     asm("ld [%%sp+88],%%o5"); \
			     asm("call %0,0" : : "r" (fun) ); \
       			     asm("nop"); _res;})

Can someone explain what are those 7 word for and what happens if I clobber
them?

Is there a better way to do this?

-- Beppe
Technical Details
Message-ID: <ATTARDI.93Dec1125940@icsib66.icsi.berkeley.edu>
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!agate!agate.berkeley.edu!attardi

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,1b9b43637b9415e4,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-12-01 13:27:00 PST
Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!agate!agate.berkeley.edu!attardi
From: attardi@icsib66.icsi.berkeley.edu (Giuseppe Attardi)
Newsgroups: gnu.gcc.help
Subject: variable length array
Date: 01 Dec 1993 20:59:39 GMT
Organization: International Computer Science Institute/U.C. Berkeley
Lines: 44
Distribution: world
Message-ID: <ATTARDI.93Dec1125940@icsib66.icsi.berkeley.edu>
NNTP-Posting-Host: icsib66.icsi.berkeley.edu