[fpc-devel] Question about Currency support

Fuxin Zhang zhangfx at lemote.com
Mon Jun 4 04:30:27 CEST 2012


hi,

  The tests/test/cg/taddcurr.pp fails for mips now, after some tracing,
I've reduced the error to a simpler one:
program t;

var
  i,j : currency;
begin
  j := -1.001;
  i := j / 10.0;

  writeln(i,' ',j);

end.
The generated code is:
  ...
        .stabn 68,0,6,.Ll2 - main
.Ll2:
        addiu   $3,$0,-10010              //load -10010 to a int64 store
        lui     $2,%hi(U_$P$T_$$_J)
        sw      $3,%lo(U_$P$T_$$_J)($2)
        addiu   $2,$0,-1
        lui     $3,%hi(U_$P$T_$$_J+4)
        addiu   $3,$3,%lo(U_$P$T_$$_J+4)
        sw      $2,($3)
        .stabn 68,0,7,.Ll3 - main
.Ll3:
        lui     $2,%hi(U_$P$T_$$_J)
        lw      $4,%lo(U_$P$T_$$_J)($2)
        lui     $2,%hi(U_$P$T_$$_J+4)
        addiu   $2,$2,%lo(U_$P$T_$$_J+4)
        lw      $5,($2)
        jal     fpc_int64_to_double    //convert it to double
        nop
        lui     $2,%hi(_$T$_Ld1)
        addiu   $2,$2,%lo(_$T$_Ld1)
        lwc1    $f2,($2)
        div.s   $f0,$f0,$f2           // div 10000.0, but problem is that
f0 contains a double value, here div.s is used
        lui     $2,%hi(_$T$_Ld2)
        addiu   $2,$2,%lo(_$T$_Ld2)
        lwc1    $f2,($2)
        div.s   $f0,$f0,$f2          // should be div 10.0
        lui     $2,%hi(_$T$_Ld1)
        addiu   $2,$2,%lo(_$T$_Ld1)
        lwc1    $f2,($2)
        mul.s   $f0,$f0,$f2          // mul 10000.0
        cvt.d.s $f0,$f0
        swc1    $f0,84($29)
        swc1    $f1,88($29)
        lw      $4,84($29)
        lw      $5,88($29)
        jal     fpc_round_real
        nop

I guess it is related to mips/ncpucvn.pas:
   tmipseltypeconvnode.first_int_to_real
when compared to ncnv.pas, it seems ignore the floatype of resultdef. But
using the inherited first_int_to_real is impossible since
int64_to_float64/float32 etc. are not implemented(how can the sparc
version work if so, it call the inherited one?)

BTW,
  for the statement i := j / 10.0, is that in the div node, resultdef
refers to i, left refers to j, and right refers to 10.0?
  But for the typeconvnode, what is the result/left/right node?
In general, is there a way for me to learn about the node generating
process? E.g. add print somewhere to show it? Add in each node seems too
much...

Thanks in advance.

Regards
Fuxin Zhang








More information about the fpc-devel mailing list