-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce possibility of CPU-specific optimization
Added Arch structure, containing function pointers to optimizable functions. Original C implementations can be overridden at runtime with faster, CPU-specific implementations.
- Loading branch information
Showing
15 changed files
with
370 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file arch.c | ||
* @brief Collection of CPU-specific functions. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#include "arch.h" | ||
|
||
#include <assert.h> | ||
|
||
#include "IAMF_utils.h" | ||
#include "arch/arch_init.h" | ||
|
||
Arch* arch_create() { | ||
Arch* arch = IAMF_MALLOCZ(Arch, 1); | ||
memset(arch, 0x0, sizeof(Arch)); | ||
|
||
arch_init(arch); | ||
|
||
return arch; | ||
} | ||
|
||
void arch_destroy(Arch* arch) { IAMF_FREE(arch); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file arch.h | ||
* @brief Collection of CPU-specific functions. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#ifndef ARCH_H_ | ||
#define ARCH_H_ | ||
|
||
typedef struct ArchCallbacks { | ||
// Functions with possible architecture-specific optimizations | ||
} Arch; | ||
|
||
Arch *arch_create(); | ||
void arch_destroy(Arch *arch); | ||
|
||
#endif /* ARCH_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file arch_common.c | ||
* @brief C implementation for CPU-specific functions. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#include "arch_common.h" | ||
|
||
// TODO: Remove this line when first function added! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file arch_common.h | ||
* @brief C implementation for CPU-specific functions. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#ifndef ARCH_COMMON_H_ | ||
#define ARCH_COMMON_H_ | ||
|
||
// TODO: Remove this line when first function added! | ||
|
||
#endif /* ARCH_COMMON_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file arch_init.c | ||
* @brief Init CPU-specific function callbacks. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#include "arch_init.h" | ||
|
||
#include <string.h> | ||
|
||
#include "arch.h" | ||
#include "arch_common.h" | ||
|
||
// To add new architecture 'ABC', follow the following pattern: | ||
// * add arch/ABC subfolder, with detect_ABC.h | ||
// * inside detect_ABC.h, if ABC target detected, define IAMF_ARCH_DETECTED_ABC, | ||
// and implement arch_override(...) function | ||
// * all files under arch/ABC must include detect_ABC.h, and be surrounded with | ||
// #if defined(IAMF_ARCH_DETECTED_ABC) | ||
#include "arm/detect_arm.h" | ||
#include "x86/detect_x86.h" | ||
#if defined(IAMF_ARCH_DETECTED_ARM) || defined(IAMF_ARCH_DETECTED_X86) | ||
#define HAS_ARCH_OVERRIDE (1) | ||
#endif | ||
|
||
#if defined(HAS_ARCH_OVERRIDE) | ||
// Implemented in each architecture-specific subfolder, | ||
// behind IAMF_ARCH_DETECTED_... ifdef | ||
void arch_override(Arch* arch); | ||
#endif | ||
|
||
void arch_init(Arch* arch) { | ||
memset(arch, 0x0, sizeof(Arch)); | ||
|
||
// Fill with reference implementations | ||
|
||
// arch->myfn = &myfn_c; // myfn_c is in arch_common.h/.c | ||
// TODO: Remove these lines when first function added! | ||
|
||
#if defined(HAS_ARCH_OVERRIDE) | ||
// Override with platform-specific functions, if available | ||
arch_override(arch); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file arch_init.h | ||
* @brief Init CPU-specific function callbacks. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#ifndef ARCH_INIT_H_ | ||
#define ARCH_INIT_H_ | ||
|
||
typedef struct ArchCallbacks Arch; | ||
|
||
void arch_init(Arch* arch); | ||
|
||
#endif /* ARCH_INIT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file detect_arm.h | ||
* @brief Detect Arm architecture during compilation. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#ifndef DETECT_ARM_H_ | ||
#define DETECT_ARM_H_ | ||
|
||
#if defined(__ARM_NEON) | ||
#define IAMF_ARCH_DETECTED_ARM (1) | ||
#endif | ||
|
||
#endif /* DETECT_ARM_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file override_arm.c | ||
* @brief Override with Arm function implementations. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#include "detect_arm.h" | ||
|
||
#if defined(IAMF_ARCH_DETECTED_ARM) | ||
|
||
#include <arm_neon.h> | ||
|
||
#include "../../arch.h" | ||
|
||
void arch_override(Arch *arch) { | ||
// Override functions with Arm implementations here | ||
|
||
// arch->myfn = &myfn_neon; | ||
// TODO: Remove this line when first function added! | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file detect_x86.h | ||
* @brief Detect x86 architecture during compilation. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#ifndef DETECT_X86_H_ | ||
#define DETECT_X86_H_ | ||
|
||
#if defined(__x86_64__) || defined(__i386__) | ||
#define IAMF_ARCH_DETECTED_X86 (1) | ||
#endif | ||
|
||
#endif /* DETECT_X86_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2024, Alliance for Open Media. All rights reserved | ||
* | ||
* This source code is subject to the terms of the BSD 3-Clause Clear License | ||
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear | ||
* License was not distributed with this source code in the LICENSE file, you | ||
* can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the | ||
* Alliance for Open Media Patent License 1.0 was not distributed with this | ||
* source code in the PATENTS file, you can obtain it at | ||
* www.aomedia.org/license/patent. | ||
*/ | ||
|
||
/** | ||
* @file override_x86.c | ||
* @brief Override with x86 function implementations. | ||
* @version 0.1 | ||
* @date Created 10/24/2024 | ||
**/ | ||
|
||
#include "detect_x86.h" | ||
|
||
#if defined(IAMF_ARCH_DETECTED_X86) | ||
|
||
#include "../../arch.h" | ||
|
||
void arch_override(Arch* arch) { | ||
// Override functions with x86 implementations here | ||
} | ||
|
||
#endif /* IAMF_ARCH_DETECTED_X86 */ |
Oops, something went wrong.