Recent

Author Topic: Conversion from C#  (Read 3925 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Conversion from C#
« on: August 22, 2014, 01:28:46 pm »
Is this correct?
C#
Code: [Select]
h32 ^= h32 >> 15;FPC
Code: [Select]
h32 := h32 xor (h32 shr 15);
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Leledumbo

  • Hero Member
  • *****
  • Posts: 8114
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Conversion from C#
« Reply #1 on: August 22, 2014, 03:01:33 pm »
yes

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: Conversion from C#
« Reply #2 on: August 22, 2014, 05:30:16 pm »
Thanks. I'm converting xxHash (https://code.google.com/p/xxhash/) to FPC. My first attempt was to pass the original C code thru C2PAS32 (AstonShell) convertor but the code was a pure chaos for me - to many directives since it is the code for 32 and 64 bits and for little and big endian.
There are ports to other languages so I choosed C# 'cause it looked nice to me.
Luckily it gives me correct results now, I'll try to work on performance a little and I'll consider if it will be plain pascal or an object.

EDIT: I forgot to mention, I tried to Google for "xxHash delphi" - no luck. I also tried to find some documentation for xxHash but seems there's nothing around, only C code.
« Last Edit: August 22, 2014, 05:32:49 pm by Blaazen »
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Conversion from C#
« Reply #3 on: August 23, 2014, 05:49:22 pm »
I'm converting xxHash (https://code.google.com/p/xxhash/) to FPC.
According to the link:
Quote
32-bits hash comparison (single thread, Windows Seven 32 bits, using Open Source's SMHasher on a Core 2 Duo @3GHz)
...
xxHash          5.4 GB/s     10
That's an impressive speed. I did not get anything near it here.  :(

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: Conversion from C#
« Reply #4 on: August 23, 2014, 06:14:27 pm »
On my machine (Core2Duo P7350@2GHz), I got following results:
From original C code:
Code: [Select]
[v1@msi-NB xxHash-r35]$ ./xxHash /media/disk/v1/maverick.iso
*** xxHash tester 64-bits , by Yann Collet (Aug 20 2014) ***
Sanity check -- all tests ok                                                   
Loading /media/disk/v1/maverick.iso...       
XXH32            :  728754176 ->  3259.9 MB/s   0xB62779A6                     
XXH32 (unaligned :  728754175 ->  2730.7 MB/s                                 
XXH64            :  728754176 ->  3354.8 MB/s   0x55474CC558423F11             
[v1@msi-NB xxHash-r35]$
And FPC port:
Code: [Select]
/media/disk/v1/maverick.iso
aLength 728754176
File loaded
Average time: 449.860ms
Average speed: 1544.912MB/s
B62779A6
...
/media/disk/v1/maverick.iso
aLength 728754176
File loaded
Average time: 276.780ms
Average speed: 2510.998MB/s
55474CC558423F11

Results for 64-bits looks good, I see there a space for optimalizations but 32-bits results looks strange. To me it seems that GCC does some magic for 32-bit operations on 64-bit CPU because speed of FPC is almost exactly 50%.

EDIT:
I'm already at 3200MB/s with 64-bit version, it's 93% of GNU GCC.  :)
« Last Edit: August 23, 2014, 06:53:03 pm by Blaazen »
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

engkin

  • Hero Member
  • *****
  • Posts: 2513
Re: Conversion from C#
« Reply #5 on: August 24, 2014, 02:48:13 am »
Thanks for sharing your results, Blaazen. They look great! I'll have to check what's wrong on my side.