On Fri, Feb 17, 2012 at 1:32 AM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com">clattner@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="im">On Feb 17, 2012, at 12:26 AM, Talin wrote:<br>
> OK here's a patch with the latest, including unit tests. I've also tried to make the comments clear that this is intended for the case of "generic" key types, where you are either hashing multiple data types together, or you don't know in advance what the data type will be - for cases such as strings where a tailored algorithm is available, you should use that instead of this.<br>


<br>
</div>Makes sense.<br>
<br>
+  /// Add a pointer value.<br>
+  /// Note: this adds pointers to the hash using sizes and endianness that<br>
+  /// depend on the host.  It doesn't matter however, because hashing on<br>
+  /// pointer values is inherently unstable.<br>
<br>
This makes perfect sense.<br>
<br></blockquote><div>It should, as the comment was copied verbatim from FoldingSetNodeID :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  /// Add an ArrayRef of arbitrary data.<br>
+  template<typename T><br>
+  GeneralHash& add(ArrayRef<T> ArrayVal) {<br>
+    addBits(ArrayVal.begin(), ArrayVal.end());<br>
+    return *this;<br>
+  }<br>
<br>
Doesn't this have the same host-specificity problem, except that it will cause things that *are* stable to vary, such as arrays of char, or is the alignment check enough?<br>
<br></blockquote><div>I thought about whether it would be possible to prevent people from passing in ArrayRefs with unstable things, and I came to the conclusion that there's no simple way to distinguish between stable and unstable ArrayRefs. This is why I decided not to make a special "addPointer" method for pointers, because you could easily subvert it by wrapping it in a singleton ArrayRef.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  /// Add a float<br>
+  GeneralHash& add(float Data) {<br>
<br>
It is worth adding a comment here that this does a bitwise hash, so -0.0 and +0.0 will hash to different values even though they compare equal and two identical NaN's will hash to the same value even though they compare unequal.<br>


<br></blockquote><div>BTW, are there in fact any maps in LLVM that use floats as keys, other than uniquing of constants? And in the latter case, would you not want to distinguish between a -0.0 and +0.0 constant? </div><div>

 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The mix logic is inherently a series of 32-bit operations.  Would it be possible and make more sense to implement them as 64-bit operations?  64-bit hosts are the vast majority of the machines that run a compiler these days.  OTOH, making it depend on the host brings up host instability issues.<br>


<br>
Actually, how much do we care about host instability here?  If this is used by hashing containers, we can just declare that iteration order is undefined even for non-pointer values.  The real problem I guess is that we'd have to go check out all the existing DenseMap's etc to make sure people aren't doing well-defined iteration right now and fixing the code.  What do you think?<br>


<div class="im"><br></div></blockquote><div>I think that you are thinking that existing uses of DenseMap and other ADT containers will be affected by this. That wasn't my plan - I was going to basically use the hashing class to create a custom DenseMapInfo for specific maps which could benefit from the optimization. Other DenseMaps would remain as they are.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
> There's a couple of things I don't like: First, there's too many levels of inlined function calls - my experience is that compilers aren't as good at inlining nested calls as is often advertised, however I couldn't figure out a way to get the same effect without the nested calls.<br>


<br>
</div>Is there a specific observed concern here (e.g. when built with Clang) or is this a historical problem?  Compilers have gotten much better about inlining stuff that is actually small, if Clang handles it then I think we're good.  Marking these attribute(always_inline) is massive overkill.<br>


<br></blockquote><div>Well, it is historical from about 5 years ago when I was working on EASTL. The compilers we were using at the time were gcc and MSVC. We found cases in the standard STL where inlines were nested up to 10 levels deep, and in some of those cases the compiler just gave up trying to inline things that deeply.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Overall the code is looking great.  I'd recommend checking in the new API separately from switching Constants.cpp to use it though (just so that any problems doesn't cause both to get reverted).<br>
<font color="#888888"><br></font></blockquote><div>OK. I'm still working on getting a consensus from the hashing experts :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<font color="#888888">
-Chris<br>
</font></blockquote></div><br>-- <br>-- Talin<br>