SDCC 4.1.0 will likely use a different calling convention from the
current one for stm8. There is no final decision on the new one yet, and
there might still be delays or changes of plans.

But experiments done so far indicate that the following could be a good
candidate:

* Return values are passed as no (8-bit in a, 16-bit in x, 24-bit in
ylx, 32-bit in yx).
* For functions that do not have variable arguments, the first parameter
is passed in a for 8-bit, x for 16-bit, on the stack otherwise. If hte
first parameter is in a, and the second has 16 bits, it is passed in x;
if the firs is i x, and the second has 8 bits, it is passed in a. This
aspect is similar to Raisonance, and to some degree IAR.
* For the medium memory model, stack cleanup for stack parameters is
done by the calle for some cases (there is no return value of more than
16 bits, or both the return value and the first parameter are of type
float).

For those that want to experiment with the new calling convnetion:
- In current trunk, functions can be declared __sdccnewcall to use the
new calling convention for individual functions.
- In the current callingconvention branch, by applying the attached
patch, the new calling convention is used for all functions (works for
medium memory model only.

Philipp
Index: src/stm8/gen.c
===================================================================
--- src/stm8/gen.c	(Revision 12441)
+++ src/stm8/gen.c	(Arbeitskopie)
@@ -1247,13 +1247,13 @@
   switch (size)
     {
    case 1:
-      return (ASMOP_A);
-    case 2:
-      return (ASMOP_X);
-    case 3:
-      return (ASMOP_XYL);
-    case 4:
-      return (ASMOP_XY);
+      return (ASMOP_A);
+    case 2:
+      return (ASMOP_X);
+    case 3:
+      return (ASMOP_XYL);
+    case 4:
+      return (ASMOP_XY);
     default:
       return 0;
     }
@@ -1392,6 +1392,15 @@
   // .* -> void
   else if (nArgs == 1 && IS_PTR (arg1->type))
     ;
+
+  if (i == 1 && getSize (args->type) == 1)
+    return ASMOP_A;
+  if (i == 2 && getSize (args->next->type) == 1 && aopArg (ftype, 1) && aopArg (ftype, 1) != ASMOP_A)
+    return ASMOP_A;
+  if (i == 1 && getSize (args->type) == 2)
+    return ASMOP_X;
+  if (i == 2 && getSize (args->next->type) == 2 && aopArg (ftype, 1) && aopArg (ftype, 1) != ASMOP_X)
+    return ASMOP_X;

   return 0;
 }
@@ -1445,7 +1438,28 @@
   else if (nArgs == 1 && IS_PTR (arg1->type))
     ;

+  _Bool farg = !FUNC_HASVARARGS (ftype) && FUNC_ARGS (ftype) && IS_FLOAT (FUNC_ARGS (ftype)->type); 
+  if (!FUNC_HASVARARGS(ftype) && (!ftype->next || getSize (ftype->next) == 0) && !farg && 1)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && (!ftype->next || getSize (ftype->next) == 0) && farg && 2)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 1 && !farg && 4)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 1 && farg && 8)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 2 && !farg && 16)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 2 && farg && 32)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 4 && !IS_FLOAT (ftype->next) && !farg && 0)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 4 && !IS_FLOAT (ftype->next) && farg && 0)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 4 && IS_FLOAT (ftype->next) && !farg && 0)
+    return (true);
+  if (!FUNC_HASVARARGS(ftype) && ftype->next && getSize (ftype->next) == 4 && IS_FLOAT (ftype->next) && farg && 512)
+    return (true);
  return (IFFUNC_ISZ88DK_CALLEE (ftype));
 }

 static void
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to