!
!	"@(#)misalign.il 1.3 88/05/06 Copyr 1987 Sun Micro"
!

!	Copyright (c) 1987 by Sun Microsystems,Inc.

!
! Inline code templates for compiler support of misaligned memory
! references.  These are expansions of C-compatible function calls,
! which are generated by the sparc code generator(s) with the -malign(sic)
! option enabled.
!

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! int inline_ld_int(p)
! char *p;
! {
!	/* load 32-bit int from possibly misaligned address */
! }
!
	.inline	inline_ld_int,4
	andcc	%o0,3,%g0
	bne	1f
	nop
	ld	[%o0],%o0
	b	2f
	nop
1:	call	ld_int,1
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! int inline_ld_short(p)
! char *p;
! {
!	/* load 16-bit signed int from possibly misaligned address */
! }
!
	.inline	inline_ld_short,4
	ldsb	[%o0],%o1
	ldub	[%o0+1],%o0
	sll	%o1,8,%o1
	or	%o1,%o0,%o0
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! int inline_ld_ushort(p)
! char *p;
! {
!	/* load 16-bit unsigned int from possibly misaligned address */
! }
!
	.inline	inline_ld_ushort,4
	ldub	[%o0],%o1
	ldub	[%o0+1],%o0
	sll	%o1,8,%o1
	or	%o1,%o0,%o0
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! float inline_ld_float(p)
! char *p;
! {
!	/* load 32-bit float (not double!) from possibly misaligned address */
! }
!
	.inline	inline_ld_float,4
	andcc	%o0,3,%g0
	bne	1f
	nop
	ld	[%o0],%f0
	b	2f
	nop
1:	call	ld_float,1
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! double inline_ld_double(p)
! char *p;
! {
!	/* load 64-bit float from possibly misaligned address */
! }
!
	.inline	inline_ld_double,4
	andcc	%o0,7,%g0
	bne	1f
	nop
	ldd	[%o0],%f0
	b	2f
	nop
1:
	call	ld_double,1
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! int inline_st_int(x,p)
! int x;
! char *p;
! {
!	/* store 32-bit int from possibly misaligned address;
!	   return stored value */
! }
!
	.inline	inline_st_int,8
	andcc	%o1,3,%g0
	bne	1f
	nop
	st	%o0,[%o1]
	b	2f
	nop
1:
	call	st_int,2
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! int inline_st_short(x,p)
! int x;
! char *p;
! {
!	/* store 16-bit int from possibly misaligned address.
!	   return sign extended value */
! }
!
	.inline	inline_st_short,8
	srl	%o0,8,%o2
	stb	%o2,[%o1]
	stb	%o0,[%o1+1]
	sll	%o0,16,%o0
	sra	%o0,16,%o0
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! int inline_st_ushort(x,p)
! int x;
! char *p;
! {
!	/* store 16-bit int from possibly misaligned address.
!	   return zero extended value */
! }
!
	.inline	inline_st_ushort,8
	srl	%o0,8,%o2
	stb	%o2,[%o1]
	stb	%o0,[%o1+1]
	sll	%o0,16,%o0
	srl	%o0,16,%o0
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! void inline_st_short_foreff(x,p)
! int x;
! char *p;
! {
!	/* store 16-bit int from possibly misaligned address */
! }
!
	.inline	inline_st_short_foreff,8
	srl	%o0,8,%o2
	stb	%o2,[%o1]
	stb	%o0,[%o1+1]
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! void inline_st_float_foreff(x,p)
! float x;
! char *p;
! {
!	/* store 32-bit float from possibly misaligned address */
! }
!
	.inline	inline_st_float_foreff,8
	andcc	%o1,3,%g0
	bne	1f
	nop
	st	%o0,[%o1]
	b	2f
	nop
1:
	call	st_float_foreff,2
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! void inline_st_double_foreff(x,p)
! double x;
! char *p;
! {
!	/* store 64-bit float from possibly misaligned address */
! }
!
	.inline	inline_st_double_foreff,12
	andcc	%o2,7,%g0
	bne	1f
	nop
	std	%o0,[%o2]
	b	2f
	nop
1:
	call	st_double_foreff,3
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! float inline_st_float(x,p)
! float x;
! char *p;
! {
!	/* store 32-bit float from possibly misaligned address;
!	   return stored value */
! }
!
	.inline	inline_st_float,8
	andcc	%o1,3,%g0
	bne	1f
	nop
	st	%o0,[%o1]
	ld	[%o1],%f0
	b	2f
	nop
1:
	call	st_float,2
	nop
2:
	.end

!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

!
! double inline_st_double(x,p)
! double x;
! char *p;
! {
!	/* store 64-bit float from possibly misaligned address;
!	   return stored value */
! }
!
	.inline	inline_st_double,12
	andcc	%o2,7,%g0
	bne	1f
	nop
	std	%o0,[%o2]
	ldd	[%o2],%f0
	b	2f
	nop
1:
	call	st_double,3
	nop
2:
	.end
