Oz and Mozart Hackers Mailing List

Re: good news from the inline-opcode-map branch


From: Kevin Glynn (glynn@info.ucl.ac.be)
Date: Thu Dec 04 2003 - 14:41:14 CET


Attached is the conftest.C program I can successfully compile and
run.

k


//#line 9803 "configure"
//#include "confdefs.h"
#ifdef __cplusplus
extern "C" void exit(int);
#endif

int engine(void**);
bool equal(int,int);

static void* program[6];

int main()
{
  (void) engine(0);
  return engine(program);
}

#define OP0_VALUE 0
#define OP1_VALUE 1
#define OP2_VALUE 2
#define OP3_VALUE 3
#define OP4_VALUE 4
#define OP5_VALUE 5

#define OP0_STRING "0"
#define OP1_STRING "1"
#define OP2_STRING "2"
#define OP3_STRING "3"
#define OP4_STRING "4"
#define OP5_STRING "5"

/*
 * define a C++ label
 * then also define an ASM label
 * and fill the bytes between them with the opcode
 * we will actually jump to the ASM label
 * but given the ASM label, we can immediately
 * recover the corresponding opcode by reading
 * the preceding byte
 */

#define REPEAT_FOR_ALIGNMENT(S) S;S;S;S

#define CASE(N) FAKE_ ##N :REPEAT_FOR_ALIGNMENT(asm(".byte " OP##N##_STRING)); asm("LABEL" OP##N##_STRING":");

/*
 * appear to use the C++ label
 * but really store ASM label
 */

#if defined(ARCH_I486)
#define LOAD_LABEL(N) asm("movl $LABEL"OP##N##_STRING",%0" : "=m" (*ptr))
#elif defined(ARCH_SPARC)
#define LOAD_LABEL(N) asm("sethi\t%%hi(LABEL"OP##N##_STRING"), %0\n\tor\t%0, %%lo(LABEL"OP##N##_STRING"), %0" : "=r" (*ptr))
#else
#error platform not supported
#endif

#define LOAD(N) *ptr = && FAKE_##N; LOAD_LABEL(N); ++ptr;

#define DO(N) if (N!=n-- || !equal(OP##N##_VALUE,((char*)*(bytecode-1))[-1])) return 1

#define DISPATCH goto **bytecode++

int engine(void**bytecode)
{
  int n;
  if (! bytecode)
    {
      void** ptr = program;
      LOAD(5);
      LOAD(4);
      LOAD(3);
      LOAD(2);
      LOAD(1);
      LOAD(0);
      return 0;
    }

  n = 5;
  DISPATCH;
  CASE(0) { DO(0); return 0; }
  CASE(1) { DO(1); DISPATCH; }
  CASE(2) { DO(2); DISPATCH; }
  CASE(3) { DO(3); DISPATCH; }
  CASE(4) { DO(4); DISPATCH; }
  CASE(5) { DO(5); DISPATCH; }
}

bool equal(int want,int have)
{
  return want==have;
}


duchier@ps.uni-sb.de writes:
> darn! it looks like the solaris assembler doesn't actually support
> the set (macro) instruction. I expanded it into its two constitutive
> instructions sethi (for hight 22 bits) and or (for low 10 bits). Give
> it a try and let me know.
>
> Cheers,
>
> --
> Denys Duchier - Équipe Calligramme - LORIA, Nancy, France
> -
> Please send submissions to hackers@mozart-oz.org
> and administriva mail to hackers-request@mozart-oz.org.
> The Mozart Oz web site is at http://www.mozart-oz.org/.
>

-
Please send submissions to hackers@mozart-oz.org
and administriva mail to hackers-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.



This archive was generated by hypermail 2b29.