Skip to content

Commit 6588539

Browse files
committed
Fix: تحسينات على المعالج، تحسين الـ router وإضافة asm utils
1 parent f519854 commit 6588539

File tree

17 files changed

+2174
-322
lines changed

17 files changed

+2174
-322
lines changed

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ CC = gcc
55
ASM = nasm
66
ASMFLAGS = -f elf64
77
CFLAGS = -Wall -Wextra -std=c11 -O3 -march=native -mtune=native -flto -D_POSIX_C_SOURCE=200809L
8-
LDFLAGS = -flto -lpthread -ldl -lm
8+
LDFLAGS = -no-pie -flto -lpthread -ldl -lm
99
DEBUG_CFLAGS = -Wall -Wextra -std=c11 -g -O0 -DDEBUG -D_POSIX_C_SOURCE=200809L
10-
DEBUG_LDFLAGS = -lpthread -ldl -lm
10+
DEBUG_LDFLAGS = -no-pie -lpthread -ldl -lm
1111

1212
# Directories
1313
SRC_DIR = src
@@ -75,8 +75,14 @@ dirs:
7575
$(BUILD_DIR)/ai/%.o: $(AI_DIR)/%.c
7676
$(CC) $(CFLAGS) -I$(INCLUDE_DIR) -I$(AI_INCLUDE_DIR) -c $< -o $@
7777

78-
# Compile assembly files
79-
$(BUILD_DIR)/%.o: $(ASM_DIR)/%.s
78+
# Compile assembly files - specific rules for each file
79+
$(BUILD_DIR)/crc32.o: $(ASM_DIR)/crc32.s
80+
$(ASM) $(ASMFLAGS) $< -o $@
81+
82+
$(BUILD_DIR)/json_fast.o: $(ASM_DIR)/json_fast.s
83+
$(ASM) $(ASMFLAGS) $< -o $@
84+
85+
$(BUILD_DIR)/memcpy_asm.o: $(ASM_DIR)/memcpy_asm.s
8086
$(ASM) $(ASMFLAGS) $< -o $@
8187

8288
# Compile test files

include/asm_utils.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef ASM_UTILS_H
2+
#define ASM_UTILS_H
3+
4+
#include <stddef.h>
5+
#include <stdint.h>
6+
7+
// CRC32 functions
8+
extern uint32_t crc32_asm(const void *data, size_t length);
9+
extern uint32_t crc32_asm_avx2(const void *data, size_t length);
10+
11+
// JSON tokenizer functions
12+
extern void json_fast_tokenizer(const char *json_str, size_t length);
13+
extern void json_fast_tokenizer_avx2(const char *json_str, size_t length);
14+
15+
// Memory copy functions
16+
extern void *memcpy_asm(void *dest, const void *src, size_t n);
17+
extern void *memcpy_asm_avx2(void *dest, const void *src, size_t n);
18+
extern void *memcpy_asm_avx512(void *dest, const void *src, size_t n);
19+
20+
// Hardware detection functions
21+
int has_avx2_support(void);
22+
int has_avx512_support(void);
23+
24+
#endif // ASM_UTILS_H

include/parser.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ typedef enum {
1616
HTTP_UNKNOWN
1717
} HTTPMethod;
1818

19+
// JSON value types
20+
typedef enum {
21+
JSON_OBJECT,
22+
JSON_ARRAY,
23+
JSON_STRING,
24+
JSON_NUMBER,
25+
JSON_BOOLEAN,
26+
JSON_NULL
27+
} JSONType;
28+
29+
// JSON value structure
30+
typedef struct {
31+
JSONType type;
32+
char *key;
33+
union {
34+
char *str;
35+
double number;
36+
int boolean;
37+
} value;
38+
JSONType value_type;
39+
} JSONValue;
1940

2041
typedef struct {
2142
HTTPMethod method;
@@ -25,6 +46,7 @@ typedef struct {
2546
int header_count;
2647
char *body;
2748
size_t body_length;
49+
char *content_type; // Added missing field
2850
} HTTPRequest;
2951

3052

@@ -44,10 +66,11 @@ int parse_http_request(const char *raw_request, HTTPRequest *request);
4466
void free_http_request(HTTPRequest *request);
4567
int parse_json(const char *json_string, void *output);
4668
int json_get_value(const char *json_string, const char *key, char *output, size_t output_size);
69+
int parse_json_with_fast_tokenizer(const char *json_str, size_t length, JSONValue *result); // Added function declaration
4770

4871

4972
extern void json_fast_tokenizer(const char *json_string, size_t length);
5073
extern void *memcpy_asm(void *dest, const void *src, size_t n);
51-
extern uint32_t crc32_asm(const unsigned char *data, size_t length);
74+
extern uint32_t crc32_asm(const void *data, size_t length);
5275

5376
#endif // AIONIC_PARSER_H

include/stream.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "parser.h"
55

6-
76
typedef struct {
87
int client_fd;
98
char *buffer;
@@ -13,11 +12,26 @@ typedef struct {
1312
int chunked_encoding;
1413
} StreamData;
1514

15+
// Stream buffer structure for in-memory operations
16+
typedef struct {
17+
char *data;
18+
size_t size;
19+
size_t pos;
20+
size_t capacity;
21+
} StreamBuffer;
1622

23+
// Stream functions
1724
int stream_init(StreamData *stream, int client_fd);
1825
int stream_send_chunk(StreamData *stream, const char *data, size_t length);
1926
int stream_end(StreamData *stream);
2027
int stream_response(int client_fd, RouteResponse *response);
2128
void stream_cleanup(StreamData *stream);
2229

30+
// Stream buffer functions
31+
int stream_buffer_init(StreamBuffer *stream, size_t initial_size);
32+
int stream_buffer_write(StreamBuffer *stream, const void *data, size_t size);
33+
int stream_buffer_read(StreamBuffer *stream, void *data, size_t size);
34+
void stream_buffer_reset(StreamBuffer *stream);
35+
void stream_buffer_cleanup(StreamBuffer *stream);
36+
2337
#endif // AIONIC_STREAM_H

0 commit comments

Comments
 (0)