1156cd587Sjoerg /*===-- ashrdi3.c - Implement __ashrdi3 -----------------------------------=== 2156cd587Sjoerg * 3156cd587Sjoerg * The LLVM Compiler Infrastructure 4156cd587Sjoerg * 5156cd587Sjoerg * This file is dual licensed under the MIT and the University of Illinois Open 6156cd587Sjoerg * Source Licenses. See LICENSE.TXT for details. 7156cd587Sjoerg * 8156cd587Sjoerg * ===----------------------------------------------------------------------=== 9156cd587Sjoerg * 10156cd587Sjoerg * This file implements __ashrdi3 for the compiler_rt library. 11156cd587Sjoerg * 12156cd587Sjoerg * ===----------------------------------------------------------------------=== 13156cd587Sjoerg */ 14156cd587Sjoerg 15156cd587Sjoerg #include "int_lib.h" 16156cd587Sjoerg 17156cd587Sjoerg /* Returns: arithmetic a >> b */ 18156cd587Sjoerg 19156cd587Sjoerg /* Precondition: 0 <= b < bits_in_dword */ 20156cd587Sjoerg 21156cd587Sjoerg COMPILER_RT_ABI di_int __ashrdi3(di_int a,si_int b)22156cd587Sjoerg__ashrdi3(di_int a, si_int b) 23156cd587Sjoerg { 24156cd587Sjoerg const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); 25156cd587Sjoerg dwords input; 26156cd587Sjoerg dwords result; 27156cd587Sjoerg input.all = a; 28156cd587Sjoerg if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ 29156cd587Sjoerg { 30156cd587Sjoerg /* result.s.high = input.s.high < 0 ? -1 : 0 */ 31156cd587Sjoerg result.s.high = input.s.high >> (bits_in_word - 1); 32156cd587Sjoerg result.s.low = input.s.high >> (b - bits_in_word); 33156cd587Sjoerg } 34156cd587Sjoerg else /* 0 <= b < bits_in_word */ 35156cd587Sjoerg { 36156cd587Sjoerg if (b == 0) 37156cd587Sjoerg return a; 38156cd587Sjoerg result.s.high = input.s.high >> b; 39156cd587Sjoerg result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b); 40156cd587Sjoerg } 41156cd587Sjoerg return result.all; 42156cd587Sjoerg } 433044ee7eSrin 443044ee7eSrin #if defined(__ARM_EABI__) 45*d3143459Srin AEABI_RTABI di_int __aeabi_lasr(di_int a, si_int b) COMPILER_RT_ALIAS(__ashrdi3); 463044ee7eSrin #endif 47