Mercurial > projects > ldc
comparison runtime/llvmdc.diff @ 529:cef0cbcf7d22
Updated tango patch, with rewrittten Atomics using llvm atomic intrinsics.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Wed, 20 Aug 2008 19:03:28 +0200 |
parents | 283d113d4753 |
children | f775ea9d09d3 |
comparison
equal
deleted
inserted
replaced
528:3197ffdc2811 | 529:cef0cbcf7d22 |
---|---|
1 Index: object.di | 1 Index: object.di |
2 =================================================================== | 2 =================================================================== |
3 --- object.di (revision 3831) | 3 --- object.di (revision 3880) |
4 +++ object.di (working copy) | 4 +++ object.di (working copy) |
5 @@ -150,6 +150,9 @@ | 5 @@ -150,6 +150,9 @@ |
6 void function() dtor; | 6 void function() dtor; |
7 void function() unitTest; | 7 void function() unitTest; |
8 | 8 |
10 + void function() ictor; | 10 + void function() ictor; |
11 + | 11 + |
12 static int opApply( int delegate( inout ModuleInfo ) ); | 12 static int opApply( int delegate( inout ModuleInfo ) ); |
13 } | 13 } |
14 | 14 |
15 Index: lib/unittest.sh | |
16 =================================================================== | |
17 --- lib/unittest.sh (revision 3880) | |
18 +++ lib/unittest.sh (working copy) | |
19 @@ -18,8 +18,9 @@ | |
20 --help: This message | |
21 --run-all: Reports result instead of breaking. Do not use this if you want to | |
22 run unittest runner through a debugger. | |
23 - dmd: Builds unittests for dmd | |
24 - gdc: Builds unittests for gdc | |
25 + dmd: Builds unittests for dmd | |
26 + gdc: Builds unittests for gdc | |
27 + llvmdc: Builds unittests for llvmdc | |
28 | |
29 <none>: Builds unittests for all known compilers.' | |
30 exit 0 | |
31 @@ -86,7 +87,7 @@ | |
32 void main() {} | |
33 EOF | |
34 | |
35 - rebuild -w -d -g -L-ldl -L-lz -L-lbz2 -debug=UnitTest -debug -full -clean -unittest \ | |
36 + rebuild -w -d -L-ldl -L-lz -L-lbz2 -debug=UnitTest -debug -full -clean -unittest \ | |
37 -version=UnitTest $EXE.d tango/core/*.d tango/core/sync/*.d tango/io/digest/*.d \ | |
38 tango/io/model/*.d tango/io/protocol/*.d tango/io/selector/*.d tango/io/*.d \ | |
39 tango/io/vfs/*.d tango/io/vfs/model/*.d \ | |
40 @@ -125,6 +126,9 @@ | |
41 gdc) | |
42 GDC=1 | |
43 ;; | |
44 + llvmdc) | |
45 + LLVMDC=1 | |
46 + ;; | |
47 *) | |
48 usage | |
49 ;; | |
50 @@ -132,10 +136,11 @@ | |
51 shift | |
52 done | |
53 | |
54 -if [ ! "$DMD" -a ! "$GDC" ] | |
55 +if [ ! "$DMD" -a ! "$GDC" -a ! "$LLVMDC" ] | |
56 then | |
57 DMD=1 | |
58 GDC=1 | |
59 + LLVMDC=1 | |
60 fi | |
61 | |
62 if [ "$DMD" = "1" ] | |
63 @@ -146,4 +151,7 @@ | |
64 then | |
65 compile gdc runUnitTest_gdc | |
66 fi | |
67 - | |
68 +if [ "$LLVMDC" = "1" ] | |
69 +then | |
70 + compile llvmdc runUnitTest_llvmdc | |
71 +fi | |
15 Index: lib/common/tango/core/BitManip.d | 72 Index: lib/common/tango/core/BitManip.d |
16 =================================================================== | 73 =================================================================== |
17 --- lib/common/tango/core/BitManip.d (revision 3831) | 74 --- lib/common/tango/core/BitManip.d (revision 3880) |
18 +++ lib/common/tango/core/BitManip.d (working copy) | 75 +++ lib/common/tango/core/BitManip.d (working copy) |
19 @@ -171,6 +171,10 @@ | 76 @@ -171,6 +171,10 @@ |
20 */ | 77 */ |
21 uint outpl( uint port_address, uint value ); | 78 uint outpl( uint port_address, uint value ); |
22 } | 79 } |
27 else | 84 else |
28 { | 85 { |
29 public import std.intrinsic; | 86 public import std.intrinsic; |
30 Index: lib/common/tango/core/Thread.d | 87 Index: lib/common/tango/core/Thread.d |
31 =================================================================== | 88 =================================================================== |
32 --- lib/common/tango/core/Thread.d (revision 3831) | 89 --- lib/common/tango/core/Thread.d (revision 3880) |
33 +++ lib/common/tango/core/Thread.d (working copy) | 90 +++ lib/common/tango/core/Thread.d (working copy) |
34 @@ -244,10 +244,33 @@ | 91 @@ -244,10 +244,33 @@ |
35 } | 92 } |
36 body | 93 body |
37 { | 94 { |
92 + else version( D_InlineAsm_X86 ) | 149 + else version( D_InlineAsm_X86 ) |
93 + { | 150 + { |
94 version( X86_64 ) | 151 version( X86_64 ) |
95 { | 152 { |
96 | 153 |
97 Index: lib/unittest.sh | |
98 =================================================================== | |
99 --- lib/unittest.sh (revision 3831) | |
100 +++ lib/unittest.sh (working copy) | |
101 @@ -18,8 +18,9 @@ | |
102 --help: This message | |
103 --run-all: Reports result instead of breaking. Do not use this if you want to | |
104 run unittest runner through a debugger. | |
105 - dmd: Builds unittests for dmd | |
106 - gdc: Builds unittests for gdc | |
107 + dmd: Builds unittests for dmd | |
108 + gdc: Builds unittests for gdc | |
109 + llvmdc: Builds unittests for llvmdc | |
110 | |
111 <none>: Builds unittests for all known compilers.' | |
112 exit 0 | |
113 @@ -125,6 +126,9 @@ | |
114 gdc) | |
115 GDC=1 | |
116 ;; | |
117 + llvmdc) | |
118 + LLVMDC=1 | |
119 + ;; | |
120 *) | |
121 usage | |
122 ;; | |
123 @@ -132,10 +136,11 @@ | |
124 shift | |
125 done | |
126 | |
127 -if [ ! "$DMD" -a ! "$GDC" ] | |
128 +if [ ! "$DMD" -a ! "$GDC" -a ! "$LLVMDC" ] | |
129 then | |
130 DMD=1 | |
131 GDC=1 | |
132 + LLVMDC=1 | |
133 fi | |
134 | |
135 if [ "$DMD" = "1" ] | |
136 @@ -146,4 +151,7 @@ | |
137 then | |
138 compile gdc runUnitTest_gdc | |
139 fi | |
140 - | |
141 +if [ "$LLVMDC" = "1" ] | |
142 +then | |
143 + compile llvmdc runUnitTest_llvmdc | |
144 +fi | |
145 Index: lib/gc/basic/gcx.d | 154 Index: lib/gc/basic/gcx.d |
146 =================================================================== | 155 =================================================================== |
147 --- lib/gc/basic/gcx.d (revision 3831) | 156 --- lib/gc/basic/gcx.d (revision 3880) |
148 +++ lib/gc/basic/gcx.d (working copy) | 157 +++ lib/gc/basic/gcx.d (working copy) |
149 @@ -2178,6 +2178,28 @@ | 158 @@ -2178,6 +2178,28 @@ |
150 __builtin_unwind_init(); | 159 __builtin_unwind_init(); |
151 sp = & sp; | 160 sp = & sp; |
152 } | 161 } |
186 else | 195 else |
187 { | 196 { |
188 asm | 197 asm |
189 Index: lib/gc/basic/gcbits.d | 198 Index: lib/gc/basic/gcbits.d |
190 =================================================================== | 199 =================================================================== |
191 --- lib/gc/basic/gcbits.d (revision 3831) | 200 --- lib/gc/basic/gcbits.d (revision 3880) |
192 +++ lib/gc/basic/gcbits.d (working copy) | 201 +++ lib/gc/basic/gcbits.d (working copy) |
193 @@ -39,6 +39,10 @@ | 202 @@ -39,6 +39,10 @@ |
194 { | 203 { |
195 // use the unoptimized version | 204 // use the unoptimized version |
196 } | 205 } |
201 else version (D_InlineAsm_X86) | 210 else version (D_InlineAsm_X86) |
202 { | 211 { |
203 version = Asm86; | 212 version = Asm86; |
204 Index: tango/text/convert/Layout.d | 213 Index: tango/text/convert/Layout.d |
205 =================================================================== | 214 =================================================================== |
206 --- tango/text/convert/Layout.d (revision 3831) | 215 --- tango/text/convert/Layout.d (revision 3880) |
207 +++ tango/text/convert/Layout.d (working copy) | 216 +++ tango/text/convert/Layout.d (working copy) |
208 @@ -47,6 +47,12 @@ | 217 @@ -47,6 +47,12 @@ |
209 alias void* Arg; | 218 alias void* Arg; |
210 alias va_list ArgList; | 219 alias va_list ArgList; |
211 } | 220 } |
238 int[64] intargs = void; | 247 int[64] intargs = void; |
239 byte[64] byteargs = void; | 248 byte[64] byteargs = void; |
240 long[64] longargs = void; | 249 long[64] longargs = void; |
241 Index: tango/core/Vararg.d | 250 Index: tango/core/Vararg.d |
242 =================================================================== | 251 =================================================================== |
243 --- tango/core/Vararg.d (revision 3831) | 252 --- tango/core/Vararg.d (revision 3880) |
244 +++ tango/core/Vararg.d (working copy) | 253 +++ tango/core/Vararg.d (working copy) |
245 @@ -15,6 +15,10 @@ | 254 @@ -15,6 +15,10 @@ |
246 { | 255 { |
247 public import std.stdarg; | 256 public import std.stdarg; |
248 } | 257 } |
251 + public import llvmdc.vararg; | 260 + public import llvmdc.vararg; |
252 +} | 261 +} |
253 else | 262 else |
254 { | 263 { |
255 /** | 264 /** |
265 Index: tango/core/Variant.d | |
266 =================================================================== | |
267 --- tango/core/Variant.d (revision 3880) | |
268 +++ tango/core/Variant.d (working copy) | |
269 @@ -102,13 +102,45 @@ | |
270 const isInterface = false; | |
271 } | |
272 | |
273 - template isStaticArray(T) | |
274 +// template isStaticArray(T) | |
275 +// { | |
276 +// static if( is( typeof(T.init)[(T).sizeof / typeof(T.init).sizeof] == T ) ) | |
277 +// const isStaticArray = true; | |
278 +// else | |
279 +// const isStaticArray = false; | |
280 +// } | |
281 + /* ******************************************* | |
282 + */ | |
283 + template isStaticArray_impl(T) | |
284 { | |
285 - static if( is( typeof(T.init)[(T).sizeof / typeof(T.init).sizeof] == T ) ) | |
286 - const isStaticArray = true; | |
287 + const T inst = void; | |
288 + | |
289 + static if (is(typeof(T.length))) | |
290 + { | |
291 + static if (!is(T == typeof(T.init))) | |
292 + { // abuses the fact that int[5].init == int | |
293 + static if (is(T == typeof(T[0])[inst.length])) | |
294 + { // sanity check. this check alone isn't enough because dmd complains about dynamic arrays | |
295 + const bool res = true; | |
296 + } | |
297 + else | |
298 + const bool res = false; | |
299 + } | |
300 else | |
301 - const isStaticArray = false; | |
302 + const bool res = false; | |
303 + } | |
304 + else | |
305 + { | |
306 + const bool res = false; | |
307 + } | |
308 } | |
309 + /** | |
310 + * Detect whether type T is a static array. | |
311 + */ | |
312 + template isStaticArray(T) | |
313 + { | |
314 + const bool isStaticArray = isStaticArray_impl!(T).res; | |
315 + } | |
316 | |
317 bool isAny(T,argsT...)(T v, argsT args) | |
318 { | |
319 Index: tango/core/Atomic.d | |
320 =================================================================== | |
321 --- tango/core/Atomic.d (revision 3880) | |
322 +++ tango/core/Atomic.d (working copy) | |
323 @@ -270,6 +270,161 @@ | |
324 | |
325 | |
326 //////////////////////////////////////////////////////////////////////////////// | |
327 +// LLVMDC Atomics Implementation | |
328 +//////////////////////////////////////////////////////////////////////////////// | |
329 + | |
330 + | |
331 +else version( LLVMDC ) | |
332 +{ | |
333 + import llvmdc.intrinsics; | |
334 + | |
335 + | |
336 + //////////////////////////////////////////////////////////////////////////// | |
337 + // Atomic Load | |
338 + //////////////////////////////////////////////////////////////////////////// | |
339 + | |
340 + | |
341 + template atomicLoad( msync ms = msync.seq, T ) | |
342 + { | |
343 + T atomicLoad(ref T val) | |
344 + { | |
345 + llvm_memory_barrier( | |
346 + ms == msync.hlb || ms == msync.acq || ms == msync.seq, | |
347 + ms == msync.hsb || ms == msync.acq || ms == msync.seq, | |
348 + ms == msync.slb || ms == msync.rel || ms == msync.seq, | |
349 + ms == msync.ssb || ms == msync.rel || ms == msync.seq, | |
350 + false); | |
351 + static if (isPointerType!(T)) | |
352 + { | |
353 + return cast(T)llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 0); | |
354 + } | |
355 + else | |
356 + { | |
357 + return llvm_atomic_load_add!(T)(&val, cast(T)0); | |
358 + } | |
359 + } | |
360 + } | |
361 + | |
362 + | |
363 + //////////////////////////////////////////////////////////////////////////// | |
364 + // Atomic Store | |
365 + //////////////////////////////////////////////////////////////////////////// | |
366 + | |
367 + | |
368 + template atomicStore( msync ms = msync.seq, T ) | |
369 + { | |
370 + void atomicStore( ref T val, T newval ) | |
371 + { | |
372 + llvm_memory_barrier( | |
373 + ms == msync.hlb || ms == msync.acq || ms == msync.seq, | |
374 + ms == msync.hsb || ms == msync.acq || ms == msync.seq, | |
375 + ms == msync.slb || ms == msync.rel || ms == msync.seq, | |
376 + ms == msync.ssb || ms == msync.rel || ms == msync.seq, | |
377 + false); | |
378 + static if (isPointerType!(T)) | |
379 + { | |
380 + llvm_atomic_swap!(size_t)(cast(size_t*)&val, cast(size_t)newval); | |
381 + } | |
382 + else static if (is(T == bool)) | |
383 + { | |
384 + llvm_atomic_swap!(ubyte)(cast(ubyte*)&val, newval?1:0); | |
385 + } | |
386 + else | |
387 + { | |
388 + llvm_atomic_swap!(T)(&val, newval); | |
389 + } | |
390 + } | |
391 + } | |
392 + | |
393 + | |
394 + //////////////////////////////////////////////////////////////////////////// | |
395 + // Atomic Store If | |
396 + //////////////////////////////////////////////////////////////////////////// | |
397 + | |
398 + | |
399 + template atomicStoreIf( msync ms = msync.seq, T ) | |
400 + { | |
401 + bool atomicStoreIf( ref T val, T newval, T equalTo ) | |
402 + { | |
403 + llvm_memory_barrier( | |
404 + ms == msync.hlb || ms == msync.acq || ms == msync.seq, | |
405 + ms == msync.hsb || ms == msync.acq || ms == msync.seq, | |
406 + ms == msync.slb || ms == msync.rel || ms == msync.seq, | |
407 + ms == msync.ssb || ms == msync.rel || ms == msync.seq, | |
408 + false); | |
409 + T oldval = void; | |
410 + static if (isPointerType!(T)) | |
411 + { | |
412 + oldval = cast(T)llvm_atomic_cmp_swap!(size_t)(cast(size_t*)&val, cast(size_t)equalTo, cast(size_t)newval); | |
413 + } | |
414 + else static if (is(T == bool)) | |
415 + { | |
416 + oldval = llvm_atomic_cmp_swap!(ubyte)(cast(ubyte*)&val, equalTo?1:0, newval?1:0)?0:1; | |
417 + } | |
418 + else | |
419 + { | |
420 + oldval = llvm_atomic_cmp_swap!(T)(&val, equalTo, newval); | |
421 + } | |
422 + return oldval == equalTo; | |
423 + } | |
424 + } | |
425 + | |
426 + | |
427 + //////////////////////////////////////////////////////////////////////////// | |
428 + // Atomic Increment | |
429 + //////////////////////////////////////////////////////////////////////////// | |
430 + | |
431 + | |
432 + template atomicIncrement( msync ms = msync.seq, T ) | |
433 + { | |
434 + // | |
435 + // NOTE: This operation is only valid for integer or pointer types | |
436 + // | |
437 + static assert( isValidNumericType!(T) ); | |
438 + | |
439 + | |
440 + T atomicIncrement( ref T val ) | |
441 + { | |
442 + static if (isPointerType!(T)) | |
443 + { | |
444 + return cast(T)llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 1); | |
445 + } | |
446 + else | |
447 + { | |
448 + return llvm_atomic_load_add!(T)(&val, cast(T)1); | |
449 + } | |
450 + } | |
451 + } | |
452 + | |
453 + | |
454 + //////////////////////////////////////////////////////////////////////////// | |
455 + // Atomic Decrement | |
456 + //////////////////////////////////////////////////////////////////////////// | |
457 + | |
458 + | |
459 + template atomicDecrement( msync ms = msync.seq, T ) | |
460 + { | |
461 + // | |
462 + // NOTE: This operation is only valid for integer or pointer types | |
463 + // | |
464 + static assert( isValidNumericType!(T) ); | |
465 + | |
466 + | |
467 + T atomicDecrement( ref T val ) | |
468 + { | |
469 + static if (isPointerType!(T)) | |
470 + { | |
471 + return cast(T)llvm_atomic_load_sub!(size_t)(cast(size_t*)&val, 1); | |
472 + } | |
473 + else | |
474 + { | |
475 + return llvm_atomic_load_sub!(T)(&val, cast(T)1); | |
476 + } | |
477 + } | |
478 + } | |
479 +} | |
480 + | |
481 +//////////////////////////////////////////////////////////////////////////////// | |
482 // x86 Atomic Function Implementation | |
483 //////////////////////////////////////////////////////////////////////////////// | |
484 | |
256 Index: tango/math/Math.d | 485 Index: tango/math/Math.d |
257 =================================================================== | 486 =================================================================== |
258 --- tango/math/Math.d (revision 3831) | 487 --- tango/math/Math.d (revision 3880) |
259 +++ tango/math/Math.d (working copy) | 488 +++ tango/math/Math.d (working copy) |
260 @@ -76,6 +76,14 @@ | 489 @@ -76,6 +76,14 @@ |
261 version = DigitalMars_D_InlineAsm_X86; | 490 version = DigitalMars_D_InlineAsm_X86; |
262 } | 491 } |
263 } | 492 } |
402 } | 631 } |
403 | 632 |
404 debug(UnitTest) { | 633 debug(UnitTest) { |
405 Index: tango/stdc/stdlib.d | 634 Index: tango/stdc/stdlib.d |
406 =================================================================== | 635 =================================================================== |
407 --- tango/stdc/stdlib.d (revision 3831) | 636 --- tango/stdc/stdlib.d (revision 3880) |
408 +++ tango/stdc/stdlib.d (working copy) | 637 +++ tango/stdc/stdlib.d (working copy) |
409 @@ -94,6 +94,11 @@ | 638 @@ -94,6 +94,11 @@ |
410 { | 639 { |
411 void* alloca(size_t size); | 640 void* alloca(size_t size); |
412 } | 641 } |
418 else version( GNU ) | 647 else version( GNU ) |
419 { | 648 { |
420 private import gcc.builtins; | 649 private import gcc.builtins; |
421 Index: tango/stdc/stdarg.d | 650 Index: tango/stdc/stdarg.d |
422 =================================================================== | 651 =================================================================== |
423 --- tango/stdc/stdarg.d (revision 3831) | 652 --- tango/stdc/stdarg.d (revision 3880) |
424 +++ tango/stdc/stdarg.d (working copy) | 653 +++ tango/stdc/stdarg.d (working copy) |
425 @@ -13,6 +13,10 @@ | 654 @@ -13,6 +13,10 @@ |
426 { | 655 { |
427 public import std.c.stdarg; | 656 public import std.c.stdarg; |
428 } | 657 } |