diff gen/tollvm.cpp @ 344:e20ce6d8d374 trunk

[svn r365] Implemented raw struct equality comparison, uses C memcmp. Renamed DtoDelegateCompare to DtoDelegateEquals, for consistency with the other equality helpers.
author lindquist
date Sun, 13 Jul 2008 04:11:08 +0200
parents 7086a84ab3d6
children f273f5c58a9a
line wrap: on
line diff
--- a/gen/tollvm.cpp	Sun Jul 13 03:02:15 2008 +0200
+++ b/gen/tollvm.cpp	Sun Jul 13 04:11:08 2008 +0200
@@ -186,9 +186,9 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-LLValue* DtoDelegateCompare(TOK op, LLValue* lhs, LLValue* rhs)
+LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs)
 {
-    Logger::println("Doing delegate compare");
+    Logger::println("Doing delegate equality");
     llvm::ICmpInst::Predicate pred = (op == TOKequal || op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
     llvm::Value *b1, *b2;
     if (rhs == NULL)
@@ -444,6 +444,29 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
+LLValue* DtoMemCmp(LLValue* lhs, LLValue* rhs, LLValue* nbytes)
+{
+    // int memcmp ( const void * ptr1, const void * ptr2, size_t num );
+
+    LLFunction* fn = gIR->module->getFunction("memcmp");
+    if (!fn)
+    {
+        std::vector<const LLType*> params(3);
+        params[0] = getVoidPtrType();
+        params[1] = getVoidPtrType();
+        params[2] = DtoSize_t();
+        const LLFunctionType* fty = LLFunctionType::get(LLType::Int32Ty, params, false);
+        fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", gIR->module);
+    }
+
+    lhs = DtoBitCast(lhs,getVoidPtrType());
+    rhs = DtoBitCast(rhs,getVoidPtrType());
+
+    return gIR->ir->CreateCall3(fn, lhs, rhs, nbytes, "tmp");
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
 void DtoAggrZeroInit(LLValue* v)
 {
     uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0));