Revision 4b74fe1f tests/test-i386.c

b/tests/test-i386.c
14 14
#define CC_S    0x0080
15 15
#define CC_O    0x0800
16 16

  
17
/* XXX: currently no A flag */
18
#define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
19

  
20 17
#define __init_call	__attribute__ ((unused,__section__ (".initcall.init")))
21 18

  
22 19
static void *call_start __init_call = NULL;
23 20

  
21
#define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O | CC_A)
22

  
24 23
#define OP add
25 24
#include "test-i386.h"
26 25

  
......
67 66
#define OP1
68 67
#include "test-i386.h"
69 68

  
69
#undef CC_MASK
70
#define CC_MASK (CC_C | CC_P | CC_Z | CC_S | CC_O)
71

  
70 72
#define OP shl
71 73
#include "test-i386-shift.h"
72 74

  
......
268 270
    TEST_JCC("jns", 0, 0);
269 271
}
270 272

  
273
#undef CC_MASK
274
#define CC_MASK (CC_O | CC_C)
275

  
276
#define OP mul
277
#include "test-i386-muldiv.h"
278

  
279
#define OP imul
280
#include "test-i386-muldiv.h"
281

  
282
#undef CC_MASK
283
#define CC_MASK (0)
284

  
285
#define OP div
286
#include "test-i386-muldiv.h"
287

  
288
#define OP idiv
289
#include "test-i386-muldiv.h"
290

  
291
void test_imulw2(int op0, int op1) 
292
{
293
    int res, s1, s0, flags;
294
    s0 = op0;
295
    s1 = op1;
296
    res = s0;
297
    flags = 0;
298
    asm ("push %4\n\t"
299
         "popf\n\t"
300
         "imulw %w2, %w0\n\t" 
301
         "pushf\n\t"
302
         "popl %1\n\t"
303
         : "=q" (res), "=g" (flags)
304
         : "q" (s1), "0" (res), "1" (flags));
305
    printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
306
           "imulw", s0, s1, res, flags & CC_MASK);
307
}
308

  
309
void test_imull2(int op0, int op1) 
310
{
311
    int res, s1, s0, flags;
312
    s0 = op0;
313
    s1 = op1;
314
    res = s0;
315
    flags = 0;
316
    asm ("push %4\n\t"
317
         "popf\n\t"
318
         "imull %2, %0\n\t" 
319
         "pushf\n\t"
320
         "popl %1\n\t"
321
         : "=q" (res), "=g" (flags)
322
         : "q" (s1), "0" (res), "1" (flags));
323
    printf("%-10s A=%08x B=%08x R=%08x CC=%04x\n",
324
           "imull", s0, s1, res, flags & CC_MASK);
325
}
326

  
327
void test_mul(void)
328
{
329
    test_imulb(0x1234561d, 4);
330
    test_imulb(3, -4);
331
    test_imulb(0x80, 0x80);
332
    test_imulb(0x10, 0x10);
333

  
334
    test_imulw(0, 0x1234001d, 45);
335
    test_imulw(0, 23, -45);
336
    test_imulw(0, 0x8000, 0x8000);
337
    test_imulw(0, 0x100, 0x100);
338

  
339
    test_imull(0, 0x1234001d, 45);
340
    test_imull(0, 23, -45);
341
    test_imull(0, 0x80000000, 0x80000000);
342
    test_imull(0, 0x10000, 0x10000);
343

  
344
    test_mulb(0x1234561d, 4);
345
    test_mulb(3, -4);
346
    test_mulb(0x80, 0x80);
347
    test_mulb(0x10, 0x10);
348

  
349
    test_mulw(0, 0x1234001d, 45);
350
    test_mulw(0, 23, -45);
351
    test_mulw(0, 0x8000, 0x8000);
352
    test_mulw(0, 0x100, 0x100);
353

  
354
    test_mull(0, 0x1234001d, 45);
355
    test_mull(0, 23, -45);
356
    test_mull(0, 0x80000000, 0x80000000);
357
    test_mull(0, 0x10000, 0x10000);
358

  
359
    test_imulw2(0x1234001d, 45);
360
    test_imulw2(23, -45);
361
    test_imulw2(0x8000, 0x8000);
362
    test_imulw2(0x100, 0x100);
363

  
364
    test_imull2(0x1234001d, 45);
365
    test_imull2(23, -45);
366
    test_imull2(0x80000000, 0x80000000);
367
    test_imull2(0x10000, 0x10000);
368

  
369
    test_idivb(0x12341678, 0x127e);
370
    test_idivb(0x43210123, -5);
371
    test_idivb(0x12340004, -1);
372

  
373
    test_idivw(0, 0x12345678, 12347);
374
    test_idivw(0, -23223, -45);
375
    test_idivw(0, 0x12348000, -1);
376
    test_idivw(0x12343, 0x12345678, 0x81238567);
377

  
378
    test_idivl(0, 0x12345678, 12347);
379
    test_idivl(0, -233223, -45);
380
    test_idivl(0, 0x80000000, -1);
381
    test_idivl(0x12343, 0x12345678, 0x81234567);
382

  
383
    test_divb(0x12341678, 0x127e);
384
    test_divb(0x43210123, -5);
385
    test_divb(0x12340004, -1);
386

  
387
    test_divw(0, 0x12345678, 12347);
388
    test_divw(0, -23223, -45);
389
    test_divw(0, 0x12348000, -1);
390
    test_divw(0x12343, 0x12345678, 0x81238567);
391

  
392
    test_divl(0, 0x12345678, 12347);
393
    test_divl(0, -233223, -45);
394
    test_divl(0, 0x80000000, -1);
395
    test_divl(0x12343, 0x12345678, 0x81234567);
396
}
397

  
398

  
271 399
static void *call_end __init_call = NULL;
272 400

  
273 401
int main(int argc, char **argv)
274 402
{
275 403
    void **ptr;
276 404
    void (*func)(void);
405

  
406
    test_mul();
407
#if 0
277 408
    ptr = &call_start + 1;
278 409
    while (*ptr != NULL) {
279 410
        func = *ptr++;
280 411
        func();
281 412
    }
282
    test_lea();
283 413
    test_jcc();
414
    test_lea();
415
#endif
284 416
    return 0;
285 417
}

Also available in: Unified diff