On 31/08/2015 01:05, Joe Taylor wrote:
> Hi Bill,
Hi Joe,
>
> Thanks for your work on making a more rugged Fortran-to-C interface for
> the nhash function.  I'm sure it will make a good addition to our code
> base.
OK, I will test properly and commit to the wsjtx_exp branch when done.
>
> Here and elsewhere, as I'm sure you have long recognized, my approach
> has often used quick-and-dirty approaches to test a new idea, make it
> work, maybe tune it some for performance... and then, eventually, clean
> up the code.  Your efforts will be a big help, once again, in seeing
> this sequence of steps through to the end.
Inter language interoperation is a minefield and IMHO using any compiler 
based tools to specify formal interfaces saves time in the long run. The 
end is a long way off :(
>
> Simple answer to your question about why this hash algorithm is used:
> it's handy, fast, has been used in WSPR mode for > 5 years, and is
> already present in the WSJT-X code base.
OK, that's fine. I mentioned it because Intel SSE4 has a crc32 
instruction which will beat any software or table based CRC32 
implementation hands down for performance at better than 5 bytes 
processed per CPU cycle. The zlib library is one common way of getting 
hash and CRC functions but I don't think it takes advantage of SSE SIMD 
instructions. All probably academic for our tiny messages.
>
>       -- 73, Joe, K1JT
73
Bill
G4WJS.
>
> On 8/30/2015 4:48 PM, Bill Somerville wrote:
>> Hi Joe,
>>
>> I note the changes around the nhash C function and despite it not being
>> the root cause of the initially reported JTMSK crashes it seems
>> appropriate to suggest that we make use of the Fortran/C
>> interoperability features of modern Fortran to ensure that
>> interoperation is more robust and potentially a little more efficient.
>>
>> As an example I have prepared a module the defines the interface to the
>> nhash C function for calling from Fortran which looks like:
>>
>> module hashing
>> interface
>> integer(c_int32_t) function nhash (key, length, initval) bind(C,
>> name="nhash")
>> use iso_c_binding, only: c_ptr, c_size_t, c_int32_t
>> type(c_ptr), intent(in), value :: key
>> integer(c_size_t), intent(in), value :: length
>> integer(c_int32_t), intent(in), value :: initval
>> end function nhash
>> end interface
>> end module hashing
>>
>> This can be called without any extra wrapping code, argument
>> manipulation or, function renaming and allows any contiguous block of
>> memory that is represented by a Fortran scalar or contiguous vector to
>> be hashed. For example in the source lib/hash.f90:
>>
>> subroutine hash(string,len,ihash)
>> use iso_c_binding, only: c_loc
>> use hashing
>> parameter (MASK15=32767)
>> character*(*), target :: string
>> i=nhash(c_loc(string),len,146)
>> ihash=iand(i,MASK15)
>>
>> ! print*,'C',ihash,len,string
>> return
>> end subroutine hash
>>
>> rather than the current copy to an integer array.
>>
>> A more complete patch is attached that uses the module to define the
>> interface in all places nhash is called from Fortran.
>>
>> I have tested this patch in ^/branches/wsjtx_exp in a trivial back to
>> back JTMSK QSO more as a test of building that a thorough regression test.
>>
>> I also wonder why the nhash algorithm has been used for a CRC on JTMSK
>> messages since there are probably simpler well tried and tested CRC
>> algorithms in common usage.
>>
>> Comments?
>>
>> 73
>> Bill
>> G4WJS.
>>


------------------------------------------------------------------------------
_______________________________________________
wsjt-devel mailing list
wsjt-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wsjt-devel

Reply via email to