muldi3.c revision 214152
1214152Sed/* ===-- muldi3.c - Implement __muldi3 -------------------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5214152Sed * This file is distributed under the University of Illinois Open Source 6214152Sed * License. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __muldi3 for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 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 43214152Seddi_int 44214152Sed__muldi3(di_int a, di_int b) 45214152Sed{ 46214152Sed dwords x; 47214152Sed x.all = a; 48214152Sed dwords y; 49214152Sed y.all = b; 50214152Sed dwords r; 51214152Sed r.all = __muldsi3(x.s.low, y.s.low); 52214152Sed r.s.high += x.s.high * y.s.low + x.s.low * y.s.high; 53214152Sed return r.all; 54214152Sed} 55