delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/03/12:09:53

Xref: news-dnh.mv.net comp.os.msdos.djgpp:4098
Path: news-dnh.mv.net!mv!news.sprintlink.net!rain.fr!jussieu.fr!oleane!tank.news.pipex.net!pipex!news.mathworks.com!newsfeed.internetmci.com!EU.net!Norway.EU.net!nntp.uio.no!news.vu.lt!santaka.sc-uni.ktu.lt!algikun
From: Martynas Kunigelis <algikun AT santaka DOT sc-uni DOT ktu DOT lt>
Newsgroups: comp.os.msdos.djgpp
Subject: GCC272: params in regs
Date: Wed, 3 Jan 1996 14:48:35 +0200
Organization: LITNET
Lines: 76
Message-ID: <Pine.HPP.3.91.960103141043.14026A-100000@santaka.sc-uni.ktu.lt>
NNTP-Posting-Host: santaka.sc-uni.ktu.lt
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


	I always thought Watcom's advantage against DJGPP (i.e. GCC) was 
its capability to pass first 4 parameters to functions in registers. It 
also had 2 libraries: one compiled with standard (stack) and the other 
one with register calling conventions. Depending on switches, the 
compiler used the apropriate call. convention and the linker linked 
apropriate library. But now GCC 2.7.2 also has these _cool_ -mregparm=N and 
-fomit-frame-pointer options (the latter somehow not activated by -Ox), so 
you can get _really_ effective code, combining them with _best_ever_ GCC 
optimization. The only thing is that the libraries and startup files must 
also be compiled with reg cc (calling convention). I thought I could do 
this myself, but there are many *.s files in djlsr200. Some of them I 
managed to rewrite, but some (int86.s, dpmi functions) need a complete 
change in register usage. And also I have no clue about the startup 
files. So here's my question: could you, people who wrote the c library, 
modify it to be register-callable. It is possible to retain compatibility 
using the preprocessor, e. g. #ifdef _RREGPARM_ ... #else ... #endif. I 
have thought of some macros like ENTER_1, LEAVE_1, ENTER_2.... etc. which 
are defined depending on the state of _REGPARM_ or whatever. If _REGPARM_ 
is defined, those macros do nothing, otherwise they initialize the 
appropriate registers from the frame pointer and adjust the pointer, i.e.

#ifdef _REGPARM_
#define ENTER_3m 
#define LEAVE_3m
#else
#define ENTER_3m \
      movl 4(%esp),%eax \
      movl 8(%esp),%edx \
      movl 12(%esp),%ecx \
      addl $12,%esp 
#define LEAVE_3m subl $12,%esp
#endif

Since the greatest N for -mregparm=N is 3, all paramters after the 3rd 
one are passed through stack, so the above macro adjusts the stack ptr. 
For all other macros (ENTER_1, .._2, .._3 and LEAVE_..), the stack 
adjustment is not necessary, e.g.

#ifdef _REGPARM_
..... /* from the previous example */
#else
#define ENTER_2 \
   movl 4(%esp),%eax \
   movl 8(%esp),%edx
#endif /* no LEAVE_2 required */

so now every asm f-n you write should look like this:

/* void my_proc(int a, int b); */
	.globl _my_proc
_my_proc:
	ENTER_2
	... /* assume a in eax and b in edx */
        LEAVE_2 /* just in case... */
        ret

and the above peace of code should compile properly for both register and 
stack calling conventions. Don't you people think it's cool?

I'm waiting for response from the DJGPP crew and people who think my 
ideas are worth reading. Thanx in advance.

Martynas

P.S. Can anyone help me to get MASM 6.11? I still can't get used to AT&T 
asm syntax, and also as is damn buggy [sometimes].


+---------------------------------+--------------------------------+
| Martynas Kunigelis              | e-mail: algikun AT santaka DOT ktu DOT lt |
| Kaunas University of Technology | "I have seen the top of the    |
| Informatics faculty student     |   mountain..." Butt-head, 1995 |
+---------------------------------+--------------------------------+

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019