fpcnv.ssa 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # floating point casts and conversions
  2. export
  3. function s $fneg(s %f) {
  4. @fneg
  5. %b0 =w cast %f
  6. %b1 =w xor 2147483648, %b0
  7. %rs =s cast %b1
  8. ret %rs
  9. }
  10. export
  11. function d $ftrunc(d %f) {
  12. @ftrunc
  13. %l0 =w dtosi %f
  14. %rt =d swtof %l0
  15. ret %rt
  16. }
  17. export
  18. function s $wtos(w %w) {
  19. @start
  20. %rt =s uwtof %w
  21. ret %rt
  22. }
  23. export
  24. function d $wtod(w %w) {
  25. @start
  26. %rt =d uwtof %w
  27. ret %rt
  28. }
  29. export
  30. function s $ltos(l %l) {
  31. @start
  32. %rt =s ultof %l
  33. ret %rt
  34. }
  35. export
  36. function d $ltod(l %l) {
  37. @start
  38. %rt =d ultof %l
  39. ret %rt
  40. }
  41. export
  42. function w $stow(s %f) {
  43. @start
  44. %rt =w stoui %f
  45. ret %rt
  46. }
  47. export
  48. function w $dtow(d %f) {
  49. @start
  50. %rt =w dtoui %f
  51. ret %rt
  52. }
  53. export
  54. function l $stol(s %f) {
  55. @start
  56. %rt =l stoui %f
  57. ret %rt
  58. }
  59. export
  60. function l $dtol(d %f) {
  61. @start
  62. %rt =l dtoui %f
  63. ret %rt
  64. }
  65. # >>> driver
  66. # #include <float.h>
  67. # #include <limits.h>
  68. #
  69. # extern float fneg(float);
  70. # extern double ftrunc(double);
  71. #
  72. # extern float wtos(unsigned int);
  73. # extern double wtod(unsigned int);
  74. # extern float ltos(long long unsigned int);
  75. # extern double ltod(long long unsigned int);
  76. #
  77. # extern unsigned int stow(float);
  78. # extern unsigned int dtow(double);
  79. # extern unsigned long long stol(float);
  80. # extern unsigned long long dtol(double);
  81. #
  82. # unsigned long long iin[] = { 0, 1, 16, 234987, 427386245, 0x7fff0000,
  83. # 0xffff0000, 23602938196141, 72259248152500195, 9589010795705032704ull,
  84. # 0xdcf5fbe299d0148aull, 0xffffffff00000000ull, -1 };
  85. #
  86. # double fin[] = { 0.17346516197824458, 442.0760005466251, 4342856.879893436,
  87. # 4294967295.0, 98547543006.49626, 236003043787688.3, 9.499222733527032e+18,
  88. # 1.1936266170755652e+19 };
  89. #
  90. # int main() {
  91. # int i;
  92. #
  93. # if (fneg(1.23f) != -1.23f) return 1;
  94. # if (ftrunc(3.1415) != 3.0) return 2;
  95. # if (ftrunc(-1.234) != -1.0) return 3;
  96. #
  97. # for (i=0; i<sizeof(iin)/sizeof(iin[0]); i++) {
  98. # if (wtos(iin[i]) != (float) (unsigned int)iin[i])
  99. # return 4;
  100. # if (wtod(iin[i]) != (double)(unsigned int)iin[i])
  101. # return 5;
  102. # if (ltos(iin[i]) != (float) iin[i])
  103. # return 6;
  104. # if (ltod(iin[i]) != (double)iin[i])
  105. # return 7;
  106. # }
  107. # for (i=0; i<sizeof(fin)/sizeof(fin[0]); i++) {
  108. # if (fin[i] >= 1LL << DBL_MANT_DIG)
  109. # break;
  110. # if (dtol(fin[i]) != (unsigned long long)fin[i])
  111. # return 8;
  112. # if((unsigned long long)fin[i] > UINT_MAX)
  113. # continue;
  114. # if (dtow(fin[i]) != (unsigned int)fin[i])
  115. # return 9;
  116. # if (fin[i] >= 1LL << FLT_MANT_DIG)
  117. # continue;
  118. # if (stol((float)fin[i]) != (unsigned long long)(float)fin[i])
  119. # return 10;
  120. # if (stow((float)fin[i]) != (unsigned int)(float)fin[i])
  121. # return 11;
  122. # }
  123. # return 0;
  124. # }
  125. # <<<