169 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_mulodi43 4#include "int_lib.h"5#include <stdio.h>6 7extern COMPILER_RT_ABI di_int __mulodi4(di_int a, di_int b, int* overflow);8 9int test__mulodi4(di_int a, di_int b, di_int expected, int expected_overflow)10{11 int ov;12 di_int x = __mulodi4(a, b, &ov);13 if (ov != expected_overflow)14 printf("error in __mulodi4: overflow=%d expected=%d\n",15 ov, expected_overflow);16 else if (!expected_overflow && x != expected) {17 printf("error in __mulodi4: 0x%llX * 0x%llX = 0x%llX (overflow=%d), "18 "expected 0x%llX (overflow=%d)\n",19 a, b, x, ov, expected, expected_overflow);20 return 1;21 }22 return 0;23}24 25int main()26{27 if (test__mulodi4(0, 0, 0, 0))28 return 1;29 if (test__mulodi4(0, 1, 0, 0))30 return 1;31 if (test__mulodi4(1, 0, 0, 0))32 return 1;33 if (test__mulodi4(0, 10, 0, 0))34 return 1;35 if (test__mulodi4(10, 0, 0, 0))36 return 1;37 if (test__mulodi4(0, 81985529216486895LL, 0, 0))38 return 1;39 if (test__mulodi4(81985529216486895LL, 0, 0, 0))40 return 1;41 42 if (test__mulodi4(0, -1, 0, 0))43 return 1;44 if (test__mulodi4(-1, 0, 0, 0))45 return 1;46 if (test__mulodi4(0, -10, 0, 0))47 return 1;48 if (test__mulodi4(-10, 0, 0, 0))49 return 1;50 if (test__mulodi4(0, -81985529216486895LL, 0, 0))51 return 1;52 if (test__mulodi4(-81985529216486895LL, 0, 0, 0))53 return 1;54 55 if (test__mulodi4(1, 1, 1, 0))56 return 1;57 if (test__mulodi4(1, 10, 10, 0))58 return 1;59 if (test__mulodi4(10, 1, 10, 0))60 return 1;61 if (test__mulodi4(1, 81985529216486895LL, 81985529216486895LL, 0))62 return 1;63 if (test__mulodi4(81985529216486895LL, 1, 81985529216486895LL, 0))64 return 1;65 66 if (test__mulodi4(1, -1, -1, 0))67 return 1;68 if (test__mulodi4(1, -10, -10, 0))69 return 1;70 if (test__mulodi4(-10, 1, -10, 0))71 return 1;72 if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0))73 return 1;74 if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0))75 return 1;76 77 if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0))78 return 1;79 if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0))80 return 1;81 if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0))82 return 1;83 if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0))84 return 1;85 86 if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0))87 return 1;88 if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0))89 return 1;90 if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0))91 return 1;92 if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0))93 return 1;94 95 if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0))96 return 1;97 if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0))98 return 1;99 if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0))100 return 1;101 if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0))102 return 1;103 104 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -2, 2, 1))105 return 1;106 if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL, 2, 1))107 return 1;108 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -1, 0x8000000000000001LL, 0))109 return 1;110 if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 0))111 return 1;112 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 0, 0, 0))113 return 1;114 if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL, 0, 0))115 return 1;116 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 1, 0x7FFFFFFFFFFFFFFFLL, 0))117 return 1;118 if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL, 0))119 return 1;120 if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL, 1))121 return 1;122 if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 1))123 return 1;124 125 if (test__mulodi4(0x8000000000000000LL, -2, 0x8000000000000000LL, 1))126 return 1;127 if (test__mulodi4(-2, 0x8000000000000000LL, 0x8000000000000000LL, 1))128 return 1;129 if (test__mulodi4(0x8000000000000000LL, -1, 0x8000000000000000LL, 1))130 return 1;131 if (test__mulodi4(-1, 0x8000000000000000LL, 0x8000000000000000LL, 1))132 return 1;133 if (test__mulodi4(0x8000000000000000LL, 0, 0, 0))134 return 1;135 if (test__mulodi4(0, 0x8000000000000000LL, 0, 0))136 return 1;137 if (test__mulodi4(0x8000000000000000LL, 1, 0x8000000000000000LL, 0))138 return 1;139 if (test__mulodi4(1, 0x8000000000000000LL, 0x8000000000000000LL, 0))140 return 1;141 if (test__mulodi4(0x8000000000000000LL, 2, 0x8000000000000000LL, 1))142 return 1;143 if (test__mulodi4(2, 0x8000000000000000LL, 0x8000000000000000LL, 1))144 return 1;145 146 if (test__mulodi4(0x8000000000000001LL, -2, 0x8000000000000001LL, 1))147 return 1;148 if (test__mulodi4(-2, 0x8000000000000001LL, 0x8000000000000001LL, 1))149 return 1;150 if (test__mulodi4(0x8000000000000001LL, -1, 0x7FFFFFFFFFFFFFFFLL, 0))151 return 1;152 if (test__mulodi4(-1, 0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL, 0))153 return 1;154 if (test__mulodi4(0x8000000000000001LL, 0, 0, 0))155 return 1;156 if (test__mulodi4(0, 0x8000000000000001LL, 0, 0))157 return 1;158 if (test__mulodi4(0x8000000000000001LL, 1, 0x8000000000000001LL, 0))159 return 1;160 if (test__mulodi4(1, 0x8000000000000001LL, 0x8000000000000001LL, 0))161 return 1;162 if (test__mulodi4(0x8000000000000001LL, 2, 0x8000000000000000LL, 1))163 return 1;164 if (test__mulodi4(2, 0x8000000000000001LL, 0x8000000000000000LL, 1))165 return 1;166 167 return 0;168}169