|
|
/* ----------------------------------------------------------------------------
|
|
|
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2019. All rights reserved.
|
|
|
* Description: ToolChain
|
|
|
* Author: Huawei LiteOS Team
|
|
|
* Create: 2013-01-01
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
* conditions and the following disclaimer.
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
* provided with the distribution.
|
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
|
|
* to endorse or promote products derived from this software without specific prior written
|
|
|
* permission.
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
* --------------------------------------------------------------------------- */
|
|
|
/*这段代码提供了一些通用的宏和函数,可以帮助开发者在不同的编译环境下编写跨平台的代码,并提供了一些位操作的便利功能。*/
|
|
|
/**
|
|
|
* @defgroup los_toolchain
|
|
|
* @ingroup kernel
|
|
|
*/
|
|
|
|
|
|
#ifndef _LOS_TOOLCHAIN_H
|
|
|
#define _LOS_TOOLCHAIN_H
|
|
|
|
|
|
#if defined ( __ICCARM__ )
|
|
|
#include "iccarm_builtin.h"
|
|
|
#endif
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
#if __cplusplus
|
|
|
extern "C" {
|
|
|
#endif /* __cplusplus */
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
/* for ARM Compiler */
|
|
|
#if defined ( __CC_ARM )
|
|
|
#ifndef ASM
|
|
|
#define ASM __asm
|
|
|
#endif
|
|
|
|
|
|
#ifndef INLINE
|
|
|
#define INLINE __inline
|
|
|
#endif
|
|
|
|
|
|
#ifndef STATIC_INLINE
|
|
|
#define STATIC_INLINE static __inline
|
|
|
#endif
|
|
|
|
|
|
#ifndef USED
|
|
|
#define USED __attribute__((used))
|
|
|
#endif
|
|
|
|
|
|
#ifndef WEAK
|
|
|
#define WEAK __attribute__((weak))
|
|
|
#endif
|
|
|
|
|
|
#ifndef CLZ
|
|
|
#define CLZ(value) (__clz(value))
|
|
|
#endif
|
|
|
/*这段代码是宏定义,用于在 ARM Compiler 下定义一些与编译器相关的宏和函数。
|
|
|
|
|
|
ASM 宏定义了一个 __asm 关键字,用于在 C 语言中嵌入汇编代码。
|
|
|
INLINE 宏定义了一个 __inline 关键字,用于将函数声明为内联函数。
|
|
|
STATIC_INLINE 宏定义了一个 static __inline 关键字组合,用于将函数声明为静态内联函数。
|
|
|
USED 宏使用了 GCC 的 __attribute__((used)) 属性,用于告诉编译器某个变量或函数可能会被其他地方使用,即使看起来没有被引用。
|
|
|
WEAK 宏使用了 GCC 的 __attribute__((weak)) 属性,用于声明一个弱符号(weak symbol),表示该符号可以被覆盖。
|
|
|
CLZ 宏定义了一个函数,用于计算一个数的二进制表示中前导零的位数。它使用了编译器自带的 __clz 内置函数。
|
|
|
这些宏的定义是针对 IAR Compiler 编译器的,可以帮助代码在不同的编译环境中正确地进行编译和链接*/
|
|
|
/* for IAR Compiler */
|
|
|
#elif defined ( __ICCARM__ )
|
|
|
|
|
|
#ifndef ASM
|
|
|
#define ASM __asm
|
|
|
#endif
|
|
|
|
|
|
#ifndef INLINE
|
|
|
#define INLINE inline
|
|
|
#endif
|
|
|
|
|
|
#ifndef STATIC_INLINE
|
|
|
#define STATIC_INLINE static inline
|
|
|
#endif
|
|
|
|
|
|
#ifndef USED
|
|
|
#define USED __root
|
|
|
#endif
|
|
|
|
|
|
#ifndef WEAK
|
|
|
#define WEAK __weak
|
|
|
#endif
|
|
|
|
|
|
#ifndef CLZ
|
|
|
#define CLZ(value) (__iar_builtin_CLZ(value))
|
|
|
#endif
|
|
|
|
|
|
#ifndef CTZ
|
|
|
#define CTZ(value) (__UNDEFINED(value))
|
|
|
#endif
|
|
|
/*这段代码是宏定义,用于在 IAR Compiler 下定义一些与编译器相关的宏和函数。
|
|
|
|
|
|
ASM 宏定义了一个 __asm 关键字,用于在 C 语言中嵌入汇编代码。
|
|
|
INLINE 宏定义了一个 inline 关键字,用于将函数声明为内联函数。
|
|
|
STATIC_INLINE 宏定义了一个 static inline 关键字组合,用于将函数声明为静态内联函数。
|
|
|
USED 宏使用了 IAR Compiler 的 __root 属性,用于告诉编译器某个变量或函数可能会被其他地方使用,即使看起来没有被引用。
|
|
|
WEAK 宏使用了 IAR Compiler 的 __weak 属性,用于声明一个弱符号(weak symbol),表示该符号可以被覆盖。
|
|
|
CLZ 宏定义了一个函数,用于计算一个数的二进制表示中前导零的位数。它使用了 IAR Compiler 提供的 __iar_builtin_CLZ 内置函数。
|
|
|
CTZ 宏定义了一个函数,用于计算一个数的二进制表示中末尾零的位数。它使用了一个未定义的函数 __UNDEFINED。
|
|
|
这些宏的定义是针对 IAR Compiler 编译器的,可以帮助代码在不同的编译环境中正确地进行编译和链接。*/
|
|
|
/* for GNU Compiler */
|
|
|
#elif defined ( __GNUC__ )
|
|
|
|
|
|
#ifndef ASM
|
|
|
#define ASM __asm
|
|
|
#endif
|
|
|
|
|
|
#ifndef INLINE
|
|
|
#define INLINE __inline
|
|
|
#endif
|
|
|
|
|
|
#ifndef STATIC_INLINE
|
|
|
#define STATIC_INLINE static inline
|
|
|
#endif
|
|
|
|
|
|
#ifndef USED
|
|
|
#define USED __attribute__((used))
|
|
|
#endif
|
|
|
|
|
|
#ifndef WEAK
|
|
|
#define WEAK __attribute__((weak))
|
|
|
#endif
|
|
|
|
|
|
#ifndef CLZ
|
|
|
#define CLZ(value) (__builtin_clz(value))
|
|
|
#endif
|
|
|
|
|
|
#ifndef CTZ
|
|
|
#define CTZ(value) (__builtin_ctz(value))
|
|
|
#endif
|
|
|
|
|
|
#ifndef FFS
|
|
|
#define FFS(value) (__builtin_ffs(value))
|
|
|
#endif
|
|
|
/*这段代码是宏定义,用于在 GNU Compiler 下定义一些与编译器相关的宏和函数。
|
|
|
|
|
|
ASM 宏定义了一个 __asm 关键字,用于在 C 语言中嵌入汇编代码。
|
|
|
INLINE 宏定义了一个 __inline 关键字,用于将函数声明为内联函数。
|
|
|
STATIC_INLINE 宏定义了一个 static inline 关键字组合,用于将函数声明为静态内联函数。
|
|
|
USED 宏使用了 GNU Compiler 的 __attribute__((used)) 属性,用于告诉编译器某个变量或函数可能会被其他地方使用,即使看起来没有被引用。
|
|
|
WEAK 宏使用了 GNU Compiler 的 __attribute__((weak)) 属性,用于声明一个弱符号(weak symbol),表示该符号可以被覆盖。
|
|
|
CLZ 宏定义了一个函数,用于计算一个数的二进制表示中前导零的位数。它使用了 GNU Compiler 提供的 __builtin_clz 内置函数。
|
|
|
CTZ 宏定义了一个函数,用于计算一个数的二进制表示中末尾零的位数。它使用了 GNU Compiler 提供的 __builtin_ctz 内置函数。
|
|
|
FFS 宏定义了一个函数,用于计算一个数的二进制表示中最低位(从右往左)的非零位的位置。它使用了 GNU Compiler 提供的 __builtin_ffs 内置函数。
|
|
|
这些宏的定义是针对 GNU Compiler 编译器的,可以帮助代码在不同的编译环境中正确地进行编译和链接。*/
|
|
|
#else
|
|
|
#error Unknown compiler.
|
|
|
#endif
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
#if __cplusplus
|
|
|
}
|
|
|
#endif /* __cplusplus */
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
#endif /* _LOS_TOOLCHAIN_H */
|