[PATCH 2/4] SPARC: optimize window overflow trap entry

Daniel Hellstrom daniel at gaisler.com
Wed Nov 19 15:35:50 UTC 2014


By using a optimized trap entry we can move instructions from
the window overflow function into the trap entry vector. By
using the saved locals instead of g1 we don't need to save
that register temporarily. Also spead out non store instructions
inbetween stores to use the write buffer better.
---
 c/src/lib/libbsp/sparc/shared/start/start.S |   11 ++++++++++-
 c/src/lib/libcpu/sparc/reg_win/window.S     |   24 +++++++++---------------
 2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/start/start.S b/c/src/lib/libbsp/sparc/shared/start/start.S
index eb8e3c4..b7067b3 100644
--- a/c/src/lib/libbsp/sparc/shared/start/start.S
+++ b/c/src/lib/libbsp/sparc/shared/start/start.S
@@ -42,6 +42,15 @@
    subcc %g1, 3, %g0; ! prepare for syscall 3 check
 
 /*
+ * Window Overflow optimized trap table entry
+ */
+#define WOTRAP(_vector, _handler)  \
+  sethi %hi(_handler), %l4; \
+  jmp   %l4+%lo(_handler); \
+    save; \
+  nop
+
+/*
  *  Software trap. Treat as BAD_TRAP for the time being...
  */
 
@@ -72,7 +81,7 @@ SYM(trap_table):
   BAD_TRAP;                                     ! 02 illegal instruction
   BAD_TRAP;                                     ! 03 privileged instruction
   BAD_TRAP;                                     ! 04 fp disabled
-  TRAP( 5, SYM(window_overflow_trap_handler) ); ! 05 window overflow
+  WOTRAP(5, SYM(window_overflow_trap_handler)); ! 05 window overflow
   TRAP( 6, SYM(window_underflow_trap_handler) );! 06 window underflow
   BAD_TRAP;                                     ! 07 memory address not aligned
   BAD_TRAP;                                     ! 08 fp exception
diff --git a/c/src/lib/libcpu/sparc/reg_win/window.S b/c/src/lib/libcpu/sparc/reg_win/window.S
index 453cc74..535dc83 100644
--- a/c/src/lib/libcpu/sparc/reg_win/window.S
+++ b/c/src/lib/libcpu/sparc/reg_win/window.S
@@ -29,9 +29,8 @@
          *
          *  On entry:
          *
-         *    l0 = psr (from trap table)
-         *    l1 = pc
-         *    l2 = npc
+         *    prev regwin l1 = pc
+         *    prev regwin l2 = npc
          */
 
         PUBLIC(window_overflow_trap_handler)
@@ -51,28 +50,23 @@ SYM(window_overflow_trap_handler):
          *        register will result in the local register set changing.
          */
 
-        mov  %wim, %l3                   ! l3 = WIM
-        mov  %g1, %l7                    ! save g1
-        srl  %l3, 1, %g1                 ! g1 = WIM >> 1
-        sll  %l3, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %l4
-                                         ! l4 = WIM << (Number Windows - 1)
-        or   %l4, %g1, %g1               ! g1 = (WIM >> 1) |
-                                         !      (WIM << (Number Windows - 1))
-
-        save                             ! Get into window to be saved.
-        mov  %g1, %wim                   ! load new WIM
         std  %l0, [%sp + 0x00]           ! save local register set
         std  %l2, [%sp + 0x08]
+        mov  %wim, %l3
+        sll  %l3, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %l2
+                                         ! l2  = WIM << (Number Windows - 1)
         std  %l4, [%sp + 0x10]
         std  %l6, [%sp + 0x18]
+        srl  %l3, 1, %l3                 ! l3  = WIM >> 1
+        wr   %l3, %l2, %wim              ! WIM = (WIM >> 1) ^
+                                         !       (WIM << (Number Windows - 1))
         std  %i0, [%sp + 0x20]           ! save input register set
         std  %i2, [%sp + 0x28]
         std  %i4, [%sp + 0x30]
         std  %i6, [%sp + 0x38]
         restore                          ! Go back to trap window.
-        mov  %l7, %g1                    ! restore g1
         jmp  %l1                         ! Re-execute save.
-        rett %l2
+         rett %l2
 
         /*
          *  Window underflow trap handler.
-- 
1.7.0.4




More information about the devel mailing list