#ifndef I386_ASM_H
#define I386_ASM_H
+#include "auto-target.h"
#include "auto-host.h"
#define PASTE2(a, b) PASTE2a(a, b)
#ifdef MS2SYSV_STUB_AVX
# define MS2SYSV_STUB_PREFIX __avx_
-# define MOVAPS vmovaps
+# ifdef HAVE_AS_AVX
+# define MOVAPS vmovaps
+# endif
#elif defined(MS2SYSV_STUB_SSE)
# define MS2SYSV_STUB_PREFIX __sse_
# define MOVAPS movaps
#endif
-#if defined (MS2SYSV_STUB_PREFIX) && defined (MOVAPS)
+#ifdef MS2SYSV_STUB_PREFIX
# define MS2SYSV_STUB_BEGIN(base_name) \
HIDDEN_FUNC(PASTE2(MS2SYSV_STUB_PREFIX, base_name))
# define MS2SYSV_STUB_END(base_name) \
FUNC_END(PASTE2(MS2SYSV_STUB_PREFIX, base_name))
-/* Save SSE registers 6-15. off is the offset of rax to get to xmm6. */
-# define SSE_SAVE \
+/* If expanding for sse or avx and we have assembler support. */
+# ifdef MOVAPS
+/* Save SSE registers 6-15 using rax as the base address. */
+# define SSE_SAVE \
MOVAPS %xmm15,-0x30(%rax); \
MOVAPS %xmm14,-0x20(%rax); \
MOVAPS %xmm13,-0x10(%rax); \
MOVAPS %xmm7, 0x50(%rax); \
MOVAPS %xmm6, 0x60(%rax)
-/* Restore SSE registers 6-15. off is the offset of rsi to get to xmm6. */
-# define SSE_RESTORE \
+/* Restore SSE registers 6-15 using rsi as the base address. */
+# define SSE_RESTORE \
MOVAPS -0x30(%rsi), %xmm15; \
MOVAPS -0x20(%rsi), %xmm14; \
MOVAPS -0x10(%rsi), %xmm13; \
MOVAPS 0x40(%rsi), %xmm8 ; \
MOVAPS 0x50(%rsi), %xmm7 ; \
MOVAPS 0x60(%rsi), %xmm6
-
-#endif /* defined (MS2SYSV_STUB_ISA) && defined (MOVAPS) */
+# else /* MOVAPS */
+/* If the assembler doesn't support AVX then directly emit machine code
+ for the instructions above. */
+# define SSE_SAVE \
+ .byte 0xc5, 0x78, 0x29, 0x78, 0xd0; /* vmovaps %xmm15,-0x30(%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x70, 0xe0; /* vmovaps %xmm14,-0x20(%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x68, 0xf0; /* vmovaps %xmm13,-0x10(%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x20; /* vmovaps %xmm12, (%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x58, 0x10; /* vmovaps %xmm11, 0x10(%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x50, 0x20; /* vmovaps %xmm10, 0x20(%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x48, 0x30; /* vmovaps %xmm9, 0x30(%rax) */ \
+ .byte 0xc5, 0x78, 0x29, 0x40, 0x40; /* vmovaps %xmm8, 0x40(%rax) */ \
+ .byte 0xc5, 0xf8, 0x29, 0x78, 0x50; /* vmovaps %xmm7, 0x50(%rax) */ \
+ .byte 0xc5, 0xf8, 0x29, 0x70, 0x60; /* vmovaps %xmm6, 0x60(%rax) */
+# define SSE_RESTORE \
+ .byte 0xc5, 0x78, 0x28, 0x7e, 0xd0; /* vmovaps -0x30(%rsi),%xmm15 */ \
+ .byte 0xc5, 0x78, 0x28, 0x76, 0xe0; /* vmovaps -0x20(%rsi),%xmm14 */ \
+ .byte 0xc5, 0x78, 0x28, 0x6e, 0xf0; /* vmovaps -0x10(%rsi),%xmm13 */ \
+ .byte 0xc5, 0x78, 0x28, 0x26; /* vmovaps (%rsi),%xmm12 */ \
+ .byte 0xc5, 0x78, 0x28, 0x5e, 0x10; /* vmovaps 0x10(%rsi),%xmm11 */ \
+ .byte 0xc5, 0x78, 0x28, 0x56, 0x20; /* vmovaps 0x20(%rsi),%xmm10 */ \
+ .byte 0xc5, 0x78, 0x28, 0x4e, 0x30; /* vmovaps 0x30(%rsi),%xmm9 */ \
+ .byte 0xc5, 0x78, 0x28, 0x46, 0x40; /* vmovaps 0x40(%rsi),%xmm8 */ \
+ .byte 0xc5, 0xf8, 0x28, 0x7e, 0x50; /* vmovaps 0x50(%rsi),%xmm7 */ \
+ .byte 0xc5, 0xf8, 0x28, 0x76, 0x60; /* vmovaps 0x60(%rsi),%xmm6 */
+# endif /* MOVAPS */
+#endif /* MS2SYSV_STUB_PREFIX */
#endif /* I386_ASM_H */