Raw instruction code on sparc64?

Andy Dougherty doughera at lafayette.edu
Tue Feb 3 20:31:53 UTC 2009


On Tue, 3 Feb 2009, Mark Glines wrote:

> Hi,
> 
> There's some code at the top of trace_system_areas() in src/gc/system.c
> to flush the register windows on sparc.  The code in question:
> 
>         /* Flush the register windows. For sparc systems, we use hand-coded
>            assembly language to create a small function that flushes the
>            register windows. Store the code in a union with a double to
>            ensure proper memory alignment. */
>         static union {
>             unsigned int insns[4];
>             double align_hack[2];
>         } u = { {
> #  ifdef __sparcv9
>                             0x81580000, /* flushw */
> #  else
>                             0x91d02003, /* ta ST_FLUSH_WINDOWS */
> #  endif
>                             0x81c3e008, /* retl */
>                             0x01000000  /* nop */
>         } };
> 
>         /* Turn the array of machine code values above into a function
> pointer.
>            Call the new function pointer to flush the register windows. */
>         static void (*fn_ptr)(void) = (void (*)(void))&u.align_hack[0];
>         fn_ptr();
> 
> 
> 
> 
> According to "svn blame", some of this code dates all the way back to
> 2002, so I'm not really sure who to ask.  We have reports of failed
> builds on sparc64/openbsd (see Trac #271) which raised the question:
> will this code work on sparc64?

I'm not sure.  I'd think that replacing it by the actual assembly language 
commands would work, however.  Something like the patch below, perhaps. 
asm("flushw") ought to work as well on 64-bit as it does on 32-bit. (I 
don't have a sparcv9 to test this on, however.)

I can verify that for sparcv8 using the asm("ta 3") command doesn't change 
the output of 'make coretest' in any significant way.  However, also 
commenting out the asm("ta 3") and just doing *nothing* also doesn't 
change the output in any significant way, so I don't know how to really 
test any of this.


--- parrot-svn/src/gc/system.c	Tue Feb  3 13:34:22 2009
+++ parrot-andy/src/gc/system.c	Tue Feb  3 13:49:11 2009
@@ -1,10 +1,10 @@
 /*
 Copyright (C) 2001-2008, The Perl Foundation.
-$Id: system.c 36325 2009-02-03 16:41:34Z whiteknight $
+$Id: system.c 36260 2009-02-01 21:36:47Z whiteknight $
 
 =head1 NAME
 
-src/gc/system.c - CPU-dependent mark/sweep functions
+src/cpu_dep.c - CPU-dependent functions
 
 =head1 DESCRIPTION
 
@@ -62,27 +62,12 @@
     ASSERT_ARGS(trace_system_areas)
     {
 #if defined(__sparc)
-        /* Flush the register windows. For sparc systems, we use hand-coded
-           assembly language to create a small function that flushes the
-           register windows. Store the code in a union with a double to
-           ensure proper memory alignment. */
-        static union {
-            unsigned int insns[4];
-            double align_hack[2];
-        } u = { {
+        /* Flush the register windows. */
 #  ifdef __sparcv9
-                            0x81580000, /* flushw */
+        asm("flushw");
 #  else
-                            0x91d02003, /* ta ST_FLUSH_WINDOWS */
+        asm("ta 3");  /* ta ST_FLUSH_WINDOWS */
 #  endif
-                            0x81c3e008, /* retl */
-                            0x01000000  /* nop */
-        } };
-
-        /* Turn the array of machine code values above into a function pointer.
-           Call the new function pointer to flush the register windows. */
-        static void (*fn_ptr)(void) = (void (*)(void))&u.align_hack[0];
-        fn_ptr();
 
 #elif defined(__ia64__)
 

-- 
    Andy Dougherty		doughera at lafayette.edu


More information about the parrot-dev mailing list