view align8.h @ 13:de3961f74f30 tip

Add Linux/gcc Makefile; build fix
author Chris Cannam
date Mon, 05 Sep 2011 15:22:35 +0100
parents 4b35f8ac5113
children
line wrap: on
line source
/*
    Harmonic sinusoidal modelling and tools

    C++ code package for harmonic sinusoidal modelling and relevant signal processing.
    Centre for Digital Music, Queen Mary, University of London.
    This file copyright 2011 Wen Xue.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.
*/
//---------------------------------------------------------------------------

#ifndef align8H
#define align8H

/**
  \file align8.h - 8-byte (64-bit) alignment routines.

  This file provides tools for aligning boundaries of arrays, particularly of 64-bit units, e.g. double-
  precision floating points, to physical addresses divisible by 8, including aligning dynamically
  allocated memory block and aligning call stack. Currently stack alignment is disabled due to lack
  of compiler support for Intel assembly.

  Further reading: "Double precision floating point alignment issue.pdf"
*/

//--stack alignment----------------------------------------------------------
/*
  These two macros are used to envelop a function call so that the function is called with a stack
  pointer that is a multiple of 8. Aligning the stack does not automatically ensure that local double
  -precision floating-point variables (or other variables one wants to align to 8-byte boundaries) are
  aligned to 8-byte boundaries; one has to adjust the variable declaration order, using dummy variables
  if necessary, to make the alignment happen.
*/
//macro ALIGN_STACK_8 moves the current stack pointer to a multiple of 8
#define ALIGN_STACK_8 {int alignstack; asm {mov alignstack, esp} asm {and esp, 0xFFFFFFF8}
//macro RESTORE_STACK moves the stack pointer back to where it was before ALIGN_STACK_8
#define RESTORE_STACK asm {mov esp, alignstack}}

//ALIGN8 ensures F is executed with a start stack pointer divisible by 8. Currently disabled.
#define ALIGN8(F) F
//uncomment the following line to enable stack alignment
//#define ALIGN8(F) ALIGN_STACK_8 F RESTORE_STACK

//--64-bit aligned memory allocation routines--------------------------------
void* malloc8(unsigned size);
void free8(void* buffer8);

#endif