View Issue Details

IDProjectCategoryView StatusLast Update
0036885FPCCompilerpublic2020-04-12 08:57
ReporterChristo Crause Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.3.1 
Summary0036885: Xtensa [patch] Alternative instructions if SEXT is not supported by core
DescriptionThe esp8266 does not support the SEXT instruction. The attached patch provides a fallback implementation with shl/sar instructions.
TagsNo tags attached.
Fixed in Revision44689
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2020-04-08 11:44

manager   ~0122022

Can it be that you forgot to attach the patch? ;)

Christo Crause

2020-04-08 12:58

reporter   ~0122030

Oh dear, let me try again. I seem to recall deleting the previous patch before uploading because it was incomplete...
xtensa-sext-alternative.patch (3,573 bytes)   
diff --git a/compiler/xtensa/cgcpu.pas b/compiler/xtensa/cgcpu.pas
index 9a2a40db74..8d013491c4 100644
--- a/compiler/xtensa/cgcpu.pas
+++ b/compiler/xtensa/cgcpu.pas
@@ -175,14 +175,26 @@ implementation
                   list.concat(taicpu.op_reg_reg_const_const(A_EXTUI,reg2,reg1,0,8));
                 OS_S8:
                   begin
-                    list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,7));
+                    if CPUXTENSA_HAS_SEXT in cpu_capabilities[current_settings.cputype] then
+                      list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,7))
+                    else
+                      begin
+                        list.concat(taicpu.op_reg_reg_const(A_SLLI,reg2,reg1,24));
+                        list.concat(taicpu.op_reg_reg_const(A_SRAI,reg2,reg2,24));
+                      end;
                     if tosize=OS_16 then
                       list.concat(taicpu.op_reg_reg_const_const(A_EXTUI,reg2,reg2,0,16));
                   end;
                 OS_16:
                   list.concat(taicpu.op_reg_reg_const_const(A_EXTUI,reg2,reg1,0,16));
                 OS_S16:
-                  list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,15));
+                  if CPUXTENSA_HAS_SEXT in cpu_capabilities[current_settings.cputype] then
+                    list.concat(taicpu.op_reg_reg_const(A_SEXT,reg2,reg1,15))
+                  else
+                    begin
+                      list.concat(taicpu.op_reg_reg_const(A_SLLI,reg2,reg1,16));
+                      list.concat(taicpu.op_reg_reg_const(A_SRAI,reg2,reg2,16));
+                    end;
                 else
                   conv_done:=false;
               end;
@@ -266,7 +278,13 @@ implementation
         list.concat(taicpu.op_reg_ref(op,reg,href));
 
         if (fromsize=OS_S8) and not(tosize in [OS_S8,OS_8]) then
-          list.concat(taicpu.op_reg_reg_const(A_SEXT,reg,reg,7));
+          if CPUXTENSA_HAS_SEXT in cpu_capabilities[current_settings.cputype] then
+            list.concat(taicpu.op_reg_reg_const(A_SEXT,reg,reg,7))
+          else
+            begin
+              list.concat(taicpu.op_reg_reg_const(A_SLLI,reg,reg,24));
+              list.concat(taicpu.op_reg_reg_const(A_SRAI,reg,reg,24));
+            end;
         if (fromsize<>tosize) and (not (tosize in [OS_SINT,OS_INT])) then
           a_load_reg_reg(list,fromsize,tosize,reg,reg);
       end;
diff --git a/compiler/xtensa/cpuinfo.pas b/compiler/xtensa/cpuinfo.pas
index c5aabd72f3..57c73f1af7 100644
--- a/compiler/xtensa/cpuinfo.pas
+++ b/compiler/xtensa/cpuinfo.pas
@@ -135,7 +135,8 @@ Const
  type
    tcpuflags =
       (
-        CPUXTENSA_REGWINDOW
+        CPUXTENSA_REGWINDOW,
+        CPUXTENSA_HAS_SEXT
       );
 
    tfpuflags =
@@ -149,7 +150,7 @@ Const
      (
        { cpu_none     } [],
        { cpu_lx106    } [],
-       { cpu_lx6      } [CPUXTENSA_REGWINDOW]
+       { cpu_lx6      } [CPUXTENSA_REGWINDOW, CPUXTENSA_HAS_SEXT]
      );
 
    fpu_capabilities : array[tfputype] of set of tfpuflags =
diff --git a/compiler/xtensa/xtensaatt.inc b/compiler/xtensa/xtensaatt.inc
index 58ef29eb49..26d9784717 100644
--- a/compiler/xtensa/xtensaatt.inc
+++ b/compiler/xtensa/xtensaatt.inc
@@ -48,6 +48,7 @@
 'sll',
 'slli',
 'sra',
+'srai',
 'srl',
 'srli',
 'ssi',
diff --git a/compiler/xtensa/xtensaop.inc b/compiler/xtensa/xtensaop.inc
index c1da8025b9..b7e2430a34 100644
--- a/compiler/xtensa/xtensaop.inc
+++ b/compiler/xtensa/xtensaop.inc
@@ -48,6 +48,7 @@ A_SEXT,
 A_SLL,
 A_SLLI,
 A_SRA,
+A_SRAI,
 A_SRL,
 A_SRLI,
 A_SSI,
xtensa-sext-alternative.patch (3,573 bytes)   

Florian

2020-04-11 16:59

administrator   ~0122076

Thanks applied.

Christo Crause

2020-04-12 08:57

reporter   ~0122091

Thanks!

Issue History

Date Modified Username Field Change
2020-04-07 21:45 Christo Crause New Issue
2020-04-08 11:44 Sven Barth Status new => feedback
2020-04-08 11:44 Sven Barth FPCTarget => -
2020-04-08 11:44 Sven Barth Note Added: 0122022
2020-04-08 12:58 Christo Crause File Added: xtensa-sext-alternative.patch
2020-04-08 12:58 Christo Crause Note Added: 0122030
2020-04-08 12:58 Christo Crause Status feedback => new
2020-04-11 16:59 Florian Assigned To => Florian
2020-04-11 16:59 Florian Status new => resolved
2020-04-11 16:59 Florian Resolution open => fixed
2020-04-11 16:59 Florian Fixed in Revision => 44689
2020-04-11 16:59 Florian Note Added: 0122076
2020-04-12 08:57 Christo Crause Status resolved => closed
2020-04-12 08:57 Christo Crause Note Added: 0122091