Page MenuHomePhabricator

Add new flag and intrinsic support for MWAITX and MONITORX instructions.

Authored by GGanesh on May 2 2016, 12:17 AM.



This patch adds new intrinsics, new flag (-mwaitx) and flag enablement based on cpuid for the instructions MONITORX and MWAITX. Testcases that tests the intrinsics which uses the flag are also added.

These instructions provide similar capability to the MONITOR/MWAIT pair while adding a timer function, such that another termination of the MWAITX instruction occurs when the timer expires. The presence of the MONITORX and MWAITX instructions is indicated by CPUID 8000_0001, ECX, bit 29.

The MONITORX and MWAITX instructions are intercepted by the same bits that intercept MONITOR and MWAIT. MONITORX instruction establishes a range to be monitored. MWAITX instruction causes the processor to stop instruction execution and enter an implementation-dependent optimized state until occurrence of a class of events.

Opcode of MONITORX instruction is "0F 01 FA". Opcode of MWAITX instruction is "0F 01 FB". These opcode information is used in adding tests for the disassembler.

Diff Detail


Event Timeline

GGanesh updated this revision to Diff 55787.May 2 2016, 12:17 AM
GGanesh retitled this revision from to Add new flag and intrinsic support for MWAITX and MONITORX instructions..
GGanesh updated this object.
GGanesh added reviewers: echristo, craig.topper.
GGanesh set the repository for this revision to rL LLVM.
GGanesh added a subscriber: llvm-commits.
RKSimon added a subscriber: RKSimon.
RKSimon added inline comments.
8722 ↗(On Diff #55787)

Why is _sse3_ in the intrinsic name? I realise the original monitor/mwait came out at the same time as SSE3 (and are included in the same header) but these certainly didn't.

806 ↗(On Diff #55787)

align the '='

GGanesh updated this revision to Diff 57000.May 11 2016, 11:08 PM

Incorporated comments from Simon!

RKSimon edited edge metadata.May 12 2016, 3:35 AM

Should FeatureMWAITX be added to the bdver4 feature list?

GGanesh updated this revision to Diff 57150.May 13 2016, 2:59 AM
GGanesh edited edge metadata.

Added FeatureMWAITX to bdver4.

RKSimon accepted this revision.May 13 2016, 3:17 AM
RKSimon edited edge metadata.

LGTM with one minor

3 ↗(On Diff #57150)

Add -mcpu=bdver4 tests as well

This revision is now accepted and ready to land.May 13 2016, 3:17 AM

Thank you!

I am adding below tests in mwaitx.ll and will commit the changes.

; RUN: llc < %s -mtriple=x86_64-linux -mcpu=bdver4 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-win32 -mcpu=bdver4 | FileCheck %s -check-prefix=WIN64

This revision was automatically updated to reflect the committed changes.