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.
6 ; Copyright (C) 2023, Aliaksiej Kandracienka.
9 ; x86 SIMD extension for IJG JPEG library
10 ; Copyright (C) 1999-2006, MIYASAKA Masaru.
11 ; For conditions of distribution and use, see copyright notice in jsimdext.inc
13 ; This file should be assembled with NASM (Netwide Assembler),
14 ; can *not* be assembled with Microsoft's MASM or any compatible
15 ; assembler (including Borland's Turbo Assembler).
16 ; NASM is available from http://nasm.sourceforge.net/ or
17 ; http://sourceforge.net/project/showfiles.php?group_id=6208
19 %include "jsimdext.inc"
21 ; --------------------------------------------------------------------------
25 ; Check if the CPU supports SIMD instructions
27 ; GLOBAL(unsigned int)
28 ; jpeg_simd_cpu_support(void)
32 GLOBAL_FUNCTION(jpeg_simd_cpu_support)
34 EXTN(jpeg_simd_cpu_support):
40 xor rdi, rdi ; simd support flag
42 ; Assume that all x86-64 processors support SSE & SSE2 instructions
46 ; Check whether CPUID leaf 07H is supported
47 ; (leaf 07H is used to check for AVX2 instruction support)
51 jl short .return ; Maximum leaf < 07H
53 ; Check for AVX2 instruction support
57 mov rax, rbx ; rax = Extended feature flags
59 test rax, 1<<5 ; bit5:AVX2
62 ; Check for AVX2 O/S support
67 jz short .return ; O/S does not support XSAVE
69 jz short .return ; CPU does not support AVX2
74 cmp rax, 6 ; O/S does not manage XMM/YMM state
88 ; For some reason, the OS X linker does not honor the request to align the
89 ; segment unless we do this.