Skip to content

Commit

Permalink
i#1569 AArch64: Add "nzcv" test, an alternative to "eflags" test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Zhou authored and egrimley-arm committed Jul 7, 2016
1 parent 9f40776 commit 9edd275
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 7 deletions.
24 changes: 17 additions & 7 deletions suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,17 @@ if (WIN32)
torunonly(common.decode-stress common.decode common/decode.c
"-stress_recreate_state" "")
endif (WIN32)

if (X86)
set(control_flags "eflags")
elseif (AARCH64)
set(control_flags "nzcv")
endif ()
if (NOT ARM) # FIXME i#1551: port eflags/nzcv to ARM
tobuild(common.${control_flags} common/${control_flags}.c)
endif ()

if (X86) # FIXME i#1551, i#1569: port asm to ARM and AArch64
tobuild(common.eflags common/eflags.c)
tobuild(common.floatpc common/floatpc.c)
torunonly(common.floatpc_xl8all common.floatpc common/floatpc.c "-translate_fpu_pc" "")
tobuild(common.getretaddr common/getretaddr.c)
Expand Down Expand Up @@ -2237,17 +2246,18 @@ if (CLIENT_INTERFACE)
if (NOT ARM) # FIXME i#1551: fix bugs on ARM
get_property(sample_list GLOBAL PROPERTY DynamoRIO_sample_list)
foreach (sample ${sample_list})
torunonly_ci(sample.${sample} common.eflags ${sample} common/eflags.c "" "" "")
torunonly_ci(sample.${sample} common.${control_flags}
${sample} common/${control_flags}.c "" "" "")
if (sample STREQUAL "inscount")
# test out-of-line clean call
torunonly_ci(sample.${sample}.cleancall common.eflags ${sample}
common/eflags.c "" "-opt_cleancall 0" "")
torunonly_ci(sample.${sample}.cleancall common.${control_flags} ${sample}
common/${control_flags}.c "" "-opt_cleancall 0" "")
if (UNIX)
torunonly_ci(sample.${sample}.prof-pcs.cleancall common.eflags ${sample}
common/eflags.c "" "-prof_pcs -opt_cleancall 0" "")
torunonly_ci(sample.${sample}.prof-pcs.cleancall common.${control_flags}
${sample} common/${control_flags}.c "" "-prof_pcs -opt_cleancall 0" "")
if (NOT X64)
torunonly_ci(sample.${sample}.prof-pcs.thread-private.cleancall
common.eflags ${sample} common/eflags.c ""
common.${control_flags} ${sample} common/${control_flags}.c ""
"-thread_private -prof_pcs -opt_cleancall 0" "")
endif (NOT X64)
endif (UNIX)
Expand Down
138 changes: 138 additions & 0 deletions suite/tests/common/nzcv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* **********************************************************
* Copyright (c) 2014-2015 Google, Inc. All rights reserved.
* Copyright (c) 2005-2008 VMware, Inc. All rights reserved.
* **********************************************************/

/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of VMware, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/

#ifndef ASM_CODE_ONLY /* C code */
/* Tests preservation of eflags across indirect branches
*/

#include "tools.h"

#define VERBOSE 0

/* asm routine */
void test_nzcv_pos(uint pos);

const char *flags[] = {
"N", "Z", "C", "V"
};

const uint nzcv_pos[] = {
31, 30, 29, 28
};

#define NUM_FLAGS (sizeof(nzcv_pos) / sizeof(nzcv_pos[0]))

void
test_flag(uint nzcv, uint pos, bool set)
{
const char *flag = "*";
int i;
#if VERBOSE
print("NZCV where %c should be %d: "PFX"\n", flag, set, nzcv);
#endif
bool value = TEST(nzcv, 1U << pos);

for (i = 0; i < NUM_FLAGS; i++) {
if (nzcv_pos[i] == pos)
flag = flags[i];
}

if (value != set)
print("ERROR %d %s\n", set, flag);
else
print("OK %d %s\n", set, flag);
}

int
main()
{
uint i;
INIT();

for (i = 0; i < NUM_FLAGS; i++) {
test_nzcv_pos(nzcv_pos[i]);
}
}

#else /* asm code *************************************************************/
#include "asm_defines.asm"
START_FILE

DECL_EXTERN(test_flag)

#define FUNCNAME test_nzcv_pos
DECLARE_FUNC(FUNCNAME)
GLOBAL_LABEL(FUNCNAME:)
mov x19, ARG1
mov x20, x30
CALLC1(GLOBAL_REF(set_flag), x19)
mrs x0, nzcv
mov w1, w19
CALLC3(GLOBAL_REF(test_flag), x0, x1, 1)
CALLC1(GLOBAL_REF(clear_flag), x19)
mrs x0, nzcv
mov w1, w19
CALLC3(GLOBAL_REF(test_flag), x0, x1, 0)
mov x30, x20
ret
END_FUNC(FUNCNAME)

/* void set_flag(uint pos) */
#undef FUNCNAME
#define FUNCNAME set_flag
DECLARE_FUNC(FUNCNAME)
GLOBAL_LABEL(FUNCNAME:)
mov w1, #1
lsl w1, w1, w0
mrs x0, nzcv
orr w0, w0, w1
msr nzcv, x0
ret
END_FUNC(FUNCNAME)

/* void clear_flag(uint pos) */
#undef FUNCNAME
#define FUNCNAME clear_flag
DECLARE_FUNC(FUNCNAME)
GLOBAL_LABEL(FUNCNAME:)
mov w1, #1
lsl w1, w1, w0
mvn w1, w1
mrs x0, nzcv
and w0, w0, w1
msr nzcv, x0
ret
END_FUNC(FUNCNAME)

END_FILE
#endif
8 changes: 8 additions & 0 deletions suite/tests/common/nzcv.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OK 1 N
OK 0 N
OK 1 Z
OK 0 Z
OK 1 C
OK 0 C
OK 1 V
OK 0 V

0 comments on commit 9edd275

Please sign in to comment.