1 1.1 joerg /* ===-- muldi3.c - Implement __muldi3 -------------------------------------=== 2 1.1 joerg * 3 1.1 joerg * The LLVM Compiler Infrastructure 4 1.1 joerg * 5 1.1 joerg * This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg * Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg * 8 1.1 joerg * ===----------------------------------------------------------------------=== 9 1.1 joerg * 10 1.1 joerg * This file implements __muldi3 for the compiler_rt library. 11 1.1 joerg * 12 1.1 joerg * ===----------------------------------------------------------------------=== 13 1.1 joerg */ 14 1.1 joerg 15 1.1 joerg #include "int_lib.h" 16 1.1 joerg 17 1.1 joerg /* Returns: a * b */ 18 1.1 joerg 19 1.1 joerg static 20 1.1 joerg di_int 21 1.1 joerg __muldsi3(su_int a, su_int b) 22 1.1 joerg { 23 1.1 joerg dwords r; 24 1.1 joerg const int bits_in_word_2 = (int)(sizeof(si_int) * CHAR_BIT) / 2; 25 1.1 joerg const su_int lower_mask = (su_int)~0 >> bits_in_word_2; 26 1.1 joerg r.s.low = (a & lower_mask) * (b & lower_mask); 27 1.1 joerg su_int t = r.s.low >> bits_in_word_2; 28 1.1 joerg r.s.low &= lower_mask; 29 1.1 joerg t += (a >> bits_in_word_2) * (b & lower_mask); 30 1.1 joerg r.s.low += (t & lower_mask) << bits_in_word_2; 31 1.1 joerg r.s.high = t >> bits_in_word_2; 32 1.1 joerg t = r.s.low >> bits_in_word_2; 33 1.1 joerg r.s.low &= lower_mask; 34 1.1 joerg t += (b >> bits_in_word_2) * (a & lower_mask); 35 1.1 joerg r.s.low += (t & lower_mask) << bits_in_word_2; 36 1.1 joerg r.s.high += t >> bits_in_word_2; 37 1.1 joerg r.s.high += (a >> bits_in_word_2) * (b >> bits_in_word_2); 38 1.1 joerg return r.all; 39 1.1 joerg } 40 1.1 joerg 41 1.1 joerg /* Returns: a * b */ 42 1.1 joerg 43 1.1 joerg COMPILER_RT_ABI di_int 44 1.1 joerg __muldi3(di_int a, di_int b) 45 1.1 joerg { 46 1.1 joerg dwords x; 47 1.1 joerg x.all = a; 48 1.1 joerg dwords y; 49 1.1 joerg y.all = b; 50 1.1 joerg dwords r; 51 1.1 joerg r.all = __muldsi3(x.s.low, y.s.low); 52 1.1 joerg r.s.high += x.s.high * y.s.low + x.s.low * y.s.high; 53 1.1 joerg return r.all; 54 1.1 joerg } 55 1.2 rin 56 1.2 rin #if defined(__ARM_EABI__) 57 1.3 rin AEABI_RTABI di_int __aeabi_lmul(di_int a, di_int b) COMPILER_RT_ALIAS(__muldi3); 58 1.2 rin #endif 59