mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-03-13 17:57:12 +08:00
x86-host-specific performance improvement
If we're on an x86 host, we can do unaligned littleendian memory references directly. Just do'em.
This commit is contained in:
parent
d1fb15c154
commit
d13f30e08f
30
nasmlib.c
30
nasmlib.c
@ -361,6 +361,34 @@ int32_t seg_alloc(void)
|
||||
return (next_seg += 2) - 2;
|
||||
}
|
||||
|
||||
#if X86_MEMORY
|
||||
|
||||
void fwriteint16_t(int data, FILE * fp)
|
||||
{
|
||||
uint16_t d = data;
|
||||
fwrite(&d, 1, 2, fp);
|
||||
}
|
||||
|
||||
void fwriteint32_t(int32_t data, FILE * fp)
|
||||
{
|
||||
uint32_t d = data;
|
||||
fwrite(&d, 1, 4, fp);
|
||||
}
|
||||
|
||||
void fwriteint64_t(int64_t data, FILE * fp)
|
||||
{
|
||||
uint64_t d = data;
|
||||
fwrite(&d, 1, 8, fp);
|
||||
}
|
||||
|
||||
void fwriteaddr(int64_t data, int size, FILE * fp)
|
||||
{
|
||||
uint64_t d = data;
|
||||
fwrite(&d, 1, size, fp);
|
||||
}
|
||||
|
||||
#else /* !X86_MEMORY */
|
||||
|
||||
void fwriteint16_t(int data, FILE * fp)
|
||||
{
|
||||
char buffer[2], *p = buffer;
|
||||
@ -389,6 +417,8 @@ void fwriteaddr(int64_t data, int size, FILE * fp)
|
||||
fwrite(buffer, 1, size, fp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void standard_extension(char *inname, char *outname, char *extension,
|
||||
efunc error)
|
||||
{
|
||||
|
37
nasmlib.h
37
nasmlib.h
@ -178,6 +178,41 @@ void standard_extension(char *inname, char *outname, char *extension,
|
||||
* format in memory
|
||||
*/
|
||||
|
||||
#if X86_MEMORY
|
||||
|
||||
#define WRITECHAR(p,v) \
|
||||
do { \
|
||||
*(uint8_t *)(p) = (v); \
|
||||
(p) += 1; \
|
||||
} while (0)
|
||||
|
||||
#define WRITESHORT(p,v) \
|
||||
do { \
|
||||
*(uint16_t *)(p) = (v); \
|
||||
(p) += 2; \
|
||||
} while (0)
|
||||
|
||||
#define WRITELONG(p,v) \
|
||||
do { \
|
||||
*(uint32_t *)(p) = (v); \
|
||||
(p) += 4; \
|
||||
} while (0)
|
||||
|
||||
#define WRITEDLONG(p,v) \
|
||||
do { \
|
||||
*(uint64_t *)(p) = (v); \
|
||||
(p) += 8; \
|
||||
} while (0)
|
||||
|
||||
#define WRITEADDR(p,v,s) \
|
||||
do { \
|
||||
uint64_t _v = (v); \
|
||||
memcpy((p), &_v, (s)); \
|
||||
(p) += (s); \
|
||||
} while (0)
|
||||
|
||||
#else /* !X86_MEMORY */
|
||||
|
||||
#define WRITECHAR(p,v) \
|
||||
do { \
|
||||
*(p)++ = (v) & 0xFF; \
|
||||
@ -219,6 +254,8 @@ void standard_extension(char *inname, char *outname, char *extension,
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* and routines to do the same thing to a file
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user