Skip to content

Commit 50be9e8

Browse files
authored
Merge pull request #11 from Unam3dd/5-feat-implement-cpu-extension-detection-for-etheria-standard-project
[FEAT] 🧠 Implement CPU Extension Detection for Etheria Standard Project
2 parents 0920dc2 + 303019b commit 50be9e8

File tree

12 files changed

+1010
-87
lines changed

12 files changed

+1010
-87
lines changed

.github/workflows/memcpy_naive_test.yml renamed to .github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Ubuntu - Memcpy Naive implementation Tests
1+
name: Ubuntu - Tests
22

33
on: [push, pull_request]
44

@@ -41,9 +41,9 @@ jobs:
4141
task build-tests
4242
echo "🎉 Build completed with Meson!"
4343
44-
- name: Run test memcpy naive tests
44+
- name: Run tests
4545
env:
4646
CC: ${{ matrix.compiler }}
4747
run: |
4848
echo "🏗️ Run naive memcpy tests... with $CC"
49-
task run-test-suite -- $(task list-tests | grep "test_memcpy_naive")
49+
task run-tests-verbose

.github/workflows/types_test.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

Taskfile.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tasks:
3535
- sh: '{{if eq OS "windows"}} powershell.exe -Command Test-Path dist {{else}} test ! -d dist {{end}}'
3636
msg: "Nothing to be done."
3737
cmds:
38-
- meson setup build --buildtype=debugoptimized --prefix=$(pwd)
38+
- meson setup build --buildtype=debug --prefix=$(pwd)
3939
- ninja -C build install
4040
silent: true
4141
desc: "Build the project in dev build"
@@ -91,12 +91,21 @@ tasks:
9191
run-tests:
9292
preconditions:
9393
- sh: '{{if eq OS "windows" }} powershell.exe -Command Test-Path build {{else}} test -d build {{end}}'
94-
msg: "Build directory not exist please run build_tests before"
94+
msg: "Build directory not exist please run task build-tests before"
9595
cmds:
9696
- meson test -C build
9797
silent: true
9898
desc: "Run tests files"
9999

100+
run-tests-verbose:
101+
preconditions:
102+
- sh: '{{if eq OS "windows" }} powershell.exe -Command Test-Path build {{else}} test -d build {{end}}'
103+
msg: "Build directory not exist please run build_tests before"
104+
cmds:
105+
- meson test -C build --verbose
106+
silent: true
107+
desc: "Run tests files with verbosity"
108+
100109
run-tests-valgrind:
101110
platforms: ["linux"]
102111
preconditions:

inc/eth-cpuid-flag.h

Lines changed: 333 additions & 0 deletions
Large diffs are not rendered by default.

inc/eth-cpuid-lut.h

Lines changed: 345 additions & 0 deletions
Large diffs are not rendered by default.

inc/eth-cpuid.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef ETH_CPUID_H
2+
#define ETH_CPUID_H
3+
4+
#include <string.h>
5+
#if !defined (__x86_64__)
6+
7+
#error "Error Etheria CPUID is only supported on x86 architecture"
8+
9+
#else
10+
11+
///////////////////////////////////////
12+
//
13+
// ETHERIA TYPES
14+
//
15+
//////////////////////////////////////
16+
17+
#include "eth-types.h"
18+
19+
///////////////////////////////////////
20+
//
21+
// CPUID FLAGS
22+
//
23+
//////////////////////////////////////
24+
25+
#include "eth-cpuid-flag.h"
26+
27+
28+
///////////////////////////////////////
29+
//
30+
// CPUID
31+
//
32+
//////////////////////////////////////
33+
34+
STATIC_INLINE eth_cpuid_reg_t *eth_cpuid(u32_t eax, u32_t ecx)
35+
{
36+
static eth_cpuid_reg_t r;
37+
38+
__asm__ volatile ("cpuid"
39+
: "=a" (r.eax), "=b" (r.ebx), "=c" (r.ecx), "=d" (r.edx)
40+
: "a" (eax), "c" (ecx)
41+
: "memory"
42+
);
43+
44+
return (&r);
45+
}
46+
47+
///////////////////////////////////////
48+
//
49+
// CPU SUPPORTS
50+
//
51+
//////////////////////////////////////
52+
53+
eth_bool_t eth_cpu_support(const char *name);
54+
55+
#endif
56+
57+
#endif

inc/eth-types.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,53 @@
1111
#define NULL (void*)0
1212
#endif
1313

14+
#define GET_(x) #x
15+
16+
///////////////////////////////////////
17+
//
18+
// MACRO
19+
//
20+
//////////////////////////////////////
21+
22+
#define BIN_NUM_1(x) (1<<(x))
23+
#define BIN_NUM_2(x) (BIN_NUM_1(x))|(BIN_NUM_1(x+1))
24+
#define BIN_NUM_3(x) (BIN_NUM_2(x))|(BIN_NUM_1(x+2))
25+
#define BIN_NUM_4(x) (BIN_NUM_2(x))|(BIN_NUM_2(x+2))
26+
#define BIN_NUM_5(x) (BIN_NUM_4(x))|(BIN_NUM_1(x+4))
27+
#define BIN_NUM_6(x) (BIN_NUM_4(x))|(BIN_NUM_2(x+4))
28+
#define BIN_NUM_7(x) (BIN_NUM_4(x))|(BIN_NUM_3(x+4))
29+
#define BIN_NUM_8(x) (BIN_NUM_4(x))|(BIN_NUM_4(x+4))
30+
31+
#define ETH_AND(a, b) a & b
32+
#define ETH_OR(a, b) a | b
33+
#define ETH_XOR(a, b) a ^ b
34+
#define ETH_NOT(a) ~a
35+
#define ETH_LSH(a, b) (a << b)
36+
#define ETH_RSH(a, b) (a >> b)
37+
#define ETH_ZERO(x) ETH_XOR(x, x)
38+
#define GET_SIZE(x, y) (sizeof(x)/sizeof(y))
39+
40+
///////////////////////////////////////
41+
//
42+
// TYPES TYPEDEFS
43+
//
44+
//////////////////////////////////////
45+
46+
#define STATIC_INLINE static inline __attribute__((always_inline))
47+
48+
///////////////////////////////////////
49+
//
50+
// BOOL
51+
//
52+
//////////////////////////////////////
53+
54+
typedef enum eth_bool_t
55+
{
56+
FALSE,
57+
TRUE
58+
} eth_bool_t;
59+
60+
1461
///////////////////////////////////////
1562
//
1663
// STATIC
@@ -63,14 +110,20 @@ typedef unsigned int dword_t;
63110
typedef unsigned short word_t;
64111
typedef unsigned char byte_t;
65112

113+
typedef unsigned int eth_off32_t;
114+
typedef unsigned short eth_off_t;
115+
typedef unsigned short eth_off16_t;
116+
66117
#if defined(__linux__)
118+
typedef unsigned long eth_off64_t;
67119
typedef unsigned long qword_t;
68120
typedef unsigned long eth_size_t;
69121
typedef unsigned long size_t;
70122
typedef unsigned long u64_t;
71123
typedef unsigned long uint64_t;
72124
typedef unsigned long eth_uint64_t;
73125
#else
126+
typedef unsigned long long eth_off64_t;
74127
typedef unsigned long long qword_t;
75128
typedef unsigned long long eth_size_t;
76129
typedef unsigned long long size_t;

meson.build

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project('Etheria-std', 'c',
22
version : '0.1',
3-
default_options : ['warning_level=3', 'werror=true', 'optimization=3', 'buildtype=release'])
3+
default_options : ['warning_level=3', 'werror=true', 'optimization=0', 'buildtype=release'])
44

55

66
######################################
@@ -14,9 +14,9 @@ project('Etheria-std', 'c',
1414
cc = meson.get_compiler('c')
1515
linker = cc.get_linker_id()
1616

17-
#if not cc.has_function_attribute('ifunc')
18-
# error('The Target compiler does not support ifunc function attribute.')
19-
#endif
17+
if not cc.has_function_attribute('ifunc')
18+
error('The Target compiler does not support ifunc function attribute.')
19+
endif
2020

2121
if (host_machine.system() == 'linux')
2222
ld = find_program('ld', required : true)
@@ -52,8 +52,10 @@ incdir = include_directories('inc')
5252
#
5353
######################################
5454

55-
srcs = files('src/memory/memcpy/memcpy.c')
55+
MEMCPY_FILES = files('src/memory/memcpy/memcpy.c')
56+
CPUID_FILES = files('src/cpuid/cpuid.c')
5657

58+
SRCS = MEMCPY_FILES + CPUID_FILES
5759

5860
######################################
5961
#
@@ -65,17 +67,17 @@ srcs = files('src/memory/memcpy/memcpy.c')
6567

6668

6769
types_tests = files('tests/types/types_basic_test.c')
70+
cpuid_tests = files('tests/cpuid/cpuid_test.c')
6871

6972
memory_memcpy_naive = files('tests/memory/memcpy/memcpy_naive/memcpy_naive.c',
7073
'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_small.c',
7174
'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_mid.c',
7275
'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_aligned_big.c',
73-
'tests/memory/memcpy/memcpy_naive/memcpy_naive_overlap.c',
7476
'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_small.c',
7577
'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_mid.c',
7678
'tests/memory/memcpy/memcpy_naive/memcpy_naive_stack_buf_unaligned_big.c')
7779

78-
tests = types_tests + memory_memcpy_naive
80+
tests = types_tests + memory_memcpy_naive + cpuid_tests
7981

8082
summary({
8183
'CPU': build_machine.cpu(),
@@ -114,24 +116,25 @@ summary({
114116
######################################
115117

116118
add_project_arguments('-DNO_STATIC=1', language: 'c')
119+
add_project_arguments('-masm=intel', language: 'c')
117120

118121
if host_machine.system() == 'windows'
119122

120123
static_library('etheria-std',
121-
srcs,
124+
SRCS,
122125
install: true,
123126
install_dir: 'dist',
124127
include_directories: incdir)
125128
else
126129
lib_shared = shared_library('etheria-std',
127-
srcs,
130+
SRCS,
128131
c_args: ['-nostdlib', '-nodefaultlibs', '-fPIC'],
129132
install: true,
130133
install_dir: 'dist/shared',
131134
include_directories: incdir)
132135

133136
lib_static = static_library('etheria-std',
134-
srcs,
137+
SRCS,
135138
c_args: ['-nostdlib', '-nodefaultlibs'],
136139
install: true,
137140
install_dir: 'dist/static',

0 commit comments

Comments
 (0)