Home | History | Annotate | Download | only in Arm
      1 /** @file
      2   Compiler intrinsic for 64-bit compare, ported from LLVM code.
      3 
      4   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
      5 
      6   This program and the accompanying materials
      7   are licensed and made available under the terms and conditions of the BSD License
      8   which accompanies this distribution.  The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.php
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 /**
     16   University of Illinois/NCSA
     17   Open Source License
     18 
     19   Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
     20   All rights reserved.
     21 
     22   Developed by:
     23 
     24       LLVM Team
     25 
     26       University of Illinois at Urbana-Champaign
     27 
     28       http://llvm.org
     29 
     30   Permission is hereby granted, free of charge, to any person obtaining a copy of
     31   this software and associated documentation files (the "Software"), to deal with
     32   the Software without restriction, including without limitation the rights to
     33   use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     34   of the Software, and to permit persons to whom the Software is furnished to do
     35   so, subject to the following conditions:
     36 
     37       * Redistributions of source code must retain the above copyright notice,
     38         this list of conditions and the following disclaimers.
     39 
     40       * Redistributions in binary form must reproduce the above copyright notice,
     41         this list of conditions and the following disclaimers in the
     42         documentation and/or other materials provided with the distribution.
     43 
     44       * Neither the names of the LLVM Team, University of Illinois at
     45         Urbana-Champaign, nor the names of its contributors may be used to
     46         endorse or promote products derived from this Software without specific
     47         prior written permission.
     48 
     49   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     50   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
     51   FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     52   CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     53   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     54   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
     55   SOFTWARE.
     56 **/
     57 
     58 
     59 #include "Llvm_int_lib.h"
     60 
     61 UINT64 __udivmoddi4(UINT64 a, UINT64 b, UINT64* rem);
     62 
     63 // Returns: a / b
     64 
     65 INT64
     66 __divdi3(INT64 a, INT64 b)
     67 {
     68     const int bits_in_dword_m1 = (int)(sizeof(INT64) * CHAR_BIT) - 1;
     69     INT64 s_a = a >> bits_in_dword_m1;           // s_a = a < 0 ? -1 : 0
     70     INT64 s_b = b >> bits_in_dword_m1;           // s_b = b < 0 ? -1 : 0
     71     a = (a ^ s_a) - s_a;                         // negate if s_a == -1
     72     b = (b ^ s_b) - s_b;                         // negate if s_b == -1
     73     s_a ^= s_b;                                  // sign of quotient
     74     return (__udivmoddi4(a, b, (UINT64*)0) ^ s_a) - s_a;  // negate if s_a == -1
     75 }
     76 
     77 
     78