/* $Header$ */
#include <stdlib.h>
-#define ALIGN(x) (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1))
+/* replace undef by define */
+#define ALIGN_EIGHT_BYTES /* Use 8-byte alignment. */
+
+#ifdef ALIGN_EIGHT_BYTES
+#define ALIGN_SIZE 8
+#else
+#define ALIGN_SIZE sizeof(size_t)
+#endif
+
+#define ALIGN(x) (((x) + (ALIGN_SIZE - 1)) & ~(ALIGN_SIZE - 1))
void *
calloc(size_t nelem, size_t elsize)
/* $Header$ */
/* replace undef by define */
-#define DEBUG /* check assertions */
-#undef SLOWDEBUG /* some extra test loops (requires DEBUG) */
+#define ALIGN_EIGHT_BYTES /* Use 8-byte alignment. */
+#define DEBUG /* check assertions */
+#undef SLOWDEBUG /* some extra test loops (requires DEBUG) */
#ifndef DEBUG
#define NDEBUG
#else
#define BRKSIZE 4096
#endif
+#ifdef ALIGN_EIGHT_BYTES
+#define PTRSIZE 8
+#else
#define PTRSIZE ((int) sizeof(void *))
+#endif
#define Align(x,a) (((x) + (a - 1)) & ~(a - 1))
#define NextSlot(p) (* (void **) ((p) - PTRSIZE))
#define NextFree(p) (* (void **) (p))
* linked together by a pointer at the start of the
* user visable part, so just after the next-slot pointer.
* Free slots are merged together by free().
+ *
+ * Since modern processors prefer 8-byte alignment, we now pretend
+ * our pointers are 8 bytes wide.
*/
extern void *_sbrk(int);
}
void *
-malloc(size_t size)
+malloc(const size_t size)
{
register char *prev, *p, *next, *new;
- register unsigned len, ntries;
+ unsigned ntries;
if (size == 0)
return NULL;
for (ntries = 0; ntries < 2; ntries++) {
- if ((len = Align(size, PTRSIZE) + PTRSIZE) < 2 * PTRSIZE) {
+ unsigned len = Align(size, PTRSIZE) + PTRSIZE;
+ if (len < 2 * PTRSIZE) {
errno = ENOMEM;
return NULL;
}
pop %ecx /* Return address */
pop %eax /* Bytes to allocate */
addl $2*4+3, %eax /* Add space for two saved register variables */
- andb $0xFC, %al /* Align */
+ andb $0xF8, %al /* Align */
movl %esp, %ebx /* Keep current esp */
subl %eax, %esp /* Lower stack */
movl %esp, %eax /* Return value */
pop %ecx /* Return address */
pop %eax /* Bytes to allocate */
addl $3, %eax
- andb $0xFC, %al /* Align */
+ andb $0xF8, %al /* Align */
subl %eax, %esp /* Lower stack */
movl %esp, %eax /* Return value */
push %eax /* Dummy argument */