Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 98215d6

Browse files
committed
use CRuntime_DigitalMars/CRuntime_Microsoft instead of Win32/Win64 where appropriate
1 parent 0c439f5 commit 98215d6

16 files changed

+144
-50
lines changed

src/core/stdc/math.d

+5-12
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,7 @@ version( none )
102102
int isunordered(real x, real y);
103103
}
104104

105-
version( DigitalMars )
106-
{
107-
version( Win32 )
108-
version = DMC_RUNTIME;
109-
version( Win64 )
110-
version = MSVC_RUNTIME; // just to get it to compile for the moment - fix later
111-
}
112-
113-
version( DMC_RUNTIME )
105+
version( CRuntime_DigitalMars )
114106
{
115107
enum
116108
{
@@ -179,7 +171,7 @@ version( DMC_RUNTIME )
179171
}
180172
}
181173
}
182-
else version( MSVC_RUNTIME )
174+
else version( CRuntime_Microsoft )
183175
{
184176
enum
185177
{
@@ -198,7 +190,7 @@ else version( MSVC_RUNTIME )
198190
float _copysignf(float x, float s);
199191
float _chgsignf(float x);
200192
int _finitef(float x);
201-
int _isnanf(float x);
193+
version(Win64) int _isnanf(float x); // not available in Win32?
202194
int _fpclassf(float x);
203195

204196
double _copysign(double x, double s);
@@ -209,7 +201,8 @@ else version( MSVC_RUNTIME )
209201

210202
extern(D)
211203
{
212-
int isnan(float x) { return _isnanf(x); }
204+
version(Win64) int isnan(float x) { return _isnanf(x); }
205+
version(Win32) int isnan(float x) { return _isnan(x); }
213206
int isnan(double x) { return _isnan(x); }
214207
int isnan(real x) { return _isnan(x); }
215208
}

src/core/stdc/stdio.d

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern (C):
3535
nothrow:
3636
@nogc:
3737

38-
version( Win32 )
38+
version( CRuntime_DigitalMars )
3939
{
4040
enum
4141
{
@@ -52,7 +52,7 @@ version( Win32 )
5252
enum wstring _wP_tmpdir = "\\"; // non-standard
5353
enum int L_tmpnam = _P_tmpdir.length + 12;
5454
}
55-
else version( Win64 )
55+
else version( CRuntime_Microsoft )
5656
{
5757
enum
5858
{
@@ -178,7 +178,7 @@ enum
178178
SEEK_END
179179
}
180180

181-
version( Win32 )
181+
version( CRuntime_DigitalMars )
182182
{
183183
alias int fpos_t; //check this
184184

@@ -196,7 +196,7 @@ version( Win32 )
196196

197197
alias shared(_iobuf) FILE;
198198
}
199-
else version( Win64 )
199+
else version( CRuntime_Microsoft )
200200
{
201201
alias int fpos_t; //check this
202202

@@ -401,7 +401,7 @@ enum
401401
_F_TERM = 0x0200, // non-standard
402402
}
403403

404-
version( Win32 )
404+
version( CRuntime_DigitalMars )
405405
{
406406
enum
407407
{
@@ -429,7 +429,7 @@ version( Win32 )
429429
shared stdaux = &_iob[3];
430430
shared stdprn = &_iob[4];
431431
}
432-
else version( Win64 )
432+
else version( CRuntime_Microsoft )
433433
{
434434
enum
435435
{
@@ -675,7 +675,7 @@ version( MinGW )
675675
alias __mingw_vsnprintf _vsnprintf;
676676
alias __mingw_vsnprintf vsnprintf;
677677
}
678-
else version( Win32 )
678+
else version( CRuntime_DigitalMars )
679679
{
680680
// No unsafe pointer manipulation.
681681
extern (D) @trusted
@@ -691,7 +691,7 @@ else version( Win32 )
691691
int _vsnprintf(char* s, size_t n, in char* format, va_list arg);
692692
alias _vsnprintf vsnprintf;
693693
}
694-
else version( Win64 )
694+
else version( CRuntime_Microsoft )
695695
{
696696
// No unsafe pointer manipulation.
697697
extern (D) @trusted
@@ -828,7 +828,7 @@ else
828828

829829
void perror(in char* s);
830830

831-
version (DigitalMars) version (Win32)
831+
version(CRuntime_DigitalMars)
832832
{
833833
import core.sys.windows.windows;
834834

src/core/stdc/stdlib.d

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ long strtoll(in char* nptr, char** endptr, int base);
7070
c_ulong strtoul(in char* nptr, char** endptr, int base);
7171
ulong strtoull(in char* nptr, char** endptr, int base);
7272

73-
version (Win64)
73+
version (CRuntime_Microsoft)
7474
{
75-
real strtold(in char* nptr, char** endptr)
75+
// strtold exists starting from VS2013, so we make this a template to avoid link errors
76+
real strtold()(in char* nptr, char** endptr)
7677
{ // Fake it 'till we make it
7778
return strtod(nptr, endptr);
7879
}
@@ -154,7 +155,7 @@ else version( GNU )
154155
void* alloca(size_t size); // compiler intrinsic
155156
}
156157

157-
version (Win64)
158+
version( CRuntime_Microsoft )
158159
{
159160
ulong _strtoui64(in char *,char **,int);
160161
ulong _wcstoui64(in wchar *,wchar **,int);

src/core/stdc/wchar_.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extern (D) @trusted
6565
@trusted
6666
{
6767
wint_t ungetwc(wint_t c, FILE* stream);
68-
version( Win64 )
68+
version( CRuntime_Microsoft )
6969
{
7070
// MSVC defines this as an inline function.
7171
int fwide(FILE* stream, int mode) { return mode; }

src/core/sys/windows/dll.d

+18-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,28 @@ version( Windows )
2222
///////////////////////////////////////////////////////////////////
2323
// support fixing implicit TLS for dynamically loaded DLLs on Windows XP
2424

25+
// in this special case, we have to treat _tlsstart and _tlsend as non-TLS variables
26+
// as they are used to simulate TLS when it is not set up under XP. In this case we must
27+
// not access tls_array[tls_index] as needed for thread local _tlsstart and _tlsend
2528
extern (C)
2629
{
2730
version (Win32)
2831
{
29-
extern __gshared void* _tlsstart;
30-
extern __gshared void* _tlsend;
31-
extern __gshared void* _tls_callbacks_a;
32+
version(CRuntime_DigitalMars)
33+
{
34+
extern __gshared byte _tlsstart;
35+
extern __gshared byte _tlsend;
36+
extern __gshared void* _tls_callbacks_a;
37+
}
38+
else version(CRuntime_Microsoft)
39+
{
40+
extern __gshared byte _tls_start;
41+
extern __gshared byte _tls_end;
42+
extern __gshared void* __xl_a;
43+
alias _tls_start _tlsstart;
44+
alias _tls_end _tlsend;
45+
alias __xl_a _tls_callbacks_a;
46+
}
3247
extern __gshared int _tls_index;
3348
}
3449
}

src/rt/alloca.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ version (Posix)
1515
{
1616
version = alloca;
1717
}
18-
else version (Win64)
18+
else version (CRuntime_Microsoft)
1919
{
2020
version = alloca;
2121
}

src/rt/critical_.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private
7878

7979
version( Windows )
8080
{
81-
version (Win32)
81+
version (CRuntime_DigitalMars)
8282
pragma(lib, "snn.lib");
8383

8484
/******************************************

src/rt/dmain2.d

+21-9
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
263263
fldcw fpucw;
264264
}
265265
}
266-
267-
version (Win64)
266+
version (CRuntime_Microsoft)
268267
{
269268
auto fp = __iob_func();
270269
stdin = &fp[0];
@@ -275,14 +274,27 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
275274
_set_output_format(_TWO_DIGIT_EXPONENT);
276275

277276
// enable full precision for reals
278-
asm
277+
version(Win64)
278+
asm
279+
{
280+
push RAX;
281+
fstcw word ptr [RSP];
282+
or [RSP], 0b11_00_111111; // 11: use 64 bit extended-precision
283+
// 111111: mask all FP exceptions
284+
fldcw word ptr [RSP];
285+
pop RAX;
286+
}
287+
else version(Win32)
279288
{
280-
push RAX;
281-
fstcw word ptr [RSP];
282-
or [RSP], 0b11_00_111111; // 11: use 64 bit extended-precision
283-
// 111111: mask all FP exceptions
284-
fldcw word ptr [RSP];
285-
pop RAX;
289+
asm
290+
{
291+
push EAX;
292+
fstcw word ptr [ESP];
293+
or [ESP], 0b11_00_111111; // 11: use 64 bit extended-precision
294+
// 111111: mask all FP exceptions
295+
fldcw word ptr [ESP];
296+
pop EAX;
297+
}
286298
}
287299
}
288300

src/rt/llmath.d

+65
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,70 @@ L12: jmp __ULDIV__ ;
497497
}
498498

499499

500+
version(Win32) version(CRuntime_Microsoft)
501+
{
502+
extern(C) void _alldiv();
503+
extern(C) void _aulldiv();
504+
extern(C) void _allrem();
505+
extern(C) void _aullrem();
506+
507+
void _ms_alldiv()
508+
{
509+
asm
510+
{
511+
naked ;
512+
push ECX ;
513+
push EBX ;
514+
push EDX ;
515+
push EAX ;
516+
call _alldiv ;
517+
ret ;
518+
}
519+
}
520+
521+
void _ms_aulldiv()
522+
{
523+
asm
524+
{
525+
naked ;
526+
push ECX ;
527+
push EBX ;
528+
push EDX ;
529+
push EAX ;
530+
call _aulldiv ;
531+
ret ;
532+
}
533+
}
500534

535+
void _ms_allrem()
536+
{
537+
asm
538+
{
539+
naked ;
540+
push ECX ;
541+
push EBX ;
542+
push EDX ;
543+
push EAX ;
544+
call _allrem ;
545+
mov EBX,EAX ;
546+
mov ECX,EDX ;
547+
ret ;
548+
}
549+
}
501550

551+
void _ms_aullrem()
552+
{
553+
asm
554+
{
555+
naked ;
556+
push ECX ;
557+
push EBX ;
558+
push EDX ;
559+
push EAX ;
560+
call _aullrem ;
561+
mov EBX,EAX ;
562+
mov ECX,EDX ;
563+
ret ;
564+
}
565+
}
566+
}

src/rt/minfo.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ unittest
573573
}
574574
}
575575

576-
version (Win64)
576+
version (CRuntime_Microsoft)
577577
{
578578
// Dummy so Win32 code can still call it
579579
extern(C) void _minit() { }

src/rt/monitor_.d

+8-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ private
4949

5050
version( Windows )
5151
{
52-
version (Win32)
52+
version (CRuntime_DigitalMars)
53+
{
5354
pragma(lib, "snn.lib");
55+
}
56+
else version (CRuntime_Microsoft)
57+
{
58+
pragma(lib, "libcmt.lib");
59+
pragma(lib, "oldnames.lib");
60+
}
5461
import core.sys.windows.windows;
5562

5663
struct Monitor

src/rt/sections.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ else version (Solaris)
1818
public import rt.sections_solaris;
1919
else version (OSX)
2020
public import rt.sections_osx;
21-
else version (Win32)
21+
else version (CRuntime_DigitalMars)
2222
public import rt.sections_win32;
23-
else version (Win64)
23+
else version (CRuntime_Microsoft)
2424
public import rt.sections_win64;
2525
else version (Android)
2626
public import rt.sections_android;

src/rt/sections_win32.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
module rt.sections_win32;
1414

15-
version(Win32):
15+
version(CRuntime_DigitalMars):
1616

1717
// debug = PRINTF;
1818
debug(PRINTF) import core.stdc.stdio;

src/rt/sections_win64.d

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
module rt.sections_win64;
1414

15-
version(Win64):
15+
version(CRuntime_Microsoft):
1616

1717
// debug = PRINTF;
1818
debug(PRINTF) import core.stdc.stdio;
@@ -41,6 +41,7 @@ struct SectionGroup
4141
return _moduleGroup;
4242
}
4343

44+
version(Win64)
4445
@property immutable(FuncTable)[] ehTables() const
4546
{
4647
auto pbeg = cast(immutable(FuncTable)*)&_deh_beg;

src/rt/trace.d

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private
2222
import core.stdc.string;
2323
import rt.util.string;
2424

25-
version (Win64)
25+
version (CRuntime_Microsoft)
2626
alias core.stdc.stdlib._strtoui64 strtoull;
2727
}
2828

0 commit comments

Comments
 (0)