Re: [fpc-devel] Different results of random(int32) and random(int64) for negative limit value

2017-05-20 Thread Bart
On 5/20/17, Jonas Maebe  wrote:

> random(x) is undefined for negative parameters. It should have had an
> unsigned parameter, like in Turbo Pascal (where it is word). Delphi
> defines it as always returning a positive value, but I don't know what
> happens if you pass a negative parameter there.

I already reported that the documentation is a bit "off":
https://bugs.freepascal.org/view.php?id=31642

Bart
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Different results of random(int32) and random(int64) for negative limit value

2017-05-20 Thread Jonas Maebe

On 20/05/17 15:38, José Mejuto wrote:
At least in 3.0 (trunk not tested as I don't have it compiled) the first 
and second random numbers are always the same value, so:


That is unrelated to this thread, but has been fixed in FPC 3.0.2.


Jonas
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Different results of random(int32) and random(int64) for negative limit value

2017-05-20 Thread Mark Morgan Lloyd

On 20/05/17 13:00, Martin Schreiber wrote:

Hi,
FPC fixes_3_0, Linux X86:"var i1: int32;begin for i1:= 0 to 5 do begin  
writeln(random(int32(-16))); end; writeln('*'); for i1:= 0 to 5 do begin  
writeln(random(int64(-16))); end;end;"
produces"-9-9-11-13-10-13*395468"Is this intended? If not, which one is 
correct?https://www.freepascal.org/docs-html/current/rtl/system/random.htmlstates for 32 and 64 
bit"Random returns a random number larger or equal to 0 and strictly less than L."which raises the 
question, what means "less"?


What does it do if the parameter is +ve? Note 
https://mantis.freepascal.org/view.php?id=31693


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Different results of random(int32) and random(int64) for negative limit value

2017-05-20 Thread Jonas Maebe

On 20/05/17 14:36, Martin Schreiber wrote:

Is this intended? If not, which one is correct?


random(x) is undefined for negative parameters. It should have had an 
unsigned parameter, like in Turbo Pascal (where it is word). Delphi 
defines it as always returning a positive value, but I don't know what 
happens if you pass a negative parameter there.



Jonas
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Different results of random(int32) and random(int64) for negative limit value

2017-05-20 Thread Martin Schreiber
Hi,

FPC fixes_3_0, Linux X86:
"
var
 i1: int32;
begin
 for i1:= 0 to 5 do begin
  writeln(random(int32(-16)));
 end;
 writeln('*');
 for i1:= 0 to 5 do begin
  writeln(random(int64(-16)));
 end;
end;
"

produces
"
-9
-9
-11
-13
-10
-13
*
3
9
5
4
6
8
"
Is this intended? If not, which one is correct?
https://www.freepascal.org/docs-html/current/rtl/system/random.html
states for 32 and 64 bit
"
Random returns a random number larger or equal to 0 and strictly less than L.
"
which raises the question, what means "less"?

Martin
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Bad code generation on linux x86_64

2017-05-20 Thread C Western
The following revision seems to be generating bad code for me on 
linux/x86_64:


r36200 | florian | 2017-05-13 10:58:25 +0100 (Sat, 13 May 2017) | 1 line
Changed paths:
   M /trunk/compiler/i386/aoptcpu.pas
   M /trunk/compiler/x86/aoptx86.pas

* moved InstructionLoadsFromReg and RegReadByInstruction from 
TCpuAsmOptimizer (i386) to TX86AsmOptimizer


I am not sure how to generate a simple test case, but the code fragment 
that fails is below. As far as I can tell, r14 is used, but never 
loaded; I think r13 should have been used instead.


Colin

.section .text.n_logunit$_$tlogform_$__$$_formcreate$tobject
.balign 16,0x90
.globl  LOGUNIT$_$TLOGFORM_$__$$_FORMCREATE$TOBJECT
.type   LOGUNIT$_$TLOGFORM_$__$$_FORMCREATE$TOBJECT,@function
LOGUNIT$_$TLOGFORM_$__$$_FORMCREATE$TOBJECT:
.Lc1:
# Register rsp allocated
.Ll1:
# [LogUnit.pas]
# [95] begin
pushq   %rbx
pushq   %r12
pushq   %r13
pushq   %r14
pushq   %r15
.Lc3:
# Register rdi,rsi,rax allocated
movq%rdi,%r15
# Var $self located in register rax
# Register rsi released
# Var Sender located in register rsi
# Register r15 allocated
# Register rax released
# Var $self located in register r15
# Register sil allocated
.Ll2:
# [96] DragAcceptFiles(Self, True);
movb$1,%sil
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
callWCOMPAT_$$_DRAGACCEPTFILES$TCUSTOMFORM$BOOLEAN@PLT
# Register rcx,rdx,rsi,rdi,r8,r9,r10,r11 released
# Register rax allocated
.Ll3:
# [98] OnDropFiles := @FormDropFiles;
	movq 
LOGUNIT$_$TLOGFORM_$__$$_FORMDROPFILES$TOBJECT$array_of_ANSISTRING@GOTPCREL(%rip),%rax

movq%rax,1736(%r15)
# Register rax released
movq%r15,1744(%r15)
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
.Ll4:
# [100] 
GlobalMixture.GetEnumNames(GlobalMixture.IndexOfSetting('PrintLevel'),OutputComboBox.Items);

callGLOBAL_$$_GLOBALMIXTURE$$TMIXTURE@PLT
# Register rcx,rdx,rsi,rdi,r8,r9,r10,r11 released
# Register r13 allocated
movq%rax,%r13
# Register rax released
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
callGLOBAL_$$_GLOBALMIXTURE$$TMIXTURE@PLT
# Register rcx,rdx,rsi,r8,r9,r10,r11 released
# Register rdi allocated
movq%rax,%rdi
# Register rax released
# Register rsi allocated
leaq.Ld2(%rip),%rsi
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
callMNODE$_$TMNODE_$__$$_INDEXOFSETTING$ANSISTRING$$LONGINT@PLT
# Register rcx,rdx,rsi,rdi,r8,r9,r10,r11 released
# Register r12d allocated
movl%eax,%r12d
# Register eax released
# Register rax allocated
movq2048(%r15),%rax
# Register rbx allocated
movq1424(%rax),%rbx
# Register rax released
# Register rax,r14 allocated
# Register rax released
testq   %r13,%r13
jne .Lj6
# Register rflags released
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
callfpc_objecterror@PLT
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 released
.Lj6:
# Register rax allocated
movq(%r14),%r14
# Register r14 released
# Register r14 allocated
# Register rax released
# Register rdi allocated
movq%r14,%rdi
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
callfpc_check_object@PLT
# Register rax,rcx,rdx,rsi,r8,r9,r10,r11 released
# Register rdi allocated
movq%r13,%rdi
# Register r13 released
# Register rdx allocated
movq%rbx,%rdx
# Register rbx released
# Register esi allocated
movl%r12d,%esi
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
call*744(%r14)  <  Fail here
# Register rax,rcx,rdx,rsi,rdi,r8,r9,r10,r11 allocated
.Ll5:
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel