Skip to content

Commit

Permalink
Merge pull request #1888 from WalterBright/rm_iasm
Browse files Browse the repository at this point in the history
remove unnecessary inline asm
  • Loading branch information
MartinNowak authored and WalterBright committed Apr 12, 2013
1 parent 7c64bbf commit 8d8f352
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 145 deletions.
40 changes: 40 additions & 0 deletions src/backend/cc.h
Expand Up @@ -1633,4 +1633,44 @@ enum
DT_ibytes, // 7
};

// An efficient way to clear aligned memory
#define MEMCLEAR(p,sz) \
if ((sz) == 10 * sizeof(size_t)) \
{ \
((size_t *)(p))[0] = 0; \
((size_t *)(p))[1] = 0; \
((size_t *)(p))[2] = 0; \
((size_t *)(p))[3] = 0; \
((size_t *)(p))[4] = 0; \
((size_t *)(p))[5] = 0; \
((size_t *)(p))[6] = 0; \
((size_t *)(p))[7] = 0; \
((size_t *)(p))[8] = 0; \
((size_t *)(p))[9] = 0; \
} \
else if ((sz) == 14 * sizeof(size_t)) \
{ \
((size_t *)(p))[0] = 0; \
((size_t *)(p))[1] = 0; \
((size_t *)(p))[2] = 0; \
((size_t *)(p))[3] = 0; \
((size_t *)(p))[4] = 0; \
((size_t *)(p))[5] = 0; \
((size_t *)(p))[6] = 0; \
((size_t *)(p))[7] = 0; \
((size_t *)(p))[8] = 0; \
((size_t *)(p))[9] = 0; \
((size_t *)(p))[10] = 0; \
((size_t *)(p))[11] = 0; \
((size_t *)(p))[12] = 0; \
((size_t *)(p))[13] = 0; \
} \
else \
{ \
/*printf("%s(%d) sz = %d\n",__FILE__,__LINE__,(sz));fflush(stdout);*(char*)0=0;*/ \
for (size_t i = 0; i < sz / sizeof(size_t); ++i) \
((size_t *)(p))[i] = 0; \
}


#endif
59 changes: 9 additions & 50 deletions src/backend/code.c
@@ -1,5 +1,5 @@
// Copyright (C) 1987-1998 by Symantec
// Copyright (C) 2000-2011 by Digital Mars
// Copyright (C) 2000-2013 by Digital Mars
// All Rights Reserved
// http://www.digitalmars.com
// Written by Walter Bright
Expand All @@ -12,7 +12,9 @@
#if !SPP

#include <stdio.h>
#include <string.h>
#include <time.h>

#include "cc.h"
#include "el.h"
#include "code.h"
Expand All @@ -24,64 +26,21 @@ static code *code_list;
* Allocate code
*/

#if SCPP && __SC__ && __INTSIZE == 4 && TX86 && !_DEBUG_TRACE && !MEM_DEBUG

__declspec(naked) code *code_calloc()
{
if (sizeof(code) != 0x28)
util_assert("code",__LINE__);
__asm
{
mov EAX,code_list
test EAX,EAX
je L20
mov ECX,[EAX]
mov code_list,ECX
jmp L29

L20: push sizeof(code)
call mem_fmalloc
;add ESP,4
L29:
xor ECX,ECX
mov DWORD PTR [EAX],0

mov 4[EAX],ECX ;these pair
mov 8[EAX],ECX

mov 12[EAX],ECX
mov 16[EAX],ECX

mov 20[EAX],ECX
mov 24[EAX],ECX

mov 28[EAX],ECX
mov 32[EAX],ECX

mov 36[EAX],ECX

ret
}
}

#else

code *code_calloc()
{ code *c;
static code czero;

//printf("code %x\n", sizeof(code));
c = code_list;
{
//printf("code %d\n", sizeof(code));
code *c = code_list;
if (c)
code_list = code_next(c);
else
c = (code *)mem_fmalloc(sizeof(*c));
*c = czero; // zero it out

MEMCLEAR(c, sizeof(*c));

//dbg_printf("code_calloc: %p\n",c);
return c;
}

#endif

/*****************
* Free code
Expand Down
47 changes: 1 addition & 46 deletions src/backend/el.c
Expand Up @@ -123,53 +123,9 @@ void el_term()
* Allocate an element.
*/

#if SCPP && __SC__ && __INTSIZE == 4 && TX86 && !_DEBUG_TRACE && !MEM_DEBUG && _WIN32 && !defined(DEBUG)

__declspec(naked) elem *el_calloc()
{
__asm
{
mov EAX,elcount
push EDI

inc EAX
mov EDI,nextfree

test EDI,EDI
je L27

mov EDX,E1[EDI]
mov elcount,EAX

xor EAX,EAX
mov nextfree,EDX
jmp L30

L27: push sizeof(elem)
mov elcount,EAX
call mem_fmalloc
mov EDI,EAX
xor EAX,EAX

L30: mov EDX,EDI
mov ECX,(sizeof(elem) + 3) / 4
#if DOS386
push DS
pop ES
#endif
rep stosd
mov EAX,EDX
pop EDI
ret
}
}

#else

elem *el_calloc()
{
elem *e;
static elem ezero;

elcount++;
if (nextfree)
Expand All @@ -181,7 +137,7 @@ elem *el_calloc()
#ifdef STATS
eprm_cnt++;
#endif
*e = ezero; /* clear it */
MEMCLEAR(e, sizeof(*e));

#ifdef DEBUG
e->id = IDelem;
Expand All @@ -192,7 +148,6 @@ elem *el_calloc()
return e;
}

#endif

/***************
* Free element
Expand Down
50 changes: 1 addition & 49 deletions src/backend/symbol.c
Expand Up @@ -601,55 +601,7 @@ symbol * lookupsym(const char *p)

symbol * findsy(const char *p,symbol *rover)
{
#if __INTSIZE == 2 && TX86 && !defined(_MSC_VER)
volatile int len;
__asm
{
push DS
mov DS,word ptr p+2
les DI,p
mov DX,word ptr p
mov BX,ES:[DI]
xor AL,AL
mov CX,0FFFFh
repne scasb
not CX
sub CX,2
mov len,CX
add DX,2
mov AX,BX
les BX,rover
jmp short L1

L38C: les BX,ES:symbol.Sl[BX]
L1: test BX,BX
je L3A5
cmp AL,ES:symbol.Sident[BX]
js L38C
je L2
les BX,ES:symbol.Sr[BX]
jmp L1

L2: cmp AH,ES:symbol.Sident+1[BX]
js L38C
je L3
les BX,ES:symbol.Sr[BX]
jmp L1

L3: mov SI,DX
lea DI,symbol.Sident+2[BX]
mov CX,len
rep cmpsb
js L38C
je L3A5
les BX,ES:symbol.Sr[BX]
jmp L1

L3A5: mov DX,ES
mov AX,BX
pop DS
}
#elif __INTSIZE == 4 && TX86 && !defined(_MSC_VER) && !M_UNIX
#if __INTSIZE == 4 && TX86 && __DMC__
volatile int len;
__asm
{
Expand Down

0 comments on commit 8d8f352

Please sign in to comment.