Skip to content

Commit c9e238f

Browse files
authored
Merge pull request #73 from martinfjohansen/master
Enable AVX is supported by CPU
2 parents 29c249e + 154e825 commit c9e238f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/init/cpu.asm

+20
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ init_cpu:
8787
; Enable Math Co-processor
8888
finit
8989

90+
; Enable AVX
91+
mov eax, 1 ; CPUID Feature information 1
92+
cpuid ; Sets info in eax and ecx
93+
bt ecx, 28 ; AVX is supported if bit 28 is set in ecx
94+
jnc avx_not_supported ; Skip activating AVX if not supported
95+
96+
avx_supported:
97+
98+
mov rax, cr4
99+
bts rax, 18 ; Enable OSXSAVE (Bit 18)
100+
mov cr4, rax
101+
102+
mov rcx, 0 ; Set load XCR Nr. 0
103+
xgetbv ; Load XCR0 register
104+
bts rax, 0 ; Set X87 enable (Bit 0)
105+
bts rax, 1 ; Set SSE enable (Bit 1)
106+
bts rax, 2 ; Set AVX enable (Bit 2)
107+
xsetbv ; Save XCR0 register
108+
avx_not_supported:
109+
90110
; Enable and Configure Local APIC
91111
mov rsi, [os_LocalAPICAddress]
92112
test rsi, rsi

0 commit comments

Comments
 (0)