qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

fpcnv.ssa (2465B)


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