1975af797SJoseph Myers /* Test floating-point exceptions. */ 2975af797SJoseph Myers 3975af797SJoseph Myers #include <float.h> 4975af797SJoseph Myers #include <stdint.h> 5975af797SJoseph Myers #include <stdio.h> 6975af797SJoseph Myers 7975af797SJoseph Myers union u { 8975af797SJoseph Myers struct { uint64_t sig; uint16_t sign_exp; } s; 9975af797SJoseph Myers long double ld; 10975af797SJoseph Myers }; 11975af797SJoseph Myers 12975af797SJoseph Myers volatile float f_res; 13975af797SJoseph Myers volatile double d_res; 14975af797SJoseph Myers volatile long double ld_res; 15975af797SJoseph Myers volatile long double ld_res2; 16975af797SJoseph Myers 17975af797SJoseph Myers volatile union u ld_invalid_1 = { .s = { 1, 1234 } }; 18975af797SJoseph Myers volatile float f_snan = __builtin_nansf(""); 19975af797SJoseph Myers volatile double d_snan = __builtin_nans(""); 20975af797SJoseph Myers volatile long double ld_third = 1.0L / 3.0L; 21975af797SJoseph Myers volatile long double ld_snan = __builtin_nansl(""); 22975af797SJoseph Myers volatile long double ld_nan = __builtin_nanl(""); 23975af797SJoseph Myers volatile long double ld_inf = __builtin_infl(); 24975af797SJoseph Myers volatile long double ld_ninf = -__builtin_infl(); 25975af797SJoseph Myers volatile long double ld_one = 1.0L; 26975af797SJoseph Myers volatile long double ld_zero = 0.0L; 27975af797SJoseph Myers volatile long double ld_nzero = -0.0L; 28975af797SJoseph Myers volatile long double ld_min = LDBL_MIN; 29975af797SJoseph Myers volatile long double ld_max = LDBL_MAX; 30975af797SJoseph Myers volatile long double ld_nmax = -LDBL_MAX; 31975af797SJoseph Myers 32975af797SJoseph Myers #define IE (1 << 0) 33975af797SJoseph Myers #define ZE (1 << 2) 34975af797SJoseph Myers #define OE (1 << 3) 35975af797SJoseph Myers #define UE (1 << 4) 36975af797SJoseph Myers #define PE (1 << 5) 37975af797SJoseph Myers #define EXC (IE | ZE | OE | UE | PE) 38975af797SJoseph Myers 39975af797SJoseph Myers int main(void) 40975af797SJoseph Myers { 41975af797SJoseph Myers short sw; 42975af797SJoseph Myers unsigned char out[10]; 43975af797SJoseph Myers int ret = 0; 44975af797SJoseph Myers int16_t res_16; 45975af797SJoseph Myers int32_t res_32; 46975af797SJoseph Myers int64_t res_64; 47975af797SJoseph Myers 48975af797SJoseph Myers __asm__ volatile ("fnclex"); 49975af797SJoseph Myers ld_res = f_snan; 50975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 51975af797SJoseph Myers if ((sw & EXC) != IE) { 52975af797SJoseph Myers printf("FAIL: widen float snan\n"); 53975af797SJoseph Myers ret = 1; 54975af797SJoseph Myers } 55975af797SJoseph Myers __asm__ volatile ("fnclex"); 56975af797SJoseph Myers ld_res = d_snan; 57975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 58975af797SJoseph Myers if ((sw & EXC) != IE) { 59975af797SJoseph Myers printf("FAIL: widen double snan\n"); 60975af797SJoseph Myers ret = 1; 61975af797SJoseph Myers } 62975af797SJoseph Myers 63975af797SJoseph Myers __asm__ volatile ("fnclex"); 64975af797SJoseph Myers f_res = ld_min; 65975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 66975af797SJoseph Myers if ((sw & EXC) != (UE | PE)) { 67975af797SJoseph Myers printf("FAIL: narrow float underflow\n"); 68975af797SJoseph Myers ret = 1; 69975af797SJoseph Myers } 70975af797SJoseph Myers __asm__ volatile ("fnclex"); 71975af797SJoseph Myers d_res = ld_min; 72975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 73975af797SJoseph Myers if ((sw & EXC) != (UE | PE)) { 74975af797SJoseph Myers printf("FAIL: narrow double underflow\n"); 75975af797SJoseph Myers ret = 1; 76975af797SJoseph Myers } 77975af797SJoseph Myers 78975af797SJoseph Myers __asm__ volatile ("fnclex"); 79975af797SJoseph Myers f_res = ld_max; 80975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 81975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 82975af797SJoseph Myers printf("FAIL: narrow float overflow\n"); 83975af797SJoseph Myers ret = 1; 84975af797SJoseph Myers } 85975af797SJoseph Myers __asm__ volatile ("fnclex"); 86975af797SJoseph Myers d_res = ld_max; 87975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 88975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 89975af797SJoseph Myers printf("FAIL: narrow double overflow\n"); 90975af797SJoseph Myers ret = 1; 91975af797SJoseph Myers } 92975af797SJoseph Myers 93975af797SJoseph Myers __asm__ volatile ("fnclex"); 94975af797SJoseph Myers f_res = ld_third; 95975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 96975af797SJoseph Myers if ((sw & EXC) != PE) { 97975af797SJoseph Myers printf("FAIL: narrow float inexact\n"); 98975af797SJoseph Myers ret = 1; 99975af797SJoseph Myers } 100975af797SJoseph Myers __asm__ volatile ("fnclex"); 101975af797SJoseph Myers d_res = ld_third; 102975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 103975af797SJoseph Myers if ((sw & EXC) != PE) { 104975af797SJoseph Myers printf("FAIL: narrow double inexact\n"); 105975af797SJoseph Myers ret = 1; 106975af797SJoseph Myers } 107975af797SJoseph Myers 108975af797SJoseph Myers __asm__ volatile ("fnclex"); 109975af797SJoseph Myers f_res = ld_snan; 110975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 111975af797SJoseph Myers if ((sw & EXC) != IE) { 112975af797SJoseph Myers printf("FAIL: narrow float snan\n"); 113975af797SJoseph Myers ret = 1; 114975af797SJoseph Myers } 115975af797SJoseph Myers __asm__ volatile ("fnclex"); 116975af797SJoseph Myers d_res = ld_snan; 117975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 118975af797SJoseph Myers if ((sw & EXC) != IE) { 119975af797SJoseph Myers printf("FAIL: narrow double snan\n"); 120975af797SJoseph Myers ret = 1; 121975af797SJoseph Myers } 122975af797SJoseph Myers 123975af797SJoseph Myers __asm__ volatile ("fnclex"); 124975af797SJoseph Myers f_res = ld_invalid_1.ld; 125975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 126975af797SJoseph Myers if ((sw & EXC) != IE) { 127975af797SJoseph Myers printf("FAIL: narrow float invalid\n"); 128975af797SJoseph Myers ret = 1; 129975af797SJoseph Myers } 130975af797SJoseph Myers __asm__ volatile ("fnclex"); 131975af797SJoseph Myers d_res = ld_invalid_1.ld; 132975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 133975af797SJoseph Myers if ((sw & EXC) != IE) { 134975af797SJoseph Myers printf("FAIL: narrow double invalid\n"); 135975af797SJoseph Myers ret = 1; 136975af797SJoseph Myers } 137975af797SJoseph Myers 138975af797SJoseph Myers __asm__ volatile ("fnclex"); 139975af797SJoseph Myers __asm__ volatile ("frndint" : "=t" (ld_res) : "0" (ld_min)); 140975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 141975af797SJoseph Myers if ((sw & EXC) != PE) { 142975af797SJoseph Myers printf("FAIL: frndint min\n"); 143975af797SJoseph Myers ret = 1; 144975af797SJoseph Myers } 145975af797SJoseph Myers __asm__ volatile ("fnclex"); 146975af797SJoseph Myers __asm__ volatile ("frndint" : "=t" (ld_res) : "0" (ld_snan)); 147975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 148975af797SJoseph Myers if ((sw & EXC) != IE) { 149975af797SJoseph Myers printf("FAIL: frndint snan\n"); 150975af797SJoseph Myers ret = 1; 151975af797SJoseph Myers } 152975af797SJoseph Myers __asm__ volatile ("fnclex"); 153975af797SJoseph Myers __asm__ volatile ("frndint" : "=t" (ld_res) : "0" (ld_invalid_1.ld)); 154975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 155975af797SJoseph Myers if ((sw & EXC) != IE) { 156975af797SJoseph Myers printf("FAIL: frndint invalid\n"); 157975af797SJoseph Myers ret = 1; 158975af797SJoseph Myers } 159975af797SJoseph Myers 160975af797SJoseph Myers __asm__ volatile ("fnclex"); 161975af797SJoseph Myers __asm__ volatile ("fcom" : : "t" (ld_nan), "u" (ld_zero)); 162975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 163975af797SJoseph Myers if ((sw & EXC) != IE) { 164975af797SJoseph Myers printf("FAIL: fcom nan\n"); 165975af797SJoseph Myers ret = 1; 166975af797SJoseph Myers } 167975af797SJoseph Myers __asm__ volatile ("fnclex"); 168975af797SJoseph Myers __asm__ volatile ("fucom" : : "t" (ld_nan), "u" (ld_zero)); 169975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 170975af797SJoseph Myers if ((sw & EXC) != 0) { 171975af797SJoseph Myers printf("FAIL: fucom nan\n"); 172975af797SJoseph Myers ret = 1; 173975af797SJoseph Myers } 174975af797SJoseph Myers __asm__ volatile ("fnclex"); 175975af797SJoseph Myers __asm__ volatile ("fucom" : : "t" (ld_snan), "u" (ld_zero)); 176975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 177975af797SJoseph Myers if ((sw & EXC) != IE) { 178975af797SJoseph Myers printf("FAIL: fucom snan\n"); 179975af797SJoseph Myers ret = 1; 180975af797SJoseph Myers } 181975af797SJoseph Myers __asm__ volatile ("fnclex"); 182975af797SJoseph Myers __asm__ volatile ("fucom" : : "t" (1.0L), "u" (ld_invalid_1.ld)); 183975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 184975af797SJoseph Myers if ((sw & EXC) != IE) { 185975af797SJoseph Myers printf("FAIL: fucom invalid\n"); 186975af797SJoseph Myers ret = 1; 187975af797SJoseph Myers } 188975af797SJoseph Myers 189975af797SJoseph Myers __asm__ volatile ("fnclex"); 190975af797SJoseph Myers ld_res = ld_max + ld_max; 191975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 192975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 193975af797SJoseph Myers printf("FAIL: add overflow\n"); 194975af797SJoseph Myers ret = 1; 195975af797SJoseph Myers } 196975af797SJoseph Myers __asm__ volatile ("fnclex"); 197975af797SJoseph Myers ld_res = ld_max + ld_min; 198975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 199975af797SJoseph Myers if ((sw & EXC) != PE) { 200975af797SJoseph Myers printf("FAIL: add inexact\n"); 201975af797SJoseph Myers ret = 1; 202975af797SJoseph Myers } 203975af797SJoseph Myers __asm__ volatile ("fnclex"); 204975af797SJoseph Myers ld_res = ld_inf + ld_ninf; 205975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 206975af797SJoseph Myers if ((sw & EXC) != IE) { 207975af797SJoseph Myers printf("FAIL: add inf -inf\n"); 208975af797SJoseph Myers ret = 1; 209975af797SJoseph Myers } 210975af797SJoseph Myers __asm__ volatile ("fnclex"); 211975af797SJoseph Myers ld_res = ld_snan + ld_third; 212975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 213975af797SJoseph Myers if ((sw & EXC) != IE) { 214975af797SJoseph Myers printf("FAIL: add snan\n"); 215975af797SJoseph Myers ret = 1; 216975af797SJoseph Myers } 217975af797SJoseph Myers __asm__ volatile ("fnclex"); 218975af797SJoseph Myers ld_res = ld_third + ld_invalid_1.ld; 219975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 220975af797SJoseph Myers if ((sw & EXC) != IE) { 221975af797SJoseph Myers printf("FAIL: add invalid\n"); 222975af797SJoseph Myers ret = 1; 223975af797SJoseph Myers } 224975af797SJoseph Myers 225975af797SJoseph Myers __asm__ volatile ("fnclex"); 226975af797SJoseph Myers ld_res = ld_max - ld_nmax; 227975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 228975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 229975af797SJoseph Myers printf("FAIL: sub overflow\n"); 230975af797SJoseph Myers ret = 1; 231975af797SJoseph Myers } 232975af797SJoseph Myers __asm__ volatile ("fnclex"); 233975af797SJoseph Myers ld_res = ld_max - ld_min; 234975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 235975af797SJoseph Myers if ((sw & EXC) != PE) { 236975af797SJoseph Myers printf("FAIL: sub inexact\n"); 237975af797SJoseph Myers ret = 1; 238975af797SJoseph Myers } 239975af797SJoseph Myers __asm__ volatile ("fnclex"); 240975af797SJoseph Myers ld_res = ld_inf - ld_inf; 241975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 242975af797SJoseph Myers if ((sw & EXC) != IE) { 243975af797SJoseph Myers printf("FAIL: sub inf inf\n"); 244975af797SJoseph Myers ret = 1; 245975af797SJoseph Myers } 246975af797SJoseph Myers __asm__ volatile ("fnclex"); 247975af797SJoseph Myers ld_res = ld_snan - ld_third; 248975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 249975af797SJoseph Myers if ((sw & EXC) != IE) { 250975af797SJoseph Myers printf("FAIL: sub snan\n"); 251975af797SJoseph Myers ret = 1; 252975af797SJoseph Myers } 253975af797SJoseph Myers __asm__ volatile ("fnclex"); 254975af797SJoseph Myers ld_res = ld_third - ld_invalid_1.ld; 255975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 256975af797SJoseph Myers if ((sw & EXC) != IE) { 257975af797SJoseph Myers printf("FAIL: sub invalid\n"); 258975af797SJoseph Myers ret = 1; 259975af797SJoseph Myers } 260975af797SJoseph Myers 261975af797SJoseph Myers __asm__ volatile ("fnclex"); 262975af797SJoseph Myers ld_res = ld_max * ld_max; 263975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 264975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 265975af797SJoseph Myers printf("FAIL: mul overflow\n"); 266975af797SJoseph Myers ret = 1; 267975af797SJoseph Myers } 268975af797SJoseph Myers __asm__ volatile ("fnclex"); 269975af797SJoseph Myers ld_res = ld_third * ld_third; 270975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 271975af797SJoseph Myers if ((sw & EXC) != PE) { 272975af797SJoseph Myers printf("FAIL: mul inexact\n"); 273975af797SJoseph Myers ret = 1; 274975af797SJoseph Myers } 275975af797SJoseph Myers __asm__ volatile ("fnclex"); 276975af797SJoseph Myers ld_res = ld_min * ld_min; 277975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 278975af797SJoseph Myers if ((sw & EXC) != (UE | PE)) { 279975af797SJoseph Myers printf("FAIL: mul underflow\n"); 280975af797SJoseph Myers ret = 1; 281975af797SJoseph Myers } 282975af797SJoseph Myers __asm__ volatile ("fnclex"); 283975af797SJoseph Myers ld_res = ld_inf * ld_zero; 284975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 285975af797SJoseph Myers if ((sw & EXC) != IE) { 286975af797SJoseph Myers printf("FAIL: mul inf 0\n"); 287975af797SJoseph Myers ret = 1; 288975af797SJoseph Myers } 289975af797SJoseph Myers __asm__ volatile ("fnclex"); 290975af797SJoseph Myers ld_res = ld_snan * ld_third; 291975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 292975af797SJoseph Myers if ((sw & EXC) != IE) { 293975af797SJoseph Myers printf("FAIL: mul snan\n"); 294975af797SJoseph Myers ret = 1; 295975af797SJoseph Myers } 296975af797SJoseph Myers __asm__ volatile ("fnclex"); 297975af797SJoseph Myers ld_res = ld_third * ld_invalid_1.ld; 298975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 299975af797SJoseph Myers if ((sw & EXC) != IE) { 300975af797SJoseph Myers printf("FAIL: mul invalid\n"); 301975af797SJoseph Myers ret = 1; 302975af797SJoseph Myers } 303975af797SJoseph Myers 304975af797SJoseph Myers __asm__ volatile ("fnclex"); 305975af797SJoseph Myers ld_res = ld_max / ld_min; 306975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 307975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 308975af797SJoseph Myers printf("FAIL: div overflow\n"); 309975af797SJoseph Myers ret = 1; 310975af797SJoseph Myers } 311975af797SJoseph Myers __asm__ volatile ("fnclex"); 312975af797SJoseph Myers ld_res = ld_one / ld_third; 313975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 314975af797SJoseph Myers if ((sw & EXC) != PE) { 315975af797SJoseph Myers printf("FAIL: div inexact\n"); 316975af797SJoseph Myers ret = 1; 317975af797SJoseph Myers } 318975af797SJoseph Myers __asm__ volatile ("fnclex"); 319975af797SJoseph Myers ld_res = ld_min / ld_max; 320975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 321975af797SJoseph Myers if ((sw & EXC) != (UE | PE)) { 322975af797SJoseph Myers printf("FAIL: div underflow\n"); 323975af797SJoseph Myers ret = 1; 324975af797SJoseph Myers } 325975af797SJoseph Myers __asm__ volatile ("fnclex"); 326975af797SJoseph Myers ld_res = ld_one / ld_zero; 327975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 328975af797SJoseph Myers if ((sw & EXC) != ZE) { 329975af797SJoseph Myers printf("FAIL: div 1 0\n"); 330975af797SJoseph Myers ret = 1; 331975af797SJoseph Myers } 332975af797SJoseph Myers __asm__ volatile ("fnclex"); 333975af797SJoseph Myers ld_res = ld_inf / ld_zero; 334975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 335975af797SJoseph Myers if ((sw & EXC) != 0) { 336975af797SJoseph Myers printf("FAIL: div inf 0\n"); 337975af797SJoseph Myers ret = 1; 338975af797SJoseph Myers } 339975af797SJoseph Myers __asm__ volatile ("fnclex"); 340975af797SJoseph Myers ld_res = ld_nan / ld_zero; 341975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 342975af797SJoseph Myers if ((sw & EXC) != 0) { 343975af797SJoseph Myers printf("FAIL: div nan 0\n"); 344975af797SJoseph Myers ret = 1; 345975af797SJoseph Myers } 346975af797SJoseph Myers __asm__ volatile ("fnclex"); 347975af797SJoseph Myers ld_res = ld_zero / ld_zero; 348975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 349975af797SJoseph Myers if ((sw & EXC) != IE) { 350975af797SJoseph Myers printf("FAIL: div 0 0\n"); 351975af797SJoseph Myers ret = 1; 352975af797SJoseph Myers } 353975af797SJoseph Myers __asm__ volatile ("fnclex"); 354975af797SJoseph Myers ld_res = ld_inf / ld_inf; 355975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 356975af797SJoseph Myers if ((sw & EXC) != IE) { 357975af797SJoseph Myers printf("FAIL: div inf inf\n"); 358975af797SJoseph Myers ret = 1; 359975af797SJoseph Myers } 360975af797SJoseph Myers __asm__ volatile ("fnclex"); 361975af797SJoseph Myers ld_res = ld_snan / ld_third; 362975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 363975af797SJoseph Myers if ((sw & EXC) != IE) { 364975af797SJoseph Myers printf("FAIL: div snan\n"); 365975af797SJoseph Myers ret = 1; 366975af797SJoseph Myers } 367975af797SJoseph Myers __asm__ volatile ("fnclex"); 368975af797SJoseph Myers ld_res = ld_third / ld_invalid_1.ld; 369975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 370975af797SJoseph Myers if ((sw & EXC) != IE) { 371975af797SJoseph Myers printf("FAIL: div invalid\n"); 372975af797SJoseph Myers ret = 1; 373975af797SJoseph Myers } 374975af797SJoseph Myers 375975af797SJoseph Myers __asm__ volatile ("fnclex"); 376975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_max)); 377975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 378975af797SJoseph Myers if ((sw & EXC) != PE) { 379975af797SJoseph Myers printf("FAIL: fsqrt inexact\n"); 380975af797SJoseph Myers ret = 1; 381975af797SJoseph Myers } 382975af797SJoseph Myers __asm__ volatile ("fnclex"); 383975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_nmax)); 384975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 385975af797SJoseph Myers if ((sw & EXC) != IE) { 386975af797SJoseph Myers printf("FAIL: fsqrt -max\n"); 387975af797SJoseph Myers ret = 1; 388975af797SJoseph Myers } 389975af797SJoseph Myers __asm__ volatile ("fnclex"); 390975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_ninf)); 391975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 392975af797SJoseph Myers if ((sw & EXC) != IE) { 393975af797SJoseph Myers printf("FAIL: fsqrt -inf\n"); 394975af797SJoseph Myers ret = 1; 395975af797SJoseph Myers } 396975af797SJoseph Myers __asm__ volatile ("fnclex"); 397975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_snan)); 398975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 399975af797SJoseph Myers if ((sw & EXC) != IE) { 400975af797SJoseph Myers printf("FAIL: fsqrt snan\n"); 401975af797SJoseph Myers ret = 1; 402975af797SJoseph Myers } 403975af797SJoseph Myers __asm__ volatile ("fnclex"); 404975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_invalid_1.ld)); 405975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 406975af797SJoseph Myers if ((sw & EXC) != IE) { 407975af797SJoseph Myers printf("FAIL: fsqrt invalid\n"); 408975af797SJoseph Myers ret = 1; 409975af797SJoseph Myers } 410975af797SJoseph Myers __asm__ volatile ("fnclex"); 411975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_nzero)); 412975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 413975af797SJoseph Myers if ((sw & EXC) != 0) { 414975af797SJoseph Myers printf("FAIL: fsqrt -0\n"); 415975af797SJoseph Myers ret = 1; 416975af797SJoseph Myers } 417975af797SJoseph Myers __asm__ volatile ("fnclex"); 418975af797SJoseph Myers __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (-__builtin_nanl(""))); 419975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 420975af797SJoseph Myers if ((sw & EXC) != 0) { 421975af797SJoseph Myers printf("FAIL: fsqrt -nan\n"); 422975af797SJoseph Myers ret = 1; 423975af797SJoseph Myers } 424975af797SJoseph Myers 425975af797SJoseph Myers __asm__ volatile ("fnclex"); 426*6012d963SRichard Henderson __asm__ volatile ("fistps %0" : "=m" (res_16) : "t" (1.5L) : "st"); 427975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 428975af797SJoseph Myers if ((sw & EXC) != PE) { 429975af797SJoseph Myers printf("FAIL: fistp inexact\n"); 430975af797SJoseph Myers ret = 1; 431975af797SJoseph Myers } 432975af797SJoseph Myers __asm__ volatile ("fnclex"); 433*6012d963SRichard Henderson __asm__ volatile ("fistps %0" : "=m" (res_16) : "t" (32767.5L) : "st"); 434975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 435975af797SJoseph Myers if ((sw & EXC) != IE) { 436975af797SJoseph Myers printf("FAIL: fistp 32767.5\n"); 437975af797SJoseph Myers ret = 1; 438975af797SJoseph Myers } 439975af797SJoseph Myers __asm__ volatile ("fnclex"); 440*6012d963SRichard Henderson __asm__ volatile ("fistps %0" : "=m" (res_16) : "t" (-32768.51L) : "st"); 441975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 442975af797SJoseph Myers if ((sw & EXC) != IE) { 443975af797SJoseph Myers printf("FAIL: fistp -32768.51\n"); 444975af797SJoseph Myers ret = 1; 445975af797SJoseph Myers } 446975af797SJoseph Myers __asm__ volatile ("fnclex"); 447*6012d963SRichard Henderson __asm__ volatile ("fistps %0" : "=m" (res_16) : "t" (ld_nan) : "st"); 448975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 449975af797SJoseph Myers if ((sw & EXC) != IE) { 450975af797SJoseph Myers printf("FAIL: fistp nan\n"); 451975af797SJoseph Myers ret = 1; 452975af797SJoseph Myers } 453975af797SJoseph Myers __asm__ volatile ("fnclex"); 454*6012d963SRichard Henderson __asm__ volatile ("fistps %0" : "=m" (res_16) : "t" (ld_invalid_1.ld) : 455975af797SJoseph Myers "st"); 456975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 457975af797SJoseph Myers if ((sw & EXC) != IE) { 458975af797SJoseph Myers printf("FAIL: fistp invalid\n"); 459975af797SJoseph Myers ret = 1; 460975af797SJoseph Myers } 461975af797SJoseph Myers 462975af797SJoseph Myers __asm__ volatile ("fnclex"); 463975af797SJoseph Myers __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (1.5L) : "st"); 464975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 465975af797SJoseph Myers if ((sw & EXC) != PE) { 466975af797SJoseph Myers printf("FAIL: fistpl inexact\n"); 467975af797SJoseph Myers ret = 1; 468975af797SJoseph Myers } 469975af797SJoseph Myers __asm__ volatile ("fnclex"); 470975af797SJoseph Myers __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (2147483647.5L) : 471975af797SJoseph Myers "st"); 472975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 473975af797SJoseph Myers if ((sw & EXC) != IE) { 474975af797SJoseph Myers printf("FAIL: fistpl 2147483647.5\n"); 475975af797SJoseph Myers ret = 1; 476975af797SJoseph Myers } 477975af797SJoseph Myers __asm__ volatile ("fnclex"); 478975af797SJoseph Myers __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (-2147483648.51L) : 479975af797SJoseph Myers "st"); 480975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 481975af797SJoseph Myers if ((sw & EXC) != IE) { 482975af797SJoseph Myers printf("FAIL: fistpl -2147483648.51\n"); 483975af797SJoseph Myers ret = 1; 484975af797SJoseph Myers } 485975af797SJoseph Myers __asm__ volatile ("fnclex"); 486975af797SJoseph Myers __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (ld_nan) : "st"); 487975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 488975af797SJoseph Myers if ((sw & EXC) != IE) { 489975af797SJoseph Myers printf("FAIL: fistpl nan\n"); 490975af797SJoseph Myers ret = 1; 491975af797SJoseph Myers } 492975af797SJoseph Myers __asm__ volatile ("fnclex"); 493975af797SJoseph Myers __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (ld_invalid_1.ld) : 494975af797SJoseph Myers "st"); 495975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 496975af797SJoseph Myers if ((sw & EXC) != IE) { 497975af797SJoseph Myers printf("FAIL: fistpl invalid\n"); 498975af797SJoseph Myers ret = 1; 499975af797SJoseph Myers } 500975af797SJoseph Myers 501975af797SJoseph Myers __asm__ volatile ("fnclex"); 502975af797SJoseph Myers __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (1.5L) : "st"); 503975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 504975af797SJoseph Myers if ((sw & EXC) != PE) { 505975af797SJoseph Myers printf("FAIL: fistpll inexact\n"); 506975af797SJoseph Myers ret = 1; 507975af797SJoseph Myers } 508975af797SJoseph Myers __asm__ volatile ("fnclex"); 509975af797SJoseph Myers __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (0x1p63) : 510975af797SJoseph Myers "st"); 511975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 512975af797SJoseph Myers if ((sw & EXC) != IE) { 513975af797SJoseph Myers printf("FAIL: fistpll 0x1p63\n"); 514975af797SJoseph Myers ret = 1; 515975af797SJoseph Myers } 516975af797SJoseph Myers __asm__ volatile ("fnclex"); 517975af797SJoseph Myers __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (-0x1.1p63L) : 518975af797SJoseph Myers "st"); 519975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 520975af797SJoseph Myers if ((sw & EXC) != IE) { 521975af797SJoseph Myers printf("FAIL: fistpll -0x1.1p63\n"); 522975af797SJoseph Myers ret = 1; 523975af797SJoseph Myers } 524975af797SJoseph Myers __asm__ volatile ("fnclex"); 525975af797SJoseph Myers __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (ld_nan) : "st"); 526975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 527975af797SJoseph Myers if ((sw & EXC) != IE) { 528975af797SJoseph Myers printf("FAIL: fistpll nan\n"); 529975af797SJoseph Myers ret = 1; 530975af797SJoseph Myers } 531975af797SJoseph Myers __asm__ volatile ("fnclex"); 532975af797SJoseph Myers __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (ld_invalid_1.ld) : 533975af797SJoseph Myers "st"); 534975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 535975af797SJoseph Myers if ((sw & EXC) != IE) { 536975af797SJoseph Myers printf("FAIL: fistpll invalid\n"); 537975af797SJoseph Myers ret = 1; 538975af797SJoseph Myers } 539975af797SJoseph Myers 540975af797SJoseph Myers __asm__ volatile ("fnclex"); 541*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (1.5L) : "st"); 542975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 543975af797SJoseph Myers if ((sw & EXC) != PE) { 544975af797SJoseph Myers printf("FAIL: fisttp inexact\n"); 545975af797SJoseph Myers ret = 1; 546975af797SJoseph Myers } 547975af797SJoseph Myers __asm__ volatile ("fnclex"); 548*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (32768.0L) : "st"); 549975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 550975af797SJoseph Myers if ((sw & EXC) != IE) { 551975af797SJoseph Myers printf("FAIL: fisttp 32768\n"); 552975af797SJoseph Myers ret = 1; 553975af797SJoseph Myers } 554975af797SJoseph Myers __asm__ volatile ("fnclex"); 555*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (32768.5L) : "st"); 556975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 557975af797SJoseph Myers if ((sw & EXC) != IE) { 558975af797SJoseph Myers printf("FAIL: fisttp 32768.5\n"); 559975af797SJoseph Myers ret = 1; 560975af797SJoseph Myers } 561975af797SJoseph Myers __asm__ volatile ("fnclex"); 562*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (-32769.0L) : "st"); 563975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 564975af797SJoseph Myers if ((sw & EXC) != IE) { 565975af797SJoseph Myers printf("FAIL: fisttp -32769\n"); 566975af797SJoseph Myers ret = 1; 567975af797SJoseph Myers } 568975af797SJoseph Myers __asm__ volatile ("fnclex"); 569*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (-32769.5L) : "st"); 570975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 571975af797SJoseph Myers if ((sw & EXC) != IE) { 572975af797SJoseph Myers printf("FAIL: fisttp -32769.5\n"); 573975af797SJoseph Myers ret = 1; 574975af797SJoseph Myers } 575975af797SJoseph Myers __asm__ volatile ("fnclex"); 576*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (ld_nan) : "st"); 577975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 578975af797SJoseph Myers if ((sw & EXC) != IE) { 579975af797SJoseph Myers printf("FAIL: fisttp nan\n"); 580975af797SJoseph Myers ret = 1; 581975af797SJoseph Myers } 582975af797SJoseph Myers __asm__ volatile ("fnclex"); 583*6012d963SRichard Henderson __asm__ volatile ("fisttps %0" : "=m" (res_16) : "t" (ld_invalid_1.ld) : 584975af797SJoseph Myers "st"); 585975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 586975af797SJoseph Myers if ((sw & EXC) != IE) { 587975af797SJoseph Myers printf("FAIL: fisttp invalid\n"); 588975af797SJoseph Myers ret = 1; 589975af797SJoseph Myers } 590975af797SJoseph Myers 591975af797SJoseph Myers __asm__ volatile ("fnclex"); 592975af797SJoseph Myers __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (1.5L) : "st"); 593975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 594975af797SJoseph Myers if ((sw & EXC) != PE) { 595975af797SJoseph Myers printf("FAIL: fisttpl inexact\n"); 596975af797SJoseph Myers ret = 1; 597975af797SJoseph Myers } 598975af797SJoseph Myers __asm__ volatile ("fnclex"); 599975af797SJoseph Myers __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (2147483648.0L) : 600975af797SJoseph Myers "st"); 601975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 602975af797SJoseph Myers if ((sw & EXC) != IE) { 603975af797SJoseph Myers printf("FAIL: fisttpl 2147483648\n"); 604975af797SJoseph Myers ret = 1; 605975af797SJoseph Myers } 606975af797SJoseph Myers __asm__ volatile ("fnclex"); 607975af797SJoseph Myers __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (-2147483649.0L) : 608975af797SJoseph Myers "st"); 609975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 610975af797SJoseph Myers if ((sw & EXC) != IE) { 611975af797SJoseph Myers printf("FAIL: fisttpl -2147483649\n"); 612975af797SJoseph Myers ret = 1; 613975af797SJoseph Myers } 614975af797SJoseph Myers __asm__ volatile ("fnclex"); 615975af797SJoseph Myers __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (ld_nan) : "st"); 616975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 617975af797SJoseph Myers if ((sw & EXC) != IE) { 618975af797SJoseph Myers printf("FAIL: fisttpl nan\n"); 619975af797SJoseph Myers ret = 1; 620975af797SJoseph Myers } 621975af797SJoseph Myers __asm__ volatile ("fnclex"); 622975af797SJoseph Myers __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (ld_invalid_1.ld) : 623975af797SJoseph Myers "st"); 624975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 625975af797SJoseph Myers if ((sw & EXC) != IE) { 626975af797SJoseph Myers printf("FAIL: fisttpl invalid\n"); 627975af797SJoseph Myers ret = 1; 628975af797SJoseph Myers } 629975af797SJoseph Myers 630975af797SJoseph Myers __asm__ volatile ("fnclex"); 631975af797SJoseph Myers __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (1.5L) : "st"); 632975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 633975af797SJoseph Myers if ((sw & EXC) != PE) { 634975af797SJoseph Myers printf("FAIL: fisttpll inexact\n"); 635975af797SJoseph Myers ret = 1; 636975af797SJoseph Myers } 637975af797SJoseph Myers __asm__ volatile ("fnclex"); 638975af797SJoseph Myers __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (0x1p63) : 639975af797SJoseph Myers "st"); 640975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 641975af797SJoseph Myers if ((sw & EXC) != IE) { 642975af797SJoseph Myers printf("FAIL: fisttpll 0x1p63\n"); 643975af797SJoseph Myers ret = 1; 644975af797SJoseph Myers } 645975af797SJoseph Myers __asm__ volatile ("fnclex"); 646975af797SJoseph Myers __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (-0x1.1p63L) : 647975af797SJoseph Myers "st"); 648975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 649975af797SJoseph Myers if ((sw & EXC) != IE) { 650975af797SJoseph Myers printf("FAIL: fisttpll -0x1.1p63\n"); 651975af797SJoseph Myers ret = 1; 652975af797SJoseph Myers } 653975af797SJoseph Myers __asm__ volatile ("fnclex"); 654975af797SJoseph Myers __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (ld_nan) : "st"); 655975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 656975af797SJoseph Myers if ((sw & EXC) != IE) { 657975af797SJoseph Myers printf("FAIL: fisttpll nan\n"); 658975af797SJoseph Myers ret = 1; 659975af797SJoseph Myers } 660975af797SJoseph Myers __asm__ volatile ("fnclex"); 661975af797SJoseph Myers __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (ld_invalid_1.ld) : 662975af797SJoseph Myers "st"); 663975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 664975af797SJoseph Myers if ((sw & EXC) != IE) { 665975af797SJoseph Myers printf("FAIL: fisttpll invalid\n"); 666975af797SJoseph Myers ret = 1; 667975af797SJoseph Myers } 668975af797SJoseph Myers 669975af797SJoseph Myers __asm__ volatile ("fnclex"); 670975af797SJoseph Myers __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) : 671975af797SJoseph Myers "0" (ld_zero)); 672975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 673975af797SJoseph Myers if ((sw & EXC) != ZE) { 674975af797SJoseph Myers printf("FAIL: fxtract 0\n"); 675975af797SJoseph Myers ret = 1; 676975af797SJoseph Myers } 677975af797SJoseph Myers __asm__ volatile ("fnclex"); 678975af797SJoseph Myers __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) : 679975af797SJoseph Myers "0" (ld_nzero)); 680975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 681975af797SJoseph Myers if ((sw & EXC) != ZE) { 682975af797SJoseph Myers printf("FAIL: fxtract -0\n"); 683975af797SJoseph Myers ret = 1; 684975af797SJoseph Myers } 685975af797SJoseph Myers __asm__ volatile ("fnclex"); 686975af797SJoseph Myers __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) : 687975af797SJoseph Myers "0" (ld_inf)); 688975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 689975af797SJoseph Myers if ((sw & EXC) != 0) { 690975af797SJoseph Myers printf("FAIL: fxtract inf\n"); 691975af797SJoseph Myers ret = 1; 692975af797SJoseph Myers } 693975af797SJoseph Myers __asm__ volatile ("fnclex"); 694975af797SJoseph Myers __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) : 695975af797SJoseph Myers "0" (ld_nan)); 696975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 697975af797SJoseph Myers if ((sw & EXC) != 0) { 698975af797SJoseph Myers printf("FAIL: fxtract nan\n"); 699975af797SJoseph Myers ret = 1; 700975af797SJoseph Myers } 701975af797SJoseph Myers __asm__ volatile ("fnclex"); 702975af797SJoseph Myers __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) : 703975af797SJoseph Myers "0" (ld_snan)); 704975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 705975af797SJoseph Myers if ((sw & EXC) != IE) { 706975af797SJoseph Myers printf("FAIL: fxtract snan\n"); 707975af797SJoseph Myers ret = 1; 708975af797SJoseph Myers } 709975af797SJoseph Myers __asm__ volatile ("fnclex"); 710975af797SJoseph Myers __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) : 711975af797SJoseph Myers "0" (ld_invalid_1.ld)); 712975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 713975af797SJoseph Myers if ((sw & EXC) != IE) { 714975af797SJoseph Myers printf("FAIL: fxtract invalid\n"); 715975af797SJoseph Myers ret = 1; 716975af797SJoseph Myers } 717975af797SJoseph Myers 718975af797SJoseph Myers __asm__ volatile ("fnclex"); 719975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_min), "u" (ld_max)); 720975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 721975af797SJoseph Myers if ((sw & EXC) != (OE | PE)) { 722975af797SJoseph Myers printf("FAIL: fscale overflow\n"); 723975af797SJoseph Myers ret = 1; 724975af797SJoseph Myers } 725975af797SJoseph Myers __asm__ volatile ("fnclex"); 726975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_max), "u" (ld_nmax)); 727975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 728975af797SJoseph Myers if ((sw & EXC) != (UE | PE)) { 729975af797SJoseph Myers printf("FAIL: fscale underflow\n"); 730975af797SJoseph Myers ret = 1; 731975af797SJoseph Myers } 732975af797SJoseph Myers __asm__ volatile ("fnclex"); 733975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_zero), "u" (ld_inf)); 734975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 735975af797SJoseph Myers if ((sw & EXC) != IE) { 736975af797SJoseph Myers printf("FAIL: fscale 0 inf\n"); 737975af797SJoseph Myers ret = 1; 738975af797SJoseph Myers } 739975af797SJoseph Myers __asm__ volatile ("fnclex"); 740975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_inf), "u" (ld_ninf)); 741975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 742975af797SJoseph Myers if ((sw & EXC) != IE) { 743975af797SJoseph Myers printf("FAIL: fscale inf -inf\n"); 744975af797SJoseph Myers ret = 1; 745975af797SJoseph Myers } 746975af797SJoseph Myers __asm__ volatile ("fnclex"); 747975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_one), "u" (ld_snan)); 748975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 749975af797SJoseph Myers if ((sw & EXC) != IE) { 750975af797SJoseph Myers printf("FAIL: fscale 1 snan\n"); 751975af797SJoseph Myers ret = 1; 752975af797SJoseph Myers } 753975af797SJoseph Myers __asm__ volatile ("fnclex"); 754975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_snan), "u" (ld_nan)); 755975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 756975af797SJoseph Myers if ((sw & EXC) != IE) { 757975af797SJoseph Myers printf("FAIL: fscale snan nan\n"); 758975af797SJoseph Myers ret = 1; 759975af797SJoseph Myers } 760975af797SJoseph Myers __asm__ volatile ("fnclex"); 761975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : 762975af797SJoseph Myers "0" (ld_invalid_1.ld), "u" (ld_one)); 763975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 764975af797SJoseph Myers if ((sw & EXC) != IE) { 765975af797SJoseph Myers printf("FAIL: fscale invalid 1\n"); 766975af797SJoseph Myers ret = 1; 767975af797SJoseph Myers } 768975af797SJoseph Myers __asm__ volatile ("fnclex"); 769975af797SJoseph Myers __asm__ volatile ("fscale" : "=t" (ld_res) : 770975af797SJoseph Myers "0" (ld_invalid_1.ld), "u" (ld_nan)); 771975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 772975af797SJoseph Myers if ((sw & EXC) != IE) { 773975af797SJoseph Myers printf("FAIL: fscale invalid nan\n"); 774975af797SJoseph Myers ret = 1; 775975af797SJoseph Myers } 776975af797SJoseph Myers 777975af797SJoseph Myers __asm__ volatile ("fnclex"); 778975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (1.5L) : 779975af797SJoseph Myers "st"); 780975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 781975af797SJoseph Myers if ((sw & EXC) != PE) { 782975af797SJoseph Myers printf("FAIL: fbstp 1.5\n"); 783975af797SJoseph Myers ret = 1; 784975af797SJoseph Myers } 785975af797SJoseph Myers __asm__ volatile ("fnclex"); 786975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (999999999999999999.5L) : 787975af797SJoseph Myers "st"); 788975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 789975af797SJoseph Myers if ((sw & EXC) != IE) { 790975af797SJoseph Myers printf("FAIL: fbstp 999999999999999999.5\n"); 791975af797SJoseph Myers ret = 1; 792975af797SJoseph Myers } 793975af797SJoseph Myers __asm__ volatile ("fnclex"); 794975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-1000000000000000000.0L) : 795975af797SJoseph Myers "st"); 796975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 797975af797SJoseph Myers if ((sw & EXC) != IE) { 798975af797SJoseph Myers printf("FAIL: fbstp -1000000000000000000\n"); 799975af797SJoseph Myers ret = 1; 800975af797SJoseph Myers } 801975af797SJoseph Myers __asm__ volatile ("fnclex"); 802975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_inf) : "st"); 803975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 804975af797SJoseph Myers if ((sw & EXC) != IE) { 805975af797SJoseph Myers printf("FAIL: fbstp inf\n"); 806975af797SJoseph Myers ret = 1; 807975af797SJoseph Myers } 808975af797SJoseph Myers __asm__ volatile ("fnclex"); 809975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_nan) : "st"); 810975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 811975af797SJoseph Myers if ((sw & EXC) != IE) { 812975af797SJoseph Myers printf("FAIL: fbstp nan\n"); 813975af797SJoseph Myers ret = 1; 814975af797SJoseph Myers } 815975af797SJoseph Myers __asm__ volatile ("fnclex"); 816975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_snan) : "st"); 817975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 818975af797SJoseph Myers if ((sw & EXC) != IE) { 819975af797SJoseph Myers printf("FAIL: fbstp snan\n"); 820975af797SJoseph Myers ret = 1; 821975af797SJoseph Myers } 822975af797SJoseph Myers __asm__ volatile ("fnclex"); 823975af797SJoseph Myers __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_invalid_1.ld) : "st"); 824975af797SJoseph Myers __asm__ volatile ("fnstsw" : "=a" (sw)); 825975af797SJoseph Myers if ((sw & EXC) != IE) { 826975af797SJoseph Myers printf("FAIL: fbstp invalid\n"); 827975af797SJoseph Myers ret = 1; 828975af797SJoseph Myers } 829975af797SJoseph Myers 830975af797SJoseph Myers return ret; 831975af797SJoseph Myers } 832