added memory_set'function
This commit is contained in:
parent
35a6894d9f
commit
9092d1276a
5
Makefile
5
Makefile
@ -7,6 +7,11 @@ LD_FLAGS := --strip-all
|
|||||||
DEBUG_LD_FLAGS := -g
|
DEBUG_LD_FLAGS := -g
|
||||||
DEBUG_NASM_FLAGS := -g -F dwarf
|
DEBUG_NASM_FLAGS := -g -F dwarf
|
||||||
|
|
||||||
|
# check for avx2 support
|
||||||
|
ifeq ($(shell grep -o 'avx2[^ ]*' /proc/cpuinfo | head -n 1),avx2)
|
||||||
|
NASM_FLAGS += -DAVX2
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
SRC_PATH := src
|
SRC_PATH := src
|
||||||
OBJ_PATH := build/obj
|
OBJ_PATH := build/obj
|
||||||
|
@ -6,13 +6,16 @@ section .bss
|
|||||||
extern term_rows
|
extern term_rows
|
||||||
extern term_cols
|
extern term_cols
|
||||||
|
|
||||||
section .data
|
simulation_running: RESB 1
|
||||||
|
|
||||||
|
section .rodata
|
||||||
clear: db ESC_CHAR, "[2J", 0
|
clear: db ESC_CHAR, "[2J", 0
|
||||||
reset: db ESC_CHAR, "[0m", 0
|
reset: db ESC_CHAR, "[0m", 0
|
||||||
|
|
||||||
statusbar: db ESC_CHAR, "[100m", "Use arrow keys to move cursor, enter to invert cell, p to simulation", 0
|
statusbar: db ESC_CHAR, "[100m", "Use arrow keys to move cursor, enter to invert cell, p to simulation", 0
|
||||||
|
|
||||||
|
start_str: db "START", 0
|
||||||
|
stop_str: db "STOP", 0
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
extern print_str
|
extern print_str
|
||||||
@ -51,4 +54,5 @@ print_game_ui:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
@ -3,15 +3,17 @@
|
|||||||
section .bss
|
section .bss
|
||||||
multipurpuse_buf: RESB 8
|
multipurpuse_buf: RESB 8
|
||||||
|
|
||||||
|
global term_rows
|
||||||
term_rows: RESW 1
|
term_rows: RESW 1
|
||||||
|
global term_cols
|
||||||
term_cols: RESW 1
|
term_cols: RESW 1
|
||||||
|
|
||||||
|
global gameboard_ptr
|
||||||
gameboard_ptr: RESQ 1
|
gameboard_ptr: RESQ 1
|
||||||
|
|
||||||
extern cursor_rows
|
extern cursor_rows
|
||||||
extern cursor_cols
|
extern cursor_cols
|
||||||
|
|
||||||
section .data
|
|
||||||
|
|
||||||
section .text
|
section .text
|
||||||
extern print_str
|
extern print_str
|
||||||
|
76
src/str.asm
76
src/str.asm
@ -60,15 +60,83 @@ unsigned_int_to_ascii: ; takes pointer to array in rdi and value stored in rsi D
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
global string_copy
|
||||||
string_copy:; takes pointer to destination in rdi and pointer to source in rsi
|
string_copy:; takes pointer to destination in rdi and pointer to source in rsi
|
||||||
|
|
||||||
xor rax, rax
|
xor rax, rax
|
||||||
|
|
||||||
.copy_next_byte:
|
.copy_next_byte:
|
||||||
mov byte al, [rdi+rax]
|
mov byte cl, [rsi+rax]
|
||||||
mov [rsi+rax], al
|
test cl, cl
|
||||||
|
jz .exit
|
||||||
|
mov [rdi+rax], cl
|
||||||
inc rax
|
inc rax
|
||||||
test rax,rax
|
jmp .copy_next_byte
|
||||||
jnz .copy_next_byte
|
|
||||||
|
.exit:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
global memory_set:
|
||||||
|
memory_set:; takes destination in rdi, byte in sil and lenght in rdx
|
||||||
|
; first check if value is 16 byte alligned
|
||||||
|
|
||||||
|
mov r9, rdi
|
||||||
|
|
||||||
|
mov rax, rdi
|
||||||
|
and rax, 0xF; offset is stored in rax
|
||||||
|
test al, al; check if resault is 0
|
||||||
|
jz .addr_is_16_Byte_alligned
|
||||||
|
mov r8b, 16
|
||||||
|
sub r8b, al; now offset to first higher 16 byte alligned address is stored in r8
|
||||||
|
sub rdx, r8; we will write these bytes now
|
||||||
|
|
||||||
|
movzx rax, sil
|
||||||
|
imul rax, 0x01010101; to extend across whoule register
|
||||||
|
shl rax, 32; to extend across whoule register
|
||||||
|
|
||||||
|
;add rdi, rdx
|
||||||
|
; we know that rdi has initial address and rdx offset so well fill just add to it
|
||||||
|
mov rcx, 1; we will allwais copy only once
|
||||||
|
|
||||||
|
|
||||||
|
.check_qword:; check if offset is more than qword
|
||||||
|
cmp r8b, 8
|
||||||
|
jl .check_dword
|
||||||
|
rep stosq
|
||||||
|
|
||||||
|
.check_dword:
|
||||||
|
cmp r8b, 4
|
||||||
|
jl .check_word
|
||||||
|
rep stosd
|
||||||
|
|
||||||
|
.check_word:
|
||||||
|
cmp r8b, 2
|
||||||
|
jl .check_byte
|
||||||
|
rep stosw
|
||||||
|
|
||||||
|
.check_byte:
|
||||||
|
test r8b, r8b; check if offset is 1 or 0
|
||||||
|
jz .addr_is_16_Byte_alligned
|
||||||
|
rep stosb
|
||||||
|
|
||||||
|
|
||||||
|
.addr_is_16_Byte_alligned:
|
||||||
|
shr rdx, 4; set it to how many 128bit(16Byte) chunk we need
|
||||||
|
|
||||||
|
%ifdef AVX2
|
||||||
|
vpbroadcastq xmm8, rax
|
||||||
|
%else
|
||||||
|
movq xmm8, rax
|
||||||
|
shufpd xmm8, xmm8, 0x00
|
||||||
|
%endif
|
||||||
|
|
||||||
|
.move_16_bytes:
|
||||||
|
movdqa [rdi], xmm8
|
||||||
|
add rdi, 16
|
||||||
|
dec rdx
|
||||||
|
|
||||||
|
test rdx,rdx; test if rdx is zero
|
||||||
|
jnz .move_16_bytes
|
||||||
|
|
||||||
|
mov rax, r9; return pointer to memory area same as memset in libc
|
||||||
|
ret
|
||||||
|
Loading…
x
Reference in New Issue
Block a user