00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <stdio.h>
00037 #include "arith.h"
00038 #include "arith.internal.h"
00039
00040 #if !defined __sun && (!defined __STDC__ || !defined _CRAY || _RELEASE < 4)
00041 #error Must be compiled with gcc or Cray Standard C Compiler, version >= 4.0.
00042 #endif
00043
00044 #if defined _CRAY
00045
00046 typedef signed int SINT46;
00047 typedef unsigned int UINT46;
00048 typedef unsigned long UINT64;
00049 typedef signed long SINT64;
00050
00051 # define LS46(v) (*(SINT46*)v)
00052 # define LU46(v) (*(UINT46*)v)
00053 # define LS64(v) (*(SINT64*)v)
00054 # define LU64(v) (*(UINT64*)v)
00055
00056 #elif defined __sun
00057
00058 typedef unsigned long long int UINT64;
00059 typedef signed long long int SINT64;
00060 typedef signed long long int SINT46;
00061
00062
00063
00064
00065
00066
00067 SINT46 LS46(AR_INT_64 *vp)
00068 {
00069 return((((SINT46) vp->part1) << 48) |
00070 (((SINT46) vp->part2) << 32) |
00071 (((SINT46) vp->part3) << 16) |
00072 (((SINT46) vp->part4) ));
00073 }
00074
00075 SINT64 LS64(AR_INT_64 *vp)
00076 {
00077 return((((SINT64) vp->part1) << 48) |
00078 (((SINT64) vp->part2) << 32) |
00079 (((SINT64) vp->part3) << 16) |
00080 (((SINT64) vp->part4) ));
00081 }
00082
00083 UINT64 LU64(AR_INT_64 *vp)
00084 {
00085 return((((UINT64) vp->part1) << 48) |
00086 (((UINT64) vp->part2) << 32) |
00087 (((UINT64) vp->part3) << 16) |
00088 (((UINT64) vp->part4) ));
00089 }
00090 #endif
00091
00092
00093 AR_INT_64 cool_ints[] =
00094 {
00095
00096 {0x0000, 0x0000, 0x0000, 0x0000},
00097 {0x0000, 0x0000, 0x0000, 0x0001},
00098 {0x0000, 0x0000, 0x0000, 0x0002},
00099 {0x0000, 0x0000, 0x0000, 0x0004},
00100 {0x0000, 0x0000, 0x0000, 0x0010},
00101 {0x0000, 0x0000, 0x0000, 0x0040},
00102 {0x0000, 0x0000, 0x0000, 0x0100},
00103 {0x0000, 0x0000, 0x0000, 0x0400},
00104 {0x0000, 0x0000, 0x0000, 0x1000},
00105 {0x0000, 0x0000, 0x0000, 0x4000},
00106 {0x0000, 0x0000, 0x0001, 0x0000},
00107 {0x0000, 0x0000, 0x0004, 0x0000},
00108 {0x0000, 0x0000, 0x0010, 0x0000},
00109 {0x0000, 0x0000, 0x0040, 0x0000},
00110 {0x0000, 0x0000, 0x0100, 0x0000},
00111 {0x0000, 0x0000, 0x0400, 0x0000},
00112 {0x0000, 0x0000, 0x1000, 0x0000},
00113 {0x0000, 0x0000, 0x4000, 0x0000},
00114 {0x0000, 0x0001, 0x0000, 0x0000},
00115 {0x0000, 0x0004, 0x0000, 0x0000},
00116 {0x0000, 0x0010, 0x0000, 0x0000},
00117 {0x0000, 0x0040, 0x0000, 0x0000},
00118 {0x0000, 0x0100, 0x0000, 0x0000},
00119 {0x0000, 0x0400, 0x0000, 0x0000},
00120 {0x0000, 0x1000, 0x0000, 0x0000},
00121 {0x0000, 0x4000, 0x0000, 0x0000},
00122 {0x0001, 0x0000, 0x0000, 0x0000},
00123 {0x0004, 0x0000, 0x0000, 0x0000},
00124 {0x0010, 0x0000, 0x0000, 0x0000},
00125 {0x0040, 0x0000, 0x0000, 0x0000},
00126 {0x0100, 0x0000, 0x0000, 0x0000},
00127 {0x0400, 0x0000, 0x0000, 0x0000},
00128 {0x1000, 0x0000, 0x0000, 0x0000},
00129 {0x2000, 0x0000, 0x0000, 0x0000},
00130 {0x4000, 0x0000, 0x0000, 0x0000},
00131 {0x8000, 0x0000, 0x0000, 0x0000},
00132
00133
00134 {0x8000, 0x0000, 0x8000, 0x0000},
00135 {0x8000, 0x0000, 0x8000, 0x0001},
00136 {0x8000, 0x0000, 0x8000, 0x0002},
00137 {0x8000, 0x0000, 0x8000, 0x0004},
00138 {0x8000, 0x0000, 0x8000, 0x0010},
00139 {0x8000, 0x0000, 0x8000, 0x0040},
00140 {0x8000, 0x0000, 0x8000, 0x0100},
00141 {0x8000, 0x0000, 0x8000, 0x0400},
00142 {0x8000, 0x0000, 0x8000, 0x1000},
00143 {0x8000, 0x0000, 0x8000, 0x4000},
00144 {0x8000, 0x0000, 0x8001, 0x0000},
00145 {0x8000, 0x0000, 0x8004, 0x0000},
00146 {0x8000, 0x0000, 0x8010, 0x0000},
00147 {0x8000, 0x0000, 0x8040, 0x0000},
00148 {0x8000, 0x0000, 0x8100, 0x0000},
00149 {0x8000, 0x0000, 0x8400, 0x0000},
00150 {0x8000, 0x0000, 0x9000, 0x0000},
00151 {0x8000, 0x0000, 0xc000, 0x0000},
00152 {0x8000, 0x0001, 0x0000, 0x0000},
00153 {0x8000, 0x0004, 0x0000, 0x0000},
00154 {0x8000, 0x0010, 0x0000, 0x0000},
00155 {0x8000, 0x0040, 0x0000, 0x0000},
00156 {0x8000, 0x0100, 0x0000, 0x0000},
00157 {0x8000, 0x0400, 0x0000, 0x0000},
00158 {0x8000, 0x1000, 0x0000, 0x0000},
00159 {0x8000, 0x4000, 0x0000, 0x0000},
00160 {0x8001, 0x0000, 0x0000, 0x0000},
00161 {0x8004, 0x0000, 0x0000, 0x0000},
00162 {0x8010, 0x0000, 0x0000, 0x0000},
00163 {0x8040, 0x0000, 0x0000, 0x0000},
00164 {0x8100, 0x0000, 0x0000, 0x0000},
00165 {0x8400, 0x0000, 0x0000, 0x0000},
00166 {0x9000, 0x0000, 0x0000, 0x0000},
00167 {0xa000, 0x0000, 0x0000, 0x0000},
00168 {0xc000, 0x0000, 0x0000, 0x0000},
00169
00170
00171
00172 {0x0000, 0x0000, 0x0000, 0x0003},
00173 {0x0000, 0x0000, 0x0000, 0x0007},
00174 {0x0000, 0x0000, 0x0000, 0x000f},
00175 {0x0000, 0x0000, 0x0000, 0x003f},
00176 {0x0000, 0x0000, 0x0000, 0x00ff},
00177 {0x0000, 0x0000, 0x0000, 0x03ff},
00178 {0x0000, 0x0000, 0x0000, 0x0fff},
00179 {0x0000, 0x0000, 0x0000, 0x3fff},
00180 {0x0000, 0x0000, 0x0000, 0xffff},
00181 {0x0000, 0x0000, 0x0003, 0xffff},
00182 {0x0000, 0x0000, 0x000f, 0xffff},
00183 {0x0000, 0x0000, 0x003f, 0xffff},
00184 {0x0000, 0x0000, 0x00ff, 0xffff},
00185 {0x0000, 0x0000, 0x03ff, 0xffff},
00186 {0x0000, 0x0000, 0x0fff, 0xffff},
00187 {0x0000, 0x0000, 0x3fff, 0xffff},
00188 {0x0000, 0x0000, 0xffff, 0xffff},
00189 {0x0000, 0x0003, 0xffff, 0xffff},
00190 {0x0000, 0x000f, 0xffff, 0xffff},
00191 {0x0000, 0x003f, 0xffff, 0xffff},
00192 {0x0000, 0x00ff, 0xffff, 0xffff},
00193 {0x0000, 0x03ff, 0xffff, 0xffff},
00194 {0x0000, 0x0fff, 0xffff, 0xffff},
00195 {0x0000, 0x3fff, 0xffff, 0xffff},
00196 {0x0000, 0xffff, 0xffff, 0xffff},
00197 {0x0003, 0xffff, 0xffff, 0xffff},
00198 {0x000f, 0xffff, 0xffff, 0xffff},
00199 {0x003f, 0xffff, 0xffff, 0xffff},
00200 {0x00ff, 0xffff, 0xffff, 0xffff},
00201 {0x03ff, 0xffff, 0xffff, 0xffff},
00202 {0x0fff, 0xffff, 0xffff, 0xffff},
00203 {0x3fff, 0xffff, 0xffff, 0xffff},
00204 {0x7fff, 0xffff, 0xffff, 0xfffe},
00205 {0x7fff, 0xffff, 0xffff, 0xfff8},
00206 {0x7fff, 0xffff, 0xffff, 0xffe0},
00207 {0x7fff, 0xffff, 0xffff, 0xff80},
00208 {0x7fff, 0xffff, 0xffff, 0xfe00},
00209 {0x7fff, 0xffff, 0xffff, 0xf800},
00210 {0x7fff, 0xffff, 0xffff, 0xe000},
00211 {0x7fff, 0xffff, 0xffff, 0x8000},
00212 {0x7fff, 0xffff, 0xfffe, 0x0000},
00213 {0x7fff, 0xffff, 0xfff8, 0x0000},
00214 {0x7fff, 0xffff, 0xffe0, 0x0000},
00215 {0x7fff, 0xffff, 0xff80, 0x0000},
00216 {0x7fff, 0xffff, 0xfe00, 0x0000},
00217 {0x7fff, 0xffff, 0xf800, 0x0000},
00218 {0x7fff, 0xffff, 0xe000, 0x0000},
00219 {0x7fff, 0xffff, 0x8000, 0x0000},
00220 {0x7fff, 0xfffe, 0x0000, 0x0000},
00221 {0x7fff, 0xfff8, 0x0000, 0x0000},
00222 {0x7fff, 0xffe0, 0x0000, 0x0000},
00223 {0x7fff, 0xff80, 0x0000, 0x0000},
00224 {0x7fff, 0xfe00, 0x0000, 0x0000},
00225 {0x7fff, 0xf800, 0x0000, 0x0000},
00226 {0x7fff, 0xe000, 0x0000, 0x0000},
00227 {0x7fff, 0x8000, 0x0000, 0x0000},
00228 {0x7ffe, 0x0000, 0x0000, 0x0000},
00229 {0x7ff8, 0x0000, 0x0000, 0x0000},
00230 {0x7fe0, 0x0000, 0x0000, 0x0000},
00231 {0x7f80, 0x0000, 0x0000, 0x0000},
00232 {0x7e00, 0x0000, 0x0000, 0x0000},
00233 {0x7800, 0x0000, 0x0000, 0x0000},
00234 {0x7000, 0x0000, 0x0000, 0x0000},
00235 {0x6000, 0x0000, 0x0000, 0x0000},
00236 {0x4000, 0x0000, 0x0000, 0x0000},
00237
00238
00239 {0x8000, 0x0000, 0x0000, 0x0001},
00240 {0x8000, 0x0000, 0x0000, 0x0003},
00241 {0x8000, 0x0000, 0x0000, 0x0007},
00242 {0x8000, 0x0000, 0x0000, 0x000f},
00243 {0x8000, 0x0000, 0x0000, 0x001f},
00244 {0x8000, 0x0000, 0x0000, 0x007f},
00245 {0x8000, 0x0000, 0x0000, 0x01ff},
00246 {0x8000, 0x0000, 0x0000, 0x07ff},
00247 {0x8000, 0x0000, 0x0000, 0x1fff},
00248 {0x8000, 0x0000, 0x0000, 0x7fff},
00249 {0x8000, 0x0000, 0x0001, 0xffff},
00250 {0x8000, 0x0000, 0x0007, 0xffff},
00251 {0x8000, 0x0000, 0x001f, 0xffff},
00252 {0x8000, 0x0000, 0x007f, 0xffff},
00253 {0x8000, 0x0000, 0x01ff, 0xffff},
00254 {0x8000, 0x0000, 0x07ff, 0xffff},
00255 {0x8000, 0x0000, 0x1fff, 0xffff},
00256 {0x8000, 0x0000, 0x7fff, 0xffff},
00257 {0x8000, 0x0001, 0xffff, 0xffff},
00258 {0x8000, 0x0007, 0xffff, 0xffff},
00259 {0x8000, 0x001f, 0xffff, 0xffff},
00260 {0x8000, 0x007f, 0xffff, 0xffff},
00261 {0x8000, 0x01ff, 0xffff, 0xffff},
00262 {0x8000, 0x07ff, 0xffff, 0xffff},
00263 {0x8000, 0x1fff, 0xffff, 0xffff},
00264 {0x8000, 0x7fff, 0xffff, 0xffff},
00265 {0x8001, 0xffff, 0xffff, 0xffff},
00266 {0x8007, 0xffff, 0xffff, 0xffff},
00267 {0x801f, 0xffff, 0xffff, 0xffff},
00268 {0x807f, 0xffff, 0xffff, 0xffff},
00269 {0x81ff, 0xffff, 0xffff, 0xffff},
00270 {0x87ff, 0xffff, 0xffff, 0xffff},
00271 {0x9fff, 0xffff, 0xffff, 0xffff},
00272 {0xffff, 0xffff, 0xffff, 0xffff},
00273 {0xffff, 0xffff, 0xffff, 0xfffc},
00274 {0xffff, 0xffff, 0xffff, 0xfff0},
00275 {0xffff, 0xffff, 0xffff, 0xffc0},
00276 {0xffff, 0xffff, 0xffff, 0xff00},
00277 {0xffff, 0xffff, 0xffff, 0xfc00},
00278 {0xffff, 0xffff, 0xffff, 0xf000},
00279 {0xffff, 0xffff, 0xffff, 0xc000},
00280 {0xffff, 0xffff, 0xffff, 0x0000},
00281 {0xffff, 0xffff, 0xfffc, 0x0000},
00282 {0xffff, 0xffff, 0xfff0, 0x0000},
00283 {0xffff, 0xffff, 0xffc0, 0x0000},
00284 {0xffff, 0xffff, 0xff00, 0x0000},
00285 {0xffff, 0xffff, 0xfc00, 0x0000},
00286 {0xffff, 0xffff, 0xf000, 0x0000},
00287 {0xffff, 0xffff, 0xc000, 0x0000},
00288 {0xffff, 0xffff, 0x0000, 0x0000},
00289 {0xffff, 0xfffc, 0x0000, 0x0000},
00290 {0xffff, 0xfff0, 0x0000, 0x0000},
00291 {0xffff, 0xffc0, 0x0000, 0x0000},
00292 {0xffff, 0xff00, 0x0000, 0x0000},
00293 {0xffff, 0xfc00, 0x0000, 0x0000},
00294 {0xffff, 0xf000, 0x0000, 0x0000},
00295 {0xffff, 0xc000, 0x0000, 0x0000},
00296 {0xffff, 0x0000, 0x0000, 0x0000},
00297 {0xfffc, 0x0000, 0x0000, 0x0000},
00298 {0xfff0, 0x0000, 0x0000, 0x0000},
00299 {0xffc0, 0x0000, 0x0000, 0x0000},
00300 {0xff00, 0x0000, 0x0000, 0x0000},
00301 {0xfc00, 0x0000, 0x0000, 0x0000},
00302 {0xf000, 0x0000, 0x0000, 0x0000},
00303 {0xe000, 0x0000, 0x0000, 0x0000},
00304 {0xc000, 0x0000, 0x0000, 0x0000}
00305 };
00306 int num_cool_ints = sizeof(cool_ints)/sizeof(AR_INT_64);
00307
00308
00309 AR_INT_64 dshift_vals[] =
00310 {
00311 {0x0000, 0x0000, 0x0000, 0x0000},
00312 {0x0000, 0x0000, 0x0000, 0x0001},
00313 {0x0000, 0x0000, 0x0000, 0x000a},
00314 {0x0000, 0x0000, 0x0000, 0x0010},
00315 {0x0000, 0x0000, 0x0000, 0x0015},
00316 {0x0000, 0x0000, 0x0000, 0x001f},
00317 {0x0000, 0x0000, 0x0000, 0x0020},
00318 {0x0000, 0x0000, 0x0000, 0x0021},
00319 {0x0000, 0x0000, 0x0000, 0x002b},
00320 {0x0000, 0x0000, 0x0000, 0x003f},
00321 {0x0000, 0x0000, 0x0000, 0x0040},
00322 {0x0000, 0x0000, 0x0000, 0x0041},
00323 {0xffff, 0xffff, 0xffff, 0xffff}
00324 };
00325 int num_dshift_vals = sizeof(dshift_vals)/sizeof(AR_INT_64);
00326
00327
00328 AR_TYPE ar_types[] =
00329 {
00330 AR_Int_8_S,
00331 AR_Int_8_U,
00332 AR_Int_16_S,
00333 AR_Int_16_U,
00334 AR_Int_24_S,
00335 AR_Int_24_U,
00336 AR_Int_32_S,
00337 AR_Int_32_U,
00338 AR_Int_46_S,
00339 AR_Int_64_S,
00340 AR_Int_64_U
00341 };
00342 int num_ar_types = sizeof(ar_types) / sizeof(AR_TYPE);
00343
00344 #define IS_SUPPORTED_INT_TYPE(t) \
00345 ((t) == AR_Int_8_S || (t) == AR_Int_8_U || \
00346 (t) == AR_Int_16_S || (t) == AR_Int_16_U || \
00347 (t) == AR_Int_32_S || (t) == AR_Int_32_U || \
00348 (t) == AR_Int_46_S || \
00349 (t) == AR_Int_64_S || (t) == AR_Int_64_U)
00350
00351 AR_TYPE sint8_artype = AR_Int_8_S;
00352 AR_TYPE uint8_artype = AR_Int_8_U;
00353 AR_TYPE sint16_artype = AR_Int_16_S;
00354 AR_TYPE uint16_artype = AR_Int_16_U;
00355 AR_TYPE sint24_artype = AR_Int_24_S;
00356 AR_TYPE uint24_artype = AR_Int_24_U;
00357 AR_TYPE sint32_artype = AR_Int_32_S;
00358 AR_TYPE uint32_artype = AR_Int_32_U;
00359 AR_TYPE sint46_artype = AR_Int_46_S;
00360 AR_TYPE sint64_artype = AR_Int_64_S;
00361 AR_TYPE uint64_artype = AR_Int_64_U;
00362
00363 SINT64 act_result [sizeof(cool_ints)/sizeof(AR_INT_64)];
00364 int act_status [sizeof(cool_ints)/sizeof(AR_INT_64)];
00365
00366 AR_INT_64 test_result[sizeof(cool_ints)/sizeof(AR_INT_64)];
00367 int test_status[sizeof(cool_ints)/sizeof(AR_INT_64)];
00368
00369
00370
00371
00372
00373
00374 #if defined __sun
00375
00376
00377
00378
00379
00380 static SINT64 _dshiftl(SINT64 op1, SINT64 op2, SINT64 shcnt)
00381 {
00382 SINT64 rshcnt = ((SINT64) 64) - shcnt;
00383
00384 if (shcnt == 0)
00385 return(op1);
00386 else if (shcnt == 64)
00387 return(op2);
00388 return((op1 << shcnt) | (((UINT64) op2) >> rshcnt));
00389 }
00390
00391 static SINT64 _dshiftr(SINT64 op1, SINT64 op2, SINT64 shcnt)
00392 {
00393 SINT64 rshcnt = ((SINT64) 64) - shcnt;
00394
00395 if (shcnt == 0)
00396 return(op2);
00397 else if (shcnt == 64)
00398 return(op1);
00399 return((op1 << rshcnt) | (((UINT64) op2) >> shcnt));
00400 }
00401
00402 static UINT64 shftl64(UINT64 op, SINT64 shcnt)
00403 {
00404 if (shcnt == 0)
00405 return(op);
00406 else if (shcnt == 64)
00407 return(0);
00408 return(op << shcnt);
00409 }
00410
00411 static UINT64 shftr64(UINT64 op, SINT64 shcnt)
00412 {
00413 if (shcnt == 0)
00414 return(op);
00415 else if (shcnt == 64)
00416 return(0);
00417 return(op >> shcnt);
00418 }
00419
00420 static SINT64 _mask(SINT64 bits)
00421 {
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 union
00434 {
00435 AR_INT_64 u64p;
00436 UINT64 u64w;
00437 } u;
00438
00439 u.u64p.part1 = u.u64p.part2 = u.u64p.part3 = u.u64p.part4 = 0xFFFF;
00440
00441 if (bits > 0 && bits <= 63)
00442 return((SINT64) (u.u64w << (((SINT64) 64) - bits)));
00443 else if (bits >= 64 && bits < 128)
00444 return((SINT64) (u.u64w >> (bits - ((SINT64) 64))));
00445 return(0);
00446 }
00447
00448 static SINT64 _leadz(SINT64 val)
00449 {
00450 int lz_bits;
00451
00452 if (val == 0)
00453 return(64);
00454 for (lz_bits = 0; val > 0; val <<= 1, lz_bits++)
00455 ;
00456 return((SINT64) lz_bits);
00457 }
00458
00459 static SINT64 _popcnt(SINT64 val)
00460 {
00461 int pop_bits, bit_count;
00462
00463 for (pop_bits = bit_count = 0;
00464 bit_count < 64;
00465 pop_bits += val & 0x1, val >>= 1, bit_count++)
00466 ;
00467 return((SINT64) pop_bits);
00468 }
00469
00470 static SINT64 _poppar(SINT64 val)
00471 {
00472 return(_popcnt(val) & ((SINT64) 0x1));
00473 }
00474 #endif
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 SINT64 DSEXT8(SINT64 v)
00487 {
00488 return(v & 0xFF);
00489 }
00490
00491 SINT64 SEXT8(SINT64 v)
00492 {
00493 return((( - ((v >> 7) & 0x1)) << 8) | DSEXT8(v));
00494 }
00495
00496
00497
00498
00499
00500 SINT64 LS8(AR_INT_64 *vp)
00501 {
00502 return(SEXT8((UINT64) (vp->part4 & 0xFF)));
00503 }
00504
00505 UINT64 LU8(AR_INT_64 *vp)
00506 {
00507 return((UINT64) (vp->part4 & 0xFF));
00508 }
00509
00510
00511
00512
00513
00514 #define is_zero8(v) (DSEXT8(v) == 0)
00515 #define is_neg8(v) (((v) & 0x80) != 0)
00516
00517
00518
00519
00520
00521 static SINT64 _dshiftl8(SINT64 op1, SINT64 op2, SINT64 shcnt)
00522 {
00523 SINT64 rshcnt = ((SINT64) 8) - shcnt;
00524
00525 op2 &= 0xFF;
00526 return(((op1 << shcnt) | (op2 >> rshcnt)) & 0xFF);
00527 }
00528
00529 static SINT64 _dshiftr8(SINT64 op1, SINT64 op2, SINT64 shcnt)
00530 {
00531 SINT64 rshcnt = ((SINT64) 8) - shcnt;
00532
00533 op2 &= 0xFF;
00534 return(((op1 << rshcnt) | (op2 >> shcnt)) & 0xFF);
00535 }
00536
00537 static SINT64 _mask8(SINT64 bits)
00538 {
00539 bits &= 0xFF;
00540 if (bits > 0 && bits < 8)
00541 return((SINT64) ((0xFF << (((SINT64) 8) - bits)) & 0xFF));
00542 else if (bits >= 8 && bits < 16)
00543 return((SINT64) (((UINT64) 0xFF) >> (bits - 8)));
00544 return(0);
00545 }
00546
00547 static SINT64 _leadz8(SINT64 val)
00548 {
00549 int lz_bits;
00550
00551 val <<= 56;
00552 if (val == 0)
00553 return(8);
00554 for (lz_bits = 0; val >= 0; val <<= 1) {
00555 lz_bits++;
00556 }
00557 return((SINT64) lz_bits);
00558 }
00559
00560 static SINT64 _popcnt8(SINT64 val)
00561 {
00562 int pop_bits, bit_count;
00563
00564 for (pop_bits = bit_count = 0;
00565 bit_count < 8;
00566 pop_bits += val & 0x1, val >>= 1, bit_count++)
00567 ;
00568 return((SINT64) pop_bits);
00569 }
00570
00571 static SINT64 _poppar8(SINT64 val)
00572 {
00573 return(_popcnt8(val) & ((SINT64) 0x1));
00574 }
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586 SINT64 DSEXT16(SINT64 v)
00587 {
00588 return(v & 0xFFFF);
00589 }
00590
00591 SINT64 SEXT16(SINT64 v)
00592 {
00593 return((( - ((v >> 15) & 0x1)) << 16) | DSEXT16(v));
00594 }
00595
00596
00597
00598
00599
00600 SINT64 LS16(AR_INT_64 *vp)
00601 {
00602 return(SEXT16((UINT64) vp->part4));
00603 }
00604
00605 UINT64 LU16(AR_INT_64 *vp)
00606 {
00607 return((UINT64) vp->part4);
00608 }
00609
00610
00611
00612
00613
00614 #define is_zero16(v) (DSEXT16(v) == 0)
00615 #define is_neg16(v) (((v) & 0x8000) != 0)
00616
00617
00618
00619
00620
00621 static SINT64 _dshiftl16(SINT64 op1, SINT64 op2, SINT64 shcnt)
00622 {
00623 SINT64 rshcnt = ((SINT64) 16) - shcnt;
00624
00625 op2 &= 0xFFFF;
00626 return(((op1 << shcnt) | (op2 >> rshcnt)) & 0xFFFF);
00627 }
00628
00629 static SINT64 _dshiftr16(SINT64 op1, SINT64 op2, SINT64 shcnt)
00630 {
00631 SINT64 rshcnt = ((SINT64) 16) - shcnt;
00632
00633 op2 &= 0xFFFF;
00634 return(((op1 << rshcnt) | (op2 >> shcnt)) & 0xFFFF);
00635 }
00636
00637 static SINT64 _mask16(SINT64 bits)
00638 {
00639 bits &= 0xFFFF;
00640 if (bits > 0 && bits < 16)
00641 return((SINT64) ((0xFFFF << (((SINT64) 16) - bits)) & 0xFFFF));
00642 else if (bits >= 16 && bits < 32)
00643 return((SINT64) (((UINT64) 0xFFFF) >> (bits - 16)));
00644 return(0);
00645 }
00646
00647 static SINT64 _leadz16(SINT64 val)
00648 {
00649 int lz_bits;
00650
00651 val <<= 48;
00652 if (val == 0)
00653 return(16);
00654 for (lz_bits = 0; val >= 0; val <<= 1) {
00655 lz_bits++;
00656 }
00657 return((SINT64) lz_bits);
00658 }
00659
00660 static SINT64 _popcnt16(SINT64 val)
00661 {
00662 int pop_bits, bit_count;
00663
00664 for (pop_bits = bit_count = 0;
00665 bit_count < 16;
00666 pop_bits += val & 0x1, val >>= 1, bit_count++)
00667 ;
00668 return((SINT64) pop_bits);
00669 }
00670
00671 static SINT64 _poppar16(SINT64 val)
00672 {
00673 return(_popcnt16(val) & ((SINT64) 0x1));
00674 }
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686 SINT64 DSEXT32(SINT64 v)
00687 {
00688 return(v & 0xFFFFFFFF);
00689 }
00690
00691 SINT64 SEXT32(SINT64 v)
00692 {
00693 return((( - ((v >> 31) & 0x1)) << 32) | DSEXT32(v));
00694 }
00695
00696
00697
00698
00699
00700 SINT64 LS32(AR_INT_64 *vp)
00701 {
00702 return(SEXT32((((UINT64) vp->part3) << 16) | ((UINT64) vp->part4)));
00703 }
00704
00705 UINT64 LU32(AR_INT_64 *vp)
00706 {
00707 return((((UINT64) vp->part3) << 16) | (((UINT64) vp->part4)));
00708 }
00709
00710
00711
00712
00713
00714 #define is_zero32(v) (DSEXT32(v) == 0)
00715 #define is_neg32(v) (((v) & 0x80000000) != 0)
00716
00717
00718
00719
00720
00721 static SINT64 _dshiftl32(SINT64 op1, SINT64 op2, SINT64 shcnt)
00722 {
00723 SINT64 rshcnt = ((SINT64) 32) - shcnt;
00724
00725 op2 &= 0xFFFFFFFF;
00726 return(((op1 << shcnt) | (op2 >> rshcnt)) & 0xFFFFFFFF);
00727 }
00728
00729 static SINT64 _dshiftr32(SINT64 op1, SINT64 op2, SINT64 shcnt)
00730 {
00731 SINT64 rshcnt = ((SINT64) 32) - shcnt;
00732
00733 op2 &= 0xFFFFFFFF;
00734 return(((op1 << rshcnt) | (op2 >> shcnt)) & 0xFFFFFFFF);
00735 }
00736
00737 static SINT64 _mask32(SINT64 bits)
00738 {
00739 bits &= 0xFFFFFFFF;
00740 if (bits > 0 && bits < 32)
00741 return((SINT64) ((0xFFFFFFFF << (((SINT64) 32) - bits)) & 0xFFFFFFFF));
00742 else if (bits >= 32 && bits < 64)
00743 return((SINT64) (((UINT64) 0xFFFFFFFF) >> (bits - 32)));
00744 return(0);
00745 }
00746
00747 static SINT64 _leadz32(SINT64 val)
00748 {
00749 int lz_bits;
00750
00751 val <<= 32;
00752 if (val == 0)
00753 return(32);
00754 for (lz_bits = 0; val >= 0; val <<= 1) {
00755 lz_bits++;
00756 }
00757 return((SINT64) lz_bits);
00758 }
00759
00760 static SINT64 _popcnt32(SINT64 val)
00761 {
00762 int pop_bits, bit_count;
00763
00764 for (pop_bits = bit_count = 0;
00765 bit_count < 32;
00766 pop_bits += val & 0x1, val >>= 1, bit_count++)
00767 ;
00768 return((SINT64) pop_bits);
00769 }
00770
00771 static SINT64 _poppar32(SINT64 val)
00772 {
00773 return(_popcnt32(val) & ((SINT64) 0x1));
00774 }
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 SINT64 DSEXT46(SINT64 v)
00788 {
00789 return(v);
00790 }
00791
00792 SINT64 SEXT46(SINT64 v)
00793 {
00794 return(v);
00795 }
00796
00797
00798
00799
00800
00801 #define is_zero46(v) ((v) == 0)
00802 #define is_neg46(v) ((v) < 0)
00803
00804
00805
00806
00807
00808
00809 static SINT64 _dshiftl46(SINT64 op1, SINT64 op2, SINT64 shcnt)
00810 {
00811 return(_dshiftl(op1, op2, shcnt));
00812 }
00813
00814 static SINT64 _dshiftr46(SINT64 op1, SINT64 op2, SINT64 shcnt)
00815 {
00816 return(_dshiftr(op1, op2, shcnt));
00817 }
00818
00819 static SINT64 _mask46(SINT64 bits)
00820 {
00821 return(_mask(bits));
00822 }
00823
00824 static SINT64 _leadz46(SINT64 val)
00825 {
00826 return(_leadz(val));
00827 }
00828
00829 static SINT64 _popcnt46(SINT64 val)
00830 {
00831 return(_popcnt(val));
00832 }
00833
00834 static SINT64 _poppar46(SINT64 val)
00835 {
00836 return(_poppar(val));
00837 }
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850 SINT64 DSEXT64(SINT64 v)
00851 {
00852 return(v);
00853 }
00854
00855 SINT64 SEXT64(SINT64 v)
00856 {
00857 return(v);
00858 }
00859
00860
00861
00862
00863
00864 #define is_zero64(v) ((v) == 0)
00865 #define is_neg64(v) ((v) < 0)
00866
00867
00868
00869
00870
00871
00872 static SINT64 _dshiftl64(SINT64 op1, SINT64 op2, SINT64 shcnt)
00873 {
00874 return(_dshiftl(op1, op2, shcnt));
00875 }
00876
00877 static SINT64 _dshiftr64(SINT64 op1, SINT64 op2, SINT64 shcnt)
00878 {
00879 return(_dshiftr(op1, op2, shcnt));
00880 }
00881
00882 static SINT64 _mask64(SINT64 bits)
00883 {
00884 return(_mask(bits));
00885 }
00886
00887 static SINT64 _leadz64(SINT64 val)
00888 {
00889 return(_leadz(val));
00890 }
00891
00892 static SINT64 _popcnt64(SINT64 val)
00893 {
00894 return(_popcnt(val));
00895 }
00896
00897 static SINT64 _poppar64(SINT64 val)
00898 {
00899 return(_poppar(val));
00900 }
00901
00902
00903 main()
00904 {
00905 test_bitor();
00906 test_bitand();
00907 test_bitxor();
00908 test_bitcomplement();
00909 test_shiftl();
00910 test_shiftr();
00911 test_dshiftl();
00912 test_dshiftr();
00913 test_ishft();
00914 test_ishftc();
00915 test_ibits();
00916 test_mask();
00917 test_leadz();
00918 test_popcnt();
00919 test_poppar();
00920 test_arstatus();
00921 test_add();
00922 test_subtract();
00923 test_negate();
00924 test_abs();
00925 test_multiply();
00926 test_divide();
00927 test_modulo();
00928 test_compare();
00929 exit(0);
00930 }
00931
00932
00933
00934
00935
00936
00937
00938
00939 #define TEST_BINARY_BIT_OP_SIGNED(size, opr, func) \
00940 do { \
00941 int i, j; \
00942 \
00943 printf(" Testing: SIGNED %2d INT %-10s: ", size, #opr); \
00944 \
00945 for (i=0; i<num_cool_ints; i++) \
00946 { \
00947 for (j=0; j<num_cool_ints; j++) \
00948 { \
00949 act_result[j] = DSEXT##size(LS##size(&cool_ints[i]) opr \
00950 LS##size(&cool_ints[j])); \
00951 \
00952 act_status[j] = is_zero##size(act_result[j]) \
00953 ? AR_STAT_ZERO : AR_STAT_OK; \
00954 if (is_neg##size(act_result[j])) \
00955 act_status[j] |= AR_STAT_NEGATIVE; \
00956 \
00957 test_result[j].part1 = 0; \
00958 test_result[j].part2 = 0; \
00959 test_result[j].part3 = 0; \
00960 test_result[j].part4 = 0; \
00961 \
00962 test_status[j] = func((AR_DATA *)&test_result[j], \
00963 &sint##size##_artype, \
00964 (AR_DATA *)&cool_ints[i], \
00965 &sint##size##_artype, \
00966 (AR_DATA *)&cool_ints[j], \
00967 &sint##size##_artype); \
00968 \
00969 if (LU64(&test_result[j]) != act_result[j]) \
00970 { \
00971 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
00972 abort(); \
00973 } \
00974 \
00975 if (act_status[j] != test_status[j]) \
00976 { \
00977 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
00978 abort(); \
00979 } \
00980 } \
00981 } \
00982 \
00983 printf("PASSED\n"); \
00984 } while (0)
00985
00986
00987 #define TEST_BINARY_BIT_OP_UNSIGNED(size, opr, func) \
00988 do { \
00989 int i, j; \
00990 \
00991 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, #opr); \
00992 \
00993 for (i=0; i<num_cool_ints; i++) \
00994 { \
00995 for (j=0; j<num_cool_ints; j++) \
00996 { \
00997 act_result[j] = DSEXT##size(LU##size(&cool_ints[i]) opr \
00998 LU##size(&cool_ints[j])); \
00999 \
01000 act_status[j] = is_zero##size(act_result[j]) \
01001 ? AR_STAT_ZERO \
01002 : AR_STAT_OK; \
01003 \
01004 test_result[j].part1 = 0; \
01005 test_result[j].part2 = 0; \
01006 test_result[j].part3 = 0; \
01007 test_result[j].part4 = 0; \
01008 \
01009 test_status[j] = func((AR_DATA *)&test_result[j], \
01010 &uint##size##_artype, \
01011 (AR_DATA *)&cool_ints[i], \
01012 &uint##size##_artype, \
01013 (AR_DATA *)&cool_ints[j], \
01014 &uint##size##_artype); \
01015 \
01016 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
01017 { \
01018 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
01019 abort(); \
01020 } \
01021 \
01022 if (act_status[j] != test_status[j]) \
01023 { \
01024 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
01025 abort(); \
01026 } \
01027 } \
01028 } \
01029 \
01030 printf("PASSED\n"); \
01031 } while (0)
01032
01033
01034 #define TEST_BINARY_BIT_OP_TYPES(opr, func) \
01035 do { \
01036 int i, j, k; \
01037 \
01038 printf(" Testing: types %-10s: ", #opr); \
01039 \
01040 for (i=0; i<num_ar_types; i++) \
01041 { \
01042 for (j=0; j<num_ar_types; j++) \
01043 { \
01044 for (k=0; k<num_ar_types; k++) \
01045 { \
01046 act_status[k] = AR_STAT_OK; \
01047 if (ar_types[i] != ar_types[j] || \
01048 ar_types[j] != ar_types[k] || \
01049 !IS_SUPPORTED_INT_TYPE(ar_types[i])) \
01050 act_status[k] = AR_STAT_INVALID_TYPE; \
01051 \
01052 test_status[k] = func((AR_DATA *)&test_result[1], \
01053 &ar_types[i], \
01054 (AR_DATA *)&cool_ints[1], \
01055 &ar_types[j], \
01056 (AR_DATA *)&cool_ints[1], \
01057 &ar_types[k]); \
01058 \
01059 if ((act_status[k] ^ test_status[k]) & \
01060 AR_STAT_INVALID_TYPE) \
01061 { \
01062 printf(" ERROR: incorrect status at %d,%d,%d\n", \
01063 i, j, k); \
01064 abort(); \
01065 } \
01066 } \
01067 } \
01068 } \
01069 \
01070 printf("PASSED\n"); \
01071 } while (0)
01072
01073
01074 #define TEST_UNARY_BIT_OP_SIGNED(size, opr, func) \
01075 do { \
01076 int j; \
01077 \
01078 printf(" Testing: SIGNED %2d INT %-10s: ", size, #opr); \
01079 \
01080 for (j=0; j<num_cool_ints; j++) \
01081 { \
01082 act_result[j] = DSEXT##size(opr LS##size(&cool_ints[j])); \
01083 \
01084 act_status[j] = is_zero##size(act_result[j]) \
01085 ? AR_STAT_ZERO \
01086 : AR_STAT_OK; \
01087 if (is_neg##size(act_result[j])) \
01088 act_status[j] |= AR_STAT_NEGATIVE; \
01089 \
01090 test_result[j].part1 = 0; \
01091 test_result[j].part2 = 0; \
01092 test_result[j].part3 = 0; \
01093 test_result[j].part4 = 0; \
01094 \
01095 test_status[j] = func((AR_DATA *)&test_result[j], \
01096 &sint##size##_artype, \
01097 (AR_DATA *)&cool_ints[j], \
01098 &sint##size##_artype); \
01099 \
01100 if (LU64(&test_result[j]) != act_result[j]) \
01101 { \
01102 printf(" ERROR: incorrect result at %d\n", j); \
01103 abort(); \
01104 } \
01105 \
01106 if (act_status[j] != test_status[j]) \
01107 { \
01108 printf(" ERROR: incorrect status at %d\n", j); \
01109 abort(); \
01110 } \
01111 } \
01112 \
01113 printf("PASSED\n"); \
01114 } while (0)
01115
01116
01117 #define TEST_UNARY_BIT_OP_UNSIGNED(size, opr, func) \
01118 do { \
01119 int j; \
01120 \
01121 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, #opr); \
01122 \
01123 for (j=0; j<num_cool_ints; j++) \
01124 { \
01125 act_result[j] = DSEXT##size(opr LU##size(&cool_ints[j])); \
01126 \
01127 act_status[j] = is_zero##size(act_result[j]) \
01128 ? AR_STAT_ZERO \
01129 : AR_STAT_OK; \
01130 \
01131 test_result[j].part1 = 0; \
01132 test_result[j].part2 = 0; \
01133 test_result[j].part3 = 0; \
01134 test_result[j].part4 = 0; \
01135 \
01136 test_status[j] = func((AR_DATA *)&test_result[j], \
01137 &uint##size##_artype, \
01138 (AR_DATA *)&cool_ints[j], \
01139 &uint##size##_artype); \
01140 \
01141 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
01142 { \
01143 printf(" ERROR: incorrect result at %d\n", j); \
01144 abort(); \
01145 } \
01146 \
01147 if (act_status[j] != test_status[j]) \
01148 { \
01149 printf(" ERROR: incorrect status at %d\n", j); \
01150 abort(); \
01151 } \
01152 } \
01153 \
01154 printf("PASSED\n"); \
01155 } while (0)
01156
01157
01158 #define TEST_UNARY_BIT_OP_TYPES(opr, func) \
01159 do { \
01160 int j, k; \
01161 \
01162 printf(" Testing: types %-10s: ", #opr); \
01163 \
01164 for (j=0; j<num_ar_types; j++) \
01165 { \
01166 for (k=0; k<num_ar_types; k++) \
01167 { \
01168 act_status[k] = AR_STAT_OK; \
01169 if (ar_types[j] != ar_types[k] || \
01170 !IS_SUPPORTED_INT_TYPE(ar_types[j])) \
01171 act_status[k] = AR_STAT_INVALID_TYPE; \
01172 \
01173 test_status[k] = func((AR_DATA *)&test_result[1], \
01174 &ar_types[j], \
01175 (AR_DATA *)&cool_ints[1], \
01176 &ar_types[k]); \
01177 \
01178 if ((act_status[k] ^ test_status[k]) & \
01179 AR_STAT_INVALID_TYPE) \
01180 { \
01181 printf(" ERROR: incorrect status at %d,%d\n", j, k); \
01182 abort(); \
01183 } \
01184 } \
01185 } \
01186 \
01187 printf("PASSED\n"); \
01188 } while (0)
01189
01190
01191 test_bitor()
01192 {
01193
01194 TEST_BINARY_BIT_OP_SIGNED( 8, |, AR_bitor );
01195 TEST_BINARY_BIT_OP_UNSIGNED( 8, |, AR_bitor );
01196
01197 TEST_BINARY_BIT_OP_SIGNED( 16, |, AR_bitor );
01198 TEST_BINARY_BIT_OP_UNSIGNED(16, |, AR_bitor );
01199
01200 TEST_BINARY_BIT_OP_SIGNED( 32, |, AR_bitor );
01201 TEST_BINARY_BIT_OP_UNSIGNED(32, |, AR_bitor );
01202
01203 TEST_BINARY_BIT_OP_SIGNED( 46, |, AR_bitor );
01204
01205 TEST_BINARY_BIT_OP_SIGNED( 64, |, AR_bitor );
01206 TEST_BINARY_BIT_OP_UNSIGNED(64, |, AR_bitor );
01207
01208 TEST_BINARY_BIT_OP_TYPES( |, AR_bitor );
01209
01210 }
01211
01212
01213 test_bitand()
01214 {
01215
01216 TEST_BINARY_BIT_OP_SIGNED( 8, &, AR_bitand);
01217 TEST_BINARY_BIT_OP_UNSIGNED( 8, &, AR_bitand);
01218
01219 TEST_BINARY_BIT_OP_SIGNED( 16, &, AR_bitand);
01220 TEST_BINARY_BIT_OP_UNSIGNED(16, &, AR_bitand);
01221
01222 TEST_BINARY_BIT_OP_SIGNED( 32, &, AR_bitand);
01223 TEST_BINARY_BIT_OP_UNSIGNED(32, &, AR_bitand);
01224
01225 TEST_BINARY_BIT_OP_SIGNED( 46, &, AR_bitand);
01226
01227 TEST_BINARY_BIT_OP_SIGNED( 64, &, AR_bitand);
01228 TEST_BINARY_BIT_OP_UNSIGNED(64, &, AR_bitand);
01229
01230 TEST_BINARY_BIT_OP_TYPES( &, AR_bitand);
01231
01232 }
01233
01234
01235 test_bitxor()
01236 {
01237
01238 TEST_BINARY_BIT_OP_SIGNED( 8, ^, AR_bitxor);
01239 TEST_BINARY_BIT_OP_UNSIGNED( 8, ^, AR_bitxor);
01240
01241 TEST_BINARY_BIT_OP_SIGNED( 16, ^, AR_bitxor);
01242 TEST_BINARY_BIT_OP_UNSIGNED(16, ^, AR_bitxor);
01243
01244 TEST_BINARY_BIT_OP_SIGNED( 32, ^, AR_bitxor);
01245 TEST_BINARY_BIT_OP_UNSIGNED(32, ^, AR_bitxor);
01246
01247 TEST_BINARY_BIT_OP_SIGNED( 46, ^, AR_bitxor);
01248
01249 TEST_BINARY_BIT_OP_SIGNED( 64, ^, AR_bitxor);
01250 TEST_BINARY_BIT_OP_UNSIGNED(64, ^, AR_bitxor);
01251
01252 TEST_BINARY_BIT_OP_TYPES( ^, AR_bitxor);
01253
01254 }
01255
01256
01257 test_bitcomplement()
01258 {
01259
01260 TEST_UNARY_BIT_OP_SIGNED( 8, ~, AR_bitcomplement);
01261 TEST_UNARY_BIT_OP_UNSIGNED( 8, ~, AR_bitcomplement);
01262
01263 TEST_UNARY_BIT_OP_SIGNED( 16, ~, AR_bitcomplement);
01264 TEST_UNARY_BIT_OP_UNSIGNED(16, ~, AR_bitcomplement);
01265
01266 TEST_UNARY_BIT_OP_SIGNED( 32, ~, AR_bitcomplement);
01267 TEST_UNARY_BIT_OP_UNSIGNED(32, ~, AR_bitcomplement);
01268
01269 TEST_UNARY_BIT_OP_SIGNED( 46, ~, AR_bitcomplement);
01270
01271 TEST_UNARY_BIT_OP_SIGNED( 64, ~, AR_bitcomplement);
01272 TEST_UNARY_BIT_OP_UNSIGNED(64, ~, AR_bitcomplement);
01273
01274 TEST_UNARY_BIT_OP_TYPES( ~, AR_bitcomplement);
01275
01276 }
01277
01278
01279 #undef TEST_BINARY_BIT_OP_SIGNED
01280 #undef TEST_BINARY_BIT_OP_UNSIGNED
01281 #undef TEST_BINARY_BIT_OP_TYPES
01282 #undef TEST_UNARY_BIT_OP_SIGNED
01283 #undef TEST_UNARY_BIT_OP_UNSIGNED
01284 #undef TEST_UNARY_BIT_OP_TYPES
01285
01286
01287
01288
01289
01290
01291
01292
01293 #define TEST_SHIFT_OP_SIGNED(size, max_shift, opr, func) \
01294 do { \
01295 int i, j; \
01296 \
01297 printf(" Testing: SIGNED %2d INT %-10s: ", size, #opr); \
01298 \
01299 for (i=0; i<num_cool_ints; i++) \
01300 { \
01301 for (j=0; j<num_cool_ints; j++) \
01302 { \
01303 if (LS##size(&cool_ints[j]) >= max_shift || \
01304 LS##size(&cool_ints[j]) < 0) \
01305 { \
01306 act_status[j] = AR_STAT_UNDEFINED; \
01307 act_result[j] = 0; \
01308 } \
01309 else \
01310 { \
01311 act_result[j] = DSEXT##size(LS##size(&cool_ints[i]) opr \
01312 LS##size(&cool_ints[j])); \
01313 \
01314 if (size >= 46 && \
01315 strcmp(#opr, ">>") == 0 && \
01316 LS64(&cool_ints[i]) < 0) \
01317 { \
01318 \
01319 act_result[j] |= (SINT64) \
01320 ~(-1 >> LS46(&cool_ints[j])); \
01321 } \
01322 \
01323 act_status[j] = is_zero##size(act_result[j]) \
01324 ? AR_STAT_ZERO \
01325 : AR_STAT_OK; \
01326 if (is_neg##size(act_result[j])) \
01327 act_status[j] |= AR_STAT_NEGATIVE; \
01328 } \
01329 \
01330 test_result[j].part1 = 0; \
01331 test_result[j].part2 = 0; \
01332 test_result[j].part3 = 0; \
01333 test_result[j].part4 = 0; \
01334 \
01335 test_status[j] = func((AR_DATA *)&test_result[j], \
01336 &sint##size##_artype, \
01337 (AR_DATA *)&cool_ints[i], \
01338 &sint##size##_artype, \
01339 (AR_DATA *)&cool_ints[j], \
01340 &sint##size##_artype); \
01341 \
01342 if (LU64(&test_result[j]) != act_result[j]) \
01343 { \
01344 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
01345 abort(); \
01346 } \
01347 \
01348 if (act_status[j] != test_status[j]) \
01349 { \
01350 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
01351 abort(); \
01352 } \
01353 } \
01354 } \
01355 \
01356 printf("PASSED\n"); \
01357 } while (0)
01358
01359
01360 #define TEST_SHIFT_OP_UNSIGNED(size, max_shift, opr, func) \
01361 do { \
01362 int i, j; \
01363 \
01364 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, #opr); \
01365 \
01366 for (i=0; i<num_cool_ints; i++) \
01367 { \
01368 for (j=0; j<num_cool_ints; j++) \
01369 { \
01370 if (LU##size(&cool_ints[j]) >= max_shift) \
01371 { \
01372 act_status[j] = AR_STAT_UNDEFINED; \
01373 act_result[j] = 0; \
01374 } \
01375 else \
01376 { \
01377 act_result[j] = DSEXT##size(LU##size(&cool_ints[i]) opr \
01378 LU##size(&cool_ints[j])); \
01379 \
01380 act_status[j] = is_zero##size(act_result[j]) \
01381 ? AR_STAT_ZERO \
01382 : AR_STAT_OK; \
01383 } \
01384 \
01385 test_result[j].part1 = 0; \
01386 test_result[j].part2 = 0; \
01387 test_result[j].part3 = 0; \
01388 test_result[j].part4 = 0; \
01389 \
01390 test_status[j] = func((AR_DATA *)&test_result[j], \
01391 &uint##size##_artype, \
01392 (AR_DATA *)&cool_ints[i], \
01393 &uint##size##_artype, \
01394 (AR_DATA *)&cool_ints[j], \
01395 &uint##size##_artype); \
01396 \
01397 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
01398 { \
01399 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
01400 abort(); \
01401 } \
01402 \
01403 if (act_status[j] != test_status[j]) \
01404 { \
01405 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
01406 abort(); \
01407 } \
01408 } \
01409 } \
01410 \
01411 printf("PASSED\n"); \
01412 } while (0)
01413
01414
01415 #define TEST_SHIFT_OP_TYPES(opr, func) \
01416 do { \
01417 int i, j, k; \
01418 \
01419 printf(" Testing: types %-10s: ", #opr); \
01420 \
01421 for (i=0; i<num_ar_types; i++) \
01422 { \
01423 for (j=0; j<num_ar_types; j++) \
01424 { \
01425 for (k=0; k<num_ar_types; k++) \
01426 { \
01427 act_status[k] = AR_STAT_OK; \
01428 if (ar_types[i] != ar_types[j] || \
01429 !IS_SUPPORTED_INT_TYPE(ar_types[i])) \
01430 act_status[k] = AR_STAT_INVALID_TYPE; \
01431 \
01432 test_status[k] = func((AR_DATA *)&test_result[1], \
01433 &ar_types[i], \
01434 (AR_DATA *)&cool_ints[1], \
01435 &ar_types[j], \
01436 (AR_DATA *)&cool_ints[1], \
01437 &ar_types[k]); \
01438 \
01439 if ((act_status[k] ^ test_status[k]) & \
01440 AR_STAT_INVALID_TYPE) \
01441 { \
01442 printf(" ERROR: incorrect status at %d,%d,%d\n", \
01443 i, j, k); \
01444 abort(); \
01445 } \
01446 } \
01447 } \
01448 } \
01449 \
01450 printf("PASSED\n"); \
01451 } while (0)
01452
01453
01454 test_shiftl()
01455 {
01456
01457 TEST_SHIFT_OP_SIGNED( 8, 8, <<, AR_shiftl);
01458 TEST_SHIFT_OP_UNSIGNED( 8, 8, <<, AR_shiftl);
01459
01460 TEST_SHIFT_OP_SIGNED( 16, 16, <<, AR_shiftl);
01461 TEST_SHIFT_OP_UNSIGNED(16, 16, <<, AR_shiftl);
01462
01463 TEST_SHIFT_OP_SIGNED( 32, 32, <<, AR_shiftl);
01464 TEST_SHIFT_OP_UNSIGNED(32, 32, <<, AR_shiftl);
01465
01466 TEST_SHIFT_OP_SIGNED( 46, 64, <<, AR_shiftl);
01467
01468 TEST_SHIFT_OP_SIGNED( 64, 64, <<, AR_shiftl);
01469 TEST_SHIFT_OP_UNSIGNED(64, 64, <<, AR_shiftl);
01470
01471 TEST_SHIFT_OP_TYPES( <<, AR_shiftl);
01472
01473 }
01474
01475
01476 test_shiftr()
01477 {
01478
01479 TEST_SHIFT_OP_SIGNED( 8, 8, >>, AR_shiftr);
01480 TEST_SHIFT_OP_UNSIGNED( 8, 8, >>, AR_shiftr);
01481
01482 TEST_SHIFT_OP_SIGNED( 16, 16, >>, AR_shiftr);
01483 TEST_SHIFT_OP_UNSIGNED(16, 16, >>, AR_shiftr);
01484
01485 TEST_SHIFT_OP_SIGNED( 32, 32, >>, AR_shiftr);
01486 TEST_SHIFT_OP_UNSIGNED(32, 32, >>, AR_shiftr);
01487
01488 TEST_SHIFT_OP_SIGNED( 46, 64, >>, AR_shiftr);
01489
01490 TEST_SHIFT_OP_SIGNED( 64, 64, >>, AR_shiftr);
01491 TEST_SHIFT_OP_UNSIGNED(64, 64, >>, AR_shiftr);
01492
01493 TEST_SHIFT_OP_TYPES( >>, AR_shiftr);
01494
01495 }
01496
01497
01498 #undef TEST_SHIFT_OP_SIGNED
01499 #undef TEST_SHIFT_OP_UNSIGNED
01500 #undef TEST_SHIFT_OP_TYPES
01501
01502
01503 #define TEST_DSHIFT_OP_SIGNED(size, max_shift, opr) \
01504 do { \
01505 int i, j, k; \
01506 \
01507 printf(" Testing: SIGNED %2d INT %-10s: ", size, #opr); \
01508 \
01509 for (i=0; i<num_cool_ints; i++) \
01510 { \
01511 for (j=0; j<num_cool_ints; j++) \
01512 { \
01513 for (k=0; k<num_dshift_vals; k++) \
01514 { \
01515 if (LS##size(&dshift_vals[k]) > max_shift || \
01516 LS##size(&dshift_vals[k]) < 0) \
01517 { \
01518 act_status[k] = AR_STAT_UNDEFINED; \
01519 act_result[k] = 0; \
01520 } \
01521 else \
01522 { \
01523 act_result[k] = DSEXT##size( \
01524 opr##size( \
01525 LS##size(&cool_ints[i]), \
01526 LS##size(&cool_ints[j]), \
01527 LS##size(&dshift_vals[k]))); \
01528 \
01529 act_status[k] = is_zero##size(act_result[k]) \
01530 ? AR_STAT_ZERO \
01531 : AR_STAT_OK; \
01532 if (is_neg##size(act_result[k])) \
01533 act_status[k] |= AR_STAT_NEGATIVE; \
01534 } \
01535 \
01536 test_result[k].part1 = 0; \
01537 test_result[k].part2 = 0; \
01538 test_result[k].part3 = 0; \
01539 test_result[k].part4 = 0; \
01540 \
01541 test_status[k] = AR##opr((AR_DATA *)&test_result[k], \
01542 &sint##size##_artype, \
01543 (AR_DATA *)&cool_ints[i], \
01544 &sint##size##_artype, \
01545 (AR_DATA *)&cool_ints[j], \
01546 &sint##size##_artype, \
01547 (AR_DATA *)&dshift_vals[k], \
01548 &sint##size##_artype); \
01549 \
01550 if (LU64(&test_result[k]) != (UINT64)act_result[k]) \
01551 { \
01552 printf(" ERROR: incorrect result at %d,%d,%d\n", \
01553 i, j, k); \
01554 abort(); \
01555 } \
01556 \
01557 if (act_status[k] != test_status[k]) \
01558 { \
01559 printf(" ERROR: incorrect status at %d,%d,%d\n", \
01560 i, j, k); \
01561 abort(); \
01562 } \
01563 } \
01564 } \
01565 } \
01566 \
01567 printf("PASSED\n"); \
01568 } while (0)
01569
01570
01571 #define TEST_DSHIFT_OP_UNSIGNED(size, max_shift, opr) \
01572 do { \
01573 int i, j, k; \
01574 \
01575 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, #opr); \
01576 \
01577 for (i=0; i<num_cool_ints; i++) \
01578 { \
01579 for (j=0; j<num_cool_ints; j++) \
01580 { \
01581 for (k=0; k<num_dshift_vals; k++) \
01582 { \
01583 if (LU##size(&dshift_vals[k]) > max_shift) \
01584 { \
01585 act_status[k] = AR_STAT_UNDEFINED; \
01586 act_result[k] = 0; \
01587 } \
01588 else \
01589 { \
01590 act_result[k] = DSEXT##size( \
01591 opr##size( \
01592 LU##size(&cool_ints[i]), \
01593 LU##size(&cool_ints[j]), \
01594 LU##size(&dshift_vals[k]))); \
01595 \
01596 act_status[k] = is_zero##size(act_result[k]) \
01597 ? AR_STAT_ZERO \
01598 : AR_STAT_OK; \
01599 } \
01600 \
01601 test_result[k].part1 = 0; \
01602 test_result[k].part2 = 0; \
01603 test_result[k].part3 = 0; \
01604 test_result[k].part4 = 0; \
01605 \
01606 test_status[k] = AR##opr((AR_DATA *)&test_result[k], \
01607 &uint##size##_artype, \
01608 (AR_DATA *)&cool_ints[i], \
01609 &uint##size##_artype, \
01610 (AR_DATA *)&cool_ints[j], \
01611 &uint##size##_artype, \
01612 (AR_DATA *)&dshift_vals[k], \
01613 &uint##size##_artype); \
01614 \
01615 if (LU64(&test_result[k]) != (UINT64)act_result[k]) \
01616 { \
01617 printf(" ERROR: incorrect result at %d,%d,%d\n", \
01618 i, j, k); \
01619 abort(); \
01620 } \
01621 \
01622 if (act_status[k] != test_status[k]) \
01623 { \
01624 printf(" ERROR: incorrect status at %d,%d,%d\n", \
01625 i, j, k); \
01626 abort(); \
01627 } \
01628 } \
01629 } \
01630 } \
01631 \
01632 printf("PASSED\n"); \
01633 } while (0)
01634
01635
01636 #define TEST_DSHIFT_OP_TYPES(opr) \
01637 do { \
01638 int h, i, j, k; \
01639 \
01640 printf(" Testing: types %-10s: ", #opr); \
01641 \
01642 for (h=0; h<num_ar_types; h++) \
01643 { \
01644 for (i=0; i<num_ar_types; i++) \
01645 { \
01646 for (j=0; j<num_ar_types; j++) \
01647 { \
01648 for (k=0; k<num_ar_types; k++) \
01649 { \
01650 act_status[k] = AR_STAT_OK; \
01651 if (ar_types[h] != ar_types[i] || \
01652 ar_types[i] != ar_types[j] || \
01653 !IS_SUPPORTED_INT_TYPE(ar_types[h])) \
01654 act_status[k] = AR_STAT_INVALID_TYPE; \
01655 \
01656 test_status[k] = AR##opr((AR_DATA *)&test_result[1], \
01657 &ar_types[h], \
01658 (AR_DATA *)&cool_ints[1], \
01659 &ar_types[i], \
01660 (AR_DATA *)&cool_ints[1], \
01661 &ar_types[j], \
01662 (AR_DATA *)&dshift_vals[1], \
01663 &ar_types[k]); \
01664 \
01665 if ((act_status[k] ^ test_status[k]) & \
01666 AR_STAT_INVALID_TYPE) { \
01667 printf(" ERROR: incorrect status at " \
01668 "%d,%d,%d,%d\n", \
01669 h, i, j, k); \
01670 abort(); \
01671 } \
01672 } \
01673 } \
01674 } \
01675 } \
01676 \
01677 printf("PASSED\n"); \
01678 } while (0)
01679
01680
01681 test_dshiftl()
01682 {
01683
01684 TEST_DSHIFT_OP_SIGNED( 8, 8, _dshiftl);
01685 TEST_DSHIFT_OP_UNSIGNED( 8, 8, _dshiftl);
01686
01687 TEST_DSHIFT_OP_SIGNED( 16, 16, _dshiftl);
01688 TEST_DSHIFT_OP_UNSIGNED(16, 16, _dshiftl);
01689
01690 TEST_DSHIFT_OP_SIGNED( 32, 32, _dshiftl);
01691 TEST_DSHIFT_OP_UNSIGNED(32, 32, _dshiftl);
01692
01693 TEST_DSHIFT_OP_SIGNED( 46, 64, _dshiftl);
01694
01695 TEST_DSHIFT_OP_SIGNED( 64, 64, _dshiftl);
01696 TEST_DSHIFT_OP_UNSIGNED(64, 64, _dshiftl);
01697
01698 TEST_DSHIFT_OP_TYPES( _dshiftl);
01699
01700 }
01701
01702
01703 test_dshiftr()
01704 {
01705
01706 TEST_DSHIFT_OP_SIGNED( 8, 8, _dshiftr);
01707 TEST_DSHIFT_OP_UNSIGNED( 8, 8, _dshiftr);
01708
01709 TEST_DSHIFT_OP_SIGNED( 16, 16, _dshiftr);
01710 TEST_DSHIFT_OP_UNSIGNED(16, 16, _dshiftr);
01711
01712 TEST_DSHIFT_OP_SIGNED( 32, 32, _dshiftr);
01713 TEST_DSHIFT_OP_UNSIGNED(32, 32, _dshiftr);
01714
01715 TEST_DSHIFT_OP_SIGNED( 46, 64, _dshiftr);
01716
01717 TEST_DSHIFT_OP_SIGNED( 64, 64, _dshiftr);
01718 TEST_DSHIFT_OP_UNSIGNED(64, 64, _dshiftr);
01719
01720 TEST_DSHIFT_OP_TYPES( _dshiftr);
01721
01722 }
01723
01724
01725 #undef TEST_DSHIFT_OP_SIGNED
01726 #undef TEST_DSHIFT_OP_UNSIGNED
01727 #undef TEST_DSHIFT_OP_TYPES
01728
01729
01730 static
01731 void
01732 test_ishft_signed(int size)
01733 {
01734 int i, j;
01735
01736 printf(" Testing: SIGNED %2d INT %-10s: ", size, "ISHFT");
01737
01738 for (i=0; i<num_cool_ints; i++)
01739 {
01740 for (j=0; j<num_cool_ints; j++)
01741 {
01742 SINT64 shift;
01743
01744 test_result[j].part1 = 0;
01745 test_result[j].part2 = 0;
01746 test_result[j].part3 = 0;
01747 test_result[j].part4 = 0;
01748
01749 switch (size)
01750 {
01751 case 8:
01752 shift = LS8(&cool_ints[j]);
01753 if ((shift > 0 && shift > size) ||
01754 (shift < 0 && shift < -size))
01755 {
01756 act_status[j] = AR_STAT_UNDEFINED;
01757 act_result[j] = 0;
01758 }
01759 else
01760 {
01761 if (shift > 0)
01762 act_result[j] = DSEXT8(LU8(&cool_ints[i]) <<
01763 shift);
01764 else
01765 act_result[j] = DSEXT8(LU8(&cool_ints[i]) >>
01766 (-shift));
01767
01768 act_status[j] = is_zero8(act_result[j])
01769 ? AR_STAT_ZERO
01770 : AR_STAT_OK;
01771 if (is_neg8(act_result[j]))
01772 act_status[j] |= AR_STAT_NEGATIVE;
01773 }
01774
01775 test_status[j] = AR_ishft((AR_DATA *)&test_result[j],
01776 &sint8_artype,
01777 (AR_DATA *)&cool_ints[i],
01778 &sint8_artype,
01779 (AR_DATA *)&cool_ints[j],
01780 &sint8_artype);
01781 break;
01782
01783 case 16:
01784 shift = LS16(&cool_ints[j]);
01785 if ((shift > 0 && shift > size) ||
01786 (shift < 0 && shift < -size))
01787 {
01788 act_status[j] = AR_STAT_UNDEFINED;
01789 act_result[j] = 0;
01790 }
01791 else
01792 {
01793 if (shift > 0)
01794 act_result[j] = DSEXT16(LU16(&cool_ints[i]) <<
01795 shift);
01796 else
01797 act_result[j] = DSEXT16(LU16(&cool_ints[i]) >>
01798 (-shift));
01799
01800 act_status[j] = is_zero16(act_result[j])
01801 ? AR_STAT_ZERO
01802 : AR_STAT_OK;
01803 if (is_neg16(act_result[j]))
01804 act_status[j] |= AR_STAT_NEGATIVE;
01805 }
01806
01807 test_status[j] = AR_ishft((AR_DATA *)&test_result[j],
01808 &sint16_artype,
01809 (AR_DATA *)&cool_ints[i],
01810 &sint16_artype,
01811 (AR_DATA *)&cool_ints[j],
01812 &sint16_artype);
01813 break;
01814
01815 case 32:
01816 shift = LS32(&cool_ints[j]);
01817 if ((shift > 0 && shift > size) ||
01818 (shift < 0 && shift < -size))
01819 {
01820 act_status[j] = AR_STAT_UNDEFINED;
01821 act_result[j] = 0;
01822 }
01823 else
01824 {
01825 if (shift > 0)
01826 act_result[j] = DSEXT32(LU32(&cool_ints[i]) <<
01827 shift);
01828 else
01829 act_result[j] = DSEXT32(LU32(&cool_ints[i]) >>
01830 (-shift));
01831
01832 act_status[j] = is_zero32(act_result[j])
01833 ? AR_STAT_ZERO
01834 : AR_STAT_OK;
01835 if (is_neg32(act_result[j]))
01836 act_status[j] |= AR_STAT_NEGATIVE;
01837 }
01838
01839 test_status[j] = AR_ishft((AR_DATA *)&test_result[j],
01840 &sint32_artype,
01841 (AR_DATA *)&cool_ints[i],
01842 &sint32_artype,
01843 (AR_DATA *)&cool_ints[j],
01844 &sint32_artype);
01845 break;
01846
01847 case 46:
01848 case 64:
01849 shift = LS64(&cool_ints[j]);
01850 if ((shift > 0 && shift > 64) ||
01851 (shift < 0 && shift < -64))
01852 {
01853 act_status[j] = AR_STAT_UNDEFINED;
01854 act_result[j] = 0;
01855 }
01856 else
01857 {
01858 if (shift > 0)
01859 #if defined __sun
01860 act_result[j] = DSEXT64(shftl64(LU64(&cool_ints[i]),
01861 shift));
01862 #else
01863 act_result[j] = DSEXT64(LU64(&cool_ints[i]) <<
01864 shift);
01865 #endif
01866 else
01867 #if defined __sun
01868 act_result[j] = DSEXT64(shftr64(LU64(&cool_ints[i]),
01869 (-shift)));
01870 #else
01871 act_result[j] = DSEXT64(LU64(&cool_ints[i]) >>
01872 (-shift));
01873 #endif
01874
01875 act_status[j] = is_zero64(act_result[j])
01876 ? AR_STAT_ZERO
01877 : AR_STAT_OK;
01878 if (is_neg64(act_result[j]))
01879 act_status[j] |= AR_STAT_NEGATIVE;
01880 }
01881
01882 test_status[j] = AR_ishft((AR_DATA *)&test_result[j],
01883 &sint64_artype,
01884 (AR_DATA *)&cool_ints[i],
01885 &sint64_artype,
01886 (AR_DATA *)&cool_ints[j],
01887 &sint64_artype);
01888 break;
01889 }
01890
01891 if (LU64(&test_result[j]) != (UINT64)act_result[j])
01892 {
01893 printf(" ERROR: incorrect result at %d,%d\n", i, j);
01894 abort();
01895 }
01896
01897 if (act_status[j] != test_status[j])
01898 {
01899 printf(" ERROR: incorrect status at %d,%d\n", i, j);
01900 abort();
01901 }
01902 }
01903 }
01904
01905 printf("PASSED\n");
01906 }
01907
01908
01909 #define TEST_ISHFT_TYPES \
01910 do { \
01911 int i, j, k; \
01912 \
01913 printf(" Testing: types %-10s: ", "ISHFT"); \
01914 \
01915 for (i=0; i<num_ar_types; i++) \
01916 { \
01917 for (j=0; j<num_ar_types; j++) \
01918 { \
01919 for (k=0; k<num_ar_types; k++) \
01920 { \
01921 act_status[k] = AR_STAT_OK; \
01922 if (ar_types[i] != ar_types[j] || \
01923 !IS_SUPPORTED_INT_TYPE(ar_types[i]) || \
01924 !IS_SUPPORTED_INT_TYPE(ar_types[k])) \
01925 act_status[k] = AR_STAT_INVALID_TYPE; \
01926 \
01927 test_status[k] = AR_ishft((AR_DATA *)&test_result[1], \
01928 &ar_types[i], \
01929 (AR_DATA *)&cool_ints[1], \
01930 &ar_types[j], \
01931 (AR_DATA *)&cool_ints[1], \
01932 &ar_types[k]); \
01933 \
01934 if ((act_status[k] ^ test_status[k]) & \
01935 AR_STAT_INVALID_TYPE) \
01936 { \
01937 printf(" ERROR: incorrect status at %d,%d,%d\n", \
01938 i, j, k); \
01939 abort(); \
01940 } \
01941 } \
01942 } \
01943 } \
01944 \
01945 printf("PASSED\n"); \
01946 } while (0)
01947
01948
01949 test_ishft()
01950 {
01951
01952 test_ishft_signed( 8);
01953
01954 test_ishft_signed(16);
01955
01956 test_ishft_signed(32);
01957
01958 test_ishft_signed(46);
01959
01960 test_ishft_signed(64);
01961
01962 TEST_ISHFT_TYPES;
01963
01964 }
01965
01966
01967 #undef TEST_ISHFT_TYPES
01968
01969
01970 static
01971 void
01972 test_ishftc_signed(int size)
01973 {
01974 int i, j;
01975
01976 printf(" Testing: SIGNED %2d INT %-10s: ", size, "ISHFTC");
01977
01978 if (size == 46)
01979 size = 64;
01980
01981 for (i=0; i<num_cool_ints; i++)
01982 {
01983 for (j=0; j<num_cool_ints; j++)
01984 {
01985 SINT64 width;
01986 SINT64 max_shift;
01987 SINT64 shift;
01988 SINT64 unch_mask;
01989 SINT64 rot_mask;
01990
01991 switch (size)
01992 {
01993 case 8:
01994 width = LS8(&cool_ints[j]);
01995 break;
01996
01997 case 16:
01998 width = LS16(&cool_ints[j]);
01999 break;
02000
02001 case 32:
02002 width = LS32(&cool_ints[j]);
02003 break;
02004
02005 case 46:
02006 case 64:
02007 width = LS64(&cool_ints[j]);
02008 break;
02009 }
02010
02011 if (width < 1 || width > size) {
02012 max_shift = 0;
02013 unch_mask = 0;
02014 rot_mask = 0;
02015 }
02016 else {
02017 max_shift = width + 1;
02018 #if defined(__sun)
02019 unch_mask = _mask(64 - width);
02020 #else
02021 unch_mask = MASKL(64 - width);
02022 #endif
02023 rot_mask = ~unch_mask;
02024 }
02025
02026 for (shift = -(max_shift + 1); shift < max_shift; shift++)
02027 {
02028 UINT64 opnd;
02029 ar_data shift_data;
02030
02031 test_result[j].part1 = 0;
02032 test_result[j].part2 = 0;
02033 test_result[j].part3 = 0;
02034 test_result[j].part4 = 0;
02035
02036 act_status[j] = AR_STAT_OK;
02037
02038 if (width < 1 ||
02039 width > size ||
02040 (shift < 0 && shift < -size) ||
02041 (shift >= 0 && shift > size))
02042 {
02043 act_status[j] = AR_STAT_UNDEFINED;
02044 act_result[j] = 0;
02045 }
02046
02047 switch (size)
02048 {
02049 case 8:
02050 if ((shift < 0 && shift < -width) ||
02051 (shift >= 0 && shift > width))
02052 {
02053 act_status[j] = AR_STAT_UNDEFINED;
02054 act_result[j] = 0;
02055 }
02056 else if (act_status[j] == AR_STAT_OK)
02057 {
02058 opnd = LU8(&cool_ints[i]);
02059
02060 if (shift == 0)
02061 act_result[j] = opnd;
02062 else if (shift > 0)
02063 act_result[j] = (opnd & unch_mask) |
02064 (((opnd << shift) |
02065 ((opnd & rot_mask) >>
02066 (width - shift))) &
02067 rot_mask);
02068 else
02069 act_result[j] = (opnd & unch_mask) |
02070 ((((opnd & rot_mask) >> -shift) |
02071 (opnd << (width + shift))) &
02072 rot_mask);
02073 act_result[j] = DSEXT8(act_result[j]);
02074
02075 act_status[j] = is_zero8(act_result[j])
02076 ? AR_STAT_ZERO
02077 : AR_STAT_OK;
02078 if (is_neg8(act_result[j]))
02079 act_status[j] |= AR_STAT_NEGATIVE;
02080 }
02081
02082 ZERO_INT8_UPPER(&shift_data);
02083 shift_data.ar_i8.part5 = shift & 0xFF;
02084
02085 test_status[j] = AR_ishftc((AR_DATA *)&test_result[j],
02086 &sint8_artype,
02087 (AR_DATA *)&cool_ints[i],
02088 &sint8_artype,
02089 (AR_DATA *)&shift_data,
02090 &sint8_artype,
02091 (AR_DATA *)&cool_ints[j],
02092 &sint8_artype);
02093 break;
02094
02095 case 16:
02096 if ((shift < 0 && shift < -width) ||
02097 (shift >= 0 && shift > width))
02098 {
02099 act_status[j] = AR_STAT_UNDEFINED;
02100 act_result[j] = 0;
02101 }
02102 else if (act_status[j] == AR_STAT_OK)
02103 {
02104 opnd = LU16(&cool_ints[i]);
02105
02106 if (shift == 0)
02107 act_result[j] = opnd;
02108 else if (shift > 0)
02109 act_result[j] = (opnd & unch_mask) |
02110 (((opnd << shift) |
02111 ((opnd & rot_mask) >>
02112 (width - shift))) &
02113 rot_mask);
02114 else
02115 act_result[j] = (opnd & unch_mask) |
02116 ((((opnd & rot_mask) >> -shift) |
02117 (opnd << (width + shift))) &
02118 rot_mask);
02119 act_result[j] = DSEXT16(act_result[j]);
02120
02121 act_status[j] = is_zero16(act_result[j])
02122 ? AR_STAT_ZERO
02123 : AR_STAT_OK;
02124 if (is_neg16(act_result[j]))
02125 act_status[j] |= AR_STAT_NEGATIVE;
02126 }
02127
02128 ZERO_INT16_UPPER(&shift_data);
02129 shift_data.ar_i64.part4 = shift & 0xFFFF;
02130
02131 test_status[j] = AR_ishftc((AR_DATA *)&test_result[j],
02132 &sint16_artype,
02133 (AR_DATA *)&cool_ints[i],
02134 &sint16_artype,
02135 (AR_DATA *)&shift_data,
02136 &sint16_artype,
02137 (AR_DATA *)&cool_ints[j],
02138 &sint16_artype);
02139 break;
02140
02141 case 32:
02142 if ((shift < 0 && shift < -width) ||
02143 (shift >= 0 && shift > width))
02144 {
02145 act_status[j] = AR_STAT_UNDEFINED;
02146 act_result[j] = 0;
02147 }
02148 else if (act_status[j] == AR_STAT_OK)
02149 {
02150 opnd = LU32(&cool_ints[i]);
02151
02152 if (shift == 0)
02153 act_result[j] = opnd;
02154 else if (shift > 0)
02155 act_result[j] = (opnd & unch_mask) |
02156 (((opnd << shift) |
02157 ((opnd & rot_mask) >>
02158 (width - shift))) &
02159 rot_mask);
02160 else
02161 act_result[j] = (opnd & unch_mask) |
02162 ((((opnd & rot_mask) >> -shift) |
02163 (opnd << (width + shift))) &
02164 rot_mask);
02165 act_result[j] = DSEXT32(act_result[j]);
02166
02167 act_status[j] = is_zero32(act_result[j])
02168 ? AR_STAT_ZERO
02169 : AR_STAT_OK;
02170 if (is_neg32(act_result[j]))
02171 act_status[j] |= AR_STAT_NEGATIVE;
02172 }
02173
02174 ZERO_INT32_UPPER(&shift_data);
02175 shift_data.ar_i64.part3 = (shift >> 16) & 0xFFFF;
02176 shift_data.ar_i64.part4 = (shift ) & 0xFFFF;
02177
02178 test_status[j] = AR_ishftc((AR_DATA *)&test_result[j],
02179 &sint32_artype,
02180 (AR_DATA *)&cool_ints[i],
02181 &sint32_artype,
02182 (AR_DATA *)&shift_data,
02183 &sint32_artype,
02184 (AR_DATA *)&cool_ints[j],
02185 &sint32_artype);
02186 break;
02187
02188 case 46:
02189 case 64:
02190 if ((shift < 0 && shift < -width) ||
02191 (shift >= 0 && shift > width))
02192 {
02193 act_status[j] = AR_STAT_UNDEFINED;
02194 act_result[j] = 0;
02195 }
02196 else if (act_status[j] == AR_STAT_OK)
02197 {
02198 opnd = LU64(&cool_ints[i]);
02199
02200 if (shift == 0)
02201 act_result[j] = opnd;
02202 else if (shift > 0)
02203 #if defined __sun
02204 act_result[j] = (opnd & unch_mask) |
02205 ((shftl64(opnd, shift) |
02206 shftr64((opnd & rot_mask),
02207 (width - shift))) &
02208 rot_mask);
02209 #else
02210 act_result[j] = (opnd & unch_mask) |
02211 (((opnd << shift) |
02212 ((opnd & rot_mask) >>
02213 (width - shift))) &
02214 rot_mask);
02215 #endif
02216 else
02217 #if defined __sun
02218 act_result[j] = (opnd & unch_mask) |
02219 ((shftr64((opnd & rot_mask),
02220 (-shift)) |
02221 shftl64(opnd, (width + shift))) &
02222 rot_mask);
02223 #else
02224 act_result[j] = (opnd & unch_mask) |
02225 ((((opnd & rot_mask) >> -shift) |
02226 (opnd << (width + shift))) &
02227 rot_mask);
02228 #endif
02229 act_result[j] = DSEXT64(act_result[j]);
02230
02231 act_status[j] = is_zero64(act_result[j])
02232 ? AR_STAT_ZERO
02233 : AR_STAT_OK;
02234 if (is_neg64(act_result[j]))
02235 act_status[j] |= AR_STAT_NEGATIVE;
02236 }
02237
02238 shift_data.ar_i64.part1 = (shift >> 48) & 0xFFFF;
02239 shift_data.ar_i64.part2 = (shift >> 32) & 0xFFFF;
02240 shift_data.ar_i64.part3 = (shift >> 16) & 0xFFFF;
02241 shift_data.ar_i64.part4 = (shift ) & 0xFFFF;
02242
02243 test_status[j] = AR_ishftc((AR_DATA *)&test_result[j],
02244 &sint64_artype,
02245 (AR_DATA *)&cool_ints[i],
02246 &sint64_artype,
02247 (AR_DATA *)&shift_data,
02248 &sint64_artype,
02249 (AR_DATA *)&cool_ints[j],
02250 &sint64_artype);
02251 break;
02252 }
02253
02254 if (LU64(&test_result[j]) != (UINT64)act_result[j])
02255 {
02256 printf(" ERROR: incorrect result at %d,%d,%d\n",
02257 i, j, (int) shift);
02258 abort();
02259 }
02260
02261 if (act_status[j] != test_status[j])
02262 {
02263 printf(" ERROR: incorrect status at %d,%d,%d\n",
02264 i, j, (int) shift);
02265 abort();
02266 }
02267 }
02268 }
02269 }
02270
02271 printf("PASSED\n");
02272 }
02273
02274
02275 #define TEST_ISHFTC_TYPES \
02276 do { \
02277 int i, j, k, l; \
02278 \
02279 printf(" Testing: types %-10s: ", "ISHFTC"); \
02280 \
02281 for (i=0; i<num_ar_types; i++) \
02282 { \
02283 for (j=0; j<num_ar_types; j++) \
02284 { \
02285 for (k=0; k<num_ar_types; k++) \
02286 { \
02287 for (l=0; l<num_ar_types; l++) \
02288 { \
02289 act_status[l] = AR_STAT_OK; \
02290 if (ar_types[i] != ar_types[j] || \
02291 !IS_SUPPORTED_INT_TYPE(ar_types[i]) || \
02292 !IS_SUPPORTED_INT_TYPE(ar_types[k]) || \
02293 !IS_SUPPORTED_INT_TYPE(ar_types[l])) \
02294 act_status[l] = AR_STAT_INVALID_TYPE; \
02295 \
02296 test_status[l] = AR_ishftc((AR_DATA *)&test_result[1],\
02297 &ar_types[i], \
02298 (AR_DATA *)&cool_ints[1], \
02299 &ar_types[j], \
02300 (AR_DATA *)&cool_ints[1], \
02301 &ar_types[l], \
02302 (AR_DATA *)&cool_ints[1], \
02303 &ar_types[k]); \
02304 \
02305 if ((act_status[l] ^ test_status[l]) & \
02306 AR_STAT_INVALID_TYPE) \
02307 { \
02308 printf(" ERROR: incorrect status at %d,%d,%d,%d" \
02309 "\n", \
02310 i, j, k, l); \
02311 abort(); \
02312 } \
02313 } \
02314 } \
02315 } \
02316 } \
02317 \
02318 printf("PASSED\n"); \
02319 } while (0)
02320
02321
02322 test_ishftc()
02323 {
02324
02325 test_ishftc_signed( 8);
02326
02327 test_ishftc_signed(16);
02328
02329 test_ishftc_signed(32);
02330
02331 test_ishftc_signed(46);
02332
02333 test_ishftc_signed(64);
02334
02335 TEST_ISHFTC_TYPES;
02336
02337 }
02338
02339
02340 #undef TEST_ISHFTC_TYPES
02341
02342
02343
02344
02345
02346
02347
02348
02349 static
02350 void
02351 test_ibits_signed(int size)
02352 {
02353 int i, j;
02354
02355 printf(" Testing: SIGNED %2d INT %-10s: ", size, "IBITS");
02356
02357 if (size == 46)
02358 size = 64;
02359
02360 for (i=0; i<num_cool_ints; i++)
02361 {
02362 for (j=0; j<num_cool_ints; j++)
02363 {
02364 SINT64 width;
02365 SINT64 max_shift;
02366 SINT64 shift;
02367 SINT64 mask;
02368
02369 switch (size)
02370 {
02371 case 8:
02372 width = LS8(&cool_ints[j]);
02373 break;
02374
02375 case 16:
02376 width = LS16(&cool_ints[j]);
02377 break;
02378
02379 case 32:
02380 width = LS32(&cool_ints[j]);
02381 break;
02382
02383 case 46:
02384 case 64:
02385 width = LS64(&cool_ints[j]);
02386 break;
02387 }
02388
02389 if (width < 0 || width > size) {
02390 max_shift = 0;
02391 mask = 0;
02392 }
02393 else {
02394 max_shift = width + 1;
02395 #if defined(__sun)
02396 mask = _mask(128 - width);
02397 #else
02398 mask = MASKR(width);
02399 #endif
02400 }
02401
02402 for (shift = -1; shift < max_shift + 1; shift++)
02403 {
02404 UINT64 opnd;
02405 ar_data shift_data;
02406
02407 test_result[j].part1 = 0;
02408 test_result[j].part2 = 0;
02409 test_result[j].part3 = 0;
02410 test_result[j].part4 = 0;
02411
02412 act_status[j] = AR_STAT_OK;
02413
02414 if (width < 0 ||
02415 shift < 0 || shift > (size - width))
02416 {
02417 act_status[j] = AR_STAT_UNDEFINED;
02418 act_result[j] = 0;
02419 }
02420
02421 switch (size)
02422 {
02423 case 8:
02424 if (act_status[j] == AR_STAT_OK)
02425 {
02426 opnd = LU8(&cool_ints[i]);
02427
02428 if (shift == 0)
02429 act_result[j] = opnd & mask;
02430 else if (shift == size)
02431 act_result[j] = 0;
02432 else
02433 act_result[j] = (opnd >> shift) & mask;
02434
02435 act_status[j] = is_zero8(act_result[j])
02436 ? AR_STAT_ZERO
02437 : AR_STAT_OK;
02438 if (is_neg8(act_result[j]))
02439 act_status[j] |= AR_STAT_NEGATIVE;
02440 }
02441
02442 ZERO_INT8_UPPER(&shift_data);
02443 shift_data.ar_i8.part5 = shift & 0xFF;
02444
02445 test_status[j] = AR_ibits((AR_DATA *)&test_result[j],
02446 &sint8_artype,
02447 (AR_DATA *)&cool_ints[i],
02448 &sint8_artype,
02449 (AR_DATA *)&shift_data,
02450 &sint8_artype,
02451 (AR_DATA *)&cool_ints[j],
02452 &sint8_artype);
02453 break;
02454
02455 case 16:
02456 if (act_status[j] == AR_STAT_OK)
02457 {
02458 opnd = LU16(&cool_ints[i]);
02459
02460 if (shift == 0)
02461 act_result[j] = opnd & mask;
02462 else if (shift == size)
02463 act_result[j] = 0;
02464 else
02465 act_result[j] = (opnd >> shift) & mask;
02466
02467 act_status[j] = is_zero16(act_result[j])
02468 ? AR_STAT_ZERO
02469 : AR_STAT_OK;
02470 if (is_neg16(act_result[j]))
02471 act_status[j] |= AR_STAT_NEGATIVE;
02472 }
02473
02474 ZERO_INT16_UPPER(&shift_data);
02475 shift_data.ar_i64.part4 = shift & 0xFFFF;
02476
02477 test_status[j] = AR_ibits((AR_DATA *)&test_result[j],
02478 &sint16_artype,
02479 (AR_DATA *)&cool_ints[i],
02480 &sint16_artype,
02481 (AR_DATA *)&shift_data,
02482 &sint16_artype,
02483 (AR_DATA *)&cool_ints[j],
02484 &sint16_artype);
02485 break;
02486
02487 case 32:
02488 if (act_status[j] == AR_STAT_OK)
02489 {
02490 opnd = LU32(&cool_ints[i]);
02491
02492 if (shift == 0)
02493 act_result[j] = opnd & mask;
02494 else if (shift == size)
02495 act_result[j] = 0;
02496 else
02497 act_result[j] = (opnd >> shift) & mask;
02498
02499 act_status[j] = is_zero32(act_result[j])
02500 ? AR_STAT_ZERO
02501 : AR_STAT_OK;
02502 if (is_neg32(act_result[j]))
02503 act_status[j] |= AR_STAT_NEGATIVE;
02504 }
02505
02506 ZERO_INT32_UPPER(&shift_data);
02507 shift_data.ar_i64.part3 = (shift >> 16) & 0xFFFF;
02508 shift_data.ar_i64.part4 = (shift ) & 0xFFFF;
02509
02510 test_status[j] = AR_ibits((AR_DATA *)&test_result[j],
02511 &sint32_artype,
02512 (AR_DATA *)&cool_ints[i],
02513 &sint32_artype,
02514 (AR_DATA *)&shift_data,
02515 &sint32_artype,
02516 (AR_DATA *)&cool_ints[j],
02517 &sint32_artype);
02518 break;
02519
02520 case 46:
02521 case 64:
02522 if (act_status[j] == AR_STAT_OK)
02523 {
02524 opnd = LU64(&cool_ints[i]);
02525
02526 if (shift == 0)
02527 act_result[j] = opnd & mask;
02528 else if (shift == size)
02529 act_result[j] = 0;
02530 else
02531 #if defined __sun
02532 act_result[j] = shftr64(opnd, shift) & mask;
02533 #else
02534 act_result[j] = (opnd >> shift) & mask;
02535 #endif
02536
02537 act_status[j] = is_zero64(act_result[j])
02538 ? AR_STAT_ZERO
02539 : AR_STAT_OK;
02540 if (is_neg64(act_result[j]))
02541 act_status[j] |= AR_STAT_NEGATIVE;
02542 }
02543
02544 shift_data.ar_i64.part1 = (shift >> 48) & 0xFFFF;
02545 shift_data.ar_i64.part2 = (shift >> 32) & 0xFFFF;
02546 shift_data.ar_i64.part3 = (shift >> 16) & 0xFFFF;
02547 shift_data.ar_i64.part4 = (shift ) & 0xFFFF;
02548
02549 test_status[j] = AR_ibits((AR_DATA *)&test_result[j],
02550 &sint64_artype,
02551 (AR_DATA *)&cool_ints[i],
02552 &sint64_artype,
02553 (AR_DATA *)&shift_data,
02554 &sint64_artype,
02555 (AR_DATA *)&cool_ints[j],
02556 &sint64_artype);
02557 break;
02558 }
02559
02560 if (LU64(&test_result[j]) != (UINT64)act_result[j])
02561 {
02562 printf(" ERROR: incorrect result at %d,%d,%d\n",
02563 i, j, (int) shift);
02564 abort();
02565 }
02566
02567 if (act_status[j] != test_status[j])
02568 {
02569 printf(" ERROR: incorrect status at %d,%d,%d\n",
02570 i, j, (int) shift);
02571 abort();
02572 }
02573 }
02574 }
02575 }
02576
02577 printf("PASSED\n");
02578 }
02579
02580
02581 #define TEST_IBITS_TYPES \
02582 do { \
02583 int i, j, k, l; \
02584 \
02585 printf(" Testing: types %-10s: ", "IBITS"); \
02586 \
02587 for (i=0; i<num_ar_types; i++) \
02588 { \
02589 for (j=0; j<num_ar_types; j++) \
02590 { \
02591 for (k=0; k<num_ar_types; k++) \
02592 { \
02593 for (l=0; l<num_ar_types; l++) \
02594 { \
02595 act_status[l] = AR_STAT_OK; \
02596 if (ar_types[i] != ar_types[j] || \
02597 !IS_SUPPORTED_INT_TYPE(ar_types[i]) || \
02598 !IS_SUPPORTED_INT_TYPE(ar_types[k]) || \
02599 !IS_SUPPORTED_INT_TYPE(ar_types[l])) \
02600 act_status[l] = AR_STAT_INVALID_TYPE; \
02601 \
02602 test_status[l] = AR_ibits((AR_DATA *)&test_result[1],\
02603 &ar_types[i], \
02604 (AR_DATA *)&cool_ints[1], \
02605 &ar_types[j], \
02606 (AR_DATA *)&cool_ints[1], \
02607 &ar_types[l], \
02608 (AR_DATA *)&cool_ints[1], \
02609 &ar_types[k]); \
02610 \
02611 if ((act_status[l] ^ test_status[l]) & \
02612 AR_STAT_INVALID_TYPE) \
02613 { \
02614 printf(" ERROR: incorrect status at %d,%d,%d,%d" \
02615 "\n", \
02616 i, j, k, l); \
02617 abort(); \
02618 } \
02619 } \
02620 } \
02621 } \
02622 } \
02623 \
02624 printf("PASSED\n"); \
02625 } while (0)
02626
02627
02628 test_ibits()
02629 {
02630
02631 test_ibits_signed( 8);
02632
02633 test_ibits_signed(16);
02634
02635 test_ibits_signed(32);
02636
02637 test_ibits_signed(46);
02638
02639 test_ibits_signed(64);
02640
02641 TEST_IBITS_TYPES;
02642
02643 }
02644
02645
02646 #undef TEST_IBITS_TYPES
02647
02648
02649
02650
02651
02652
02653
02654
02655 #define TEST_MASK_OP_SIGNED(size, max_shift) \
02656 do { \
02657 int i, j; \
02658 \
02659 printf(" Testing: SIGNED %2d INT %-10s: ", size, "_mask"); \
02660 \
02661 for (j=0; j<num_cool_ints; j++) \
02662 { \
02663 if (LS##size(&cool_ints[j]) > max_shift || \
02664 LS##size(&cool_ints[j]) < 0) \
02665 { \
02666 act_result[j] = 0; \
02667 act_status[j] = AR_STAT_UNDEFINED; \
02668 } \
02669 else \
02670 { \
02671 act_result[j] = DSEXT##size( \
02672 _mask##size(LS##size(&cool_ints[j]))); \
02673 act_status[j] = is_zero##size(act_result[j]) \
02674 ? AR_STAT_ZERO : AR_STAT_OK; \
02675 if (is_neg##size(act_result[j])) \
02676 act_status[j] |= AR_STAT_NEGATIVE; \
02677 } \
02678 \
02679 test_result[j].part1 = 0; \
02680 test_result[j].part2 = 0; \
02681 test_result[j].part3 = 0; \
02682 test_result[j].part4 = 0; \
02683 \
02684 test_status[j] = AR_mask((AR_DATA *)&test_result[j], \
02685 &sint##size##_artype, \
02686 (AR_DATA *)&cool_ints[j], \
02687 &sint##size##_artype); \
02688 \
02689 if (LU64(&test_result[j]) != act_result[j]) \
02690 { \
02691 printf(" ERROR: incorrect result at %d\n", j); \
02692 abort(); \
02693 } \
02694 \
02695 if (act_status[j] != test_status[j]) \
02696 { \
02697 printf(" ERROR: incorrect status at %d\n", j); \
02698 abort(); \
02699 } \
02700 } \
02701 \
02702 printf("PASSED\n"); \
02703 } while (0)
02704
02705
02706 #define TEST_MASK_OP_UNSIGNED(size, max_shift) \
02707 do { \
02708 int i, j; \
02709 \
02710 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "_mask"); \
02711 \
02712 for (j=0; j<num_cool_ints; j++) \
02713 { \
02714 if (LU##size(&cool_ints[j]) > max_shift) \
02715 { \
02716 act_result[j] = 0; \
02717 act_status[j] = AR_STAT_UNDEFINED; \
02718 } \
02719 else \
02720 { \
02721 act_result[j] = DSEXT##size( \
02722 _mask##size(LU##size(&cool_ints[j]))); \
02723 act_status[j] = is_zero##size(act_result[j]) \
02724 ? AR_STAT_ZERO : AR_STAT_OK; \
02725 } \
02726 \
02727 test_result[j].part1 = 0; \
02728 test_result[j].part2 = 0; \
02729 test_result[j].part3 = 0; \
02730 test_result[j].part4 = 0; \
02731 \
02732 test_status[j] = AR_mask((AR_DATA *)&test_result[j], \
02733 &uint##size##_artype, \
02734 (AR_DATA *)&cool_ints[j], \
02735 &uint##size##_artype); \
02736 \
02737 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
02738 { \
02739 printf(" ERROR: incorrect result at %d\n", j); \
02740 abort(); \
02741 } \
02742 \
02743 if (act_status[j] != test_status[j]) \
02744 { \
02745 printf(" ERROR: incorrect status at %d\n", j); \
02746 abort(); \
02747 } \
02748 } \
02749 \
02750 printf("PASSED\n"); \
02751 } while (0)
02752
02753
02754 #define TEST_MASK_OP_TYPES \
02755 do { \
02756 int j, k; \
02757 \
02758 printf(" Testing: types %-10s: ", "_mask"); \
02759 \
02760 for (j=0; j<num_ar_types; j++) \
02761 { \
02762 for (k=0; k<num_ar_types; k++) \
02763 { \
02764 act_status[k] = AR_STAT_OK; \
02765 if (ar_types[j] != ar_types[k] || \
02766 !IS_SUPPORTED_INT_TYPE(ar_types[j])) \
02767 act_status[k] = AR_STAT_INVALID_TYPE; \
02768 \
02769 test_status[k] = AR_mask((AR_DATA *)&test_result[1], \
02770 &ar_types[j], \
02771 (AR_DATA *)&cool_ints[1], \
02772 &ar_types[k]); \
02773 \
02774 if ((act_status[k] ^ test_status[k]) & \
02775 AR_STAT_INVALID_TYPE) \
02776 { \
02777 printf(" ERROR: incorrect status at %d,%d\n", j, k); \
02778 abort(); \
02779 } \
02780 } \
02781 } \
02782 \
02783 printf("PASSED\n"); \
02784 } while (0)
02785
02786
02787 #define TEST_LP_OP_SIGNED(size, opr, func) \
02788 do { \
02789 int i, j; \
02790 \
02791 printf(" Testing: SIGNED %2d INT %-10s: ", size, #opr); \
02792 \
02793 for (j=0; j<num_cool_ints; j++) \
02794 { \
02795 act_result[j] = opr##size(LS##size(&cool_ints[j])); \
02796 \
02797 act_status[j] = is_zero##size(act_result[j]) \
02798 ? AR_STAT_ZERO : AR_STAT_OK; \
02799 if (is_neg##size(act_result[j])) \
02800 act_status[j] |= AR_STAT_NEGATIVE; \
02801 \
02802 test_result[j].part1 = 0; \
02803 test_result[j].part2 = 0; \
02804 test_result[j].part3 = 0; \
02805 test_result[j].part4 = 0; \
02806 \
02807 test_status[j] = func((AR_DATA *)&test_result[j], \
02808 &sint##size##_artype, \
02809 (AR_DATA *)&cool_ints[j], \
02810 &sint##size##_artype); \
02811 \
02812 if (LU64(&test_result[j]) != act_result[j]) \
02813 { \
02814 printf(" ERROR: incorrect result at %d\n", j); \
02815 abort(); \
02816 } \
02817 \
02818 if (act_status[j] != test_status[j]) \
02819 { \
02820 printf(" ERROR: incorrect status at %d\n", j); \
02821 abort(); \
02822 } \
02823 } \
02824 \
02825 printf("PASSED\n"); \
02826 } while (0)
02827
02828
02829 #define TEST_LP_OP_UNSIGNED(size, opr, func) \
02830 do { \
02831 int i, j; \
02832 \
02833 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, #opr); \
02834 \
02835 for (j=0; j<num_cool_ints; j++) \
02836 { \
02837 act_result[j] = opr##size(LU##size(&cool_ints[j])); \
02838 act_status[j] = is_zero##size(act_result[j]) \
02839 ? AR_STAT_ZERO : AR_STAT_OK; \
02840 \
02841 test_result[j].part1 = 0; \
02842 test_result[j].part2 = 0; \
02843 test_result[j].part3 = 0; \
02844 test_result[j].part4 = 0; \
02845 \
02846 test_status[j] = func((AR_DATA *)&test_result[j], \
02847 &uint##size##_artype, \
02848 (AR_DATA *)&cool_ints[j], \
02849 &uint##size##_artype); \
02850 \
02851 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
02852 { \
02853 printf(" ERROR: incorrect result at %d\n", j); \
02854 abort(); \
02855 } \
02856 \
02857 if (act_status[j] != test_status[j]) \
02858 { \
02859 printf(" ERROR: incorrect status at %d\n", j); \
02860 abort(); \
02861 } \
02862 } \
02863 \
02864 printf("PASSED\n"); \
02865 } while (0)
02866
02867
02868 #define TEST_LP_OP_TYPES(opr, func) \
02869 do { \
02870 int j, k; \
02871 \
02872 printf(" Testing: types %-10s: ", #opr); \
02873 \
02874 for (j=0; j<num_ar_types; j++) \
02875 { \
02876 for (k=0; k<num_ar_types; k++) \
02877 { \
02878 act_status[k] = AR_STAT_OK; \
02879 if (!IS_SUPPORTED_INT_TYPE(ar_types[j]) || \
02880 !IS_SUPPORTED_INT_TYPE(ar_types[k])) \
02881 act_status[k] = AR_STAT_INVALID_TYPE; \
02882 \
02883 test_status[k] = func((AR_DATA *)&test_result[1], \
02884 &ar_types[j], \
02885 (AR_DATA *)&cool_ints[1], \
02886 &ar_types[k]); \
02887 \
02888 if ((act_status[k] ^ test_status[k]) & \
02889 AR_STAT_INVALID_TYPE) \
02890 { \
02891 printf(" ERROR: incorrect status at %d,%d\n", j, k); \
02892 abort(); \
02893 } \
02894 } \
02895 } \
02896 \
02897 printf("PASSED\n"); \
02898 } while (0)
02899
02900
02901 test_mask()
02902 {
02903
02904 TEST_MASK_OP_SIGNED( 8, 16);
02905 TEST_MASK_OP_UNSIGNED( 8, 16);
02906
02907 TEST_MASK_OP_SIGNED( 16, 32);
02908 TEST_MASK_OP_UNSIGNED(16, 32);
02909
02910 TEST_MASK_OP_SIGNED( 32, 64);
02911 TEST_MASK_OP_UNSIGNED(32, 64);
02912
02913 TEST_MASK_OP_SIGNED( 46, 128);
02914
02915 TEST_MASK_OP_SIGNED( 64, 128);
02916 TEST_MASK_OP_UNSIGNED(64, 128);
02917
02918 TEST_MASK_OP_TYPES;
02919
02920 }
02921
02922
02923 test_leadz()
02924 {
02925
02926 TEST_LP_OP_SIGNED( 8, _leadz , AR_leadz );
02927 TEST_LP_OP_UNSIGNED( 8, _leadz , AR_leadz );
02928
02929 TEST_LP_OP_SIGNED( 16, _leadz , AR_leadz );
02930 TEST_LP_OP_UNSIGNED(16, _leadz , AR_leadz );
02931
02932 TEST_LP_OP_SIGNED( 32, _leadz , AR_leadz );
02933 TEST_LP_OP_UNSIGNED(32, _leadz , AR_leadz );
02934
02935 TEST_LP_OP_SIGNED( 46, _leadz , AR_leadz );
02936
02937 TEST_LP_OP_SIGNED( 64, _leadz , AR_leadz );
02938 TEST_LP_OP_UNSIGNED(64, _leadz , AR_leadz );
02939
02940 TEST_LP_OP_TYPES( _leadz , AR_leadz );
02941
02942 }
02943
02944
02945 test_popcnt()
02946 {
02947
02948 TEST_LP_OP_SIGNED( 8, _popcnt, AR_popcnt);
02949 TEST_LP_OP_UNSIGNED( 8, _popcnt, AR_popcnt);
02950
02951 TEST_LP_OP_SIGNED( 16, _popcnt, AR_popcnt);
02952 TEST_LP_OP_UNSIGNED(16, _popcnt, AR_popcnt);
02953
02954 TEST_LP_OP_SIGNED( 32, _popcnt, AR_popcnt);
02955 TEST_LP_OP_UNSIGNED(32, _popcnt, AR_popcnt);
02956
02957 TEST_LP_OP_SIGNED( 46, _popcnt, AR_popcnt);
02958
02959 TEST_LP_OP_SIGNED( 64, _popcnt, AR_popcnt);
02960 TEST_LP_OP_UNSIGNED(64, _popcnt, AR_popcnt);
02961
02962 TEST_LP_OP_TYPES( _popcnt, AR_popcnt);
02963
02964 }
02965
02966
02967 test_poppar()
02968 {
02969
02970 TEST_LP_OP_SIGNED( 8, _poppar, AR_poppar);
02971 TEST_LP_OP_UNSIGNED( 8, _poppar, AR_poppar);
02972
02973 TEST_LP_OP_SIGNED( 16, _poppar, AR_poppar);
02974 TEST_LP_OP_UNSIGNED(16, _poppar, AR_poppar);
02975
02976 TEST_LP_OP_SIGNED( 32, _poppar, AR_poppar);
02977 TEST_LP_OP_UNSIGNED(32, _poppar, AR_poppar);
02978
02979 TEST_LP_OP_SIGNED( 46, _poppar, AR_poppar);
02980
02981 TEST_LP_OP_SIGNED( 64, _poppar, AR_poppar);
02982 TEST_LP_OP_UNSIGNED(64, _poppar, AR_poppar);
02983
02984 TEST_LP_OP_TYPES( _poppar, AR_poppar);
02985
02986 }
02987
02988
02989 #undef TEST_MASK_SIGNED
02990 #undef TEST_MASK_UNSIGNED
02991 #undef TEST_MASK_TYPES
02992 #undef TEST_LP_OP_SIGNED
02993 #undef TEST_LP_OP_UNSIGNED
02994 #undef TEST_LP_OP_TYPES
02995
02996
02997
02998
02999
03000
03001
03002
03003 #define TEST_STATUS_SIGNED(size) \
03004 do { \
03005 int j; \
03006 \
03007 printf(" Testing: SIGNED %2d INT %-10s: ", size, "status"); \
03008 \
03009 for (j=0; j<num_cool_ints; j++) \
03010 { \
03011 act_status[j] = is_zero##size( \
03012 DSEXT##size(LS##size(&cool_ints[j]))) \
03013 ? AR_STAT_ZERO : AR_STAT_OK; \
03014 \
03015 if (is_neg##size(LS##size(&cool_ints[j]))) \
03016 act_status[j] |= AR_STAT_NEGATIVE; \
03017 \
03018 test_status[j] = AR_status((AR_DATA *)&cool_ints[j], \
03019 &sint##size##_artype); \
03020 \
03021 if (act_status[j] != test_status[j]) \
03022 { \
03023 printf(" ERROR: incorrect status at %d\n", j); \
03024 abort(); \
03025 } \
03026 } \
03027 \
03028 printf("PASSED\n"); \
03029 } while (0)
03030
03031
03032 #define TEST_STATUS_UNSIGNED(size) \
03033 do { \
03034 int j; \
03035 \
03036 printf(" Testing: SIGNED %2d INT %-10s: ", size, "status"); \
03037 \
03038 for (j=0; j<num_cool_ints; j++) \
03039 { \
03040 act_status[j] = is_zero##size(LU##size(&cool_ints[j])) \
03041 ? AR_STAT_ZERO : AR_STAT_OK; \
03042 \
03043 test_status[j] = AR_status((AR_DATA *)&cool_ints[j], \
03044 &uint##size##_artype); \
03045 \
03046 if (act_status[j] != test_status[j]) \
03047 { \
03048 printf(" ERROR: incorrect status at %d\n", j); \
03049 abort(); \
03050 } \
03051 } \
03052 \
03053 printf("PASSED\n"); \
03054 } while (0)
03055
03056
03057 #define TEST_STATUS_TYPES \
03058 do { \
03059 int k; \
03060 \
03061 printf(" Testing: types %-10s: ", "status"); \
03062 \
03063 for (k=0; k<num_ar_types; k++) \
03064 { \
03065 test_status[k] = AR_status((AR_DATA *)&cool_ints[1], \
03066 &ar_types[k]); \
03067 \
03068 if (test_status[k] & AR_STAT_INVALID_TYPE) \
03069 { \
03070 printf(" ERROR: incorrect status at %d\n", k); \
03071 abort(); \
03072 } \
03073 } \
03074 \
03075 printf("PASSED\n"); \
03076 } while (0)
03077
03078
03079 test_arstatus()
03080 {
03081
03082 TEST_STATUS_SIGNED( 8);
03083 TEST_STATUS_UNSIGNED( 8);
03084
03085 TEST_STATUS_SIGNED( 16);
03086 TEST_STATUS_UNSIGNED(16);
03087
03088 TEST_STATUS_SIGNED( 32);
03089 TEST_STATUS_UNSIGNED(32);
03090
03091 TEST_STATUS_SIGNED( 46);
03092
03093 TEST_STATUS_SIGNED( 64);
03094 TEST_STATUS_UNSIGNED(64);
03095
03096 TEST_STATUS_TYPES;
03097
03098 }
03099
03100
03101 #undef TEST_STATUS_SIGNED
03102 #undef TEST_STATUS_UNSIGNED
03103 #undef TEST_STATUS_TYPES
03104
03105
03106
03107
03108
03109
03110
03111
03112
03113 #define TEST_ADDSUB_OP_SIGNED(size, opr, func) \
03114 do { \
03115 int i, j; \
03116 \
03117 printf(" Testing: SIGNED %2d INT %-10s: ", size, #opr); \
03118 \
03119 for (i=0; i<num_cool_ints; i++) \
03120 { \
03121 for (j=0; j<num_cool_ints; j++) \
03122 { \
03123 act_result[j] = DSEXT##size(LS##size(&cool_ints[i]) opr \
03124 LS##size(&cool_ints[j])); \
03125 \
03126 act_status[j] = is_zero##size(act_result[j]) \
03127 ? AR_STAT_ZERO : AR_STAT_OK; \
03128 if (is_neg##size(act_result[j])) \
03129 act_status[j] |= AR_STAT_NEGATIVE; \
03130 \
03131 \
03132 if ((strcmp(#opr, "+") == 0 && \
03133 is_neg##size(LS##size(&cool_ints[i])) == \
03134 is_neg##size(LS##size(&cool_ints[j])) && \
03135 is_neg##size(LS##size(&cool_ints[i])) != \
03136 is_neg##size(act_result[j])) || \
03137 (strcmp(#opr, "-") == 0 && \
03138 is_neg##size(LS##size(&cool_ints[i])) != \
03139 is_neg##size(LS##size(&cool_ints[j])) && \
03140 is_neg##size(LS##size(&cool_ints[i])) != \
03141 is_neg##size(act_result[j]))) \
03142 { \
03143 act_status[j] |= AR_STAT_OVERFLOW; \
03144 } \
03145 \
03146 test_result[j].part1 = 0; \
03147 test_result[j].part2 = 0; \
03148 test_result[j].part3 = 0; \
03149 test_result[j].part4 = 0; \
03150 \
03151 test_status[j] = func((AR_DATA *)&test_result[j], \
03152 &sint##size##_artype, \
03153 (AR_DATA *)&cool_ints[i], \
03154 &sint##size##_artype, \
03155 (AR_DATA *)&cool_ints[j], \
03156 &sint##size##_artype); \
03157 \
03158 if (LU64(&test_result[j]) != act_result[j]) \
03159 { \
03160 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
03161 abort(); \
03162 } \
03163 \
03164 if (act_status[j] != test_status[j]) \
03165 { \
03166 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
03167 abort(); \
03168 } \
03169 } \
03170 } \
03171 \
03172 printf("PASSED\n"); \
03173 } while (0)
03174
03175
03176 #define TEST_ADDSUB_OP_UNSIGNED(size, opr, func) \
03177 do { \
03178 int i, j; \
03179 \
03180 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, #opr); \
03181 \
03182 for (i=0; i<num_cool_ints; i++) \
03183 { \
03184 for (j=0; j<num_cool_ints; j++) \
03185 { \
03186 act_result[j] = DSEXT##size(LU##size(&cool_ints[i]) opr \
03187 LU##size(&cool_ints[j])); \
03188 \
03189 act_status[j] = is_zero##size(act_result[j]) \
03190 ? AR_STAT_ZERO : AR_STAT_OK; \
03191 \
03192 test_result[j].part1 = 0; \
03193 test_result[j].part2 = 0; \
03194 test_result[j].part3 = 0; \
03195 test_result[j].part4 = 0; \
03196 \
03197 test_status[j] = func((AR_DATA *)&test_result[j], \
03198 &uint##size##_artype, \
03199 (AR_DATA *)&cool_ints[i], \
03200 &uint##size##_artype, \
03201 (AR_DATA *)&cool_ints[j], \
03202 &uint##size##_artype); \
03203 \
03204 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
03205 { \
03206 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
03207 abort(); \
03208 } \
03209 \
03210 if (act_status[j] != test_status[j]) \
03211 { \
03212 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
03213 abort(); \
03214 } \
03215 } \
03216 } \
03217 \
03218 printf("PASSED\n"); \
03219 } while (0)
03220
03221
03222 #define TEST_ADDSUB_OP_TYPES(opr, func) \
03223 do { \
03224 int i, j, k; \
03225 \
03226 printf(" Testing: types %-10s: ", #opr); \
03227 \
03228 for (i=0; i<num_ar_types; i++) \
03229 { \
03230 for (j=0; j<num_ar_types; j++) \
03231 { \
03232 for (k=0; k<num_ar_types; k++) \
03233 { \
03234 act_status[k] = AR_STAT_OK; \
03235 if (ar_types[i] != ar_types[j] || \
03236 ar_types[j] != ar_types[k] || \
03237 !IS_SUPPORTED_INT_TYPE(ar_types[i])) \
03238 act_status[k] = AR_STAT_INVALID_TYPE; \
03239 \
03240 test_status[k] = func((AR_DATA *)&test_result[1], \
03241 &ar_types[i], \
03242 (AR_DATA *)&cool_ints[1], \
03243 &ar_types[j], \
03244 (AR_DATA *)&cool_ints[1], \
03245 &ar_types[k]); \
03246 \
03247 if ((act_status[k] ^ test_status[k]) & \
03248 AR_STAT_INVALID_TYPE) \
03249 { \
03250 printf(" ERROR: incorrect status at %d,%d,%d\n", \
03251 i, j, k); \
03252 abort(); \
03253 } \
03254 } \
03255 } \
03256 } \
03257 \
03258 printf("PASSED\n"); \
03259 } while (0)
03260
03261
03262 test_add()
03263 {
03264
03265 TEST_ADDSUB_OP_SIGNED( 8, +, AR_add);
03266 TEST_ADDSUB_OP_UNSIGNED( 8, +, AR_add);
03267
03268 TEST_ADDSUB_OP_SIGNED( 16, +, AR_add);
03269 TEST_ADDSUB_OP_UNSIGNED(16, +, AR_add);
03270
03271 TEST_ADDSUB_OP_SIGNED( 32, +, AR_add);
03272 TEST_ADDSUB_OP_UNSIGNED(32, +, AR_add);
03273
03274 TEST_ADDSUB_OP_SIGNED( 46, +, AR_add);
03275
03276 TEST_ADDSUB_OP_SIGNED( 64, +, AR_add);
03277 TEST_ADDSUB_OP_UNSIGNED(64, +, AR_add);
03278
03279 TEST_ADDSUB_OP_TYPES( +, AR_add);
03280
03281 }
03282
03283
03284 test_subtract()
03285 {
03286
03287 TEST_ADDSUB_OP_SIGNED( 8, -, AR_subtract);
03288 TEST_ADDSUB_OP_UNSIGNED( 8, -, AR_subtract);
03289
03290 TEST_ADDSUB_OP_SIGNED( 16, -, AR_subtract);
03291 TEST_ADDSUB_OP_UNSIGNED(16, -, AR_subtract);
03292
03293 TEST_ADDSUB_OP_SIGNED( 32, -, AR_subtract);
03294 TEST_ADDSUB_OP_UNSIGNED(32, -, AR_subtract);
03295
03296 TEST_ADDSUB_OP_SIGNED( 46, -, AR_subtract);
03297
03298 TEST_ADDSUB_OP_SIGNED( 64, -, AR_subtract);
03299 TEST_ADDSUB_OP_UNSIGNED(64, -, AR_subtract);
03300
03301 TEST_ADDSUB_OP_TYPES( -, AR_subtract);
03302
03303 }
03304
03305
03306 #undef ADDSUB_OP_SIGNED
03307 #undef ADDSUB_OP_UNSIGNED
03308 #undef ADDSUB_OP_TYPES
03309
03310
03311 #define TEST_NEG_OP_SIGNED(size) \
03312 do { \
03313 int j; \
03314 \
03315 printf(" Testing: SIGNED %2d INT %-10s: ", size, "unary -"); \
03316 \
03317 for (j=0; j<num_cool_ints; j++) \
03318 { \
03319 act_result[j] = DSEXT##size(- LS##size(&cool_ints[j])); \
03320 \
03321 if (is_zero##size(act_result[j])) \
03322 { \
03323 act_status[j] = AR_STAT_ZERO; \
03324 } \
03325 else \
03326 { \
03327 if (is_neg##size(LS##size(&cool_ints[j])) == \
03328 is_neg##size(act_result[j])) \
03329 {
03330 \
03331 if(LS##size(&cool_ints[j]) != \
03332 LS##size((AR_INT_64*)&act_result[j])) \
03333 act_status[j] = AR_STAT_OVERFLOW; \
03334 else \
03335 act_status[j] = AR_STAT_SEMIVALID; \
03336 } \
03337 else \
03338 { \
03339 act_status[j] = AR_STAT_OK; \
03340 } \
03341 } \
03342 \
03343 if (is_neg##size(act_result[j])) \
03344 act_status[j] |= AR_STAT_NEGATIVE; \
03345 \
03346 test_result[j].part1 = 0; \
03347 test_result[j].part2 = 0; \
03348 test_result[j].part3 = 0; \
03349 test_result[j].part4 = 0; \
03350 \
03351 test_status[j] = AR_negate((AR_DATA *)&test_result[j], \
03352 &sint##size##_artype, \
03353 (AR_DATA *)&cool_ints[j], \
03354 &sint##size##_artype); \
03355 \
03356 if (LU64(&test_result[j]) != act_result[j]) \
03357 { \
03358 printf(" ERROR: incorrect result at %d\n", j); \
03359 abort(); \
03360 } \
03361 \
03362 if (act_status[j] != test_status[j]) \
03363 { \
03364 printf(" ERROR: incorrect status at %d\n", j); \
03365 abort(); \
03366 } \
03367 } \
03368 \
03369 printf("PASSED\n"); \
03370 } while (0)
03371
03372
03373 #define TEST_NEG_OP_UNSIGNED(size) \
03374 do { \
03375 int j; \
03376 \
03377 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "unary -"); \
03378 \
03379 for (j=0; j<num_cool_ints; j++) \
03380 { \
03381 act_result[j] = DSEXT##size(- LU##size(&cool_ints[j])); \
03382 \
03383 act_status[j] = is_zero##size(act_result[j]) \
03384 ? AR_STAT_ZERO : AR_STAT_OK; \
03385 \
03386 test_result[j].part1 = 0; \
03387 test_result[j].part2 = 0; \
03388 test_result[j].part3 = 0; \
03389 test_result[j].part4 = 0; \
03390 \
03391 test_status[j] = AR_negate((AR_DATA *)&test_result[j], \
03392 &uint##size##_artype, \
03393 (AR_DATA *)&cool_ints[j], \
03394 &uint##size##_artype); \
03395 \
03396 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
03397 { \
03398 printf(" ERROR: incorrect result at %d\n", j); \
03399 abort(); \
03400 } \
03401 \
03402 if (act_status[j] != test_status[j]) \
03403 { \
03404 printf(" ERROR: incorrect status at %d\n", j); \
03405 abort(); \
03406 } \
03407 } \
03408 \
03409 printf("PASSED\n"); \
03410 } while (0)
03411
03412
03413 #define TEST_NEG_OP_TYPES \
03414 do { \
03415 int j, k; \
03416 \
03417 printf(" Testing: types %-10s: ", "unary -"); \
03418 \
03419 for (j=0; j<num_ar_types; j++) \
03420 { \
03421 for (k=0; k<num_ar_types; k++) \
03422 { \
03423 act_status[k] = AR_STAT_OK; \
03424 if (ar_types[j] != ar_types[k] || \
03425 !IS_SUPPORTED_INT_TYPE(ar_types[j])) \
03426 act_status[k] = AR_STAT_INVALID_TYPE; \
03427 \
03428 test_status[k] = AR_negate((AR_DATA *)&test_result[1], \
03429 &ar_types[j], \
03430 (AR_DATA *)&cool_ints[1], \
03431 &ar_types[k]); \
03432 \
03433 if ((act_status[k] ^ test_status[k]) & \
03434 AR_STAT_INVALID_TYPE) \
03435 { \
03436 printf(" ERROR: incorrect status at %d,%d\n", j, k); \
03437 abort(); \
03438 } \
03439 } \
03440 } \
03441 \
03442 printf("PASSED\n"); \
03443 } while (0)
03444
03445
03446 test_negate()
03447 {
03448
03449 TEST_NEG_OP_SIGNED( 8);
03450 TEST_NEG_OP_UNSIGNED( 8);
03451
03452 TEST_NEG_OP_SIGNED( 16);
03453 TEST_NEG_OP_UNSIGNED(16);
03454
03455 TEST_NEG_OP_SIGNED( 32);
03456 TEST_NEG_OP_UNSIGNED(32);
03457
03458 TEST_NEG_OP_SIGNED( 46);
03459
03460 TEST_NEG_OP_SIGNED( 64);
03461 TEST_NEG_OP_UNSIGNED(64);
03462
03463 TEST_NEG_OP_TYPES;
03464
03465 }
03466
03467
03468 #undef TEST_NEG_SIGNED
03469 #undef TEST_NEG_UNSIGNED
03470 #undef TEST_NEG_TYPES
03471
03472
03473 #define TEST_ABS_OP_SIGNED(size) \
03474 do { \
03475 int j; \
03476 \
03477 printf(" Testing: SIGNED %2d INT %-10s: ", size, "abs"); \
03478 \
03479 for (j=0; j<num_cool_ints; j++) \
03480 { \
03481 if (is_neg##size(LS##size(&cool_ints[j]))) \
03482 act_result[j] = DSEXT##size( - LS##size(&cool_ints[j])); \
03483 else \
03484 act_result[j] = DSEXT##size( LS##size(&cool_ints[j])); \
03485 \
03486 act_status[j] = is_zero##size(act_result[j]) \
03487 ? AR_STAT_ZERO : AR_STAT_OK; \
03488 \
03489 if (is_neg##size(act_result[j])) \
03490 { \
03491 act_status[j] |= AR_STAT_NEGATIVE; \
03492 act_status[j] |= AR_STAT_OVERFLOW; \
03493 } \
03494 \
03495 test_result[j].part1 = 0; \
03496 test_result[j].part2 = 0; \
03497 test_result[j].part3 = 0; \
03498 test_result[j].part4 = 0; \
03499 \
03500 test_status[j] = AR_abs((AR_DATA *)&test_result[j], \
03501 &sint##size##_artype, \
03502 (AR_DATA *)&cool_ints[j], \
03503 &sint##size##_artype); \
03504 \
03505 if (LU64(&test_result[j]) != act_result[j]) \
03506 { \
03507 printf(" ERROR: incorrect result at %d\n", j); \
03508 abort(); \
03509 } \
03510 \
03511 if (act_status[j] != test_status[j]) \
03512 { \
03513 printf(" ERROR: incorrect status at %d\n", j); \
03514 abort(); \
03515 } \
03516 } \
03517 \
03518 printf("PASSED\n"); \
03519 } while (0)
03520
03521
03522 #define TEST_ABS_OP_UNSIGNED(size) \
03523 do { \
03524 int j; \
03525 \
03526 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "abs"); \
03527 \
03528 for (j=0; j<num_cool_ints; j++) \
03529 { \
03530 act_result[j] = DSEXT##size(LU64(&cool_ints[j])); \
03531 \
03532 act_status[j] = is_zero##size(act_result[j]) \
03533 ? AR_STAT_ZERO : AR_STAT_OK; \
03534 \
03535 test_result[j].part1 = 0; \
03536 test_result[j].part2 = 0; \
03537 test_result[j].part3 = 0; \
03538 test_result[j].part4 = 0; \
03539 \
03540 test_status[j] = AR_abs((AR_DATA *)&test_result[j], \
03541 &uint##size##_artype, \
03542 (AR_DATA *)&cool_ints[j], \
03543 &uint##size##_artype); \
03544 \
03545 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
03546 { \
03547 printf(" ERROR: incorrect result at %d\n", j); \
03548 abort(); \
03549 } \
03550 \
03551 if (act_status[j] != test_status[j]) \
03552 { \
03553 printf(" ERROR: incorrect status at %d\n", j); \
03554 abort(); \
03555 } \
03556 } \
03557 \
03558 printf("PASSED\n"); \
03559 } while (0)
03560
03561
03562 #define TEST_ABS_OP_TYPES \
03563 do { \
03564 int j, k; \
03565 \
03566 printf(" Testing: types %-10s: ", "abs"); \
03567 \
03568 for (j=0; j<num_ar_types; j++) \
03569 { \
03570 for (k=0; k<num_ar_types; k++) \
03571 { \
03572 act_status[k] = AR_STAT_OK; \
03573 if (ar_types[j] != ar_types[k] || \
03574 !IS_SUPPORTED_INT_TYPE(ar_types[j])) \
03575 act_status[k] = AR_STAT_INVALID_TYPE; \
03576 \
03577 test_status[k] = AR_abs((AR_DATA *)&test_result[1], \
03578 &ar_types[j], \
03579 (AR_DATA *)&cool_ints[1], \
03580 &ar_types[k]); \
03581 \
03582 if ((act_status[k] ^ test_status[k]) & \
03583 AR_STAT_INVALID_TYPE) \
03584 { \
03585 printf(" ERROR: incorrect status at %d,%d\n", j, k); \
03586 abort(); \
03587 } \
03588 } \
03589 } \
03590 \
03591 printf("PASSED\n"); \
03592 } while (0)
03593
03594
03595 test_abs()
03596 {
03597
03598 TEST_ABS_OP_SIGNED( 8);
03599 TEST_ABS_OP_UNSIGNED( 8);
03600
03601 TEST_ABS_OP_SIGNED( 16);
03602 TEST_ABS_OP_UNSIGNED(16);
03603
03604 TEST_ABS_OP_SIGNED( 32);
03605 TEST_ABS_OP_UNSIGNED(32);
03606
03607 TEST_ABS_OP_SIGNED( 46);
03608
03609 TEST_ABS_OP_SIGNED( 64);
03610 TEST_ABS_OP_UNSIGNED(64);
03611
03612 TEST_ABS_OP_TYPES;
03613
03614 }
03615
03616
03617 #undef TEST_ABS_OP_SIGNED
03618 #undef TEST_ABS_OP_UNSIGNED
03619 #undef TEST_ABS_OP_TYPES
03620
03621
03622 #define TEST_MUL_OP_SIGNED(size) \
03623 do { \
03624 int i, j; \
03625 \
03626 printf(" Testing: SIGNED %2d INT %-10s: ", size, "*"); \
03627 \
03628 for (i=0; i<num_cool_ints; i++) \
03629 { \
03630 for (j=0; j<num_cool_ints; j++) \
03631 { \
03632 if (size == 46) \
03633 act_result[j] = (SINT64)(LS64(&cool_ints[i]) * \
03634 LS64(&cool_ints[j])); \
03635 else \
03636 act_result[j] = DSEXT##size(LS##size(&cool_ints[i]) * \
03637 LS##size(&cool_ints[j])); \
03638 \
03639 act_status[j] = is_zero##size(act_result[j]) \
03640 ? AR_STAT_ZERO : AR_STAT_OK; \
03641 if (is_neg##size(act_result[j])) \
03642 act_status[j] |= AR_STAT_NEGATIVE; \
03643 \
03644 \
03645 if (size == 46) \
03646 { \
03647 if (((LS64(&cool_ints[i]) & ((~((SINT64) 0)) << 45)) \
03648 != 0) && \
03649 ((LS64(&cool_ints[i]) & ((~((SINT64) 0)) << 45)) \
03650 != ((~((SINT64) 0)) << 45))) \
03651 {
03652 \
03653 act_status[j] |= AR_STAT_OVERFLOW; \
03654 } \
03655 else \
03656 if (((LS64(&cool_ints[j]) & ((~((SINT64) 0)) << 45)) \
03657 != 0) && \
03658 ((LS64(&cool_ints[j]) & ((~((SINT64) 0)) << 45)) \
03659 != ((~((SINT64) 0)) << 45))) \
03660 {
03661 \
03662 act_status[j] |= AR_STAT_OVERFLOW; \
03663 } \
03664 else \
03665 if (((act_result[j] & ((~((SINT64) 0)) << 45)) \
03666 != 0) && \
03667 ((act_result[j] & ((~((SINT64) 0)) << 45)) \
03668 != ((~((SINT64) 0)) << 45))) \
03669 {
03670 \
03671 act_status[j] |= AR_STAT_OVERFLOW; \
03672 } \
03673 } \
03674 \
03675 if (LS##size(&cool_ints[i]) != 0 && \
03676 LS##size(&cool_ints[j]) != 0) \
03677 {
03678
03679
03680 \
03681 if (is_neg##size(LS##size(&cool_ints[i]) ^ \
03682 LS##size(&cool_ints[j]) ^ \
03683 act_result[j])) \
03684 {
03685 \
03686 act_status[j] |= AR_STAT_OVERFLOW; \
03687 } \
03688 else if ((SEXT##size(act_result[j]) / \
03689 LS##size(&cool_ints[i])) != \
03690 LS##size(&cool_ints[j])) \
03691 {
03692
03693
03694 \
03695 act_status[j] |= AR_STAT_OVERFLOW; \
03696 } \
03697 } \
03698 \
03699 test_result[j].part1 = 0; \
03700 test_result[j].part2 = 0; \
03701 test_result[j].part3 = 0; \
03702 test_result[j].part4 = 0; \
03703 \
03704 test_status[j] = AR_multiply((AR_DATA *)&test_result[j], \
03705 &sint##size##_artype, \
03706 (AR_DATA *)&cool_ints[i], \
03707 &sint##size##_artype, \
03708 (AR_DATA *)&cool_ints[j], \
03709 &sint##size##_artype); \
03710 \
03711 if (LU64(&test_result[j]) != act_result[j]) \
03712 { \
03713 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
03714 abort(); \
03715 } \
03716 \
03717 if (act_status[j] != test_status[j]) \
03718 { \
03719 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
03720 abort(); \
03721 } \
03722 } \
03723 } \
03724 \
03725 printf("PASSED\n"); \
03726 } while (0)
03727
03728
03729 #define TEST_MUL_OP_UNSIGNED(size) \
03730 do { \
03731 int i, j; \
03732 \
03733 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "*"); \
03734 \
03735 for (i=0; i<num_cool_ints; i++) \
03736 { \
03737 for (j=0; j<num_cool_ints; j++) \
03738 { \
03739 act_result[j] = DSEXT##size(LU##size(&cool_ints[i]) * \
03740 LU##size(&cool_ints[j])); \
03741 \
03742 act_status[j] = is_zero##size(act_result[j]) \
03743 ? AR_STAT_ZERO : AR_STAT_OK; \
03744 \
03745 test_result[j].part1 = 0; \
03746 test_result[j].part2 = 0; \
03747 test_result[j].part3 = 0; \
03748 test_result[j].part4 = 0; \
03749 \
03750 test_status[j] = AR_multiply((AR_DATA *)&test_result[j], \
03751 &uint##size##_artype, \
03752 (AR_DATA *)&cool_ints[i], \
03753 &uint##size##_artype, \
03754 (AR_DATA *)&cool_ints[j], \
03755 &uint##size##_artype); \
03756 \
03757 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
03758 { \
03759 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
03760 abort(); \
03761 } \
03762 \
03763 if (act_status[j] != test_status[j]) \
03764 { \
03765 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
03766 abort(); \
03767 } \
03768 } \
03769 } \
03770 \
03771 printf("PASSED\n"); \
03772 } while (0)
03773
03774
03775 #define TEST_MUL_OP_TYPES \
03776 do { \
03777 int i, j, k; \
03778 \
03779 printf(" Testing: types %-10s: ", "*"); \
03780 \
03781 for (i=0; i<num_ar_types; i++) \
03782 { \
03783 for (j=0; j<num_ar_types; j++) \
03784 { \
03785 for (k=0; k<num_ar_types; k++) \
03786 { \
03787 act_status[k] = AR_STAT_OK; \
03788 if (ar_types[i] != ar_types[j] || \
03789 ar_types[j] != ar_types[k] || \
03790 !IS_SUPPORTED_INT_TYPE(ar_types[i])) \
03791 act_status[k] = AR_STAT_INVALID_TYPE; \
03792 \
03793 test_status[k] = AR_multiply((AR_DATA *)&test_result[1], \
03794 &ar_types[i], \
03795 (AR_DATA *)&cool_ints[1], \
03796 &ar_types[j], \
03797 (AR_DATA *)&cool_ints[1], \
03798 &ar_types[k]); \
03799 \
03800 if ((act_status[k] ^ test_status[k]) & \
03801 AR_STAT_INVALID_TYPE) \
03802 { \
03803 printf(" ERROR: incorrect status at %d,%d,%d\n", \
03804 i, j, k); \
03805 abort(); \
03806 } \
03807 } \
03808 } \
03809 } \
03810 \
03811 printf("PASSED\n"); \
03812 } while (0)
03813
03814
03815 test_multiply()
03816 {
03817
03818 TEST_MUL_OP_SIGNED( 8);
03819 TEST_MUL_OP_UNSIGNED( 8);
03820
03821 TEST_MUL_OP_SIGNED( 16);
03822 TEST_MUL_OP_UNSIGNED(16);
03823
03824 TEST_MUL_OP_SIGNED( 32);
03825 TEST_MUL_OP_UNSIGNED(32);
03826
03827 TEST_MUL_OP_SIGNED( 46);
03828
03829 TEST_MUL_OP_SIGNED( 64);
03830 TEST_MUL_OP_UNSIGNED(64);
03831
03832 TEST_MUL_OP_TYPES;
03833
03834 }
03835
03836
03837 #undef TEST_MUL_OP_SIGNED
03838 #undef TEST_MUL_OP_UNSIGNED
03839 #undef TEST_MUL_OP_TYPES
03840
03841
03842 #define TEST_DIV_OP_SIGNED(size) \
03843 do { \
03844 int i, j; \
03845 \
03846 printf(" Testing: SIGNED %2d INT %-10s: ", size, "/"); \
03847 \
03848 for (i=0; i<num_cool_ints; i++) \
03849 { \
03850 for (j=0; j<num_cool_ints; j++) \
03851 { \
03852 act_status[j] = AR_STAT_OK; \
03853 \
03854 if (LS##size(&cool_ints[j]) == 0) \
03855 { \
03856 act_result[j] = 0; \
03857 act_status[j] |= AR_STAT_OVERFLOW; \
03858 } \
03859 else if (size == 46) \
03860 { \
03861 \
03862
03863 \
03864 act_result[j] = (SINT64)(LS64(&cool_ints[i]) / \
03865 LS64(&cool_ints[j])); \
03866 \
03867 if (((LS64(&cool_ints[i]) & ((~((SINT64) 0)) << 45)) \
03868 != 0) && \
03869 ((LS64(&cool_ints[i]) & ((~((SINT64) 0)) << 45)) \
03870 != ((~((SINT64) 0)) << 45))) \
03871 {
03872 \
03873 act_status[j] |= AR_STAT_OVERFLOW; \
03874 } \
03875 else if (((LS64(&cool_ints[j]) & ((~((SINT64) 0)) << 45))\
03876 != 0) && \
03877 ((LS64(&cool_ints[j]) & ((~((SINT64) 0)) << 45))\
03878 != ((~((SINT64) 0)) << 45))) \
03879 {
03880 \
03881 act_status[j] |= AR_STAT_OVERFLOW; \
03882 } \
03883 else if (((act_result[j] & ((~((SINT64) 0)) << 45)) \
03884 != 0) && \
03885 ((act_result[j] & ((~((SINT64) 0)) << 45)) \
03886 != ((~((SINT64) 0)) << 45))) \
03887 {
03888 \
03889 act_status[j] |= AR_STAT_OVERFLOW; \
03890 } \
03891 else if (!is_zero##size(act_result [j]) && \
03892 (LS64(&cool_ints[i]) ^ \
03893 LS64(&cool_ints[j]) ^ \
03894 act_result[j]) < 0) \
03895 { \
03896 act_status[j] |= AR_STAT_OVERFLOW; \
03897 } \
03898 } \
03899 else \
03900 { \
03901 \
03902 act_result[j] = DSEXT##size(LS##size(&cool_ints[i]) / \
03903 LS##size(&cool_ints[j])); \
03904 \
03905 if (!is_zero##size(act_result[j]) && \
03906 is_neg##size(LS##size(&cool_ints[i]) ^ \
03907 LS##size(&cool_ints[j]) ^ \
03908 act_result[j])) \
03909 { \
03910 act_status[j] |= AR_STAT_OVERFLOW; \
03911 } \
03912 } \
03913 \
03914 if (is_zero##size(act_result[j])) \
03915 act_status[j] |= AR_STAT_ZERO; \
03916 \
03917 if (is_neg##size(act_result[j])) \
03918 act_status[j] |= AR_STAT_NEGATIVE; \
03919 \
03920 test_result[j].part1 = 0; \
03921 test_result[j].part2 = 0; \
03922 test_result[j].part3 = 0; \
03923 test_result[j].part4 = 0; \
03924 \
03925 test_status[j] = AR_divide((AR_DATA *)&test_result[j], \
03926 &sint##size##_artype, \
03927 (AR_DATA *)&cool_ints[i], \
03928 &sint##size##_artype, \
03929 (AR_DATA *)&cool_ints[j], \
03930 &sint##size##_artype); \
03931 \
03932 if (LU64(&test_result[j]) != act_result[j]) \
03933 { \
03934 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
03935 abort(); \
03936 } \
03937 \
03938 if (act_status[j] != test_status[j]) \
03939 { \
03940 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
03941 abort(); \
03942 } \
03943 } \
03944 } \
03945 \
03946 printf("PASSED\n"); \
03947 } while (0)
03948
03949
03950 #define TEST_DIV_OP_UNSIGNED(size) \
03951 do { \
03952 int i, j; \
03953 \
03954 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "/"); \
03955 \
03956 for (i=0; i<num_cool_ints; i++) \
03957 { \
03958 for (j=0; j<num_cool_ints; j++) \
03959 { \
03960 act_status[j] = AR_STAT_OK; \
03961 \
03962 if (LU##size(&cool_ints[j]) == 0) \
03963 { \
03964 act_result[j] = 0; \
03965 act_status[j] |= AR_STAT_OVERFLOW; \
03966 } \
03967 else \
03968 { \
03969 act_result[j] = LU##size(&cool_ints[i]) / \
03970 LU##size(&cool_ints[j]); \
03971 } \
03972 \
03973 if (is_zero##size(act_result[j])) \
03974 act_status[j] |= AR_STAT_ZERO; \
03975 \
03976 test_result[j].part1 = 0; \
03977 test_result[j].part2 = 0; \
03978 test_result[j].part3 = 0; \
03979 test_result[j].part4 = 0; \
03980 \
03981 test_status[j] = AR_divide((AR_DATA *)&test_result[j], \
03982 &uint##size##_artype, \
03983 (AR_DATA *)&cool_ints[i], \
03984 &uint##size##_artype, \
03985 (AR_DATA *)&cool_ints[j], \
03986 &uint##size##_artype); \
03987 \
03988 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
03989 { \
03990 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
03991 abort(); \
03992 } \
03993 \
03994 if (act_status[j] != test_status[j]) \
03995 { \
03996 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
03997 abort(); \
03998 } \
03999 } \
04000 } \
04001 \
04002 printf("PASSED\n"); \
04003 } while (0)
04004
04005
04006 #define TEST_DIV_OP_TYPES \
04007 do { \
04008 int i, j, k; \
04009 \
04010 printf(" Testing: types %-10s: ", "/"); \
04011 \
04012 for (i=0; i<num_ar_types; i++) \
04013 { \
04014 for (j=0; j<num_ar_types; j++) \
04015 { \
04016 for (k=0; k<num_ar_types; k++) \
04017 { \
04018 act_status[k] = AR_STAT_OK; \
04019 if (ar_types[i] != ar_types[j] || \
04020 ar_types[j] != ar_types[k] || \
04021 !IS_SUPPORTED_INT_TYPE(ar_types[i])) \
04022 act_status[k] = AR_STAT_INVALID_TYPE; \
04023 \
04024 test_status[k] = AR_divide((AR_DATA *)&test_result[1], \
04025 &ar_types[i], \
04026 (AR_DATA *)&cool_ints[1], \
04027 &ar_types[j], \
04028 (AR_DATA *)&cool_ints[1], \
04029 &ar_types[k]); \
04030 \
04031 if ((act_status[k] ^ test_status[k]) & \
04032 AR_STAT_INVALID_TYPE) \
04033 { \
04034 printf(" ERROR: incorrect status at %d,%d,%d\n", \
04035 i, j, k); \
04036 abort(); \
04037 } \
04038 } \
04039 } \
04040 } \
04041 \
04042 printf("PASSED\n"); \
04043 } while (0)
04044
04045
04046 test_divide()
04047 {
04048 TEST_DIV_OP_SIGNED( 8);
04049 TEST_DIV_OP_UNSIGNED( 8);
04050
04051 TEST_DIV_OP_SIGNED( 16);
04052 TEST_DIV_OP_UNSIGNED(16);
04053
04054 TEST_DIV_OP_SIGNED( 32);
04055 TEST_DIV_OP_UNSIGNED(32);
04056
04057 TEST_DIV_OP_SIGNED( 46);
04058
04059 TEST_DIV_OP_SIGNED( 64);
04060 TEST_DIV_OP_UNSIGNED(64);
04061
04062 TEST_DIV_OP_TYPES;
04063
04064 }
04065
04066
04067 #undef TEST_DIV_OP_SIGNED
04068 #undef TEST_DIV_OP_UNSIGNED
04069 #undef TEST_DIV_OP_TYPES
04070
04071
04072 #define TEST_MOD_OP_SIGNED(size) \
04073 do { \
04074 int i, j; \
04075 \
04076 printf(" Testing: SIGNED %2d INT %-10s: ", size, "%"); \
04077 \
04078 for (i=0; i<num_cool_ints; i++) \
04079 { \
04080 for (j=0; j<num_cool_ints; j++) \
04081 { \
04082 act_status[j] = AR_STAT_OK; \
04083 \
04084 if (LS##size(&cool_ints[j]) == 0) \
04085 { \
04086 act_result[j] = 0; \
04087 act_status[j] |= AR_STAT_OVERFLOW; \
04088 } \
04089 else \
04090 { \
04091 act_result[j] = DSEXT##size(LS##size(&cool_ints[i]) % \
04092 LS##size(&cool_ints[j])); \
04093 \
04094 if (!is_zero##size(act_result[j]) && \
04095 is_neg##size(LS##size(&cool_ints[i]) ^ \
04096 act_result[j])) \
04097 { \
04098 act_status[j] |= AR_STAT_OVERFLOW; \
04099 } \
04100 } \
04101 \
04102 if (is_zero##size(act_result[j])) \
04103 act_status[j] |= AR_STAT_ZERO; \
04104 \
04105 if (is_neg##size(act_result[j])) \
04106 act_status[j] |= AR_STAT_NEGATIVE; \
04107 \
04108 test_result[j].part1 = 0; \
04109 test_result[j].part2 = 0; \
04110 test_result[j].part3 = 0; \
04111 test_result[j].part4 = 0; \
04112 \
04113 test_status[j] = AR_modulo((AR_DATA *)&test_result[j], \
04114 &sint##size##_artype, \
04115 (AR_DATA *)&cool_ints[i], \
04116 &sint##size##_artype, \
04117 (AR_DATA *)&cool_ints[j], \
04118 &sint##size##_artype); \
04119 \
04120 if (LU64(&test_result[j]) != act_result[j]) \
04121 { \
04122 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
04123 abort(); \
04124 } \
04125 \
04126 if (act_status[j] != test_status[j]) \
04127 { \
04128 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
04129 abort(); \
04130 } \
04131 } \
04132 } \
04133 \
04134 printf("PASSED\n"); \
04135 } while (0)
04136
04137
04138 #define TEST_MOD_OP_UNSIGNED(size) \
04139 do { \
04140 int i, j; \
04141 \
04142 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "%"); \
04143 \
04144 for (i=0; i<num_cool_ints; i++) \
04145 { \
04146 for (j=0; j<num_cool_ints; j++) \
04147 { \
04148 act_status[j] = AR_STAT_OK; \
04149 \
04150 if (LU##size(&cool_ints[j]) == 0) \
04151 { \
04152 act_result[j] = 0; \
04153 act_status[j] |= AR_STAT_OVERFLOW; \
04154 } \
04155 else \
04156 { \
04157 act_result[j] = LU##size(&cool_ints[i]) % \
04158 LU##size(&cool_ints[j]); \
04159 } \
04160 \
04161 if (is_zero##size(act_result[j])) \
04162 act_status[j] |= AR_STAT_ZERO; \
04163 \
04164 test_result[j].part1 = 0; \
04165 test_result[j].part2 = 0; \
04166 test_result[j].part3 = 0; \
04167 test_result[j].part4 = 0; \
04168 \
04169 test_status[j] = AR_modulo((AR_DATA *)&test_result[j], \
04170 &uint##size##_artype, \
04171 (AR_DATA *)&cool_ints[i], \
04172 &uint##size##_artype, \
04173 (AR_DATA *)&cool_ints[j], \
04174 &uint##size##_artype); \
04175 \
04176 if (LU64(&test_result[j]) != (UINT64)act_result[j]) \
04177 { \
04178 printf(" ERROR: incorrect result at %d,%d\n", i, j); \
04179 abort(); \
04180 } \
04181 \
04182 if (act_status[j] != test_status[j]) \
04183 { \
04184 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
04185 abort(); \
04186 } \
04187 } \
04188 } \
04189 \
04190 printf("PASSED\n"); \
04191 } while (0)
04192
04193
04194 #define TEST_MOD_OP_TYPES \
04195 do { \
04196 int i, j, k; \
04197 \
04198 printf(" Testing: types %-10s: ", "%"); \
04199 \
04200 for (i=0; i<num_ar_types; i++) \
04201 { \
04202 for (j=0; j<num_ar_types; j++) \
04203 { \
04204 for (k=0; k<num_ar_types; k++) \
04205 { \
04206 act_status[k] = AR_STAT_OK; \
04207 if (ar_types[i] != ar_types[j] || \
04208 ar_types[j] != ar_types[k] || \
04209 !IS_SUPPORTED_INT_TYPE(ar_types[i])) \
04210 act_status[k] = AR_STAT_INVALID_TYPE; \
04211 \
04212 test_status[k] = AR_modulo((AR_DATA *)&test_result[1], \
04213 &ar_types[i], \
04214 (AR_DATA *)&cool_ints[1], \
04215 &ar_types[j], \
04216 (AR_DATA *)&cool_ints[1], \
04217 &ar_types[k]); \
04218 \
04219 if ((act_status[k] ^ test_status[k]) & \
04220 AR_STAT_INVALID_TYPE) \
04221 { \
04222 printf(" ERROR: incorrect status at %d,%d,%d\n", \
04223 i, j, k); \
04224 abort(); \
04225 } \
04226 } \
04227 } \
04228 } \
04229 \
04230 printf("PASSED\n"); \
04231 } while (0)
04232
04233
04234 test_modulo()
04235 {
04236
04237 TEST_MOD_OP_SIGNED( 8);
04238 TEST_MOD_OP_UNSIGNED( 8);
04239
04240 TEST_MOD_OP_SIGNED( 16);
04241 TEST_MOD_OP_UNSIGNED(16);
04242
04243 TEST_MOD_OP_SIGNED( 32);
04244 TEST_MOD_OP_UNSIGNED(32);
04245
04246 TEST_MOD_OP_SIGNED( 46);
04247
04248 TEST_MOD_OP_SIGNED( 64);
04249 TEST_MOD_OP_UNSIGNED(64);
04250
04251 TEST_MOD_OP_TYPES;
04252
04253 }
04254
04255
04256 #undef TEST_MOD_OP_SIGNED
04257 #undef TEST_MOD_OP_UNSIGNED
04258 #undef TEST_MOD_OP_TYPES
04259
04260
04261
04262
04263
04264
04265
04266
04267
04268 #define TEST_COMPARE_OP_SIGNED(size) \
04269 do { \
04270 int i, j; \
04271 \
04272 printf(" Testing: SIGNED %2d INT %-10s: ", size, "compare"); \
04273 \
04274 for (i=0; i<num_cool_ints; i++) \
04275 { \
04276 for (j=0; j<num_cool_ints; j++) \
04277 { \
04278 if (size == 46) { \
04279 if (LS64(&cool_ints[i]) < \
04280 LS64(&cool_ints[j])) \
04281 act_status[j] = AR_Compare_LT; \
04282 else if (LS64(&cool_ints[i]) > \
04283 LS64(&cool_ints[j])) \
04284 act_status[j] = AR_Compare_GT; \
04285 else \
04286 act_status[j] = AR_Compare_EQ; \
04287 } \
04288 else { \
04289 if (LS##size(&cool_ints[i]) < \
04290 LS##size(&cool_ints[j])) \
04291 act_status[j] = AR_Compare_LT; \
04292 else if (LS##size(&cool_ints[i]) > \
04293 LS##size(&cool_ints[j])) \
04294 act_status[j] = AR_Compare_GT; \
04295 else \
04296 act_status[j] = AR_Compare_EQ; \
04297 } \
04298 \
04299 test_status[j] = AR_compare((AR_DATA *)&cool_ints[i], \
04300 &sint##size##_artype, \
04301 (AR_DATA *)&cool_ints[j], \
04302 &sint##size##_artype); \
04303 \
04304 if (act_status[j] != test_status[j]) \
04305 { \
04306 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
04307 abort(); \
04308 } \
04309 } \
04310 } \
04311 \
04312 printf("PASSED\n"); \
04313 } while (0)
04314
04315
04316 #define TEST_COMPARE_OP_UNSIGNED(size) \
04317 do { \
04318 int i, j; \
04319 \
04320 printf(" Testing: UNSIGNED %2d INT %-10s: ", size, "compare"); \
04321 \
04322 for (i=0; i<num_cool_ints; i++) \
04323 { \
04324 for (j=0; j<num_cool_ints; j++) \
04325 { \
04326 if (LU##size(&cool_ints[i]) < LU##size(&cool_ints[j])) \
04327 act_status[j] = AR_Compare_LT; \
04328 else if (LU##size(&cool_ints[i]) > LU##size(&cool_ints[j])) \
04329 act_status[j] = AR_Compare_GT; \
04330 else \
04331 act_status[j] = AR_Compare_EQ; \
04332 \
04333 test_status[j] = AR_compare((AR_DATA *)&cool_ints[i], \
04334 &uint##size##_artype, \
04335 (AR_DATA *)&cool_ints[j], \
04336 &uint##size##_artype); \
04337 \
04338 if (act_status[j] != test_status[j]) \
04339 { \
04340 printf(" ERROR: incorrect status at %d,%d\n", i, j); \
04341 abort(); \
04342 } \
04343 } \
04344 } \
04345 \
04346 printf("PASSED\n"); \
04347 } while (0)
04348
04349
04350 #define TEST_COMPARE_OP_TYPES \
04351 do { \
04352 int j, k; \
04353 \
04354 printf(" Testing: types %-10s: ", "compare"); \
04355 \
04356 for (j=0; j<num_ar_types; j++) \
04357 { \
04358 for (k=0; k<num_ar_types; k++) \
04359 { \
04360 act_status[k] = AR_STAT_OK; \
04361 if (ar_types[j] != ar_types[k] || \
04362 !IS_SUPPORTED_INT_TYPE(ar_types[j])) \
04363 act_status[k] = AR_Compare_Invalid; \
04364 \
04365 test_status[k] = AR_compare((AR_DATA *)&cool_ints[1], \
04366 &ar_types[j], \
04367 (AR_DATA *)&cool_ints[1], \
04368 &ar_types[k]); \
04369 \
04370 if ((act_status[k] == AR_Compare_Invalid) ^ \
04371 (test_status[k] == AR_Compare_Invalid)) \
04372 { \
04373 printf(" ERROR: incorrect status at %d,%d\n", j, k); \
04374 abort(); \
04375 } \
04376 } \
04377 } \
04378 \
04379 printf("PASSED\n"); \
04380 } while (0)
04381
04382
04383 test_compare()
04384 {
04385
04386 TEST_COMPARE_OP_SIGNED( 8);
04387 TEST_COMPARE_OP_UNSIGNED( 8);
04388
04389 TEST_COMPARE_OP_SIGNED( 16);
04390 TEST_COMPARE_OP_UNSIGNED(16);
04391
04392 TEST_COMPARE_OP_SIGNED( 32);
04393 TEST_COMPARE_OP_UNSIGNED(32);
04394
04395 TEST_COMPARE_OP_SIGNED( 46);
04396
04397 TEST_COMPARE_OP_SIGNED( 64);
04398 TEST_COMPARE_OP_UNSIGNED(64);
04399
04400 TEST_COMPARE_OP_TYPES;
04401
04402 }
04403
04404
04405 static char USMID [] = "\n%Z%%M% %I% %G% %U%\n";
04406 static char rcsid [] = "$Id: testint.c,v 1.1.1.1 2005/10/21 19:00:00 marcel Exp $";