diff --git a/.hgignore b/.hgignore
index 1b7a9019a265cfc9fb6ba03a1e7a9d6aa8ee2120..09031ac0fa65244dc2f14dd50a4aaa10dae8ef87 100755
--- a/.hgignore
+++ b/.hgignore
@@ -17,6 +17,7 @@ build-darwin-*
 build-vc80/
 build-vc100/
 build-vc120/
+build-vc120_x64/
 indra/build-vc[0-9]*
 indra/CMakeFiles
 indra/lib/mono/1.0/*.dll
diff --git a/autobuild.xml b/autobuild.xml
index a92fdfd4d7e7d606922ef7f5cf5aa0d1024193da..6861becb1c07add2978c96fcea5f2f38d8e077be 100644
--- a/autobuild.xml
+++ b/autobuild.xml
@@ -3204,7 +3204,7 @@
                 <key>options</key>
                 <array>
                   <string>-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo</string>
-                  <string>-DWORD_SIZE:STRING=32</string>
+                  <string>-DADDRESS_SIZE:STRING=$AUTOBUILD_ADDRSIZE</string>
                   <string>-DROOT_PROJECT_NAME:STRING=SecondLife</string>
                   <string>-DINSTALL_PROPRIETARY=TRUE</string>
                 </array>
@@ -3225,7 +3225,7 @@
                 <key>options</key>
                 <array>
                   <string>-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo</string>
-                  <string>-DWORD_SIZE:STRING=32</string>
+                  <string>-DADDRESS_SIZE:STRING=$AUTOBUILD_ADDRSIZE</string>
                   <string>-DROOT_PROJECT_NAME:STRING=SecondLife</string>
                   <string>-DINSTALL_PROPRIETARY=FALSE</string>
                 </array>
@@ -3245,7 +3245,7 @@
                 <key>options</key>
                 <array>
                   <string>-DCMAKE_BUILD_TYPE:STRING=Release</string>
-                  <string>-DWORD_SIZE:STRING=32</string>
+                  <string>-DADDRESS_SIZE:STRING=$AUTOBUILD_ADDRSIZE</string>
                   <string>-DROOT_PROJECT_NAME:STRING=SecondLife</string>
                   <string>-DINSTALL_PROPRIETARY=TRUE</string>
                 </array>
@@ -3266,7 +3266,7 @@
                 <key>options</key>
                 <array>
                   <string>-DCMAKE_BUILD_TYPE:STRING=Release</string>
-                  <string>-DWORD_SIZE:STRING=32</string>
+                  <string>-DADDRESS_SIZE:STRING=$AUTOBUILD_ADDRSIZE</string>
                   <string>-DROOT_PROJECT_NAME:STRING=SecondLife</string>
                   <string>-DINSTALL_PROPRIETARY=FALSE</string>
                 </array>
@@ -3537,7 +3537,7 @@
                 <key>options</key>
                 <array>
                   <string>/build</string>
-                  <string>"RelWithDebInfo|Win32"</string>
+                  <string>"RelWithDebInfo|${AUTOBUILD_WIN_VSPLATFORM|NOTWIN}"</string>
                 </array>
               </map>
               <key>configure</key>
@@ -3549,7 +3549,7 @@
                 <key>options</key>
                 <array>
                   <string>-G</string>
-                  <string>"Visual Studio 12"</string>
+                  <string>${AUTOBUILD_WIN_CMAKE_GEN|NOTWIN}</string>
                 </array>
               </map>
               <key>default</key>
@@ -3570,7 +3570,7 @@
                 <key>options</key>
                 <array>
                   <string>/p:Configuration=RelWithDebInfo</string>
-                  <string>/p:Platform=Win32</string>
+                  <string>/p:Platform=${AUTOBUILD_WIN_VSPLATFORM|NOTWIN}</string>
                   <string>/t:Build</string>
                   <string>/p:useenv=true</string>
                   <string>/verbosity:minimal</string>
@@ -3587,7 +3587,8 @@
                 <key>options</key>
                 <array>
                   <string>-G</string>
-                  <string>"Visual Studio 12"</string>
+                  <string>${AUTOBUILD_WIN_CMAKE_GEN|NOTWIN}</string>
+                  <string>-DUNATTENDED:BOOL=ON</string>
                   <string>-DINSTALL_PROPRIETARY=FALSE</string>
                   <string>-DUSE_KDU=FALSE</string>
                 </array>
@@ -3608,7 +3609,7 @@
                 <key>options</key>
                 <array>
                   <string>/build</string>
-                  <string>"Release|Win32"</string>
+                  <string>"Release|${AUTOBUILD_WIN_VSPLATFORM|NOTWIN}"</string>
                 </array>
               </map>
               <key>configure</key>
@@ -3620,7 +3621,7 @@
                 <key>options</key>
                 <array>
                   <string>-G</string>
-                  <string>"Visual Studio 12"</string>
+                  <string>${AUTOBUILD_WIN_CMAKE_GEN|NOTWIN}</string>
                 </array>
               </map>
               <key>name</key>
@@ -3639,7 +3640,7 @@
                 <key>options</key>
                 <array>
                   <string>/p:Configuration=Release</string>
-                  <string>/p:Platform=Win32</string>
+                  <string>/p:Platform=${AUTOBUILD_WIN_VSPLATFORM|NOTWIN}</string>
                   <string>/t:Build</string>
                   <string>/p:useenv=true</string>
                   <string>/verbosity:minimal</string>
@@ -3656,7 +3657,8 @@
                 <key>options</key>
                 <array>
                   <string>-G</string>
-                  <string>"Visual Studio 12"</string>
+                  <string>${AUTOBUILD_WIN_CMAKE_GEN|NOTWIN}</string>
+                  <string>-DUNATTENDED:BOOL=ON</string>
                   <string>-DINSTALL_PROPRIETARY=FALSE</string>
                   <string>-DUSE_KDU=FALSE</string>
                 </array>
diff --git a/indra/cmake/00-Common.cmake b/indra/cmake/00-Common.cmake
index adc134c48cc787495471cdc9ccd20688794ad784..4f335b50ec413f8fcaeeeaad05b17251f85c7278 100644
--- a/indra/cmake/00-Common.cmake
+++ b/indra/cmake/00-Common.cmake
@@ -74,9 +74,14 @@ if (WINDOWS)
       /nologo
       /Oy-
       /Zc:wchar_t-
-      /arch:SSE2
+#      /arch:SSE2
       /fp:fast
       )
+
+  # Nicky: x64 implies SSE2
+  if( ADDRESS_SIZE EQUAL 32 )
+    add_definitions( /arch:SSE2 )
+  endif()
      
   # Are we using the crummy Visual Studio KDU build workaround?
   if (NOT VS_DISABLE_FATAL_WARNINGS)
@@ -173,9 +178,9 @@ if (LINUX)
   add_definitions(-fvisibility=hidden)
   # don't catch SIGCHLD in our base application class for the viewer - some of our 3rd party libs may need their *own* SIGCHLD handler to work.  Sigh!  The viewer doesn't need to catch SIGCHLD anyway.
   add_definitions(-DLL_IGNORE_SIGCHLD)
-  if (WORD_SIZE EQUAL 32)
+  if (ADDRESS_SIZE EQUAL 32)
     add_definitions(-march=pentium4)
-  endif (WORD_SIZE EQUAL 32)
+  endif (ADDRESS_SIZE EQUAL 32)
   add_definitions(-mfpmath=sse)
   #add_definitions(-ftree-vectorize) # THIS CRASHES GCC 3.1-3.2
   if (NOT USESYSTEMLIBS)
@@ -226,13 +231,13 @@ if (LINUX OR DARWIN)
   set(CMAKE_C_FLAGS "${GCC_WARNINGS} ${CMAKE_C_FLAGS}")
   set(CMAKE_CXX_FLAGS "${GCC_CXX_WARNINGS} ${CMAKE_CXX_FLAGS}")
 
-  if (WORD_SIZE EQUAL 32)
+  if (ADDRESS_SIZE EQUAL 32)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
-  elseif (WORD_SIZE EQUAL 64)
+  elseif (ADDRESS_SIZE EQUAL 64)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
-  endif (WORD_SIZE EQUAL 32)
+  endif (ADDRESS_SIZE EQUAL 32)
 endif (LINUX OR DARWIN)
 
 
diff --git a/indra/cmake/ConfigurePkgConfig.cmake b/indra/cmake/ConfigurePkgConfig.cmake
index 82ee3e7a5b54d107e852ea17bab037c76c3d9c16..55d865392e37b294459166116c8bdf71d0fdc121 100644
--- a/indra/cmake/ConfigurePkgConfig.cmake
+++ b/indra/cmake/ConfigurePkgConfig.cmake
@@ -6,17 +6,17 @@ SET(DEBUG_PKG_CONFIG "YES")
 IF("$ENV{PKG_CONFIG_LIBDIR}" STREQUAL "")
 
   # Guess at architecture-specific system library paths.
-  if (WORD_SIZE EQUAL 32)
+  if (ADDRESS_SIZE EQUAL 32)
     SET(PKG_CONFIG_NO_MULTI_GUESS /usr/lib32 /usr/lib)
     SET(PKG_CONFIG_NO_MULTI_LOCAL_GUESS /usr/local/lib32 /usr/local/lib)
     SET(PKG_CONFIG_MULTI_GUESS /usr/lib/i386-linux-gnu)
     SET(PKG_CONFIG_MULTI_LOCAL_GUESS /usr/local/lib/i386-linux-gnu)
-  else (WORD_SIZE EQUAL 32)
+  else (ADDRESS_SIZE EQUAL 32)
     SET(PKG_CONFIG_NO_MULTI_GUESS /usr/lib64 /usr/lib)
     SET(PKG_CONFIG_NO_MULTI_LOCAL_GUESS /usr/local/lib64 /usr/local/lib)
     SET(PKG_CONFIG_MULTI_GUESS /usr/local/lib/x86_64-linux-gnu)
     SET(PKG_CONFIG_MULTI_LOCAL_GUESS /usr/local/lib/x86_64-linux-gnu)
-  endif (WORD_SIZE EQUAL 32)
+  endif (ADDRESS_SIZE EQUAL 32)
   
   # Use DPKG architecture, if available.
   IF (${DPKG_ARCH})
diff --git a/indra/cmake/Variables.cmake b/indra/cmake/Variables.cmake
index 63e296b556d243085c40d2c4ceb59522a60b1d4b..464b4c402c67ad732e62bab0da27304a2bafaea6 100644
--- a/indra/cmake/Variables.cmake
+++ b/indra/cmake/Variables.cmake
@@ -65,7 +65,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
   set(ARCH i686)
   set(LL_ARCH ${ARCH}_win32)
   set(LL_ARCH_DIR ${ARCH}-win32)
-  set(WORD_SIZE 32)
+  set(ADDRESS_SIZE 32)
 endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
 
 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
@@ -73,33 +73,33 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 
   # If someone has specified a word size, use that to determine the
   # architecture.  Otherwise, let the architecture specify the word size.
-  if (WORD_SIZE EQUAL 32)
-    #message(STATUS "WORD_SIZE is 32")
+  if (ADDRESS_SIZE EQUAL 32)
+    #message(STATUS "ADDRESS_SIZE is 32")
     set(ARCH i686)
-  elseif (WORD_SIZE EQUAL 64)
-    #message(STATUS "WORD_SIZE is 64")
+  elseif (ADDRESS_SIZE EQUAL 64)
+    #message(STATUS "ADDRESS_SIZE is 64")
     set(ARCH x86_64)
-  else (WORD_SIZE EQUAL 32)
-    #message(STATUS "WORD_SIZE is UNDEFINED")
+  else (ADDRESS_SIZE EQUAL 32)
+    #message(STATUS "ADDRESS_SIZE is UNDEFINED")
     execute_process(COMMAND uname -m COMMAND sed s/i.86/i686/
                     OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
     if (ARCH STREQUAL x86_64)
       #message(STATUS "ARCH is detected as 64; ARCH is ${ARCH}")
-      set(WORD_SIZE 64)
+      set(ADDRESS_SIZE 64)
     else (ARCH STREQUAL x86_64)
       #message(STATUS "ARCH is detected as 32; ARCH is ${ARCH}")
-      set(WORD_SIZE 32)
+      set(ADDRESS_SIZE 32)
     endif (ARCH STREQUAL x86_64)
-  endif (WORD_SIZE EQUAL 32)
+  endif (ADDRESS_SIZE EQUAL 32)
 
-  if (WORD_SIZE EQUAL 32)
+  if (ADDRESS_SIZE EQUAL 32)
     set(DEB_ARCHITECTURE i386)
     set(FIND_LIBRARY_USE_LIB64_PATHS OFF)
     set(CMAKE_SYSTEM_LIBRARY_PATH /usr/lib32 ${CMAKE_SYSTEM_LIBRARY_PATH})
-  else (WORD_SIZE EQUAL 32)
+  else (ADDRESS_SIZE EQUAL 32)
     set(DEB_ARCHITECTURE amd64)
     set(FIND_LIBRARY_USE_LIB64_PATHS ON)
-  endif (WORD_SIZE EQUAL 32)
+  endif (ADDRESS_SIZE EQUAL 32)
 
   execute_process(COMMAND dpkg-architecture -a${DEB_ARCHITECTURE} -qDEB_HOST_MULTIARCH 
       RESULT_VARIABLE DPKG_RESULT
@@ -151,7 +151,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   set(ARCH ${CMAKE_OSX_ARCHITECTURES})
   set(LL_ARCH ${ARCH}_darwin)
   set(LL_ARCH_DIR universal-darwin)
-  set(WORD_SIZE 32)
+  set(ADDRESS_SIZE 32)
 endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
 
 # Default deploy grid
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 493aa5d0f11a08d58b57a714acf0e5913d2db5a0..b29b2b2ccf63942f2f9b71aa660617a111faa3ea 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -245,13 +245,13 @@ list(APPEND llcommon_SOURCE_FILES ${llcommon_HEADER_FILES})
 
 if(LLCOMMON_LINK_SHARED)
   add_library (llcommon SHARED ${llcommon_SOURCE_FILES})
-  if(NOT WORD_SIZE EQUAL 32)
+  if(NOT ADDRESS_SIZE EQUAL 32)
     if(WINDOWS)
       add_definitions(/FIXED:NO)
     else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
       add_definitions(-fPIC)
     endif(WINDOWS)
-  endif(NOT WORD_SIZE EQUAL 32)
+  endif(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     # always generate llcommon.pdb, even for "Release" builds
     set_target_properties(llcommon PROPERTIES LINK_FLAGS "/DEBUG")
diff --git a/indra/llcommon/llcoros.cpp b/indra/llcommon/llcoros.cpp
index 0d9e19f67270b1abc0b9a23214e106bf4201fb5e..bc72faca5dc2c29db354fdb91c49f5f4588db12c 100644
--- a/indra/llcommon/llcoros.cpp
+++ b/indra/llcommon/llcoros.cpp
@@ -101,7 +101,7 @@ LLCoros::LLCoros():
     // Previously we used
     // boost::context::guarded_stack_allocator::default_stacksize();
     // empirically this is 64KB on Windows and Linux. Try quadrupling.
-#if WORD_SIZE == 64
+#if ADDRESS_SIZE == 64
     mStackSize(512*1024)
 #else
     mStackSize(256*1024)
diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h
index f56e5596f5496fd862ff3b39bf9ad21123ca5494..2024d707da5d3a0bbfe1e2a89a6dffe5b69cafdc 100644
--- a/indra/llcommon/llfasttimer.h
+++ b/indra/llcommon/llfasttimer.h
@@ -90,33 +90,15 @@ class BlockTimer
 #if LL_FASTTIMER_USE_RDTSC
 	static U32 getCPUClockCount32()
 	{
-		U32 ret_val;
-		__asm
-		{
-			_emit   0x0f
-				_emit   0x31
-				shr eax,8
-				shl edx,24
-				or eax, edx
-				mov dword ptr [ret_val], eax
-		}
-		return ret_val;
+		unsigned __int64 val = __rdtsc();
+		val = val >> 8;
+		return static_cast<U32>(val);
 	}
 
 	// return full timer value, *not* shifted by 8 bits
 	static U64 getCPUClockCount64()
 	{
-		U64 ret_val;
-		__asm
-		{
-			_emit   0x0f
-				_emit   0x31
-				mov eax,eax
-				mov edx,edx
-				mov dword ptr [ret_val+4], edx
-				mov dword ptr [ret_val], eax
-		}
-		return ret_val;
+		return static_cast<U64>( __rdtsc() );
 	}
 
 #else
@@ -173,16 +155,16 @@ class BlockTimer
 	// Mac+Linux+Solaris FAST x86 implementation of CPU clock
 	static U32 getCPUClockCount32()
 	{
-		U64 x;
-		__asm__ volatile (".byte 0x0f, 0x31": "=A"(x));
-		return (U32)(x >> 8);
+		U32 low(0),high(0);
+		__asm__ volatile (".byte 0x0f, 0x31": "=a"(low), "=d"(high) );
+		return (low>>8) | (high<<24);
 	}
 
 	static U64 getCPUClockCount64()
 	{
-		U64 x;
-		__asm__ volatile (".byte 0x0f, 0x31": "=A"(x));
-		return x;
+		U32 low(0),high(0);
+		__asm__ volatile (".byte 0x0f, 0x31": "=a"(low), "=d"(high) );
+		return (U64)low | ( ((U64)high) << 32);
 	}
 
 #endif
diff --git a/indra/llcommon/llpreprocessor.h b/indra/llcommon/llpreprocessor.h
index 2c4bcc91f6e96ec41c8e6b588de038025a3fc807..7c277c2bed9387605ae7442f19a6cc8a2c6ecea2 100644
--- a/indra/llcommon/llpreprocessor.h
+++ b/indra/llcommon/llpreprocessor.h
@@ -138,6 +138,12 @@
 #pragma warning( 3      :  4266 )	// 'function' : no override available for virtual member function from base 'type'; function is hidden
 #pragma warning (disable : 4180)	// qualifier applied to function type has no meaning; ignored
 //#pragma warning( disable : 4284 )	// silly MS warning deep inside their <map> include file
+
+#ifdef _M_AMD64
+// That one is all over the place for x64 builds.
+#pragma warning( disable : 4267 )   // 'var' : conversion from 'size_t' to 'type', possible loss of data)
+#endif
+
 #pragma warning( disable : 4503 )	// 'decorated name length exceeded, name was truncated'. Does not seem to affect compilation.
 #pragma warning( disable : 4800 )	// 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
 #pragma warning( disable : 4996 )	// warning: deprecated
diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp
index e3e1d0c3918c8cdf1c61d2b98305c46d105a2dc8..65b4507e2d7cb4d8b1683db9e92e2f647f67b830 100644
--- a/indra/llcommon/llprocessor.cpp
+++ b/indra/llcommon/llprocessor.cpp
@@ -398,7 +398,7 @@ static F64 calculate_cpu_frequency(U32 measure_msecs)
 	HANDLE hThread = GetCurrentThread();
 	unsigned long dwCurPriorityClass = GetPriorityClass(hProcess);
 	int iCurThreadPriority = GetThreadPriority(hThread);
-	unsigned long dwProcessMask, dwSystemMask, dwNewMask = 1;
+	DWORD_PTR dwProcessMask, dwSystemMask, dwNewMask = 1;
 	GetProcessAffinityMask(hProcess, &dwProcessMask, &dwSystemMask);
 
 	SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS);
diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp
index c3f235c6ee3c78d80e19a38f1093653dcee40721..52255bfaeb58b8eb401193543ba28ecc354a37a8 100644
--- a/indra/llcommon/llthread.cpp
+++ b/indra/llcommon/llthread.cpp
@@ -63,7 +63,7 @@ void set_thread_name( DWORD dwThreadID, const char* threadName)
 
 	__try
 	{
-		::RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(DWORD), (DWORD*)&info );
+		::RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR*)&info );
 	}
 	__except(EXCEPTION_CONTINUE_EXECUTION)
 	{
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index f71607096c8e7c51d6f6a6622c8b72c42644edec..a6cbcc131ec657d586e52c02dd584f64c0441eb3 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -1218,9 +1218,10 @@ void LLImageRaw::fill( const LLColor4U& color )
 	if( 4 == getComponents() )
 	{
 		U32* data = (U32*) getData();
+		U32 rgbaColor = color.asRGBA();
 		for( S32 i = 0; i < pixels; i++ )
 		{
-			data[i] = color.mAll;
+			data[ i ] = rgbaColor;
 		}
 	}
 	else
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h
index 93b9f22b25fa9cfc722697d8d96800b4314e7adf..b66a3c63d6850a064219a2545cbfae24de7633ca 100644
--- a/indra/llmath/llmath.h
+++ b/indra/llmath/llmath.h
@@ -153,7 +153,7 @@ inline F64 llabs(const F64 a)
 
 inline S32 lltrunc( F32 f )
 {
-#if LL_WINDOWS && !defined( __INTEL_COMPILER )
+#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && !defined( _M_AMD64 )
 		// Avoids changing the floating point control word.
 		// Add or subtract 0.5 - epsilon and then round
 		const static U32 zpfp[] = { 0xBEFFFFFF, 0x3EFFFFFF };
@@ -179,7 +179,7 @@ inline S32 lltrunc( F64 f )
 
 inline S32 llfloor( F32 f )
 {
-#if LL_WINDOWS && !defined( __INTEL_COMPILER )
+#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && !defined( _M_AMD64 )
 		// Avoids changing the floating point control word.
 		// Accurate (unlike Stereopsis version) for all values between S32_MIN and S32_MAX and slightly faster than Stereopsis version.
 		// Add -(0.5 - epsilon) and then round
diff --git a/indra/llmath/llsimdmath.h b/indra/llmath/llsimdmath.h
index cebd2ace7d8cee33699da11846de43f1930bc21a..9f078ec1ef36652baa7090035260fc8b24a8a6c2 100644
--- a/indra/llmath/llsimdmath.h
+++ b/indra/llmath/llsimdmath.h
@@ -31,7 +31,7 @@
 #error "Please include llmath.h before this file."
 #endif
 
-#if ( ( LL_DARWIN || LL_LINUX ) && !(__SSE2__) ) || ( LL_WINDOWS && ( _M_IX86_FP < 2 ) )
+#if ( ( LL_DARWIN || LL_LINUX ) && !(__SSE2__) ) || ( LL_WINDOWS && ( _M_IX86_FP < 2 && !_M_AMD64 ) )
 #error SSE2 not enabled. LLVector4a and related class will not compile.
 #endif
 
diff --git a/indra/llmath/v4coloru.h b/indra/llmath/v4coloru.h
index fddad349789139a076f86a1e72285245359151d0..704ce852d92717478fbff45fe5bc880779eb5607 100644
--- a/indra/llmath/v4coloru.h
+++ b/indra/llmath/v4coloru.h
@@ -47,14 +47,7 @@ class LLColor4U
 {
 public:
 
-	union
-	{
-		U8         mV[LENGTHOFCOLOR4U];
-		U32        mAll;
-		LLColor4*  mSources;
-		LLColor4U* mSourcesU;
-	};
-
+	U8 mV[LENGTHOFCOLOR4U];
 
 	LLColor4U();						// Initializes LLColor4U to (0, 0, 0, 1)
 	LLColor4U(U8 r, U8 g, U8 b);		// Initializes LLColor4U to (r, g, b, 1)
@@ -132,6 +125,9 @@ class LLColor4U
 		return LLColor4(*this);
 	}
 
+	U32 asRGBA() const;
+	void fromRGBA( U32 aVal );
+
 	static LLColor4U white;
 	static LLColor4U black;
 	static LLColor4U red;
@@ -565,6 +561,26 @@ void LLColor4U::setVecScaleClamp(const LLColor3& color)
 	mV[3] = 255;
 }
 
+inline U32 LLColor4U::asRGBA() const
+{
+	// Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here
+
+	return (mV[3] << 24) | (mV[2] << 16) | (mV[1] << 8) | mV[0];
+}
+
+inline void LLColor4U::fromRGBA( U32 aVal )
+{
+	// Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here
+
+	mV[ 0 ] = aVal & 0xFF;
+	aVal >>= 8;
+	mV[ 1 ] = aVal & 0xFF;
+	aVal >>= 8;
+	mV[ 2 ] = aVal & 0xFF;
+	aVal >>= 8;
+	mV[ 3 ] = aVal & 0xFF;
+}
+
 
 #endif
 
diff --git a/indra/llplugin/CMakeLists.txt b/indra/llplugin/CMakeLists.txt
index 84667f1b826f5a38ed400bd038cac0b912479687..22f3b24dc560a43ef1d3dfb9dbaf3c1bdd19991b 100644
--- a/indra/llplugin/CMakeLists.txt
+++ b/indra/llplugin/CMakeLists.txt
@@ -56,13 +56,13 @@ set(llplugin_HEADER_FILES
 set_source_files_properties(${llplugin_HEADER_FILES}
                             PROPERTIES HEADER_FILE_ONLY TRUE)
 
-if(NOT WORD_SIZE EQUAL 32)
+if(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     add_definitions(/FIXED:NO)
   else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
     add_definitions(-fPIC)
   endif(WINDOWS)
-endif(NOT WORD_SIZE EQUAL 32)
+endif(NOT ADDRESS_SIZE EQUAL 32)
 
 list(APPEND llplugin_SOURCE_FILES ${llplugin_HEADER_FILES})
 
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index 69420dd0bb338b07539a62847916ddfdc443743b..0e242a20f697c3d23d590eab9086939ae7a55ab0 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -2039,7 +2039,8 @@ void LLRender::vertexBatchPreTransformed(LLVector3* verts, S32 vert_count)
 		}
 	}
 
-	mVerticesp[mCount] = mVerticesp[mCount-1];
+	if( mCount > 0 ) // ND: Guard against crashes if mCount is zero, yes it can happen
+		mVerticesp[mCount] = mVerticesp[mCount-1];
 }
 
 void LLRender::vertexBatchPreTransformed(LLVector3* verts, LLVector2* uvs, S32 vert_count)
diff --git a/indra/llwindow/lldragdropwin32.cpp b/indra/llwindow/lldragdropwin32.cpp
index d00d9ab47ea1caa2d0a8347f4fbefc13ba4ebe64..0d1a47408bb6e6bd9a47043dee4cf9c26cbf3f42 100644
--- a/indra/llwindow/lldragdropwin32.cpp
+++ b/indra/llwindow/lldragdropwin32.cpp
@@ -113,7 +113,7 @@ class LLDragDropWin32Target:
 					PVOID data = GlobalLock( stgmed.hGlobal );
 					mDropUrl = std::string( (char*)data );
 					// XXX MAJOR MAJOR HACK!
-					LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLong(mAppWindowHandle, GWL_USERDATA);
+					LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLongPtr( mAppWindowHandle, GWLP_USERDATA );
 					if (NULL != window_imp)
 					{
 						LLCoordGL gl_coord( 0, 0 );
@@ -168,7 +168,7 @@ class LLDragDropWin32Target:
 			if ( mAllowDrop )
 			{
 				// XXX MAJOR MAJOR HACK!
-				LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLong(mAppWindowHandle, GWL_USERDATA);
+				LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLongPtr( mAppWindowHandle, GWLP_USERDATA );
 				if (NULL != window_imp)
 				{
 					LLCoordGL gl_coord( 0, 0 );
@@ -215,7 +215,7 @@ class LLDragDropWin32Target:
 		HRESULT __stdcall DragLeave( void )
 		{
 			// XXX MAJOR MAJOR HACK!
-			LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLong(mAppWindowHandle, GWL_USERDATA);
+			LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLongPtr( mAppWindowHandle, GWLP_USERDATA );
 			if (NULL != window_imp)
 			{
 				LLCoordGL gl_coord( 0, 0 );
@@ -232,7 +232,7 @@ class LLDragDropWin32Target:
 			if ( mAllowDrop )
 			{
 				// window impl stored in Window data (neat!)
-				LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLong( mAppWindowHandle, GWL_USERDATA );
+				LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLongPtr( mAppWindowHandle, GWLP_USERDATA );
 				if ( NULL != window_imp )
 				{
 					POINT pt_client;
diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp
index 4086db8e524069ef53c1ed4557934ac85fc31e6a..55e68283b76d544f793a77fe3e23792107ebecc6 100644
--- a/indra/llwindow/llwindowwin32.cpp
+++ b/indra/llwindow/llwindowwin32.cpp
@@ -785,7 +785,7 @@ void LLWindowWin32::close()
 	LL_DEBUGS("Window") << "Destroying Window" << LL_ENDL;
 	
 	// Don't process events in our mainWindowProc any longer.
-	SetWindowLong(mWindowHandle, GWL_USERDATA, NULL);
+	SetWindowLongPtr(mWindowHandle, GWLP_USERDATA, NULL);
 
 	// Make sure we don't leave a blank toolbar button.
 	ShowWindow(mWindowHandle, SW_HIDE);
@@ -1564,7 +1564,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, BO
 		LL_DEBUGS("Window") << "Keeping vertical sync" << LL_ENDL;
 	}
 
-	SetWindowLong(mWindowHandle, GWL_USERDATA, (U32)this);
+	SetWindowLongPtr(mWindowHandle, GWLP_USERDATA, (LONG_PTR)this);
 
 	// register this window as handling drag/drop events from the OS
 	DragAcceptFiles( mWindowHandle, TRUE );
@@ -1876,7 +1876,7 @@ LRESULT CALLBACK LLWindowWin32::mainWindowProc(HWND h_wnd, UINT u_msg, WPARAM w_
 	// This is to avoid triggering double click teleport after returning focus (see MAINT-3786).
 	static bool sHandleDoubleClick = true;
 
-	LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLong(h_wnd, GWL_USERDATA);
+	LLWindowWin32 *window_imp = (LLWindowWin32 *)GetWindowLongPtr( h_wnd, GWLP_USERDATA );
 
 
 	if (NULL != window_imp)
diff --git a/indra/media_plugins/base/CMakeLists.txt b/indra/media_plugins/base/CMakeLists.txt
index 7367b9e5e654911c75a0bf8a9fca789a1c260378..691323523664b47199db5601230b55d0732e249d 100644
--- a/indra/media_plugins/base/CMakeLists.txt
+++ b/indra/media_plugins/base/CMakeLists.txt
@@ -28,13 +28,13 @@ include_directories(SYSTEM
 
 ### media_plugin_base
 
-if(NOT WORD_SIZE EQUAL 32)
+if(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     add_definitions(/FIXED:NO)
   else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
     add_definitions(-fPIC)
   endif(WINDOWS)
-endif(NOT WORD_SIZE EQUAL 32)
+endif(NOT ADDRESS_SIZE EQUAL 32)
 
 set(media_plugin_base_SOURCE_FILES
     media_plugin_base.cpp
diff --git a/indra/media_plugins/cef/CMakeLists.txt b/indra/media_plugins/cef/CMakeLists.txt
index db471c7906c9900b9a4e77e06c475126d6fc7243..f9aada51a9888c12903485a2f6f499bc5dc57d18 100644
--- a/indra/media_plugins/cef/CMakeLists.txt
+++ b/indra/media_plugins/cef/CMakeLists.txt
@@ -34,13 +34,13 @@ include_directories(SYSTEM
 
 ### media_plugin_cef
 
-if(NOT WORD_SIZE EQUAL 32)
+if(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     add_definitions(/FIXED:NO)
   else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
     add_definitions(-fPIC)
   endif(WINDOWS)
-endif(NOT WORD_SIZE EQUAL 32)
+endif(NOT ADDRESS_SIZE EQUAL 32)
 
 set(media_plugin_cef_SOURCE_FILES
     media_plugin_cef.cpp
diff --git a/indra/media_plugins/example/CMakeLists.txt b/indra/media_plugins/example/CMakeLists.txt
index 171645ef0467e068197fd9df71dde2745235971e..d84e40855bd9ba9ca4c8d4b43875b04136e8a099 100644
--- a/indra/media_plugins/example/CMakeLists.txt
+++ b/indra/media_plugins/example/CMakeLists.txt
@@ -32,13 +32,13 @@ include_directories(SYSTEM
 
 ### media_plugin_example
 
-if(NOT WORD_SIZE EQUAL 32)
+if(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     add_definitions(/FIXED:NO)
   else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
     add_definitions(-fPIC)
   endif(WINDOWS)
-endif(NOT WORD_SIZE EQUAL 32)
+endif(NOT ADDRESS_SIZE EQUAL 32)
 
 set(media_plugin_example_SOURCE_FILES
     media_plugin_example.cpp
diff --git a/indra/media_plugins/gstreamer010/CMakeLists.txt b/indra/media_plugins/gstreamer010/CMakeLists.txt
index 447f6e06895ec7d5cbf69ab85bd03513664e178d..a10ea19b17c4066f9597250513b5f5833fe0eb7b 100644
--- a/indra/media_plugins/gstreamer010/CMakeLists.txt
+++ b/indra/media_plugins/gstreamer010/CMakeLists.txt
@@ -33,13 +33,13 @@ include_directories(SYSTEM
 
 ### media_plugin_gstreamer010
 
-if(NOT WORD_SIZE EQUAL 32)
+if(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     add_definitions(/FIXED:NO)
   else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
     add_definitions(-fPIC)
   endif(WINDOWS)
-endif(NOT WORD_SIZE EQUAL 32)
+endif(NOT ADDRESS_SIZE EQUAL 32)
 
 set(media_plugin_gstreamer010_SOURCE_FILES
     media_plugin_gstreamer010.cpp
diff --git a/indra/media_plugins/libvlc/CMakeLists.txt b/indra/media_plugins/libvlc/CMakeLists.txt
index 535d29125b763a2d51c0c9c38f92b82dc8989e93..d652a8dcf9fa1cfa5c0c19acb5b87ae00598b36f 100644
--- a/indra/media_plugins/libvlc/CMakeLists.txt
+++ b/indra/media_plugins/libvlc/CMakeLists.txt
@@ -33,13 +33,13 @@ include_directories(SYSTEM
 
 ### media_plugin_libvlc
 
-if(NOT WORD_SIZE EQUAL 32)
+if(NOT ADDRESS_SIZE EQUAL 32)
   if(WINDOWS)
     add_definitions(/FIXED:NO)
   else(WINDOWS) # not windows therefore gcc LINUX and DARWIN
     add_definitions(-fPIC)
   endif(WINDOWS)
-endif(NOT WORD_SIZE EQUAL 32)
+endif(NOT ADDRESS_SIZE EQUAL 32)
 
 set(media_plugin_libvlc_SOURCE_FILES
     media_plugin_libvlc.cpp
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index de349a03d4cafe9878c5e53bbae42b2335995c00..481c66aaf55d7dff279d29e72796a647b2d35be3 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -2132,7 +2132,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 			LLVector4a src;
 
 			U32 vec[4];
-			vec[0] = vec[1] = vec[2] = vec[3] = color.mAll;
+			vec[0] = vec[1] = vec[2] = vec[3] = color.asRGBA();
 		
 			src.loadua((F32*) vec);
 
@@ -2168,7 +2168,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
 		
 			LLColor4U glow4u = LLColor4U(0,0,0,glow);
 
-			U32 glow32 = glow4u.mAll;
+			U32 glow32 = glow4u.asRGBA();
 
 			U32 vec[4];
 			vec[0] = vec[1] = vec[2] = vec[3] = glow32;
diff --git a/indra/newview/llnetmap.cpp b/indra/newview/llnetmap.cpp
index 5fc73c67d1bfbbf4c17c1f0464bdfbe096274a51..72faa5a9e747342ce2381b8e39961c7b31fee66b 100644
--- a/indra/newview/llnetmap.cpp
+++ b/indra/newview/llnetmap.cpp
@@ -735,7 +735,7 @@ void LLNetMap::renderPoint(const LLVector3 &pos_local, const LLColor4U &color,
 				continue;
 			}
 			S32 offset = px + py * image_width;
-			((U32*)datap)[offset] = color.mAll;
+			((U32*)datap)[offset] = color.asRGBA();
 		}
 
 		// top line
@@ -748,7 +748,7 @@ void LLNetMap::renderPoint(const LLVector3 &pos_local, const LLColor4U &color,
 				continue;
 			}
 			S32 offset = px + py * image_width;
-			((U32*)datap)[offset] = color.mAll;
+			((U32*)datap)[offset] = color.asRGBA();
 		}
 	}
 	else
@@ -770,7 +770,7 @@ void LLNetMap::renderPoint(const LLVector3 &pos_local, const LLColor4U &color,
 					continue;
 				}
 				S32 offset = p_x + p_y * image_width;
-				((U32*)datap)[offset] = color.mAll;
+				((U32*)datap)[offset] = color.asRGBA();
 			}
 		}
 	}
diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp
index 4dab213fa0e8d16837edc650343a2e000d953ba6..6b4a450e6fe202537a3f4c79495ae488700de155 100644
--- a/indra/newview/llvosky.cpp
+++ b/indra/newview/llvosky.cpp
@@ -283,7 +283,7 @@ void LLSkyTex::create(const F32 brightness)
 			S32 offset = basic_offset * sComponents;
 			U32* pix = (U32*)(data + offset);
 			LLColor4U temp = LLColor4U(mSkyData[basic_offset]);
-			*pix = temp.mAll;
+			*pix = temp.asRGBA();
 		}
 	}
 	createGLImage(sCurrent);
diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h
index ee8e91fb71d3a869f6e844777665345e5c8d5678..9cfb9773bd8ccb16486e77d3aac7497b851db688 100644
--- a/indra/newview/llvosky.h
+++ b/indra/newview/llvosky.h
@@ -171,7 +171,7 @@ class LLSkyTex
 	{
 		S32 offset = (i * sResolution + j) * sComponents;
 		U32* pix = (U32*) &(mImageRaw[sCurrent]->getData()[offset]);
-		*pix = col.mAll;
+		*pix = col.asRGBA();
 	}
 
 	LLColor4U getPixel(const S32 i, const S32 j)
@@ -179,7 +179,7 @@ class LLSkyTex
 		LLColor4U col;
 		S32 offset = (i * sResolution + j) * sComponents;
 		U32* pix = (U32*) &(mImageRaw[sCurrent]->getData()[offset]);
-		col.mAll = *pix;
+		col.fromRGBA( *pix );
 		return col;
 	}