2 ; jsimdcpu.asm - SIMD instruction support check
4 ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 ; Copyright (C) 2016, D. R. Commander.
8 ; x86 SIMD extension for IJG JPEG library
9 ; Copyright (C) 1999-2006, MIYASAKA Masaru.
10 ; For conditions of distribution and use, see copyright notice in jsimdext.inc
12 ; This file should be assembled with NASM (Netwide Assembler),
13 ; can *not* be assembled with Microsoft's MASM or any compatible
14 ; assembler (including Borland's Turbo Assembler).
15 ; NASM is available from http://nasm.sourceforge.net/ or
16 ; http://sourceforge.net/project/showfiles.php?group_id=6208
18 %include "jsimdext.inc"
20 ; --------------------------------------------------------------------------
24 ; Check if the CPU supports SIMD instructions
26 ; GLOBAL(unsigned int)
27 ; jpeg_simd_cpu_support(void)
31 GLOBAL_FUNCTION(jpeg_simd_cpu_support)
33 EXTN(jpeg_simd_cpu_support):
37 xor rdi, rdi ; simd support flag
39 ; Assume that all x86-64 processors support SSE & SSE2 instructions
43 ; Check whether CPUID leaf 07H is supported
44 ; (leaf 07H is used to check for AVX2 instruction support)
48 jl short .return ; Maximum leaf < 07H
50 ; Check for AVX2 instruction support
54 mov rax, rbx ; rax = Extended feature flags
56 test rax, 1<<5 ; bit5:AVX2
59 ; Check for AVX2 O/S support
64 jz short .return ; O/S does not support XSAVE
66 jz short .return ; CPU does not support AVX2
71 cmp rax, 6 ; O/S does not manage XMM/YMM state
84 ; For some reason, the OS X linker does not honor the request to align the
85 ; segment unless we do this.