comparison runtime/llvmdc.diff @ 445:cc40db549aea

Changed the handling of variadic intrinsics a bit. Removed the -fp80 option and made real be 80bit floats on X86, this is what the D spec really says it should be and fixes a bunch of issues. Changed the handling of parameter attributes to a bit more generalized approach. Added sext/zext attributes for byte/short/ubyte/ushort parameters, fixes #60 . Parameter attribs now properly set for intrinsic calls if necessary. Made the tango.math.Math patch less intrusive. Fixed/added some mini tests.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Fri, 01 Aug 2008 17:59:58 +0200
parents f2b5f86348ef
children 283d113d4753
comparison
equal deleted inserted replaced
444:f2b5f86348ef 445:cc40db549aea
207 /** 207 /**
208 Index: tango/math/Math.d 208 Index: tango/math/Math.d
209 =================================================================== 209 ===================================================================
210 --- tango/math/Math.d (revision 3831) 210 --- tango/math/Math.d (revision 3831)
211 +++ tango/math/Math.d (working copy) 211 +++ tango/math/Math.d (working copy)
212 @@ -76,7 +76,77 @@ 212 @@ -76,6 +76,14 @@
213 version = DigitalMars_D_InlineAsm_X86; 213 version = DigitalMars_D_InlineAsm_X86;
214 } 214 }
215 } 215 }
216 +else version(LLVMDC) 216 +else version(LLVMDC)
217 +{ 217 +{
218 + private 218 + import llvmdc.intrinsics;
219 + { 219 + version(X86)
220 220 + {
221 + pragma(intrinsic, "llvm.sqrt.f32") 221 + version = LLVMDC_X86;
222 + float sqrt(float); 222 + }
223 + pragma(intrinsic, "llvm.sqrt.f64") 223 +}
224 + double sqrt(double); 224
225 +
226 + version(LLVM_X86_FP80)
227 + {
228 + alias tango.stdc.math.tanl llvm_tan;
229 + alias tango.stdc.math.acosl llvm_acos;
230 + alias tango.stdc.math.asinl llvm_asin;
231 + alias tango.stdc.math.atanl llvm_atan;
232 + alias tango.stdc.math.atan2l llvm_atan2;
233 + alias tango.stdc.math.coshl llvm_cosh;
234 + alias tango.stdc.math.sinhl llvm_sinh;
235 + alias tango.stdc.math.tanhl llvm_tanh;
236 + alias tango.stdc.math.cbrtl llvm_cbrt;
237 + alias tango.stdc.math.expl llvm_exp;
238 + alias tango.stdc.math.expm1l llvm_expm1;
239 + alias tango.stdc.math.exp2l llvm_exp2;
240 + alias tango.stdc.math.logl llvm_log;
241 + alias tango.stdc.math.log1pl llvm_log1p;
242 + alias tango.stdc.math.log2l llvm_log2;
243 + alias tango.stdc.math.log10l llvm_log10;
244 + alias tango.stdc.math.powl llvm_pow;
245 + alias tango.stdc.math.lrintl llvm_lrint;
246 + alias tango.stdc.math.llrintl llvm_llrint;
247 +
248 + pragma(intrinsic, "llvm.cos.f80")
249 + real cos(real);
250 + pragma(intrinsic, "llvm.sin.f80")
251 + real sin(real);
252 + pragma(intrinsic, "llvm.sqrt.f80")
253 + real sqrt(real);
254 + }
255 + else
256 + {
257 + alias tango.stdc.math.tan llvm_tan;
258 + alias tango.stdc.math.acos llvm_acos;
259 + alias tango.stdc.math.asin llvm_asin;
260 + alias tango.stdc.math.atan llvm_atan;
261 + alias tango.stdc.math.atan2 llvm_atan2;
262 + alias tango.stdc.math.cosh llvm_cosh;
263 + alias tango.stdc.math.sinh llvm_sinh;
264 + alias tango.stdc.math.tanh llvm_tanh;
265 + alias tango.stdc.math.cbrt llvm_cbrt;
266 + alias tango.stdc.math.exp llvm_exp;
267 + alias tango.stdc.math.expm1 llvm_expm1;
268 + alias tango.stdc.math.exp2 llvm_exp2;
269 + alias tango.stdc.math.log llvm_log;
270 + alias tango.stdc.math.log1p llvm_log1p;
271 + alias tango.stdc.math.log2 llvm_log2;
272 + alias tango.stdc.math.log10 llvm_log10;
273 + alias tango.stdc.math.pow llvm_pow;
274 + alias tango.stdc.math.lrint llvm_lrint;
275 + alias tango.stdc.math.llrint llvm_llrint;
276 +
277 + pragma(intrinsic, "llvm.cos.f64")
278 + real cos(real);
279 + pragma(intrinsic, "llvm.sin.f64")
280 + real sin(real);
281 + pragma(intrinsic, "llvm.sqrt.f64")
282 + real sqrt(real);
283 + }
284 + }
285 +}
286 +
287 /* 225 /*
288 * Constants 226 * Constants
289 */ 227 @@ -298,6 +306,24 @@
290 @@ -298,6 +368,10 @@
291 * Bugs: 228 * Bugs:
292 * Results are undefined if |x| >= $(POWER 2,64). 229 * Results are undefined if |x| >= $(POWER 2,64).
293 */ 230 */
294 +version(LLVMDC) 231 +version(LLVMDC)
295 +{} 232 +{
233 + alias llvm_cos_f32 cos;
234 + alias llvm_cos_f64 cos;
235 + version(X86)
236 + {
237 + alias llvm_cos_f80 cos;
238 + }
239 + else
240 + {
241 + real cos(real x)
242 + {
243 + return tango.stdc.math.cosl(x);
244 + }
245 + }
246 +}
296 +else 247 +else
297 +{ 248 +{
298 real cos(real x) /* intrinsic */ 249 real cos(real x) /* intrinsic */
299 { 250 {
300 version(D_InlineAsm_X86) 251 version(D_InlineAsm_X86)
301 @@ -313,6 +387,7 @@ 252 @@ -313,6 +339,7 @@
302 return tango.stdc.math.cosl(x); 253 return tango.stdc.math.cosl(x);
303 } 254 }
304 } 255 }
305 +} 256 +}
306 257
307 debug(UnitTest) { 258 debug(UnitTest) {
308 unittest { 259 unittest {
309 @@ -333,6 +408,10 @@ 260 @@ -333,6 +360,24 @@
310 * Bugs: 261 * Bugs:
311 * Results are undefined if |x| >= $(POWER 2,64). 262 * Results are undefined if |x| >= $(POWER 2,64).
312 */ 263 */
313 +version(LLVMDC) 264 +version(LLVMDC)
314 +{} 265 +{
266 + alias llvm_sin_f32 sin;
267 + alias llvm_sin_f64 sin;
268 + version(X86)
269 + {
270 + alias llvm_sin_f80 sin;
271 + }
272 + else
273 + {
274 + real sin(real x)
275 + {
276 + return tango.stdc.math.sinl(x);
277 + }
278 + }
279 +}
315 +else 280 +else
316 +{ 281 +{
317 real sin(real x) /* intrinsic */ 282 real sin(real x) /* intrinsic */
318 { 283 {
319 version(D_InlineAsm_X86) 284 version(D_InlineAsm_X86)
320 @@ -348,6 +427,7 @@ 285 @@ -348,6 +393,7 @@
321 return tango.stdc.math.sinl(x); 286 return tango.stdc.math.sinl(x);
322 } 287 }
323 } 288 }
324 +} 289 +}
325 290
326 debug(UnitTest) { 291 debug(UnitTest) {
327 unittest { 292 unittest {
328 @@ -374,6 +454,9 @@ 293 @@ -374,7 +420,11 @@
329 { 294 {
330 version (GNU) { 295 version (GNU) {
331 return tanl(x); 296 return tanl(x);
297 - } else {
332 + } 298 + }
333 + else version(LLVMDC) { 299 + else version(LLVMDC) {
334 + return llvm_tan(x); 300 + return tango.stdc.math.tanl(x);
335 } else { 301 + }
302 + else {
336 asm 303 asm
337 { 304 {
338 @@ -576,7 +659,14 @@ 305 fld x[EBP] ; // load theta
339 */ 306 @@ -947,6 +997,25 @@
340 real acos(real x)
341 {
342 - return tango.stdc.math.acosl(x);
343 + version(LLVMDC)
344 + {
345 + return llvm_acos(x);
346 + }
347 + else
348 + {
349 + return tango.stdc.math.acosl(x);
350 + }
351 }
352
353 debug(UnitTest) {
354 @@ -599,7 +689,14 @@
355 */
356 real asin(real x)
357 {
358 - return tango.stdc.math.asinl(x);
359 + version(LLVMDC)
360 + {
361 + return llvm_asin(x);
362 + }
363 + else
364 + {
365 + return tango.stdc.math.asinl(x);
366 + }
367 }
368
369 debug(UnitTest) {
370 @@ -621,7 +718,14 @@
371 */
372 real atan(real x)
373 {
374 - return tango.stdc.math.atanl(x);
375 + version(LLVMDC)
376 + {
377 + return llvm_atan(x);
378 + }
379 + else
380 + {
381 + return tango.stdc.math.atanl(x);
382 + }
383 }
384
385 debug(UnitTest) {
386 @@ -658,7 +762,14 @@
387 */
388 real atan2(real y, real x)
389 {
390 - return tango.stdc.math.atan2l(y,x);
391 + version(LLVMDC)
392 + {
393 + return llvm_atan2(y,x);
394 + }
395 + else
396 + {
397 + return tango.stdc.math.atan2l(y,x);
398 + }
399 }
400
401 debug(UnitTest) {
402 @@ -707,7 +818,14 @@
403 */
404 real cosh(real x)
405 {
406 - return tango.stdc.math.coshl(x);
407 + version(LLVMDC)
408 + {
409 + return llvm_cosh(x);
410 + }
411 + else
412 + {
413 + return tango.stdc.math.coshl(x);
414 + }
415 }
416
417 debug(UnitTest) {
418 @@ -728,7 +846,14 @@
419 */
420 real sinh(real x)
421 {
422 - return tango.stdc.math.sinhl(x);
423 + version(LLVMDC)
424 + {
425 + return llvm_sinh(x);
426 + }
427 + else
428 + {
429 + return tango.stdc.math.sinhl(x);
430 + }
431 }
432
433 debug(UnitTest) {
434 @@ -749,7 +874,14 @@
435 */
436 real tanh(real x)
437 {
438 - return tango.stdc.math.tanhl(x);
439 + version(LLVMDC)
440 + {
441 + return llvm_tanh(x);
442 + }
443 + else
444 + {
445 + return tango.stdc.math.tanhl(x);
446 + }
447 }
448
449 debug(UnitTest) {
450 @@ -947,6 +1079,10 @@
451 * <tr> <td> +&infin; <td> +&infin; <td> no 307 * <tr> <td> +&infin; <td> +&infin; <td> no
452 * ) 308 * )
453 */ 309 */
454 +version(LLVMDC) 310 +version(LLVMDC)
455 +{} 311 +{
312 + alias llvm_sqrt_f32 sqrt;
313 + alias llvm_sqrt_f64 sqrt;
314 + version(X86)
315 + {
316 + alias llvm_sqrt_f80 sqrt;
317 + }
318 + else
319 + {
320 + real sqrt(real x)
321 + {
322 + return tango.stdc.math.sqrtl(x);
323 + }
324 + }
325 +}
456 +else 326 +else
457 +{ 327 +{
328 +
458 float sqrt(float x) /* intrinsic */ 329 float sqrt(float x) /* intrinsic */
459 { 330 {
460 version(D_InlineAsm_X86) 331 version(D_InlineAsm_X86)
461 @@ -994,6 +1130,7 @@ 332 @@ -995,6 +1064,8 @@
462 return tango.stdc.math.sqrtl(x); 333 }
463 } 334 }
464 } 335
465 +} 336 +}
466 337 +
467 /** ditto */ 338 /** ditto */
468 creal sqrt(creal z) 339 creal sqrt(creal z)
469 @@ -1045,7 +1182,14 @@ 340 {
470 */ 341 @@ -1477,7 +1548,14 @@
471 real cbrt(real x) 342 }
472 { 343 }
473 - return tango.stdc.math.cbrtl(x); 344 }
474 + version(LLVMDC) 345 - return tango.stdc.math.powl(x, y);
475 + { 346 + version(LLVMDC_X86)
476 + return llvm_cbrt(x); 347 + {
348 + return llvm_pow_f80(x, y);
477 + } 349 + }
478 + else 350 + else
479 + { 351 + {
480 + return tango.stdc.math.cbrtl(x); 352 + return tango.stdc.math.powl(x, y);
481 + }
482 }
483
484
485 @@ -1067,7 +1211,14 @@
486 */
487 real exp(real x)
488 {
489 - return tango.stdc.math.expl(x);
490 + version(LLVMDC)
491 + {
492 + return llvm_exp(x);
493 + }
494 + else
495 + {
496 + return tango.stdc.math.expl(x);
497 + } 353 + }
498 } 354 }
499 355
500 debug(UnitTest) { 356 debug(UnitTest) {
501 @@ -1093,7 +1244,14 @@
502 */
503 real expm1(real x)
504 {
505 - return tango.stdc.math.expm1l(x);
506 + version(LLVMDC)
507 + {
508 + return llvm_expm1(x);
509 + }
510 + else
511 + {
512 + return tango.stdc.math.expm1l(x);
513 + }
514 }
515
516 debug(UnitTest) {
517 @@ -1115,7 +1273,14 @@
518 */
519 real exp2(real x)
520 {
521 - return tango.stdc.math.exp2l(x);
522 + version(LLVMDC)
523 + {
524 + return llvm_exp2(x);
525 + }
526 + else
527 + {
528 + return tango.stdc.math.exp2l(x);
529 + }
530 }
531
532 debug(UnitTest) {
533 @@ -1141,7 +1306,14 @@
534 */
535 real log(real x)
536 {
537 - return tango.stdc.math.logl(x);
538 + version(LLVMDC)
539 + {
540 + return llvm_log(x);
541 + }
542 + else
543 + {
544 + return tango.stdc.math.logl(x);
545 + }
546 }
547
548 debug(UnitTest) {
549 @@ -1167,7 +1339,14 @@
550 */
551 real log1p(real x)
552 {
553 - return tango.stdc.math.log1pl(x);
554 + version(LLVMDC)
555 + {
556 + return llvm_log1p(x);
557 + }
558 + else
559 + {
560 + return tango.stdc.math.log1pl(x);
561 + }
562 }
563
564 debug(UnitTest) {
565 @@ -1190,7 +1369,14 @@
566 */
567 real log2(real x)
568 {
569 - return tango.stdc.math.log2l(x);
570 + version(LLVMDC)
571 + {
572 + return llvm_log2(x);
573 + }
574 + else
575 + {
576 + return tango.stdc.math.log2l(x);
577 + }
578 }
579
580 debug(UnitTest) {
581 @@ -1212,7 +1398,14 @@
582 */
583 real log10(real x)
584 {
585 - return tango.stdc.math.log10l(x);
586 + version(LLVMDC)
587 + {
588 + return llvm_log10(x);
589 + }
590 + else
591 + {
592 + return tango.stdc.math.log10l(x);
593 + }
594 }
595
596 debug(UnitTest) {
597 @@ -1477,7 +1670,14 @@
598 }
599 }
600 }
601 - return tango.stdc.math.powl(x, y);
602 + version(LLVMDC)
603 + {
604 + return llvm_pow(x, y);
605 + }
606 + else
607 + {
608 + return tango.stdc.math.powl(x, y);
609 + }
610 }
611
612 debug(UnitTest) {
613 @@ -1823,6 +2023,10 @@
614 }
615 return n;
616 }
617 + else version(LLVMDC)
618 + {
619 + return llvm_lrint(x);
620 + }
621 else
622 {
623 return tango.stdc.math.lrintl(x);
624 @@ -1842,6 +2046,10 @@
625 }
626 return n;
627 }
628 + else version(LLVMDC)
629 + {
630 + return llvm_llrint(x);
631 + }
632 else
633 {
634 return tango.stdc.math.llrintl(x);
635 Index: tango/stdc/stdlib.d 357 Index: tango/stdc/stdlib.d
636 =================================================================== 358 ===================================================================
637 --- tango/stdc/stdlib.d (revision 3831) 359 --- tango/stdc/stdlib.d (revision 3831)
638 +++ tango/stdc/stdlib.d (working copy) 360 +++ tango/stdc/stdlib.d (working copy)
639 @@ -94,6 +94,11 @@ 361 @@ -94,6 +94,11 @@