1276789Sdim/* ===-- muldi3.c - Implement __muldi3 -------------------------------------=== 2276789Sdim * 3276789Sdim * The LLVM Compiler Infrastructure 4276789Sdim * 5276789Sdim * This file is dual licensed under the MIT and the University of Illinois Open 6276789Sdim * Source Licenses. See LICENSE.TXT for details. 7276789Sdim * 8276789Sdim * ===----------------------------------------------------------------------=== 9276789Sdim * 10276789Sdim * This file implements __muldi3 for the compiler_rt library. 11276789Sdim * 12276789Sdim * ===----------------------------------------------------------------------=== 13276789Sdim */ 14276789Sdim 15276789Sdim#include "int_lib.h" 16276789Sdim 17276789Sdim/* Returns: a * b */ 18276789Sdim 19276789Sdimstatic 20276789Sdimdi_int 21276789Sdim__muldsi3(su_int a, su_int b) 22276789Sdim{ 23276789Sdim dwords r; 24276789Sdim const int bits_in_word_2 = (int)(sizeof(si_int) * CHAR_BIT) / 2; 25276789Sdim const su_int lower_mask = (su_int)~0 >> bits_in_word_2; 26276789Sdim r.s.low = (a & lower_mask) * (b & lower_mask); 27276789Sdim su_int t = r.s.low >> bits_in_word_2; 28276789Sdim r.s.low &= lower_mask; 29276789Sdim t += (a >> bits_in_word_2) * (b & lower_mask); 30276789Sdim r.s.low += (t & lower_mask) << bits_in_word_2; 31276789Sdim r.s.high = t >> bits_in_word_2; 32276789Sdim t = r.s.low >> bits_in_word_2; 33276789Sdim r.s.low &= lower_mask; 34276789Sdim t += (b >> bits_in_word_2) * (a & lower_mask); 35276789Sdim r.s.low += (t & lower_mask) << bits_in_word_2; 36276789Sdim r.s.high += t >> bits_in_word_2; 37276789Sdim r.s.high += (a >> bits_in_word_2) * (b >> bits_in_word_2); 38276789Sdim return r.all; 39276789Sdim} 40276789Sdim 41276789Sdim/* Returns: a * b */ 42276789Sdim 43276789SdimARM_EABI_FNALIAS(lmul, muldi3) 44276789Sdim 45276789SdimCOMPILER_RT_ABI di_int 46276789Sdim__muldi3(di_int a, di_int b) 47276789Sdim{ 48276789Sdim dwords x; 49276789Sdim x.all = a; 50276789Sdim dwords y; 51276789Sdim y.all = b; 52276789Sdim dwords r; 53276789Sdim r.all = __muldsi3(x.s.low, y.s.low); 54276789Sdim r.s.high += x.s.high * y.s.low + x.s.low * y.s.high; 55276789Sdim return r.all; 56276789Sdim} 57