From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-sn1nam04olkn082e.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe4c::82e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B176421A13492 for ; Tue, 2 May 2017 22:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=v1hMCy8yra62OSNuPU/0EGjH/TU6x/QZNyvpOftetgU=; b=VpcSfPMlLL6lW9Gqqyw6XJYBZi1QqDQjwoZiLwwPNMdgvt+jauBirXpLFtfq0FbYkRN0MJ8WikFU60YIejLwgr3U6qF2doR01TcTe00FAGJaNdRz+oWXKyzhaxuThkWy0f94va5CKttgjuzNJpXH6eEUlExJ12MS2BwEMZt+OSEA8pFTRYmKiAz0WkCJCtNMMUbj9TSsPy30s6HhRIJ3Ho7jYsy566mG71tiVmbUVdeT+2rt2Yj6/uSD8Mr++V8UmBbWRHWf/HiILdDoxY6x5CF7amp3HysRLXS+uIQ0b+bz0At9mMamAv9jo2leqz82XWQ3svmAqoLGSG7nK00rAg== Received: from BN3NAM04FT049.eop-NAM04.prod.protection.outlook.com (10.152.92.56) by BN3NAM04HT166.eop-NAM04.prod.protection.outlook.com (10.152.92.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1047.9; Wed, 3 May 2017 05:48:40 +0000 Received: from MWHPR11MB1822.namprd11.prod.outlook.com (10.152.92.59) by BN3NAM04FT049.mail.protection.outlook.com (10.152.93.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1047.9 via Frontend Transport; Wed, 3 May 2017 05:48:39 +0000 Received: from MWHPR11MB1822.namprd11.prod.outlook.com ([10.175.53.137]) by MWHPR11MB1822.namprd11.prod.outlook.com ([10.175.53.137]) with mapi id 15.01.1075.010; Wed, 3 May 2017 05:48:39 +0000 From: Amit kumar To: "Kinney, Michael D" , Andrew Fish CC: "edk2-devel@lists.01.org" Thread-Topic: [edk2] Accessing AVX/AVX2 instruction in UEFI. Thread-Index: AQHSw2YUrPw3Gy/dW0iHxTLtc/HNpqHiGq96 Date: Wed, 3 May 2017 05:48:39 +0000 Message-ID: References: <0E40AA0F-3FDD-420D-9982-43FB8E0DE81A@apple.com>, In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=hotmail.com; x-incomingtopheadermarker: OriginalChecksum:9253E785B2D8A0904E2A75923D985ABFC1D12B6B9B23B15B5F3D632BE4AA513E; UpperCasedChecksum:8F2F799737C3230CA5BBEADDC4D281211F7CDF15E3C0D4DC967982E61933F608; SizeAsReceived:8452; Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [JVTKUGemwOdYWjsrbLUZ58Gnl1JkwTBA] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BN3NAM04HT166; 5:60hx/YSAXbW5B1XiGknN6bxaFJ5e29fCHMfPCJ7LY5/0baj2hfX/J+eLOz6nsdNnkI9JT/90BVt8Mp9XQfvHRu1C4HdAcugLJ3JXvwqnfybqgf8cWh+HZJpWnU70yCyFsoT6WSA1IXpx7ZqoFoDFRg==; 24:a+2S3DzqLQ1WvOw+UVyLpiExaKEIBUADR2q/kXZGSvpi4MuH/l2f7nQdUa2m6BI5GH9Az3mxbUdpIssidLa2QHgIIIcXB4SvOHfbULdlGQg=; 7:31vBmpUwdNbk+rANZQEg8MAmpb2vk9YJxX5sRHu/14bnRa9DNj0iu0+Z9tGlF40/n7kGJ2cVaHpRh3MYlZlQuXJ3N4tPt0h1TTVPEfxETajY/ZyUaQxbxG7+0pwwFelhWBqeRMRFMVYljj6PDUIjajp7jQlCSS45RTI2zK/Thz27aNSarBhoTrC2e3cQCD71tOGfKvTImKSq9FNQY3/oMeI6fGmn3zA1GSOtvwGQQqLdTJnk28h20AWfa/smP7WvUtvAv8516MW4rvn4fmWvk4IPv1LVRRdr2pHlkM3CTkyd1jsu0Fc2fNEqA2/tv+0s x-incomingheadercount: 46 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:BN3NAM04HT166; H:MWHPR11MB1822.namprd11.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 65110d3b-d4ce-44ee-6dd7-08d491e80c6e x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322274)(1603101448)(1601125374)(1701031045); SRVR:BN3NAM04HT166; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:BN3NAM04HT166; BCL:0; PCL:0; RULEID:; SRVR:BN3NAM04HT166; x-forefront-prvs: 029651C7A1 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-originalarrivaltime: 03 May 2017 05:48:39.2185 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3NAM04HT166 X-Content-Filtered-By: Mailman/MimeDel 2.1.22 Subject: Re: Accessing AVX/AVX2 instruction in UEFI. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 May 2017 05:48:42 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thank you Michael and Andrew Regards Amit ________________________________ From: Kinney, Michael D Sent: Tuesday, May 2, 2017 10:33:45 PM To: Andrew Fish; Amit kumar; Kinney, Michael D Cc: edk2-devel@lists.01.org Subject: RE: [edk2] Accessing AVX/AVX2 instruction in UEFI. Amit, The information from Andrew is correct. The document that covers this topic is the Intel(r) 64 and IA-32 Architectures Software Developer Manuals https://software.intel.com/en-us/articles/intel-sdm Volume 1, Section 13.5.3 describes the AVX State. There are More details about detecting and enabling different AVX features in that document. If the CPU supports AVX, then the basic assembly instructions required to use AVX instructions are the following that sets bits 0, 1, 2 of XCR0. mov rcx, 0 xgetbv or rax, 0007h xsetbv One additional item you need to be aware of is that UEFI firmware only saves/Restores CPU registers required for the UEFI ABI calling convention when a timer interrupt or exception is processed. This means CPU state such as the YMM registers are not saved/restored across an interrupt and may be modified if code in interrupt context also uses YMM registers. When you enable the use of extended registers, interrupts should be saved/disabled and restored around the extended register usage. You can use the following functions from MdePkg BaseLib to do this /** Disables CPU interrupts and returns the interrupt state prior to the disa= ble operation. @retval TRUE CPU interrupts were enabled on entry to this call. @retval FALSE CPU interrupts were disabled on entry to this call. **/ BOOLEAN EFIAPI SaveAndDisableInterrupts ( VOID ); /** Set the current CPU interrupt state. Sets the current CPU interrupt state to the state specified by InterruptState. If InterruptState is TRUE, then interrupts are enabled. I= f InterruptState is FALSE, then interrupts are disabled. InterruptState is returned. @param InterruptState TRUE if interrupts should enabled. FALSE if interrupts should be disabled. @return InterruptState **/ BOOLEAN EFIAPI SetInterruptState ( IN BOOLEAN InterruptState ); Algorithm: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D { BOOLEAN InterruptState; InterruptState =3D SaveAndDisableInterrupts(); // Enable use of AVX/AVX2 instructions // Use AVX/AVX2 instructions SetInterruptState (InterruptState); } Best regards, Mike > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of An= drew Fish > Sent: Tuesday, May 2, 2017 8:12 AM > To: Amit kumar > Cc: edk2-devel@lists.01.org > Subject: Re: [edk2] Accessing AVX/AVX2 instruction in UEFI. > > > > On May 2, 2017, at 6:57 AM, Amit kumar wrote: > > > > Hi, > > > > Am trying to optimize an application using AVX/AVX2, but my code hangs = while trying > to access YMM registers. > > The instruction where my code hangs is : > > > > > > vmovups ymm0, YMMWORD PTR [rax] > > > > > > I have verified the cpuid in OS and it supports AVX and AVX2 instructio= n. Processor > i7 6th gen. > > Can somebody help me out here ? Is there a way to enable YMM registers = ? > > > > Amit, > > I think these instructions will generate an illegal instruction fault unt= il you enable > AVX. You need to check the Cpu ID bits in your code, then write BIT18 of = CR4. After > that XGETBV/XSETBV instructions are enabled and you can or in the lower 2= bits of > XCR0. This basic operation is in the Intel Docs, it is just hard to find.= Usually the > OS has done this for the programmer and all the code needs to do is check= the CPU ID. > > Thanks, > > Andrew Fish > > > > > Thanks And Regards > > Amit Kumar > > > > _______________________________________________ > > edk2-devel mailing list > > edk2-devel@lists.01.org > > https://lists.01.org/mailman/listinfo/edk2-devel > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel