137a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan/* ====-- ashldi3.c - Implement __ashldi3 -----------------------------------=== 237a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * 337a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * The LLVM Compiler Infrastructure 437a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * 59ad441ffec97db647fee3725b3424284fb913e14Howard Hinnant * This file is dual licensed under the MIT and the University of Illinois Open 69ad441ffec97db647fee3725b3424284fb913e14Howard Hinnant * Source Licenses. See LICENSE.TXT for details. 737a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * 837a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * ===----------------------------------------------------------------------=== 937a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * 1037a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * This file implements __ashldi3 for the compiler_rt library. 1137a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * 1237a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan * ===----------------------------------------------------------------------=== 1337a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan */ 14b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar 15b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar#include "int_lib.h" 16b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar 1737a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan/* Returns: a << b */ 18b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar 1937a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan/* Precondition: 0 <= b < bits_in_dword */ 20b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar 210193b74976719b8aea4cb8874ba36b75836a8d6eChandler CarruthARM_EABI_FNALIAS(llsl, ashldi3) 2237b97d1cf4501b94347e0b4e880f4b25825a289fAnton Korobeynikov 231c5f89b1dd741135a4007ab577723d422f421eecAnton KorobeynikovCOMPILER_RT_ABI di_int 24b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar__ashldi3(di_int a, si_int b) 25b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar{ 26b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); 27b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar dwords input; 28b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar dwords result; 29b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar input.all = a; 3037a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ 31b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar { 328bf1e094893cb24796137b47ee0d46d18d299996Edward O'Callaghan result.s.low = 0; 338bf1e094893cb24796137b47ee0d46d18d299996Edward O'Callaghan result.s.high = input.s.low << (b - bits_in_word); 34b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar } 3537a6a455466e5b197311771a777ab241e471ed8aEdward O'Callaghan else /* 0 <= b < bits_in_word */ 36b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar { 37b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar if (b == 0) 38b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar return a; 398bf1e094893cb24796137b47ee0d46d18d299996Edward O'Callaghan result.s.low = input.s.low << b; 408bf1e094893cb24796137b47ee0d46d18d299996Edward O'Callaghan result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_word - b)); 41b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar } 42b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar return result.all; 43b3a6901e66f55b35aa9e01bcb24134e6a65ea004Daniel Dunbar} 44