Home | History | Annotate | Download | only in Arm
      1 /** @file
      2 
      3   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
      4 
      5   This program and the accompanying materials
      6   are licensed and made available under the terms and conditions of the BSD License
      7   which accompanies this distribution.  The full text of the license may be found at
      8   http://opensource.org/licenses/bsd-license.php
      9 
     10   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     11   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     12 
     13 **/
     14 /**
     15   University of Illinois/NCSA
     16   Open Source License
     17 
     18   Copyright (c) 2003-2008 University of Illinois at Urbana-Champaign.
     19   All rights reserved.
     20 
     21   Developed by:
     22 
     23       LLVM Team
     24 
     25       University of Illinois at Urbana-Champaign
     26 
     27       http://llvm.org
     28 
     29   Permission is hereby granted, free of charge, to any person obtaining a copy of
     30   this software and associated documentation files (the "Software"), to deal with
     31   the Software without restriction, including without limitation the rights to
     32   use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
     33   of the Software, and to permit persons to whom the Software is furnished to do
     34   so, subject to the following conditions:
     35 
     36       * Redistributions of source code must retain the above copyright notice,
     37         this list of conditions and the following disclaimers.
     38 
     39       * Redistributions in binary form must reproduce the above copyright notice,
     40         this list of conditions and the following disclaimers in the
     41         documentation and/or other materials provided with the distribution.
     42 
     43       * Neither the names of the LLVM Team, University of Illinois at
     44         Urbana-Champaign, nor the names of its contributors may be used to
     45         endorse or promote products derived from this Software without specific
     46         prior written permission.
     47 
     48   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     49   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
     50   FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     51   CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     52   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     53   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
     54   SOFTWARE.
     55 **/
     56 
     57 #include <Base.h>
     58 #include <Library/DebugLib.h>
     59 
     60 #define CHAR_BIT  8
     61 
     62 typedef union {
     63     INT64   all;
     64     struct {
     65         UINT32 low;
     66         INT32  high;
     67     };
     68 } dwords;
     69 
     70 typedef union {
     71     UINT64  all;
     72     struct {
     73         UINT32 low;
     74         UINT32 high;
     75     };
     76 } udwords;
     77 
     78 // __aeabi_ return values
     79 typedef struct {
     80   UINT64  Quotent;
     81   UINT64  Remainder;
     82 } ulldiv_t;
     83 
     84 typedef struct {
     85   INT64   Quotent;
     86   INT64   Remainder;
     87 } lldiv_t;
     88 
     89 typedef struct {
     90   UINT32  Quotent;
     91   UINT32  Remainder;
     92 } uidiv_return;
     93 
     94 #if __GNUC__
     95   #define COUNT_LEADING_ZEROS(_a)   __builtin_clz((_a))
     96   #define COUNT_TRAILING_ZEROS(_a)  __builtin_ctz((_a))
     97 #else
     98 #error COUNT_LEADING_ZEROS() and COUNT_TRAILING_ZEROS() macros not ported to your compiler
     99 #endif
    100