1cb5d789fSjca /* ===-- lshrti3.c - Implement __lshrti3 -----------------------------------=== 2cb5d789fSjca * 3cb5d789fSjca * The LLVM Compiler Infrastructure 4cb5d789fSjca * 5cb5d789fSjca * This file is dual licensed under the MIT and the University of Illinois Open 6cb5d789fSjca * Source Licenses. See LICENSE.TXT for details. 7cb5d789fSjca * 8cb5d789fSjca * ===----------------------------------------------------------------------=== 9cb5d789fSjca * 10cb5d789fSjca * This file implements __lshrti3 for the compiler_rt library. 11cb5d789fSjca * 12cb5d789fSjca * ===----------------------------------------------------------------------=== 13cb5d789fSjca */ 14cb5d789fSjca 15*49f00df6Sjca #include "crt_glue.h" 16*49f00df6Sjca 17cb5d789fSjca /* Returns: logical a >> b */ 18cb5d789fSjca 19cb5d789fSjca /* Precondition: 0 <= b < bits_in_tword */ 20cb5d789fSjca 21cb5d789fSjca ti_int __lshrti3(ti_int a,si_int b)22cb5d789fSjca__lshrti3(ti_int a, si_int b) 23cb5d789fSjca { 24cb5d789fSjca const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT); 25cb5d789fSjca utwords input; 26cb5d789fSjca utwords result; 27cb5d789fSjca input.all = a; 28cb5d789fSjca if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */ 29cb5d789fSjca { 30cb5d789fSjca result.s.high = 0; 31cb5d789fSjca result.s.low = input.s.high >> (b - bits_in_dword); 32cb5d789fSjca } 33cb5d789fSjca else /* 0 <= b < bits_in_dword */ 34cb5d789fSjca { 35cb5d789fSjca if (b == 0) 36cb5d789fSjca return a; 37cb5d789fSjca result.s.high = input.s.high >> b; 38cb5d789fSjca result.s.low = (input.s.high << (bits_in_dword - b)) | (input.s.low >> b); 39cb5d789fSjca } 40cb5d789fSjca return result.all; 41cb5d789fSjca } 42