Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 1 | /* ===-- muldi3.c - Implement __muldi3 -------------------------------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
| 9 | * |
| 10 | * This file implements __muldi3 for the compiler_rt library. |
| 11 | * |
| 12 | * ===----------------------------------------------------------------------=== |
Anton Korobeynikov | 1c5f89b | 2011-04-19 17:52:09 +0000 | [diff] [blame] | 13 | */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 14 | |
| 15 | #include "int_lib.h" |
| 16 | |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 17 | /* Returns: a * b */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 18 | |
| 19 | static |
| 20 | di_int |
| 21 | __muldsi3(su_int a, su_int b) |
| 22 | { |
| 23 | dwords r; |
| 24 | const int bits_in_word_2 = (int)(sizeof(si_int) * CHAR_BIT) / 2; |
| 25 | const su_int lower_mask = (su_int)~0 >> bits_in_word_2; |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 26 | r.s.low = (a & lower_mask) * (b & lower_mask); |
| 27 | su_int t = r.s.low >> bits_in_word_2; |
| 28 | r.s.low &= lower_mask; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 29 | t += (a >> bits_in_word_2) * (b & lower_mask); |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 30 | r.s.low += (t & lower_mask) << bits_in_word_2; |
| 31 | r.s.high = t >> bits_in_word_2; |
| 32 | t = r.s.low >> bits_in_word_2; |
| 33 | r.s.low &= lower_mask; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 34 | t += (b >> bits_in_word_2) * (a & lower_mask); |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 35 | r.s.low += (t & lower_mask) << bits_in_word_2; |
| 36 | r.s.high += t >> bits_in_word_2; |
| 37 | r.s.high += (a >> bits_in_word_2) * (b >> bits_in_word_2); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 38 | return r.all; |
| 39 | } |
| 40 | |
Edward O'Callaghan | 37a6a45 | 2009-08-07 20:30:09 +0000 | [diff] [blame] | 41 | /* Returns: a * b */ |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 42 | |
Chandler Carruth | 0193b74 | 2012-06-22 21:09:15 +0000 | [diff] [blame] | 43 | ARM_EABI_FNALIAS(lmul, muldi3) |
Anton Korobeynikov | 37b97d1 | 2011-04-19 17:51:24 +0000 | [diff] [blame] | 44 | |
Anton Korobeynikov | 1c5f89b | 2011-04-19 17:52:09 +0000 | [diff] [blame] | 45 | COMPILER_RT_ABI di_int |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 46 | __muldi3(di_int a, di_int b) |
| 47 | { |
| 48 | dwords x; |
| 49 | x.all = a; |
| 50 | dwords y; |
| 51 | y.all = b; |
| 52 | dwords r; |
Edward O'Callaghan | 8bf1e09 | 2009-08-09 18:41:02 +0000 | [diff] [blame] | 53 | r.all = __muldsi3(x.s.low, y.s.low); |
| 54 | r.s.high += x.s.high * y.s.low + x.s.low * y.s.high; |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 55 | return r.all; |
| 56 | } |