muldi3.c revision 239138
1214152Sed/* ===-- muldi3.c - Implement __muldi3 -------------------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open 6222656Sed * Source Licenses. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __muldi3 for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13222656Sed */ 14214152Sed 15214152Sed#include "int_lib.h" 16214152Sed 17214152Sed/* Returns: a * b */ 18214152Sed 19214152Sedstatic 20214152Seddi_int 21214152Sed__muldsi3(su_int a, su_int b) 22214152Sed{ 23214152Sed dwords r; 24214152Sed const int bits_in_word_2 = (int)(sizeof(si_int) * CHAR_BIT) / 2; 25214152Sed const su_int lower_mask = (su_int)~0 >> bits_in_word_2; 26214152Sed r.s.low = (a & lower_mask) * (b & lower_mask); 27214152Sed su_int t = r.s.low >> bits_in_word_2; 28214152Sed r.s.low &= lower_mask; 29214152Sed t += (a >> bits_in_word_2) * (b & lower_mask); 30214152Sed r.s.low += (t & lower_mask) << bits_in_word_2; 31214152Sed r.s.high = t >> bits_in_word_2; 32214152Sed t = r.s.low >> bits_in_word_2; 33214152Sed r.s.low &= lower_mask; 34214152Sed t += (b >> bits_in_word_2) * (a & lower_mask); 35214152Sed r.s.low += (t & lower_mask) << bits_in_word_2; 36214152Sed r.s.high += t >> bits_in_word_2; 37214152Sed r.s.high += (a >> bits_in_word_2) * (b >> bits_in_word_2); 38214152Sed return r.all; 39214152Sed} 40214152Sed 41214152Sed/* Returns: a * b */ 42214152Sed 43239138SandrewARM_EABI_FNALIAS(lmul, muldi3) 44222656Sed 45222656SedCOMPILER_RT_ABI di_int 46214152Sed__muldi3(di_int a, di_int b) 47214152Sed{ 48214152Sed dwords x; 49214152Sed x.all = a; 50214152Sed dwords y; 51214152Sed y.all = b; 52214152Sed dwords r; 53214152Sed r.all = __muldsi3(x.s.low, y.s.low); 54214152Sed r.s.high += x.s.high * y.s.low + x.s.low * y.s.high; 55214152Sed return r.all; 56214152Sed} 57