Home | History | Annotate | Download | only in Unit
      1 //===-- mulvsi3_test.c - Test __mulvsi3 -----------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __mulvsi3 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 // Returns: a * b
     18 
     19 // Effects: aborts if a * b overflows
     20 
     21 si_int __mulvsi3(si_int a, si_int b);
     22 
     23 int test__mulvsi3(si_int a, si_int b, si_int expected)
     24 {
     25     si_int x = __mulvsi3(a, b);
     26     if (x != expected)
     27         printf("error in __mulvsi3: %d * %d = %d, expected %d\n",
     28                a, b, x, expected);
     29     return x != expected;
     30 }
     31 
     32 int main()
     33 {
     34     if (test__mulvsi3(0, 0, 0))
     35         return 1;
     36     if (test__mulvsi3(0, 1, 0))
     37         return 1;
     38     if (test__mulvsi3(1, 0, 0))
     39         return 1;
     40     if (test__mulvsi3(0, 10, 0))
     41         return 1;
     42     if (test__mulvsi3(10, 0, 0))
     43         return 1;
     44     if (test__mulvsi3(0, 0x1234567, 0))
     45         return 1;
     46     if (test__mulvsi3(0x1234567, 0, 0))
     47         return 1;
     48 
     49     if (test__mulvsi3(0, -1, 0))
     50         return 1;
     51     if (test__mulvsi3(-1, 0, 0))
     52         return 1;
     53     if (test__mulvsi3(0, -10, 0))
     54         return 1;
     55     if (test__mulvsi3(-10, 0, 0))
     56         return 1;
     57     if (test__mulvsi3(0, -0x1234567, 0))
     58         return 1;
     59     if (test__mulvsi3(-0x1234567, 0, 0))
     60         return 1;
     61 
     62     if (test__mulvsi3(1, 1, 1))
     63         return 1;
     64     if (test__mulvsi3(1, 10, 10))
     65         return 1;
     66     if (test__mulvsi3(10, 1, 10))
     67         return 1;
     68     if (test__mulvsi3(1, 0x1234567, 0x1234567))
     69         return 1;
     70     if (test__mulvsi3(0x1234567, 1, 0x1234567))
     71         return 1;
     72 
     73     if (test__mulvsi3(1, -1, -1))
     74         return 1;
     75     if (test__mulvsi3(1, -10, -10))
     76         return 1;
     77     if (test__mulvsi3(-10, 1, -10))
     78         return 1;
     79     if (test__mulvsi3(1, -0x1234567, -0x1234567))
     80         return 1;
     81     if (test__mulvsi3(-0x1234567, 1, -0x1234567))
     82         return 1;
     83 
     84 //     if (test__mulvsi3(0x7FFFFFFF, -2, 0x80000001))  // abort
     85 //         return 1;
     86 //     if (test__mulvsi3(-2, 0x7FFFFFFF, 0x80000001))  // abort
     87 //         return 1;
     88     if (test__mulvsi3(0x7FFFFFFF, -1, 0x80000001))
     89         return 1;
     90     if (test__mulvsi3(-1, 0x7FFFFFFF, 0x80000001))
     91         return 1;
     92     if (test__mulvsi3(0x7FFFFFFF, 0, 0))
     93         return 1;
     94     if (test__mulvsi3(0, 0x7FFFFFFF, 0))
     95         return 1;
     96     if (test__mulvsi3(0x7FFFFFFF, 1, 0x7FFFFFFF))
     97         return 1;
     98     if (test__mulvsi3(1, 0x7FFFFFFF, 0x7FFFFFFF))
     99         return 1;
    100 //     if (test__mulvsi3(0x7FFFFFFF, 2, 0x80000001))  // abort
    101 //         return 1;
    102 //     if (test__mulvsi3(2, 0x7FFFFFFF, 0x80000001))  // abort
    103 //         return 1;
    104 
    105 //     if (test__mulvsi3(0x80000000, -2, 0x80000000))  // abort
    106 //         return 1;
    107 //     if (test__mulvsi3(-2, 0x80000000, 0x80000000))  // abort
    108 //         return 1;
    109 //     if (test__mulvsi3(0x80000000, -1, 0x80000000))  // abort
    110 //         return 1;
    111 //     if (test__mulvsi3(-1, 0x80000000, 0x80000000))  // abort
    112 //         return 1;
    113     if (test__mulvsi3(0x80000000, 0, 0))
    114         return 1;
    115     if (test__mulvsi3(0, 0x80000000, 0))
    116         return 1;
    117     if (test__mulvsi3(0x80000000, 1, 0x80000000))
    118         return 1;
    119     if (test__mulvsi3(1, 0x80000000, 0x80000000))
    120         return 1;
    121 //     if (test__mulvsi3(0x80000000, 2, 0x80000000))  // abort
    122 //         return 1;
    123 //     if (test__mulvsi3(2, 0x80000000, 0x80000000))  // abort
    124 //         return 1;
    125 
    126 //     if (test__mulvsi3(0x80000001, -2, 0x80000001))  // abort
    127 //         return 1;
    128 //     if (test__mulvsi3(-2, 0x80000001, 0x80000001))  // abort
    129 //         return 1;
    130     if (test__mulvsi3(0x80000001, -1, 0x7FFFFFFF))
    131         return 1;
    132     if (test__mulvsi3(-1, 0x80000001, 0x7FFFFFFF))
    133         return 1;
    134     if (test__mulvsi3(0x80000001, 0, 0))
    135         return 1;
    136     if (test__mulvsi3(0, 0x80000001, 0))
    137         return 1;
    138     if (test__mulvsi3(0x80000001, 1, 0x80000001))
    139         return 1;
    140     if (test__mulvsi3(1, 0x80000001, 0x80000001))
    141         return 1;
    142 //     if (test__mulvsi3(0x80000001, 2, 0x80000000))  // abort
    143 //         return 1;
    144 //     if (test__mulvsi3(2, 0x80000001, 0x80000000))  // abort
    145 //         return 1;
    146 
    147     return 0;
    148 }
    149