HeavyThing - align_macros.inc

Jeff Marrison

	; ------------------------------------------------------------------------
	; HeavyThing x86_64 assembly language library and showcase programs
	; Copyright © 2015-2018 2 Ton Digital
	; Homepage: https://2ton.com.au/
	; Author: Jeff Marrison <jeff@2ton.com.au>
	;
	; This file is part of the HeavyThing library.
	;
	; HeavyThing is free software: you can redistribute it and/or modify
	; it under the terms of the GNU General Public License, or
	; (at your option) any later version.
	;
	; HeavyThing is distributed in the hope that it will be useful,
	; but WITHOUT ANY WARRANTY; without even the implied warranty of
	; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	; GNU General Public License for more details.
	;
	; You should have received a copy of the GNU General Public License along
	; with the HeavyThing library. If not, see <http://www.gnu.org/licenses/>.
	; ------------------------------------------------------------------------
	;
	; align_macros.inc: multibyte nop alignment macros
	; falign == function alignment, calign == inner jump target alignment, dalign == data alignment
	;
macro falign {
if align_functions
	local a
	virtual
		align function_alignment
		a = $ - $$
	end virtual
	if a = 15
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 14
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 13
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x40, 0x00
	else if a = 12
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x00
	else if a = 11
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x66, 0x90
	else if a = 10
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x90
	else if a = 9
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
	else if a = 8
		db 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
	else if a = 7
		db 0xf, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
	else if a = 6
		db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 5
		db 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 4
		db 0xf, 0x1f, 0x40, 0x00
	else if a = 3
		db 0xf, 0x1f, 0x00
	else if a = 2
		db 0x66, 0x90
	else if a = 1
		db 0x90
	end if
end if
}
macro calign {
if align_inner
	local a
	virtual
		align inner_alignment
		a = $ - $$
	end virtual
	if a = 15
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 14
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 13
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x40, 0x00
	else if a = 12
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x00
	else if a = 11
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x66, 0x90
	else if a = 10
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x90
	else if a = 9
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
	else if a = 8
		db 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
	else if a = 7
		db 0xf, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
	else if a = 6
		db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 5
		db 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 4
		db 0xf, 0x1f, 0x40, 0x00
	else if a = 3
		db 0xf, 0x1f, 0x00
	else if a = 2
		db 0x66, 0x90
	else if a = 1
		db 0x90
	end if
end if
}
macro dalign {
if align_data
	local a
	virtual
		align data_alignment
		a = $ - $$
	end virtual
	if a = 15
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 14
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 13
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x40, 0x00
	else if a = 12
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0xf, 0x1f, 0x00
	else if a = 11
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x66, 0x90
	else if a = 10
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
		db 0x90
	else if a = 9
		db 0x66, 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
	else if a = 8
		db 0xf, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
	else if a = 7
		db 0xf, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00
	else if a = 6
		db 0x66, 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 5
		db 0xf, 0x1f, 0x44, 0x00, 0x00
	else if a = 4
		db 0xf, 0x1f, 0x40, 0x00
	else if a = 3
		db 0xf, 0x1f, 0x00
	else if a = 2
		db 0x66, 0x90
	else if a = 1
		db 0x90
	end if
end if
}