cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync/* $Id$ */
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync/** @file
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * rdtsc - Test if three consecutive rdtsc instructions return different values.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync */
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync/*
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * Copyright (C) 2009-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync *
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * available from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * General Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync *
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * The contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * of the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * VirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * CDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync *
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * You may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync * terms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync */
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync#include <stdio.h>
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncint main()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync{
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync int i;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync int cMatches = 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for (i = 0; i < 10000000; i++)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync int cMatchedNow = 0;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync __asm
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rdtsc
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ebx, eax
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov ecx, edx
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rdtsc
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov esi, eax
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync mov edi, edx
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync rdtsc
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cmp eax, ebx
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jnz l_ok1
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cmp edx, ecx
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jnz l_ok1
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync inc [cMatchedNow]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync l_ok1:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cmp eax, esi
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jnz l_ok2
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cmp edx, edi
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jnz l_ok2
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync inc [cMatchedNow]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jmp l_ok3
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync l_ok2:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cmp ebx, esi
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jnz l_ok3
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cmp ecx, edi
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync jnz l_ok3
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync inc [cMatchedNow]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync l_ok3:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync }
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if (cMatchedNow)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync {
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync printf("%08d: %d\n", i, cMatchedNow);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync cMatches += cMatchedNow;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync }
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync }
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync printf("done: %d matches\n", cMatches);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return !!cMatches;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync}