11ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher//===-- mulodi4_test.c - Test __mulodi4 -----------------------------------===// 21ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// 31ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// The LLVM Compiler Infrastructure 41ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// 51ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// This file is dual licensed under the MIT and the University of Illinois Open 61ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// Source Licenses. See LICENSE.TXT for details. 71ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// 81ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher//===----------------------------------------------------------------------===// 91ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// 101ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// This file tests __mulodi4 for the compiler_rt library. 111ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher// 121ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher//===----------------------------------------------------------------------===// 131ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 141ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher#include "int_lib.h" 151ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher#include <stdio.h> 161ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 17cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainarextern COMPILER_RT_ABI di_int __mulodi4(di_int a, di_int b, int* overflow); 181ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 191ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopherint test__mulodi4(di_int a, di_int b, di_int expected, int expected_overflow) 201ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher{ 211ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher int ov; 221ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher di_int x = __mulodi4(a, b, &ov); 231ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (ov != expected_overflow) 241ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher printf("error in __mulodi4: overflow=%d expected=%d\n", 251ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher ov, expected_overflow); 261ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher else if (!expected_overflow && x != expected) { 271ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher printf("error in __mulodi4: 0x%llX * 0x%llX = 0x%llX (overflow=%d), " 281ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher "expected 0x%llX (overflow=%d)\n", 291ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher a, b, x, ov, expected, expected_overflow); 301ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 311ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher } 321ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 0; 331ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher} 341ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 351ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopherint main() 361ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher{ 371ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 0, 0, 0)) 381ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 391ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 1, 0, 0)) 401ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 411ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 0, 0, 0)) 421ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 431ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 10, 0, 0)) 441ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 451ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(10, 0, 0, 0)) 461ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 471ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 81985529216486895LL, 0, 0)) 481ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 491ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(81985529216486895LL, 0, 0, 0)) 501ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 511ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 521ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, -1, 0, 0)) 531ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 541ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-1, 0, 0, 0)) 551ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 561ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, -10, 0, 0)) 571ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 581ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-10, 0, 0, 0)) 591ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 601ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, -81985529216486895LL, 0, 0)) 611ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 621ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-81985529216486895LL, 0, 0, 0)) 631ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 641ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 651ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 1, 1, 0)) 661ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 671ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 10, 10, 0)) 681ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 691ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(10, 1, 10, 0)) 701ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 711ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 81985529216486895LL, 81985529216486895LL, 0)) 721ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 731ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(81985529216486895LL, 1, 81985529216486895LL, 0)) 741ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 751ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 761ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, -1, -1, 0)) 771ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 781ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, -10, -10, 0)) 791ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 801ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-10, 1, -10, 0)) 811ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 821ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, -81985529216486895LL, -81985529216486895LL, 0)) 831ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 841ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-81985529216486895LL, 1, -81985529216486895LL, 0)) 851ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 861ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 871ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(3037000499LL, 3037000499LL, 9223372030926249001LL, 0)) 881ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 891ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-3037000499LL, 3037000499LL, -9223372030926249001LL, 0)) 901ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 911ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(3037000499LL, -3037000499LL, -9223372030926249001LL, 0)) 921ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 931ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-3037000499LL, -3037000499LL, 9223372030926249001LL, 0)) 941ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 951ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 961ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(4398046511103LL, 2097152LL, 9223372036852678656LL, 0)) 971ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 981ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-4398046511103LL, 2097152LL, -9223372036852678656LL, 0)) 991ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1001ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(4398046511103LL, -2097152LL, -9223372036852678656LL, 0)) 1011ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1021ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-4398046511103LL, -2097152LL, 9223372036852678656LL, 0)) 1031ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1041ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 1051ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(2097152LL, 4398046511103LL, 9223372036852678656LL, 0)) 1061ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1071ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-2097152LL, 4398046511103LL, -9223372036852678656LL, 0)) 1081ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1091ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(2097152LL, -4398046511103LL, -9223372036852678656LL, 0)) 1101ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1111ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-2097152LL, -4398046511103LL, 9223372036852678656LL, 0)) 1121ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1131ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 1141ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -2, 2, 1)) 1151ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1161ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-2, 0x7FFFFFFFFFFFFFFFLL, 2, 1)) 1171ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1181ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, -1, 0x8000000000000001LL, 0)) 1191ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1201ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-1, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 0)) 1211ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1221ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 0, 0, 0)) 1231ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1241ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 0x7FFFFFFFFFFFFFFFLL, 0, 0)) 1251ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1261ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 1, 0x7FFFFFFFFFFFFFFFLL, 0)) 1271ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1281ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL, 0)) 1291ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1301ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x7FFFFFFFFFFFFFFFLL, 2, 0x8000000000000001LL, 1)) 1311ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1321ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(2, 0x7FFFFFFFFFFFFFFFLL, 0x8000000000000001LL, 1)) 1331ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1341ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 1351ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000000LL, -2, 0x8000000000000000LL, 1)) 1361ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1371ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-2, 0x8000000000000000LL, 0x8000000000000000LL, 1)) 1381ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1391ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000000LL, -1, 0x8000000000000000LL, 1)) 1401ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1411ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-1, 0x8000000000000000LL, 0x8000000000000000LL, 1)) 1421ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1431ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000000LL, 0, 0, 0)) 1441ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1451ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 0x8000000000000000LL, 0, 0)) 1461ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1471ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000000LL, 1, 0x8000000000000000LL, 0)) 1481ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1491ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 0x8000000000000000LL, 0x8000000000000000LL, 0)) 1501ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1511ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000000LL, 2, 0x8000000000000000LL, 1)) 1521ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1531ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(2, 0x8000000000000000LL, 0x8000000000000000LL, 1)) 1541ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1551ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 1561ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000001LL, -2, 0x8000000000000001LL, 1)) 1571ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1581ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-2, 0x8000000000000001LL, 0x8000000000000001LL, 1)) 1591ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1601ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000001LL, -1, 0x7FFFFFFFFFFFFFFFLL, 0)) 1611ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1621ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(-1, 0x8000000000000001LL, 0x7FFFFFFFFFFFFFFFLL, 0)) 1631ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1641ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000001LL, 0, 0, 0)) 1651ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1661ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0, 0x8000000000000001LL, 0, 0)) 1671ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1681ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000001LL, 1, 0x8000000000000001LL, 0)) 1691ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1701ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(1, 0x8000000000000001LL, 0x8000000000000001LL, 0)) 1711ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1721ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(0x8000000000000001LL, 2, 0x8000000000000000LL, 1)) 1731ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1741ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher if (test__mulodi4(2, 0x8000000000000001LL, 0x8000000000000000LL, 1)) 1751ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 1; 1761ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher 1771ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher return 0; 1781ace4055f79f304750839d73c46bbcaeb994f1b5Eric Christopher} 179