1. Alex Rønne Petersen
  2. gdc

Commits

alexrp  committed 6ea748b

Fix a number of portability issues.

* Use D_LP64 to make bitness-dependent decisions, not X86 or X86_64.
* Remove some unnecessary version'd code.
* Use D_InlineAsm_X86 and D_InlineAsm_X86_64 to determine whether inline assembly is available.

  • Participants
  • Parent commits d1005cb
  • Branches default

Comments (0)

Files changed (10)

File d/druntime/core/stdc/inttypes.d

View file
 enum _cstr SCNxFAST32       = "lx";
 enum _cstr SCNxFAST64       = "llx";
 
-version( X86_64 )
+version( D_LP64 )
 {
     enum _cstr PRIdMAX      = PRId64;
     enum _cstr PRIiMAX      = PRIi64;

File d/druntime/core/stdc/stdint.d

View file
     alias __builtin_pointer_int  intptr_t;
     alias __builtin_pointer_uint uintptr_t;
 }
-else version( X86_64 )
+else version( D_LP64 )
 {
     alias long  intptr_t;
     alias ulong uintptr_t;

File d/druntime/core/sys/posix/sys/types.d

View file
 
 version( linux )
 {
-    version(X86)
+    version(D_LP64)
+    {
+        enum __SIZEOF_PTHREAD_ATTR_T = 56;
+        enum __SIZEOF_PTHREAD_MUTEX_T = 40;
+        enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
+        enum __SIZEOF_PTHREAD_COND_T = 48;
+        enum __SIZEOF_PTHREAD_CONDATTR_T = 4;
+        enum __SIZEOF_PTHREAD_RWLOCK_T = 56;
+        enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
+        enum __SIZEOF_PTHREAD_BARRIER_T = 32;
+        enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
+    }
+    else
     {
         enum __SIZEOF_PTHREAD_ATTR_T = 36;
         enum __SIZEOF_PTHREAD_MUTEX_T = 24;
         enum __SIZEOF_PTHREAD_BARRIER_T = 20;
         enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
     }
-    else version(X86_64)
-    {
-        enum __SIZEOF_PTHREAD_ATTR_T = 56;
-        enum __SIZEOF_PTHREAD_MUTEX_T = 40;
-        enum __SIZEOF_PTHREAD_MUTEXATTR_T = 4;
-        enum __SIZEOF_PTHREAD_COND_T = 48;
-        enum __SIZEOF_PTHREAD_CONDATTR_T = 4;
-        enum __SIZEOF_PTHREAD_RWLOCK_T = 56;
-        enum __SIZEOF_PTHREAD_RWLOCKATTR_T = 8;
-        enum __SIZEOF_PTHREAD_BARRIER_T = 32;
-        enum __SIZEOF_PTHREAD_BARRIERATTR_T = 4;
-    }
 
     union pthread_attr_t
     {

File d/druntime/core/thread.d

View file
     bool                m_lock;
     void[]              m_tls;  // spans implicit thread local storage
 
-    version( Windows )
+    version( X86 )
     {
-      version( X86 )
-      {
-        uint[8]         m_reg; // edi,esi,ebp,esp,ebx,edx,ecx,eax
-      }
-      else version( X86_64 )
-      {
-        ulong[16]       m_reg; // rdi,rsi,rbp,rsp,rbx,rdx,rcx,rax
-                               // r8,r9,r10,r11,r12,r13,r14,r15
-      }
-      else
-      {
-        static assert( "Architecture not supported." );
-      }
+      uint[8]         m_reg; // edi,esi,ebp,esp,ebx,edx,ecx,eax
     }
-    else version( OSX )
+    else version( X86_64 )
     {
-      version( X86 )
-      {
-        uint[8]         m_reg; // edi,esi,ebp,esp,ebx,edx,ecx,eax
-      }
-      else version( X86_64 )
-      {
-        ulong[16]       m_reg; // rdi,rsi,rbp,rsp,rbx,rdx,rcx,rax
-                               // r8,r9,r10,r11,r12,r13,r14,r15
-      }
-      else
-      {
-        static assert( "Architecture not supported." );
-      }
+      ulong[16]       m_reg; // rdi,rsi,rbp,rsp,rbx,rdx,rcx,rax
+                             // r8,r9,r10,r11,r12,r13,r14,r15
+    }
+    else
+    {
+      static assert( "Architecture not supported." );
     }
 
 

File d/druntime/rt/adi.d

View file
 
 extern (C) int _adCmpChar(Array a1, Array a2)
 {
-  version (X86)
+  version (D_InlineAsm_X86)
   {
     asm
     {   naked                   ;

File d/druntime/rt/dmain2.d

View file
     extern (C) void _d_hidden_func()
     {
         Object o;
-        version(X86)
+        version(D_InlineAsm_X86)
             asm
             {
                 mov o, EAX;
             }
-        else version(X86_64)
+        else version(D_InlineAsm_X86_64)
             asm
             {
                 mov o, RDI;

File d/phobos/std/stdint.d

View file
     alias __builtin_pointer_int  intptr_t;
     alias __builtin_pointer_uint uintptr_t;
 }
-else version(X86_64)
+else version(D_LP64)
 {
     alias long   intptr_t;
     alias ulong  uintptr_t;
     alias __builtin_Clong Clong_t;
     alias __builtin_Culong Culong_t;
 }
-else version(X86_64)
+else version(D_LP64)
 {
     alias long Clong_t;
     alias ulong Culong_t;

File d/phobos2/std/bitmanip.d

View file
 {
     size_t len;
     size_t* ptr;
-    version(X86)
-        enum bitsPerSizeT = 32;
-    else version(X86_64)
-        enum bitsPerSizeT = 64;
-    else
-        static assert(false, "unknown platform");
+    enum bitsPerSizeT = size_t.sizeof * 8;
 
     @property const size_t dim()
     {

File d/phobos2/std/file.d

View file
     }
     else
     {
-        version(X86)
-        {
-            struct struct_stat64        // distinguish it from the stat() function
-            {
-                ulong st_dev;        /// device
-                uint __pad1;
-                uint st_ino;        /// file serial number
-                uint st_mode;        /// file mode
-                uint st_nlink;        /// link count
-                uint st_uid;        /// user ID of file's owner
-                uint st_gid;        /// user ID of group's owner
-                ulong st_rdev;        /// if device then device number
-                uint __pad2;
-                align(4) ulong st_size;
-                int st_blksize;        /// optimal I/O block size
-                ulong st_blocks;        /// number of allocated 512 byte blocks
-                int st_atime;
-                uint st_atimensec;
-                int st_mtime;
-                uint st_mtimensec;
-                int st_ctime;
-                uint st_ctimensec;
-
-                ulong st_ino64;
-            }
-            //static assert(struct_stat64.sizeof == 88); // copied from d1, but it's currently 96 bytes, not 88.
-        }
-        else version (X86_64)
+        version(D_LP64)
         {
             struct struct_stat64
             {
             }
             static assert(struct_stat64.sizeof == 144);
         }
+        else
+        {
+            struct struct_stat64        // distinguish it from the stat() function
+            {
+                ulong st_dev;        /// device
+                uint __pad1;
+                uint st_ino;        /// file serial number
+                uint st_mode;        /// file mode
+                uint st_nlink;        /// link count
+                uint st_uid;        /// user ID of file's owner
+                uint st_gid;        /// user ID of group's owner
+                ulong st_rdev;        /// if device then device number
+                uint __pad2;
+                align(4) ulong st_size;
+                int st_blksize;        /// optimal I/O block size
+                ulong st_blocks;        /// number of allocated 512 byte blocks
+                int st_atime;
+                uint st_atimensec;
+                int st_mtime;
+                uint st_mtimensec;
+                int st_ctime;
+                uint st_ctimensec;
+
+                ulong st_ino64;
+            }
+            //static assert(struct_stat64.sizeof == 88); // copied from d1, but it's currently 96 bytes, not 88.
+        }
 
         extern(C) int fstat64(int, struct_stat64*);
         extern(C) int stat64(in char*, struct_stat64*);

File d/phobos2/std/windows/registry.d

View file
 
 private uint swap(in uint i)
 {
-    version(X86)
+    version(D_InlineAsm_X86)
     {
         asm
         {    naked;