c++ - boost::hash odd behavior on RHEL 5.4 64bit -


I've written a simple code to promote: hash behavior, source code as: < Pre> #include & lt; Iostream & gt; #include "boost / functional / hash.hpp" namespace myns {size_t get_hash (double V) {boost :: hash < Double & gt; Haser; Returning (V); }} Int main () {double arr [] = {1.0, 1.0, 2.0, 1.0, 3.0, 2.0}; {Std :: cout & lt; for int i = 0; i & lt; 6; i ++) & Lt; "Hash for" & lt; & Lt; Arrival [i] & lt; & Lt; "Is" & lt; & Lt; myns :: get_hash (ARE [i]) & lt; & Lt; Std :: endl; Scenario # 1: Running in Release Build (GCC version 4.1.2 20080704 (Red Hat 4.1.2-46)), output looks like this:

  1 For hash 4607182418800017408 has 4607182418800017408 for hash1 is 4611686018427387904 for hash 3 4607182418800017408 hash2 is 4613937818241073152 Scenario # 2: In the debug build (the same compiler), the output is:  
 For hash is 4607182418800017408 for hash1 4607182418800017408 hash2 is 4611686018427387904 hash1 for 4607182418800017408 hash3 for 4613937818241073152 hash2 Or is 4,611,686,018,427,387,904th make   

What release behavior normal? In scene # 1, the hashes of 1, 2, 3 are the same, and the hash of 1 is different for running 3 times! How can I get it working properly in Debug Build? Can someone give me some light? Thank you.

The GCC option line is: G ++ - Phone-call-exception-O2 -i / main.cpp is included in this, if I remove the fnon-call-exception option, then this problem is solved.

edited

The workaround is:

  size_t get_hash (double v) {#if (__GNUC__ & amp; __GNUC__ == 4 & amp; amp; __GNUC_MINOR__ == 1 & amp; amp; __GNUC_PATCHLEVEL__ == 2) Switch (std :: fpclassify (v)) {case fp_giro: return 0; Case FP_INFINITE: Return (std :: size_t) (v> gt? -1: -2); Case FP_NN: Returns -3; Case FP_NORMAL: Case FP_SUBNORMAL: #if Defined (__ x86_64__) Return * ((size_t *) & amp; v); # Longer time = * ((long * *) & amp; v); Size_t seed = l & a. 0xFFFFFFFF; Seed ^ = (LAT> 32) + (Beed and LT; <6) + (Seed> 2); Return seed; #endif Default: Claims (Wrong); Return 0; } #to promote: hash & lt; Double & gt; Haser; Returning (V); #endif}   

Hope for whom to meet this problem and their compiler can not be updated.

@ David Schwartz, this will not be a bug, for promotion, this problem can be reproduced with a simple code:

  #include & lt ; Iostream & gt; Size_t hash (size_t x) {return x; } Size_T hash (double D) {size_t x = * (size_t *) & amp; D; Return hash (x); } Int main () {double arr [] = {1.0, 1.0, 2.0, 1.0, 3.0, 2.0}; {Std :: cout & lt; for int i = 0; i & lt; 6; i ++) & Lt; "Hash for" & lt; & Lt; Arrival [i] & lt; & Lt; "Is" & lt; & Lt; Hash (ARI [ii]) & lt; & Lt; Std :: endl; }}   

Its assembly code (with G ++ - S) you will see:

  .LCFI0: movq (% rsp),% rdi Movsd% xmm0, (% rsp) call _z4hashm addq $ 8,% rsp ret   

Here's the% rdi error. My conclusion is: not to move a rediscovered data of double as a function parameter.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -