<commit_before>//===-- asan_asm_test.cc --------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of AddressSanitizer, an address sanity checker.
//
//===----------------------------------------------------------------------===//
#include "asan_test_utils.h"

#if defined(__linux__)

// Assembly instrumentation is broken on x86 Android (x86 + PIC + shared runtime
// library). See https://github.com/google/sanitizers/issues/353
#if defined(__x86_64__) ||                                                     \
    (defined(__i386__) && defined(__SSE2__) && !defined(__ANDROID__))

#include <emmintrin.h>

namespace {

template<typename T> void asm_write(T *ptr, T val);
template<typename T> T asm_read(T *ptr);
template<typename T> void asm_rep_movs(T *dst, T *src, size_t n);

} // End of anonymous namespace

#endif // defined(__x86_64__) || (defined(__i386__) && defined(__SSE2__))

#if defined(__x86_64__)

namespace {

#define DECLARE_ASM_WRITE(Type, Size, Mov, Reg)        \
template<> void asm_write<Type>(Type *ptr, Type val) { \
  __asm__(                                             \
    Mov " %[val], (%[ptr])  \n\t"                      \
    :                                                  \
    : [ptr] "r" (ptr), [val] Reg (val)                 \
    : "memory"                                         \
  );                                                   \
}

#define DECLARE_ASM_READ(Type, Size, Mov, Reg)     \
template<> Type asm_read<Type>(Type *ptr) {        \
  Type res;                                        \
  __asm__(                                         \
    Mov " (%[ptr]), %[res]  \n\t"                  \
    : [res] Reg (res)                              \
    : [ptr] "r" (ptr)                              \
    : "memory"                                     \
  );                                               \
  return res;                                      \
}

#define DECLARE_ASM_REP_MOVS(Type, Movs)                                       \
  template <> void asm_rep_movs<Type>(Type * dst, Type * src, size_t size) {   \
    __asm__("rep " Movs " \n\t"                                                \
            :                                                                  \
            : "D"(dst), "S"(src), "c"(size)                                    \
            : "memory");                                  \
  }

DECLARE_ASM_WRITE(U8, "8", "movq", "r");
DECLARE_ASM_READ(U8, "8", "movq", "=r");
DECLARE_ASM_REP_MOVS(U8, "movsq");

} // End of anonymous namespace

#endif // defined(__x86_64__)

#if defined(__i386__) && defined(__SSE2__) && !defined(__ANDROID__)

namespace {

#define DECLARE_ASM_WRITE(Type, Size, Mov, Reg)        \
template<> void asm_write<Type>(Type *ptr, Type val) { \
  __asm__(                                             \
    Mov " %[val], (%[ptr])  \n\t"                      \
    :                                                  \
    : [ptr] "r" (ptr), [val] Reg (val)                 \
    : "memory"                                         \
  );                                                   \
}

#define DECLARE_ASM_READ(Type, Size, Mov, Reg)     \
template<> Type asm_read<Type>(Type *ptr) {        \
  Type res;                                        \
  __asm__(                                         \
    Mov " (%[ptr]), %[res]  \n\t"                  \
    : [res] Reg (res)                              \
    : [ptr] "r" (ptr)                              \
    : "memory"                                     \
  );                                               \
  return res;                                      \
}

#define DECLARE_ASM_REP_MOVS(Type, Movs)                                       \
  template <> void asm_rep_movs<Type>(Type * dst, Type * src, size_t size) {   \
    __asm__("rep " Movs " \n\t"                                                \
            :                                                                  \
            : "D"(dst), "S"(src), "c"(size)                                    \
            : "memory");                                  \
  }

} // End of anonymous namespace

#endif  // defined(__i386__) && defined(__SSE2__)

#if defined(__x86_64__) ||                                                     \
    (defined(__i386__) && defined(__SSE2__) && !defined(__ANDROID__))

namespace {

DECLARE_ASM_WRITE(U1, "1", "movb", "r");
DECLARE_ASM_WRITE(U2, "2", "movw", "r");
DECLARE_ASM_WRITE(U4, "4", "movl", "r");
DECLARE_ASM_WRITE(__m128i, "16", "movaps", "x");

DECLARE_ASM_READ(U1, "1", "movb", "=r");
DECLARE_ASM_READ(U2, "2", "movw", "=r");
DECLARE_ASM_READ(U4, "4", "movl", "=r");
DECLARE_ASM_READ(__m128i, "16", "movaps", "=x");

DECLARE_ASM_REP_MOVS(U1, "movsb");
DECLARE_ASM_REP_MOVS(U2, "movsw");<commit_msg>[asan] Fix test broken by r290540<commit_after>//===-- asan_asm_test.cc --------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of AddressSanitizer, an address sanity checker.
//
//===----------------------------------------------------------------------===//
#include "asan_test_utils.h"

#if defined(__linux__)

// Assembly instrumentation is broken on x86 Android (x86 + PIC + shared runtime
// library). See https://github.com/google/sanitizers/issues/353
#if defined(__x86_64__) ||                                                     \
    (defined(__i386__) && defined(__SSE2__) && !defined(__ANDROID__))

#include <emmintrin.h>

namespace {

template<typename T> void asm_write(T *ptr, T val);
template<typename T> T asm_read(T *ptr);
template<typename T> void asm_rep_movs(T *dst, T *src, size_t n);

} // End of anonymous namespace

#endif // defined(__x86_64__) || (defined(__i386__) && defined(__SSE2__))

#if defined(__x86_64__)

namespace {

#define DECLARE_ASM_WRITE(Type, Size, Mov, Reg)        \
template<> void asm_write<Type>(Type *ptr, Type val) { \
  __asm__(                                             \
    Mov " %[val], (%[ptr])  \n\t"                      \
    :                                                  \
    : [ptr] "r" (ptr), [val] Reg (val)                 \
    : "memory"                                         \
  );                                                   \
}

#define DECLARE_ASM_READ(Type, Size, Mov, Reg)     \
template<> Type asm_read<Type>(Type *ptr) {        \
  Type res;                                        \
  __asm__(                                         \
    Mov " (%[ptr]), %[res]  \n\t"                  \
    : [res] Reg (res)                              \
    : [ptr] "r" (ptr)                              \
    : "memory"                                     \
  );                                               \
  return res;                                      \
}

#define DECLARE_ASM_REP_MOVS(Type, Movs)                         \
  template <>                                                    \
  void asm_rep_movs<Type>(Type * dst, Type * src, size_t size) { \
    __asm__("rep " Movs " \n\t"                                  \
            : "+D"(dst), "+S"(src), "+c"(size)                   \
            :                                                    \
            : "memory");                                         \
  }

DECLARE_ASM_WRITE(U8, "8", "movq", "r");
DECLARE_ASM_READ(U8, "8", "movq", "=r");
DECLARE_ASM_REP_MOVS(U8, "movsq");

} // End of anonymous namespace

#endif // defined(__x86_64__)

#if defined(__i386__) && defined(__SSE2__) && !defined(__ANDROID__)

namespace {

#define DECLARE_ASM_WRITE(Type, Size, Mov, Reg)        \
template<> void asm_write<Type>(Type *ptr, Type val) { \
  __asm__(                                             \
    Mov " %[val], (%[ptr])  \n\t"                      \
    :                                                  \
    : [ptr] "r" (ptr), [val] Reg (val)                 \
    : "memory"                                         \
  );                                                   \
}

#define DECLARE_ASM_READ(Type, Size, Mov, Reg)     \
template<> Type asm_read<Type>(Type *ptr) {        \
  Type res;                                        \
  __asm__(                                         \
    Mov " (%[ptr]), %[res]  \n\t"                  \
    : [res] Reg (res)                              \
    : [ptr] "r" (ptr)                              \
    : "memory"                                     \
  );                                               \
  return res;                                      \
}

#define DECLARE_ASM_REP_MOVS(Type, Movs)                         \
  template <>                                                    \
  void asm_rep_movs<Type>(Type * dst, Type * src, size_t size) { \
    __asm__("rep " Movs " \n\t"                                  \
            : "+D"(dst), "+S"(src), "+c"(size)                   \
            :                                                    \
            : "memory");                                         \
  }

} // End of anonymous namespace

#endif  // defined(__i386__) && defined(__SSE2__)

#if defined(__x86_64__) ||                                                     \
    (defined(__i386__) && defined(__SSE2__) && !defined(__ANDROID__))

namespace {

DECLARE_ASM_WRITE(U1, "1", "movb", "r");
DECLARE_ASM_WRITE(U2, "2", "movw", "r");
DECLARE_ASM_WRITE(U4, "4", "movl", "r");
DECLARE_ASM_WRITE(__m128i, "16", "movaps", "x");

DECLARE_ASM_READ(U1, "1", "movb", "=r");
DECLARE_ASM_READ(U2, "2", "movw", "=r");
DECLARE_ASM_READ(U4, "4", "movl", "=r");
DECLARE_ASM_READ(__m128i, "16", "movaps", "=x");

DECLARE_ASM_REP_MOVS(U1, "movsb");
DECLARE_ASM_REP_MOVS(U2, "movsw");
{'fraction_non_alphanumeric': 0.17102417928051897, 'fraction_numerical': 0.01552978179673678, 'mean_word_length': 0.9943159545276362, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 88, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '102148', 'n_tokens_mistral': 2951, 'n_tokens_neox': 2767, 'n_words': 590}