Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/adl/GenParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ bool GenParser::GenerateOpcodes()
}
else
{
std::cout << "Undefined opcode class '" << x->cclass << "' in definition of opcode '" << x->name << "'";
std::cout << "Undefined opcode class '" << x->cclass << "' in definition of opcode '" << x->name << "'" << std::endl;
}
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/adl/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#

CC=cl.exe
CCFLAGS = /O2 /EHs /c /nologo /I../util
CCFLAGS = /O2 /EHs /c /nologo /I../util /DTARGET_OS_WINDOWS

LINK=link.exe
LFLAGS=/LTCG:incremental /nologo /NXCOMPAT /DYNAMICBASE /MACHINE:x86 /OPT:REF /SAFESEH /OPT:ICF /TLBID:1
Expand All @@ -21,7 +21,8 @@ EXE_dependencies = \
GenParser.obj \
Loader.obj \
Tokenizer.obj \
ADLMain.obj
ADLMain.obj \
ToolChain.obj

adl.exe: $(EXE_dependencies)
$(LINK) $(TYPE) $(LFLAGS) $(COMPLIB) /LIBPATH:"$(UCRTPATH)" /LIBPATH:"$(VCINSTALLDIR)\lib" /OUT:$@ $(EXE_dependencies) ..\lib\ms\util.lib
6 changes: 2 additions & 4 deletions src/clibs/stdbit/has_single_bit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
#include <limits.h>

template <class T>
static inline unsigned int has_single_bit(T arg)
static inline bool has_single_bit(T arg)
{
int rv = 0;
for (T val = ((T)1) << sizeof(arg) * CHAR_BIT - 1; val; rv += (arg & val) != 0, val >>= 1);
return rv == 1;
return arg && !(arg & (arg - 1));
}

extern "C"
Expand Down
6 changes: 4 additions & 2 deletions src/clibs/stdinc/_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@
# define __STD_NS_QUALIFIER
# endif

# if __STDC_VERSION__ < 201112L || defined(__cplusplus)
# if __STDC_VERSION__ < 201112L && !defined(__cplusplus)
# define _NORETURN
# else
# elif __STDC_VERSION__ < 202311L && !defined(__cplusplus)
# define _NORETURN _Noreturn
#else
# define _NORETURN [[noreturn]]
# endif

/* the headers use the restrict keyword, which is not valid prior to
Expand Down
2 changes: 1 addition & 1 deletion src/clibs/stdinc/libp.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ extern "C"
{
# endif
int __ll_thrdstart(struct ithrd** thr, thrd_start_t* func, void* arglist);
void __ll_thrdexit(unsigned retval);
_NORETURN void __ll_thrdexit(unsigned retval);
void __ll_thrdsleep(unsigned ms);
void _RTL_FUNC _IMPORT __thrdRegisterModule(void* module, void* tlsStart, void* tlsEnd);
void _RTL_FUNC _IMPORT __thrdUnregisterModule(void* module);
Expand Down
79 changes: 79 additions & 0 deletions src/clibs/string/386/memcpy.c.refsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <stdint.h>
inline void* memcpy_basic(void* dest, const void* src, size_t n)
{
for (size_t i = 0; i < n; i++)
{
((char*)dest)[i] = ((const char*)src)[i];
}
return dest;
}
inline void* memmove_backwards_basic(void* s1, const void* s2, size_t sz)
{
while (sz > 0)
{
sz--;
((char*)s1)[sz] = ((const char*)s2)[sz];
}
return s1;
}
inline void* memmove_backwards(void* s1, const void* s2, size_t sz)
{
if (sz < 256)
{
return memmove_backwards_basic(s1, s2, sz);
}
char* src_end = (const char*)s2 + sz;
char* dest_end = (const char*)s1 + sz;
__asm
{
// If DF=1 ESI and EDI are subtracted each time, otherwise ESI and EDI are added to.
mov esi, [src_end];
mov edi, [dest_end];
mov ecx, [sz];
std;
rep movsb;
cld;
}
return s1;
}
inline void* memcpy_repmovs(void* s1, const void* s2, size_t sz)
{
// Garbage heuristic, check 3.7.6.3 of the Intel Architecture Optimization manual.
// In theory, once we confirm that this "style" is faster, an optimization pass to make the function absolutely tiny is
// available
if (sz < 256)
{
return memcpy_basic(s1, s2, sz);
}
__asm
{
mov esi, [s2];
mov edi, [s1];
mov ecx, [sz];
cld;
rep movsb;
}
return s1;
}

void* _RTL_FUNC memcpy(void* dest, const void* src, size_t sz)
{
// Do we overlap?
if (((uintptr_t)src) < ((uintptr_t)dest) && ((uintptr_t)dest) < (((uintptr_t)src) + sz))
{
size_t distance_beyond = ((uintptr_t)src) + sz - ((uintptr_t)dest);
size_t inverse_distance_beyond = sz - distance_beyond;
memmove_backwards_basic((char*)dest + inverse_distance_beyond, dest, distance_beyond);
// Copy the values in-between dest and src to dest
return memcpy_repmovs(dest, src, inverse_distance_beyond);
}
else
{
// Destination + size goes into source
// That is fine, we can do a forward copy without issue
return memcpy_repmovs(dest, src, sz);
}
return dest;
}

void* _RTL_FUNC memmove(void* dest, const void* src, size_t n) { return memcpy(dest, src, n); }
187 changes: 144 additions & 43 deletions src/clibs/string/386/memcpy.nas
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,152 @@

%ifdef __BUILDING_LSCRTL_DLL
[export _memcpy]
[export _memmove]
%endif
[global _memcpy]
[global memcpy_x]
[global _memmove]
SECTION code CLASS=CODE USE32
; memcpy_basic
_memcpy_basic:
; Line 2: inline void* memcpy_basic(void* dest, const void* src, size_t n)
push ebx
push esi
push edi
mov esi,dword [esp+0ch+0ch]
mov edx,dword [esp+08h+0ch]
mov eax,dword [esp+04h+0ch]
; Line 4: for (size_t i = 0; i < n; i++)
xor ebx,ebx
cmp ebx,esi
jnc L_6
L_4:
; Line 5: {
; Line 6: ((char*)dest)[i] = ((const char*)src)[i];
mov cl,byte [edx+ebx]
mov byte [eax+ebx],cl
; Line 7: }
inc ebx
L_5:
cmp ebx,esi
jc L_4
L_6:
; Line 8: return dest;
; Line 9: }
pop edi
pop esi
pop ebx
ret

; memcpy_repmovs
_memcpy_repmovs:
; Line 39: inline void* memcpy_repmovs(void* s1, const void* s2, size_t sz)
cmp dword [esp+0ch],0100h
jl _memcpy_basic
push esi
push edi
; Line 48: __asm
; Line 49: {
mov esi,dword [esp+08h+08h]
; Line 50: mov esi, [s2];
; Line 51: mov edi, [s1];
mov edi,dword [esp+04h+08h]
; Line 52: mov ecx, [sz];
mov ecx,dword [esp+0ch+08h]
; Line 53: cld;
cld
; Line 54: rep movsb;
rep movsb
; Line 55: }
; Line 56: return s1;
mov eax,dword [esp+04h+08h]
; Line 57: }
pop edi
pop esi
ret
; memcpy
_memmove:
_memcpy:
push ebp
mov ebp, esp
push ebx
mov ecx,[ebp+ 16]
jecxz x2
mov edx,[ebp+8]
mov ebx,[ebp+12]
memcpy_x: ; from MEMMOVE
dec edx
lp1:
inc edx
test dl,3
jz lp
mov al,[ebx]
inc ebx
mov [edx],al
loop lp1
jecxz x2
lp:
cmp ecx,BYTE 4
jb c1
mov eax,[ebx]
add ebx,BYTE 4
mov [edx],eax
sub ecx,BYTE 4
add edx,BYTE 4
jmp short lp
c1:
jecxz x2
dec edx
lp2:
inc edx
mov al,[ebx]
inc ebx
mov [edx],al
loop lp2
x2:
mov eax,[esp+8]
pop ebx
pop ebp
ret

; Line 59: void* _RTL_FUNC memcpy(void* dest, const void* src, size_t sz)
sub esp,byte 014h
; dest location: 04h
; src location: 08h
; size location: 0ch
; Stack size: 4 * 4 + 14h = 24h
push ebx
push ebp
push esi
push edi
L_78:
mov ebx,dword [esp+0ch+024h]
mov eax,dword [esp+08h+024h]
mov dword [esp-010h+024h],eax
mov edi,dword [esp+04h+024h]
; Line 62: if (((uintptr_t)src) < ((uintptr_t)dest) && ((uintptr_t)dest) < (((uintptr_t)src) + sz))
mov eax,edi
mov esi,edi
mov edx,dword [esp-010h+024h]
mov ecx,dword [esp-010h+024h]
cmp ecx,esi
jnc L_81
mov ecx,edx
add ecx,ebx
mov dword [esp-014h+024h],ecx
mov ebp,eax
mov esi,ebx
cmp ebp,dword [esp-014h+024h]
jnc L_81
; Line 63: {
; Line 64: size_t distance_beyond = ((uintptr_t)src) + sz - ((uintptr_t)dest);
add edx,esi
mov ecx,eax
sub ecx,edx
neg ecx
; Line 65: size_t inverse_distance_beyond = sz - distance_beyond;
sub esi,ecx
; Line 66: memmove_backwards_basic((char*)dest + inverse_distance_beyond, dest, distance_beyond);
mov ebx,eax
add ebx,esi
; Line 12: while (sz > 0)
L_100:
cmp ecx,byte 00h
jbe L_97
L_96:
; Line 13: {
; Line 14: sz--;
dec ecx
mov dl,byte [eax+ecx]
mov byte [ebx+ecx],dl
; Line 15: ((char*)s1)[sz] = ((const char*)s2)[sz];
L_98:
cmp ecx,byte 00h
ja L_96
L_97:
; Line 16: }
; Line 17: return s1;
; Line 18: }
; Line 68: return memcpy_repmovs(dest, src, inverse_distance_beyond);
push esi
push dword [esp-010h+028h]
push edi
call _memcpy_repmovs ; memcpy_repmovs
add esp,byte 0ch
jmp L_79
; Line 69: }
L_81:
; Line 70: else
; Line 71: {
; Line 74: return memcpy_repmovs(dest, src, sz);
push ebx
push dword [esp-010h+028h]
push edi
call _memcpy_repmovs ; memcpy_repmovs
add esp,byte 0ch
; Line 75: }
L_86:
L_79:
pop edi
pop esi
pop ebp
pop ebx
add esp,byte 014h
ret
55 changes: 0 additions & 55 deletions src/clibs/string/386/memmove.nas

This file was deleted.

Loading
Loading