1/* 2 * This file is in public domain. 3 * Written by Dmitry Chagin <dchagin@FreeBSD.org> 4 * 5 * $FreeBSD$ 6 */ 7 8#if defined(__FreeBSD__) 9#include <machine/specialreg.h> 10#else 11#define CPUID2_OSXSAVE 0x08000000 12#define CPUID2_AVX 0x10000000 13#define XFEATURE_ENABLED_X87 0x00000001 14#define XFEATURE_ENABLED_SSE 0x00000002 15#define XFEATURE_ENABLED_AVX 0x00000004 16#define XFEATURE_AVX \ 17 (XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE | XFEATURE_ENABLED_AVX) 18#endif 19 20 .text 21 22 .globl xregs_banks_max 23 .type xregs_banks_max, @function 24xregs_banks_max: 25 pushq %rbx 26 movl $1, %eax 27 cpuid 28 andl $(CPUID2_AVX|CPUID2_OSXSAVE), %ecx 29 cmpl $(CPUID2_AVX|CPUID2_OSXSAVE), %ecx 30 jne sse 31 xorl %ecx, %ecx 32 xgetbv 33 andl $XFEATURE_AVX, %eax 34 cmpl $XFEATURE_AVX, %eax 35 jne sse 36 movl $1, %eax 37 jmp out 38sse: 39 xorl %eax, %eax 40out: 41 popq %rbx 42 retq 43 44 .size xregs_banks_max, . - xregs_banks_max 45 46 47 .globl cpu_to_xmm 48 .type cpu_to_xmm, @function 49cpu_to_xmm: 50 movdqu %xmm0, (%rdi) 51 movdqu %xmm1, 1 * 16(%rdi) 52 movdqu %xmm2, 2 * 16(%rdi) 53 movdqu %xmm3, 3 * 16(%rdi) 54 movdqu %xmm4, 4 * 16(%rdi) 55 movdqu %xmm5, 5 * 16(%rdi) 56 movdqu %xmm6, 6 * 16(%rdi) 57 movdqu %xmm7, 7 * 16(%rdi) 58 movdqu %xmm8, 8 * 16(%rdi) 59 movdqu %xmm9, 9 * 16(%rdi) 60 movdqu %xmm10, 10 * 16(%rdi) 61 movdqu %xmm11, 11 * 16(%rdi) 62 movdqu %xmm12, 12 * 16(%rdi) 63 movdqu %xmm13, 13 * 16(%rdi) 64 movdqu %xmm14, 14 * 16(%rdi) 65 movdqu %xmm15, 15 * 16(%rdi) 66 retq 67 68 .size cpu_to_xmm, . - cpu_to_xmm 69 70 71 .globl xmm_to_cpu 72 .type xmm_to_cpu, @function 73xmm_to_cpu: 74 movdqu (%rdi), %xmm0 75 movdqu 1 * 16(%rdi), %xmm1 76 movdqu 2 * 16(%rdi), %xmm2 77 movdqu 3 * 16(%rdi), %xmm3 78 movdqu 4 * 16(%rdi), %xmm4 79 movdqu 5 * 16(%rdi), %xmm5 80 movdqu 6 * 16(%rdi), %xmm6 81 movdqu 7 * 16(%rdi), %xmm7 82 movdqu 8 * 16(%rdi), %xmm8 83 movdqu 9 * 16(%rdi), %xmm9 84 movdqu 10 * 16(%rdi), %xmm10 85 movdqu 11 * 16(%rdi), %xmm11 86 movdqu 12 * 16(%rdi), %xmm12 87 movdqu 13 * 16(%rdi), %xmm13 88 movdqu 14 * 16(%rdi), %xmm14 89 movdqu 15 * 16(%rdi), %xmm15 90 retq 91 92 .size xmm_to_cpu, . - xmm_to_cpu 93 94 95 .globl cpu_to_avx 96 .type cpu_to_avx, @function 97cpu_to_avx: 98 vmovdqu %ymm0, (%rdi) 99 vmovdqu %ymm1, 1 * 32(%rdi) 100 vmovdqu %ymm2, 2 * 32(%rdi) 101 vmovdqu %ymm3, 3 * 32(%rdi) 102 vmovdqu %ymm4, 4 * 32(%rdi) 103 vmovdqu %ymm5, 5 * 32(%rdi) 104 vmovdqu %ymm6, 6 * 32(%rdi) 105 vmovdqu %ymm7, 7 * 32(%rdi) 106 vmovdqu %ymm8, 8 * 32(%rdi) 107 vmovdqu %ymm9, 9 * 32(%rdi) 108 vmovdqu %ymm10, 10 * 32(%rdi) 109 vmovdqu %ymm11, 11 * 32(%rdi) 110 vmovdqu %ymm12, 12 * 32(%rdi) 111 vmovdqu %ymm13, 13 * 32(%rdi) 112 vmovdqu %ymm14, 14 * 32(%rdi) 113 vmovdqu %ymm15, 15 * 32(%rdi) 114 retq 115 116 .size cpu_to_avx, . - cpu_to_avx 117 118 119 .globl avx_to_cpu 120 .type avx_to_cpu, @function 121avx_to_cpu: 122 vmovdqu (%rdi), %ymm0 123 vmovdqu 1 * 32(%rdi), %ymm1 124 vmovdqu 2 * 32(%rdi), %ymm2 125 vmovdqu 3 * 32(%rdi), %ymm3 126 vmovdqu 4 * 32(%rdi), %ymm4 127 vmovdqu 5 * 32(%rdi), %ymm5 128 vmovdqu 6 * 32(%rdi), %ymm6 129 vmovdqu 7 * 32(%rdi), %ymm7 130 vmovdqu 8 * 32(%rdi), %ymm8 131 vmovdqu 9 * 32(%rdi), %ymm9 132 vmovdqu 10 * 32(%rdi), %ymm10 133 vmovdqu 11 * 32(%rdi), %ymm11 134 vmovdqu 12 * 32(%rdi), %ymm12 135 vmovdqu 13 * 32(%rdi), %ymm13 136 vmovdqu 14 * 32(%rdi), %ymm14 137 vmovdqu 15 * 32(%rdi), %ymm15 138 retq 139 140 .size avx_to_cpu, . - avx_to_cpu 141 142 .section .note.GNU-stack,"",@progbits 143