asm_swar.inc 1.76 KB
/* -----------------------------------------------------------------------------
 *  Copyright (C) 2019 daiteq s.r.o.                     http://www.daiteq.com
 *
 *  This program is distributed WITHOUT ANY WARRANTY; without even
 *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE.
 *
 * -----------------------------------------------------------------------------
 *  Filename    : asm_swar.inc
 *  Authors     : Martin Danek
 *  Description : inline assembly routines
 *  Release     :
 *  Version     : 1.0
 *  Date        : 9.4.2019
 * -----------------------------------------------------------------------------
 */

#define op_swar(A,B,RES)                \
  asm volatile (                        \
    "swar    %0,%1,%2\n"                \
    : "=r"(RES)                         \
    : "r"(A), "r"(B)                    \
  )

#define op_set_ctrl(A)                  \
  asm volatile (                        \
    "csrw   swarctrlstat, %0\n"         \
    : : "r"(A)                          \
  )

#define op_get_stat(RES)                \
  asm volatile (                        \
    "csrr   %0, swarctrlstat\n"         \
    : "=r"(RES)                         \
  )

#define op_get_acc(A,RES)               \
  asm volatile (                        \
    "csrw   swaracc, %1\n"              \
    "csrr   %0, swaracc\n"              \
    : "=r"(RES) : "r"(A)                \
  )

#ifdef DIRECT_ACCUM
#define op_get_acc(RES)                \
  asm volatile (                        \
    "csrr   %0, swaracc\n"             \
    : "=r"(RES)                         \
  )

#define op_get_acchi(RES)              \
  asm volatile (                        \
    "csrr   %0, swaracchi\n"           \
    : "=r"(RES)                         \
  )
#endif