/* Copyright (c) 1995 - 2003, Sun Microsystems, Inc.
 * Copyright (c) 2009, 2016, 2019, ZAO "MCST". All rights reserved. */

#ifndef VIS_H
#define VIS_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#ifdef VIS
#define __VIS   VIS
#endif

/*
 *----------------------------------------------------------------------
 *
 * VIS types
 *
 *----------------------------------------------------------------------
 */

/* signed 8-bit integer */
typedef signed char     vis_s8;

/* unsigned 8-bit integer */
typedef unsigned char   vis_u8;

/* signed 16-bit integer */
typedef short           vis_s16;

/* unsigned 16-bit integer */
typedef unsigned short  vis_u16;

/* signed 32-bit integer */
typedef int             vis_s32;

/* unsigned 32-bit integer */
typedef unsigned int    vis_u32;

/* 32-bit floating-point */
typedef float           vis_f32;

/* 64-bit floating-point */
typedef double          vis_d64;

/* value of an addresss */
typedef unsigned long   vis_addr;

/* pointer to an addresss */
typedef void    *       vis_paddr;

#ifdef __ptr64__

/* signed 64-bit integer */
typedef long          vis_s64;

/* unsigned 64-bit integer */
typedef unsigned long vis_u64;

#elif !defined(_NO_LONGLONG)

/* signed 64-bit integer */
typedef long long          vis_s64;

/* unsigned 64-bit integer */
typedef unsigned long long vis_u64;

#endif  /* __ptr64__ */

/*
 *----------------------------------------------------------------------
 *
 * VIS defines
 *
 *----------------------------------------------------------------------
 */

#ifdef __VIS

#define vis_edge8               __vis_edge8
#define vis_edge8l              __vis_edge8l
#define vis_edge16              __vis_edge16
#define vis_edge16l             __vis_edge16l
#define vis_edge32              __vis_edge32
#define vis_edge32l             __vis_edge32l
#define vis_alignaddr           __vis_alignaddr
#define vis_alignaddrl          __vis_alignaddrl
#define vis_faligndata          __vis_faligndata
#define vis_fcmplt16            __vis_fcmplt16
#define vis_fcmpge16            __vis_fcmpge16
#define vis_fcmple16            __vis_fcmple16
#define vis_fcmpne16            __vis_fcmpne16
#define vis_fcmpgt16            __vis_fcmpgt16
#define vis_fcmpeq16            __vis_fcmpeq16
#define vis_fcmplt32            __vis_fcmplt32
#define vis_fcmpge32            __vis_fcmpge32
#define vis_fcmple32            __vis_fcmple32
#define vis_fcmpne32            __vis_fcmpne32
#define vis_fcmpgt32            __vis_fcmpgt32
#define vis_fcmpeq32            __vis_fcmpeq32
#define vis_fmul8x16            __vis_fmul8x16
#define vis_fmul8x16au          __vis_fmul8x16au
#define vis_fmul8x16al          __vis_fmul8x16al
#define vis_fmul8sux16          __vis_fmul8sux16
#define vis_fmul8ulx16          __vis_fmul8ulx16
#define vis_fmuld8ulx16         __vis_fmuld8ulx16
#define vis_fmuld8sux16         __vis_fmuld8sux16
#define vis_fpadd16             __vis_fpadd16
#define vis_fpadd16s            __vis_fpadd16s
#define vis_fpadd32             __vis_fpadd32
#define vis_fpadd32s            __vis_fpadd32s
#define vis_fpsub16             __vis_fpsub16
#define vis_fpsub16s            __vis_fpsub16s
#define vis_fpsub32             __vis_fpsub32
#define vis_fpsub32s            __vis_fpsub32s
#define vis_fpack16             __vis_fpack16
#define vis_fpack32             __vis_fpack32
#define vis_fpackfix            __vis_fpackfix
#define vis_fpack16_pair        __vis_fpack16_pair
#define vis_fpackfix_pair       __vis_fpackfix_pair
#define vis_st2_fpack16         __vis_st2_fpack16
#define vis_std_fpack16         __vis_std_fpack16
#define vis_st2_fpackfix        __vis_st2_fpackfix
#define vis_fpack16_to_hi       __vis_fpack16_to_hi
#define vis_fpack16_to_lo       __vis_fpack16_to_lo
#define vis_pdist               __vis_pdist
#define vis_fpmerge             __vis_fpmerge
#define vis_fexpand             __vis_fexpand
#define vis_fexpand_hi         __vis_fexpand_hi
#define vis_fexpand_lo         __vis_fexpand_lo
#define vis_fnor                __vis_fnor
#define vis_fnors               __vis_fnors
#define vis_fandnot             __vis_fandnot
#define vis_fandnots            __vis_fandnots
#define vis_fnot                __vis_fnot
#define vis_fnots               __vis_fnots
#define vis_fxor                __vis_fxor
#define vis_fxors               __vis_fxors
#define vis_fnand               __vis_fnand
#define vis_fnands              __vis_fnands
#define vis_fand                __vis_fand
#define vis_fands               __vis_fands
#define vis_fxnor               __vis_fxnor
#define vis_fxnors              __vis_fxnors
#define vis_fsrc                __vis_fsrc
#define vis_fsrcs               __vis_fsrcs
#define vis_fornot              __vis_fornot
#define vis_fornots             __vis_fornots
#define vis_for                 __vis_for
#define vis_fors                __vis_fors
#define vis_fzero               __vis_fzero
#define vis_fzeros              __vis_fzeros
#define vis_fone                __vis_fone
#define vis_fones               __vis_fones
#define vis_st_u8               __vis_st_u8
#define vis_st_u8_i             __vis_st_u8_i
#define vis_st_u16              __vis_st_u16
#define vis_st_u16_i            __vis_st_u16_i
#define vis_st_u8_le            __vis_st_u8_le
#define vis_st_u8_le_i          __vis_st_u8_le_i
#define vis_st_u16_le           __vis_st_u16_le
#define vis_st_u16_le_i         __vis_st_u16_le_i
#define vis_ld_u8               __vis_ld_u8
#define vis_ld_u8_i             __vis_ld_u8_i
#define vis_ld_u16              __vis_ld_u16
#define vis_ld_u16_i            __vis_ld_u16_i
#define vis_ld_u8_le            __vis_ld_u8_le
#define vis_ld_u8_le_i          __vis_ld_u8_le_i
#define vis_ld_u16_le           __vis_ld_u16_le
#define vis_ld_u16_le_i         __vis_ld_u16_le_i
#define vis_pst_8               __vis_pst_8
#define vis_pst_16              __vis_pst_16
#define vis_pst_32              __vis_pst_32
#define vis_pst_8_le            __vis_pst_8_le
#define vis_pst_16_le           __vis_pst_16_le
#define vis_pst_32_le           __vis_pst_32_le
#define vis_ld_f32_asi          __vis_ld_f32_asi
#define vis_ld_f32              __vis_ld_f32
#define vis_ld_f32_i            __vis_ld_f32_i
#define vis_ld_f32_le           __vis_ld_f32_le
#define vis_ld_f32_le_i         __vis_ld_f32_le_i
#define vis_ld_d64_asi          __vis_ld_d64_asi
#define vis_ld_d64              __vis_ld_d64
#define vis_ld_d64_i            __vis_ld_d64_i
#define vis_ld_d64_le           __vis_ld_d64_le
#define vis_ld_d64_le_i         __vis_ld_d64_le_i
#define vis_st_f32_asi          __vis_st_f32_asi
#define vis_st_f32              __vis_st_f32
#define vis_st_f32_i            __vis_st_f32_i
#define vis_st_f32_le           __vis_st_f32_le
#define vis_st_f32_le_i         __vis_st_f32_le_i
#define vis_st_d64_asi          __vis_st_d64_asi
#define vis_st_d64              __vis_st_d64
#define vis_st_d64_i            __vis_st_d64_i
#define vis_st_d64_le           __vis_st_d64_le
#define vis_st_d64_le_i         __vis_st_d64_le_i
#define vis_read_gsr            __vis_read_gsr
#define vis_write_gsr           __vis_write_gsr
#define vis_read_hi             __vis_read_hi
#define vis_read_lo             __vis_read_lo
#define vis_write_hi            __vis_write_hi
#define vis_write_lo            __vis_write_lo

#if defined (__r2000__) || defined (__r2000plus__)

#define vis_freg_pair           __vis_fmerge32_r2000
#define vis_to_float            __vis_movwtos_r2000
#define vis_to_double           __vis_to_double_r2000
#define vis_to_double_dup       __vis_to_double_dup_r2000

#else /* defined (__r2000__) || defined (__r2000plus__) */

#define vis_freg_pair           __vis_freg_pair
#define vis_to_float            __vis_to_float
#define vis_to_double           __vis_to_double
#define vis_to_double_dup       __vis_to_double_dup

#endif /* defined (__r2000__) || defined (__r2000plus__) */

#define vis_read_asi            __vis_read_asi
#define vis_write_asi           __vis_write_asi
#define vis_prefetch_read       __vis_prefetch_read
#define vis_prefetch_write      __vis_prefetch_write

#define vis_ld_s8_nf            __vis_ld_s8_nf
#define vis_ld_s8_nf_i          __vis_ld_s8_nf_i
#define vis_ld_s8_nf_le         __vis_ld_s8_nf_le
#define vis_ld_s8_nf_le_i       __vis_ld_s8_nf_le_i
#define vis_ld_u8_nf            __vis_ld_u8_nf
#define vis_ld_u8_nf_i          __vis_ld_u8_nf_i
#define vis_ld_u8_nf_le         __vis_ld_u8_nf_le
#define vis_ld_u8_nf_le_i       __vis_ld_u8_nf_le_i
#define vis_ld_s16_nf           __vis_ld_s16_nf
#define vis_ld_s16_nf_i         __vis_ld_s16_nf_i
#define vis_ld_s16_nf_le        __vis_ld_s16_nf_le
#define vis_ld_s16_nf_le_i      __vis_ld_s16_nf_le_i
#define vis_ld_u16_nf           __vis_ld_u16_nf
#define vis_ld_u16_nf_i         __vis_ld_u16_nf_i
#define vis_ld_u16_nf_le        __vis_ld_u16_nf_le
#define vis_ld_u16_nf_le_i      __vis_ld_u16_nf_le_i
#define vis_ld_s32_nf           __vis_ld_s32_nf
#define vis_ld_s32_nf_i         __vis_ld_s32_nf_i
#define vis_ld_s32_nf_le        __vis_ld_s32_nf_le
#define vis_ld_s32_nf_le_i      __vis_ld_s32_nf_le_i
#define vis_ld_u32_nf           __vis_ld_u32_nf
#define vis_ld_u32_nf_i         __vis_ld_u32_nf_i
#define vis_ld_u32_nf_le        __vis_ld_u32_nf_le
#define vis_ld_u32_nf_le_i      __vis_ld_u32_nf_le_i
#define vis_ld_s64_nf           __vis_ld_s64_nf
#define vis_ld_s64_nf_i         __vis_ld_s64_nf_i
#define vis_ld_s64_nf_le        __vis_ld_s64_nf_le
#define vis_ld_s64_nf_le_i      __vis_ld_s64_nf_le_i
#define vis_ld_u64_nf           __vis_ld_u64_nf
#define vis_ld_u64_nf_i         __vis_ld_u64_nf_i
#define vis_ld_u64_nf_le        __vis_ld_u64_nf_le
#define vis_ld_u64_nf_le_i      __vis_ld_u64_nf_le_i
#define vis_ld_f32_nf           __vis_ld_f32_nf
#define vis_ld_f32_nf_i         __vis_ld_f32_nf_i
#define vis_ld_f32_nf_le        __vis_ld_f32_nf_le
#define vis_ld_f32_nf_le_i      __vis_ld_f32_nf_le_i
#define vis_ld_d64_nf           __vis_ld_d64_nf
#define vis_ld_d64_nf_i         __vis_ld_d64_nf_i
#define vis_ld_d64_nf_le        __vis_ld_d64_nf_le
#define vis_ld_d64_nf_le_i      __vis_ld_d64_nf_le_i

#if !defined(_NO_LONGLONG) || defined(__ptr64__)
#define vis_array8              __vis_array8
#define vis_array16             __vis_array16
#define vis_array32             __vis_array32
#if (defined(__r2000__) || defined (__r2000plus__)) && defined(__ptr64__)
#define vis_ll_to_double        __vis_movxtod_r2000
#else /* (defined(__r2000__) || defined (__r2000plus__)) && defined(__ptr64__) */
#define vis_ll_to_double        __vis_ll_to_double
#endif /* (defined(__r2000__) || defined (__r2000plus__)) && defined(__ptr64__) */
#endif  /* !defined(_NO_LONGLONG) || defined(__ptr64__) */

#if __VIS >= 0x200

#define vis_write_bmask         __vis_write_bmask
#define vis_bshuffle            __vis_bshuffle
#define vis_read_bmask          __vis_read_bmask
#define vis_read_gsr64          __vis_read_gsr64
#define vis_write_gsr64         __vis_write_gsr64

#if __VIS >= 0x300

#define vis_fmadds              __vis_fmadds_r1000
#define vis_fmsubs              __vis_fmsubs_r1000
#define vis_fnmadds             __vis_fnmadds_r1000
#define vis_fnmsubs             __vis_fnmsubs_r1000
#define vis_fmaddd              __vis_fmaddd_r1000
#define vis_fmsubd              __vis_fmsubd_r1000
#define vis_fnmaddd             __vis_fnmaddd_r1000
#define vis_fnmsubd             __vis_fnmsubd_r1000
#define vis_pfmadds             __vis_pfmadds_r1000
#define vis_pfmsubs             __vis_pfmsubs_r1000
#define vis_pfnmadds            __vis_pfnmadds_r1000
#define vis_pfnmsubs            __vis_pfnmsubs_r1000
#define vis_pfabss              __vis_pfabss_r1000
#define vis_pfnegs              __vis_pfnegs_r1000
#define vis_pfadds              __vis_pfadds_r1000
#define vis_pfsubs              __vis_pfsubs_r1000
#define vis_pfmuls              __vis_pfmuls_r1000

#if defined (__r2000__) || defined (__r2000plus__)

#define vis_fpcmpeq8            __vis_fpcmpeq8_r2000
#define vis_fpcmpne8            __vis_fpcmpne8_r2000
#define vis_fpcmpule8           __vis_fpcmpule8_r2000
#define vis_fpcmpugt8           __vis_fpcmpugt8_r2000
#define vis_fpadds16            __vis_fpadds16_r2000
#define vis_fpadds16s           __vis_fpadds16s_r2000
#define vis_fpadds32            __vis_fpadds32_r2000
#define vis_fpadds32s           __vis_fpadds32s_r2000
#define vis_fpsubs16            __vis_fpsubs16_r2000
#define vis_fpsubs16s           __vis_fpsubs16s_r2000
#define vis_fpsubs32            __vis_fpsubs32_r2000
#define vis_fpsubs32s           __vis_fpsubs32s_r2000
#define vis_fsll16              __vis_fsll16_r2000
#define vis_fsll32              __vis_fsll32_r2000
#define vis_fsrl16              __vis_fsrl16_r2000
#define vis_fsrl32              __vis_fsrl32_r2000
#define vis_fslas16             __vis_fslas16_r2000
#define vis_fslas32             __vis_fslas32_r2000
#define vis_fsra16              __vis_fsra16_r2000
#define vis_fsra32              __vis_fsra32_r2000
#define vis_lzcnt               __vis_lzcnt_r2000
#define vis_fmerge32            __vis_fmerge32_r2000
#define vis_movstosw            __vis_movstosw_r2000
#define vis_movstouw            __vis_movstouw_r2000
#define vis_movdtox             __vis_movdtox_r2000
#define vis_movwtos             __vis_movwtos_r2000
#define vis_movxtod             __vis_movxtod_r2000

#ifdef __r2000plus__

#define vis_fchksm16            __vis_fchksm16_r2000plus
#define vis_fmean16             __vis_fmean16_r2000plus
#define vis_pdistn              __vis_pdistn_r2000plus
#define vis_xmulx               __vis_xmulx_r2000plus
#define vis_xmulxhi             __vis_xmulxhi_r2000plus
#define vis_fpadd64             __vis_fpadd64_r2000plus
#define vis_fpsub64             __vis_fpsub64_r2000plus
#define vis_fpadd8              __vis_fpadd8_r2000plus
#define vis_fpsub8              __vis_fpsub8_r2000plus
#define vis_fpadds8             __vis_fpadds8_r2000plus
#define vis_fpsubs8             __vis_fpsubs8_r2000plus
#define vis_fpaddus8            __vis_fpaddus8_r2000plus
#define vis_fpsubus8            __vis_fpsubus8_r2000plus
#define vis_fpaddus16           __vis_fpaddus16_r2000plus
#define vis_fpsubus16           __vis_fpsubus16_r2000plus
#define vis_fpcmple8            __vis_fpcmple8_r2000plus
#define vis_fpcmpgt8            __vis_fpcmpgt8_r2000plus
#define vis_fpcmpule16          __vis_fpcmpule16_r2000plus
#define vis_fpcmpugt16          __vis_fpcmpugt16_r2000plus
#define vis_fpcmpule32          __vis_fpcmpule32_r2000plus
#define vis_fpcmpugt32          __vis_fpcmpugt32_r2000plus
#define vis_fpmax8              __vis_fpmax8_r2000plus
#define vis_fpmin8              __vis_fpmin8_r2000plus
#define vis_fpmax16             __vis_fpmax16_r2000plus
#define vis_fpmin16             __vis_fpmin16_r2000plus
#define vis_fpmax32             __vis_fpmax32_r2000plus
#define vis_fpmin32             __vis_fpmin32_r2000plus
#define vis_fpmaxu8             __vis_fpmaxu8_r2000plus
#define vis_fpminu8             __vis_fpminu8_r2000plus
#define vis_fpmaxu16            __vis_fpmaxu16_r2000plus
#define vis_fpminu16            __vis_fpminu16_r2000plus
#define vis_fpmaxu32            __vis_fpmaxu32_r2000plus
#define vis_fpminu32            __vis_fpminu32_r2000plus
#define vis_fpcsl32             __vis_fpcsl32_r2000plus
#define vis_fpcsl64             __vis_fpcsl64_r2000plus
#define vis_fpcsr32             __vis_fpcsr32_r2000plus
#define vis_fpcsr64             __vis_fpcsr64_r2000plus

#endif /* __r2000plus__ */

#endif /* defined (__r2000__) || defined (__r2000plus__) */

#else  /* __VIS >= 0x300 */

/* Emulate r1000 operations via ordinary operations */
#define vis_fmadds              __vis_fmadds_ultrasparc
#define vis_fmsubs              __vis_fmsubs_ultrasparc
#define vis_fnmadds             __vis_fnmadds_ultrasparc
#define vis_fnmsubs             __vis_fnmsubs_ultrasparc
#define vis_fmaddd              __vis_fmaddd_ultrasparc
#define vis_fmsubd              __vis_fmsubd_ultrasparc
#define vis_fnmaddd             __vis_fnmaddd_ultrasparc
#define vis_fnmsubd             __vis_fnmsubd_ultrasparc
#define vis_pfmadds             __vis_pfmadds_ultrasparc
#define vis_pfmsubs             __vis_pfmsubs_ultrasparc
#define vis_pfnmadds            __vis_pfnmadds_ultrasparc
#define vis_pfnmsubs            __vis_pfnmsubs_ultrasparc
#define vis_pfabss              __vis_pfabss_ultrasparc
#define vis_pfnegs              __vis_pfnegs_ultrasparc
#define vis_pfadds              __vis_pfadds_ultrasparc
#define vis_pfsubs              __vis_pfsubs_ultrasparc
#define vis_pfmuls              __vis_pfmuls_ultrasparc

#endif  /* __VIS >= 0x300 */

#endif  /* __VIS >= 0x200 */

#endif  /* __VIS */

/*
 *----------------------------------------------------------------------
 *
 * Prototypes for the inline templates in vis.il
 *
 *----------------------------------------------------------------------
 */

/* Pure edge handling instructions */
int __vis_edge8(void * /*frs1*/, void * /*frs2*/);
int __vis_edge8l(void * /*frs1*/, void * /*frs2*/);
int __vis_edge16(void * /*frs1*/, void * /*frs2*/);
int __vis_edge16l(void * /*frs1*/, void * /*frs2*/);
int __vis_edge32(void * /*frs1*/, void * /*frs2*/);
int __vis_edge32l(void * /*frs1*/, void * /*frs2*/);

/* Edge handling instructions with negative return values if cc set. */
int __vis_edge8cc(void * /*frs1*/, void * /*frs2*/);
int __vis_edge8lcc(void * /*frs1*/, void * /*frs2*/);
int __vis_edge16cc(void * /*frs1*/, void * /*frs2*/);
int __vis_edge16lcc(void * /*frs1*/, void * /*frs2*/);
int __vis_edge32cc(void * /*frs1*/, void * /*frs2*/);
int __vis_edge32lcc(void * /*frs1*/, void * /*frs2*/);

/* Alignment instructions. */
void *__vis_alignaddr(void * /*rs1*/, int /*rs2*/);
void *__vis_alignaddrl(void * /*rs1*/, int /*rs2*/);
double __vis_faligndata(double /*frs1*/, double /*frs2*/);

/* Partitioned comparison instructions. */
int __vis_fcmple16(double /*frs1*/, double /*frs2*/);
int __vis_fcmpne16(double /*frs1*/, double /*frs2*/);
int __vis_fcmple32(double /*frs1*/, double /*frs2*/);
int __vis_fcmpne32(double /*frs1*/, double /*frs2*/);
int __vis_fcmpgt16(double /*frs1*/, double /*frs2*/);
int __vis_fcmpeq16(double /*frs1*/, double /*frs2*/);
int __vis_fcmpgt32(double /*frs1*/, double /*frs2*/);
int __vis_fcmpeq32(double /*frs1*/, double /*frs2*/);

/* Partitioned multiplication. */
double __vis_fmul8x16_dummy(float /*frs1*/, int /*dummy*/, double /*frs2*/);
#ifdef __ptr64__
double __vis_fmul8x16(float /*frs1*/, double /*frs2*/);
#else  /* __ptr64__ */
#define __vis_fmul8x16(farg,darg) __vis_fmul8x16_dummy((farg),0,(darg))
#endif  /* __ptr64__ */

double __vis_fmul8x16au(float /*frs1*/, float /*frs2*/);
double __vis_fmul8x16al(float /*frs1*/, float /*frs2*/);
double __vis_fmul8sux16(double /*frs1*/, double /*frs2*/);
double __vis_fmul8ulx16(double /*frs1*/, double /*frs2*/);
double __vis_fmuld8ulx16(float /*frs1*/, float /*frs2*/);
double __vis_fmuld8sux16(float /*frs1*/, float /*frs2*/);

/* Partitioned addition & subtraction. */
double __vis_fpadd16(double /*frs1*/, double /*frs2*/);
float __vis_fpadd16s(float /*frs1*/, float /*frs2*/);
double __vis_fpadd32(double /*frs1*/, double /*frs2*/);
float __vis_fpadd32s(float /*frs1*/, float /*frs2*/);
double __vis_fpsub16(double /*frs1*/, double /*frs2*/);
float __vis_fpsub16s(float /*frs1*/, float /*frs2*/);
double __vis_fpsub32(double /*frs1*/, double /*frs2*/);
float __vis_fpsub32s(float /*frs1*/, float /*frs2*/);

/* Pixel packing & clamping. */
float __vis_fpack16(double /*frs2*/);
double __vis_fpack32(double /*frs1*/, double /*frs2*/);
float __vis_fpackfix(double /*frs2*/);

/* Combined pack ops. */
double __vis_fpack16_pair(double /*frs2*/, double /*frs2*/);
double __vis_fpackfix_pair(double /*frs2*/, double /*frs2*/);
void __vis_st2_fpack16(double, double, double *);
void __vis_std_fpack16(double, double, double *);
void __vis_st2_fpackfix(double, double, double *);

double __vis_fpack16_to_hi(double /*frs1*/, double /*frs2*/);
double __vis_fpack16_to_lo(double /*frs1*/, double /*frs2*/);

/* Motion estimation. */
#ifdef __ptr64__
#define __vis_pdist(px1,px2,acc) __vis_pxldist64(acc,px1,px2)
double __vis_pxldist64(double accum /*frd*/, double pxls1 /*frs1*/,
                       double pxls2 /*frs2*/);
#else  /* __ptr64__ */
double __vis_pdist(double /*frs1*/, double /*frs2*/, double /*frd*/);
#endif  /* __ptr64__ */

/* Channel merging. */
double __vis_fpmerge(float /*frs1*/, float /*frs2*/);

/* Pixel expansion. */
double __vis_fexpand(float /*frs2*/);
double __vis_fexpand_hi(double /*frs2*/);
double __vis_fexpand_lo(double /*frs2*/);

/* Bitwise logical operators. */
double __vis_fnor(double /*frs1*/, double /*frs2*/);
float __vis_fnors(float /*frs1*/, float /*frs2*/);
double __vis_fandnot(double /*frs1*/, double /*frs2*/);
float __vis_fandnots(float /*frs1*/, float /*frs2*/);
double __vis_fnot(double /*frs1*/);
float __vis_fnots(float /*frs1*/);
double __vis_fxor(double /*frs1*/, double /*frs2*/);
float __vis_fxors(float /*frs1*/, float /*frs2*/);
double __vis_fnand(double /*frs1*/, double /*frs2*/);
float __vis_fnands(float /*frs1*/, float /*frs2*/);
double __vis_fand(double /*frs1*/, double /*frs2*/);
float __vis_fands(float /*frs1*/, float /*frs2*/);
double __vis_fxnor(double /*frs1*/, double /*frs2*/);
float __vis_fxnors(float /*frs1*/, float /*frs2*/);
double __vis_fsrc(double /*frs1*/);
float __vis_fsrcs(float /*frs1*/);
double __vis_fornot(double /*frs1*/, double /*frs2*/);
float __vis_fornots(float /*frs1*/, float /*frs2*/);
double __vis_for(double /*frs1*/, double /*frs2*/);
float __vis_fors(float /*frs1*/, float /*frs2*/);
double __vis_fzero(void);
float __vis_fzeros(void);
double __vis_fone(void);
float __vis_fones(void);

/* Partial stores. */
//void __vis_stdfa_ASI_PST8P(double /*frd*/, void * /*rs1*/, int /*rmask*/);
//void __vis_stdfa_ASI_PST16P(double /*frd*/, void * /*rs1*/, int /*rmask*/);
//void __vis_stdfa_ASI_PST32P(double /*frd*/, void * /*rs1*/, int /*rmask*/);

//void __vis_stdfa_ASI_PST8PL(double /*frd*/, void * /*rs1*/, int /*rmask*/);
//void __vis_stdfa_ASI_PST16PL(double /*frd*/, void * /*rs1*/, int /*rmask*/);
//void __vis_stdfa_ASI_PST32PL(double /*frd*/, void * /*rs1*/, int /*rmask*/);

void __vis_stdfa_ASI_PST8S(double /*frd*/, void * /*rs1*/, int /*rmask*/);
void __vis_stdfa_ASI_PST16S(double /*frd*/, void * /*rs1*/, int /*rmask*/);
void __vis_stdfa_ASI_PST32S(double /*frd*/, void * /*rs1*/, int /*rmask*/);

void __vis_stdfa_ASI_PST8P_int_pair(void * /*rs1*/, void * /*rs2*/,
                                    void * /*rs3*/, int /*rmask*/);

/* Byte & short stores. */
//void __vis_stdfa_ASI_FL8P(double /*frd*/, void * /*rs1*/);
//void __vis_stdfa_ASI_FL8P_index(double /*frd*/, void * /*rs1*/, long /*index*/);
//void __vis_stdfa_ASI_FL16P(double /*frd*/, void * /*rs1*/);
//void __vis_stdfa_ASI_FL16P_index(double /*frd*/, void * /*rs1*/, long /*index*/);

//void __vis_stdfa_ASI_FL8PL(double /*frd*/, void * /*rs1*/);
//void __vis_stdfa_ASI_FL8PL_index(double /*frd*/, void * /*rs1*/, long /*index*/);
//void __vis_stdfa_ASI_FL16PL(double /*frd*/, void * /*rs1*/);
//void __vis_stdfa_ASI_FL16PL_index(double /*frd*/, void * /*rs1*/, long /*index*/);

void __vis_stdfa_ASI_FL8S(double /*frd*/, void * /*rs1*/);
void __vis_stdfa_ASI_FL16S(double /*frd*/, void * /*rs1*/);
void __vis_stdfa_ASI_FL8SL(double /*frd*/, void * /*rs1*/);
void __vis_stdfa_ASI_FL16SL(double /*frd*/, void * /*rs1*/);

/* Byte & short loads. */
//double __vis_lddfa_ASI_FL8P(void * /*rs1*/);
//double __vis_lddfa_ASI_FL8P_index(void * /*rs1*/, long /*index*/);
//double __vis_lddfa_ASI_FL16P(void * /*rs1*/);
//double __vis_lddfa_ASI_FL16P_index(void * /*rs1*/, long /*index*/);

//double __vis_lddfa_ASI_FL8PL(void * /*rs1*/);
//double __vis_lddfa_ASI_FL8PL_index(void * /*rs1*/, long /*index*/);
//double __vis_lddfa_ASI_FL16PL(void * /*rs1*/);
//double __vis_lddfa_ASI_FL16PL_index(void * /*rs1*/, long /*index*/);

double __vis_lddfa_ASI_FL8S(void * /*rs1*/);
double __vis_lddfa_ASI_FL16S(void * /*rs1*/);
double __vis_lddfa_ASI_FL8SL(void * /*rs1*/);
double __vis_lddfa_ASI_FL16SL(void * /*rs1*/);

double __vis_lddfa_ASI_FL8P_hi(void * /*rs1*/, unsigned int /*index*/);
double __vis_lddfa_ASI_FL8P_lo(void * /*rs1*/, unsigned int /*index*/);

/* Direct write to GSR, read from GSR. */
void __vis_write_gsr32(unsigned int /*GSR*/);
unsigned int __vis_read_gsr32(void);

#define __vis_write_gsr     __vis_write_gsr32
#define __vis_read_gsr      __vis_read_gsr32

/* Voxel texture mapping. */
#ifdef __ptr64__
unsigned long __vis_array8(unsigned long /*rs1*/, int /*rs2*/);
unsigned long __vis_array16(unsigned long /*rs1*/, int /*rs2*/);
unsigned long __vis_array32(unsigned long /*rs1*/, int /*rs2*/);
#elif !defined(_NO_LONGLONG)
unsigned long __vis_array8(unsigned long long /*rs1*/, int /*rs2*/);
unsigned long __vis_array16(unsigned long long /*rs1*/, int /*rs2*/);
unsigned long __vis_array32(unsigned long long /*rs1*/, int /*rs2*/);
#endif  /* __ptr64__ */

/* Register aliasing and type casts. */
float __vis_read_hi(double /*frs1*/);
float __vis_read_lo(double /*frs1*/);
double __vis_write_hi(double /*frs1*/, float /*frs2*/);
double __vis_write_lo(double /*frs1*/, float /*frs2*/);
double __vis_freg_pair(float /*frs1*/, float /*frs2*/);
float __vis_to_float(unsigned int /*value*/);
#if defined (__r2000__) || defined (__r2000plus__)
double __vis_to_double_r2000(unsigned int /*value1*/, unsigned int /*value2*/);
double __vis_to_double_dup_r2000(unsigned int /*value*/);
#else /* defined (__r2000__) || defined (__r2000plus__) */
double __vis_to_double(unsigned int /*value1*/, unsigned int /*value2*/);
double __vis_to_double_dup(unsigned int /*value*/);
#endif /* defined (__r2000__) || defined (__r2000plus__) */

#ifdef __ptr64__
double __vis_ll_to_double(unsigned long /*value*/);
#elif !defined(_NO_LONGLONG)
double __vis_ll_to_double(unsigned long long /*value*/);
#endif  /* __ptr64__ */

/* Direct access to ASI. */
/* normal asi = 0x82, big endian = 0x80, little endian = 0x88 */
unsigned int __vis_read_asi(void);
void __vis_write_asi(unsigned int /*ASI*/);

/* Big/little endian loads. */
float __vis_ldfa_ASI_REG(void * /*rs1*/);
float __vis_ldfa_ASI_P(void * /*rs1*/);
float __vis_ldfa_ASI_P_index(void * /*rs1*/, long /*index*/);
//float __vis_ldfa_ASI_PL(void * /*rs1*/);
//float __vis_ldfa_ASI_PL_index(void * /*rs1*/, long /*index*/);
double __vis_lddfa_ASI_REG(void * /*rs1*/);
double __vis_lddfa_ASI_P(void * /*rs1*/);
double __vis_lddfa_ASI_P_index(void * /*rs1*/, long /*index*/);
//double __vis_lddfa_ASI_PL(void * /*rs1*/);
//double __vis_lddfa_ASI_PL_index(void * /*rs1*/, long /*index*/);

/* Big/little endian stores. */
void __vis_stfa_ASI_REG(float /*frs*/, void * /*rs1*/);
void __vis_stfa_ASI_P(float /*frs*/, void * /*rs1*/);
void __vis_stfa_ASI_P_index(float /*frs*/, void * /*rs1*/, long /*index*/);
void __vis_stfa_ASI_PL(float /*frs*/, void * /*rs1*/);
void __vis_stfa_ASI_PL_index(float /*frs*/, void * /*rs1*/, long /*index*/);
void __vis_stdfa_ASI_REG(double /*frd*/, void * /*rs1*/);
void __vis_stdfa_ASI_P(double /*frd*/, void * /*rs1*/);
void __vis_stdfa_ASI_P_index(double /*frd*/, void * /*rs1*/, long /*index*/);
void __vis_stdfa_ASI_PL(double /*frd*/, void * /*rs1*/);
void __vis_stdfa_ASI_PL_index(double /*frd*/, void * /*rs1*/, long /*index*/);

/* Unsigned short big/little endian loads. */
unsigned short __vis_lduha_ASI_REG(void * /*rs1*/);
unsigned short __vis_lduha_ASI_P(void * /*rs1*/);
unsigned short __vis_lduha_ASI_PL(void * /*rs1*/);
unsigned short __vis_lduha_ASI_P_index(void * /*rs1*/, long /*index*/);
unsigned short __vis_lduha_ASI_PL_index(void * /*rs1*/, long /*index*/);

/* Nicknames for explicit ASI loads and stores. */
#define __vis_st_u8        __vis_stdfa_ASI_FL8P
#define __vis_st_u8_i      __vis_stdfa_ASI_FL8P_index
#define __vis_st_u16       __vis_stdfa_ASI_FL16P
#define __vis_st_u16_i     __vis_stdfa_ASI_FL16P_index

#define __vis_st_u8_le     __vis_stdfa_ASI_FL8PL
#define __vis_st_u8_le_i   __vis_stdfa_ASI_FL8PL_index
#define __vis_st_u16_le    __vis_stdfa_ASI_FL16PL
#define __vis_st_u16_le_i  __vis_stdfa_ASI_FL16PL_index

#define __vis_ld_u8        __vis_lddfa_ASI_FL8P
#define __vis_ld_u8_i      __vis_lddfa_ASI_FL8P_index
#define __vis_ld_u16       __vis_lddfa_ASI_FL16P
#define __vis_ld_u16_i     __vis_lddfa_ASI_FL16P_index

#define __vis_ld_u8_le     __vis_lddfa_ASI_FL8PL
#define __vis_ld_u8_le_i   __vis_lddfa_ASI_FL8PL_index
#define __vis_ld_u16_le    __vis_lddfa_ASI_FL16PL
#define __vis_ld_u16_le_i  __vis_lddfa_ASI_FL16PL_index

#define __vis_pst_8        __vis_stdfa_ASI_PST8P
#define __vis_pst_16       __vis_stdfa_ASI_PST16P
#define __vis_pst_32       __vis_stdfa_ASI_PST32P

#define __vis_pst_8_le     __vis_stdfa_ASI_PST8PL
#define __vis_pst_16_le    __vis_stdfa_ASI_PST16PL
#define __vis_pst_32_le    __vis_stdfa_ASI_PST32PL

#define __vis_ld_f32_asi  __vis_ldfa_ASI_REG
#define __vis_ld_f32      __vis_ldfa_ASI_P
#define __vis_ld_f32_i    __vis_ldfa_ASI_P_index
#define __vis_ld_f32_le   __vis_ldfa_ASI_PL
#define __vis_ld_f32_le_i __vis_ldfa_ASI_PL_index

#define __vis_ld_d64_asi  __vis_lddfa_ASI_REG
#define __vis_ld_d64      __vis_lddfa_ASI_P
#define __vis_ld_d64_i    __vis_lddfa_ASI_P_index
#define __vis_ld_d64_le   __vis_lddfa_ASI_PL
#define __vis_ld_d64_le_i __vis_lddfa_ASI_PL_index

#define __vis_st_f32_asi  __vis_stfa_ASI_REG
#define __vis_st_f32      __vis_stfa_ASI_P
#define __vis_st_f32_i    __vis_stfa_ASI_P_index
#define __vis_st_f32_le   __vis_stfa_ASI_PL
#define __vis_st_f32_le_i __vis_stfa_ASI_PL_index

#define __vis_st_d64_asi  __vis_stdfa_ASI_REG
#define __vis_st_d64      __vis_stdfa_ASI_P
#define __vis_st_d64_i    __vis_stdfa_ASI_P_index
#define __vis_st_d64_le   __vis_stdfa_ASI_PL
#define __vis_st_d64_le_i __vis_stdfa_ASI_PL_index

/* "<" and ">=" may be implemented in terms of ">" and "<=". */
#define __vis_fcmplt16(a,b) __vis_fcmpgt16((b),(a))
#define __vis_fcmplt32(a,b) __vis_fcmpgt32((b),(a))
#define __vis_fcmpge16(a,b) __vis_fcmple16((b),(a))
#define __vis_fcmpge32(a,b) __vis_fcmple32((b),(a))

/* Prefetch */
void __vis_prefetch_read(void * /*address*/);
void __vis_prefetch_write(void * /*address*/);

#pragma no_side_effect(__vis_prefetch_read)
#pragma no_side_effect(__vis_prefetch_write)

/* Nonfaulting load */
char __vis_ldsba_ASI_PNF(void * /*rs1*/);
char __vis_ldsba_ASI_PNF_index(void * /*rs1*/, long /*index*/);
char __vis_ldsba_ASI_PNFL(void * /*rs1*/);
char __vis_ldsba_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

//unsigned char __vis_lduba_ASI_PNF(void * /*rs1*/);
//unsigned char __vis_lduba_ASI_PNF_index(void * /*rs1*/, long /*index*/);
//unsigned char __vis_lduba_ASI_PNFL(void * /*rs1*/);
//unsigned char __vis_lduba_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

short __vis_ldsha_ASI_PNF(void * /*rs1*/);
short __vis_ldsha_ASI_PNF_index(void * /*rs1*/, long /*index*/);
short __vis_ldsha_ASI_PNFL(void * /*rs1*/);
short __vis_ldsha_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

//unsigned short __vis_lduha_ASI_PNF(void * /*rs1*/);
//unsigned short __vis_lduha_ASI_PNF_index(void * /*rs1*/, long /*index*/);
//unsigned short __vis_lduha_ASI_PNFL(void * /*rs1*/);
//unsigned short __vis_lduha_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

int __vis_ldswa_ASI_PNF(void * /*rs1*/);
int __vis_ldswa_ASI_PNF_index(void * /*rs1*/, long /*index*/);
int __vis_ldswa_ASI_PNFL(void * /*rs1*/);
int __vis_ldswa_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

//unsigned int __vis_lduwa_ASI_PNF(void * /*rs1*/);
//unsigned int __vis_lduwa_ASI_PNF_index(void * /*rs1*/, long /*index*/);
//unsigned int __vis_lduwa_ASI_PNFL(void * /*rs1*/);
//unsigned int __vis_lduwa_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

#ifdef __ptr64__
long __vis_ldxa_ASI_PNF(void * /*rs1*/);
long __vis_ldxa_ASI_PNF_index(void * /*rs1*/, long /*index*/);
long __vis_ldxa_ASI_PNFL(void * /*rs1*/);
long __vis_ldxa_ASI_PNFL_index(void * /*rs1*/, long /*index*/);
#elif !defined(_NO_LONGLONG)
long long __vis_ldda_ASI_PNF(void * /*rs1*/);
long long __vis_ldda_ASI_PNF_index(void * /*rs1*/, long /*index*/);
long long __vis_ldda_ASI_PNFL(void * /*rs1*/);
long long __vis_ldda_ASI_PNFL_index(void * /*rs1*/, long /*index*/);
#endif  /* __ptr64__ */

//float __vis_ldfa_ASI_PNF(void * /*rs1*/);
//float __vis_ldfa_ASI_PNF_index(void * /*rs1*/, long /*index*/);
//float __vis_ldfa_ASI_PNFL(void * /*rs1*/);
//float __vis_ldfa_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

//double __vis_lddfa_ASI_PNF(void * /*rs1*/);
//double __vis_lddfa_ASI_PNF_index(void * /*rs1*/, long /*index*/);
//double __vis_lddfa_ASI_PNFL(void * /*rs1*/);
//double __vis_lddfa_ASI_PNFL_index(void * /*rs1*/, long /*index*/);

#define __vis_ld_s8_nf            __vis_ldsba_ASI_PNF
#define __vis_ld_s8_nf_i          __vis_ldsba_ASI_PNF_index
#define __vis_ld_s8_nf_le         __vis_ldsba_ASI_PNFL
#define __vis_ld_s8_nf_le_i       __vis_ldsba_ASI_PNFL_index

#define __vis_ld_u8_nf            __vis_lduba_ASI_PNF
#define __vis_ld_u8_nf_i          __vis_lduba_ASI_PNF_index
#define __vis_ld_u8_nf_le         __vis_lduba_ASI_PNFL
#define __vis_ld_u8_nf_le_i       __vis_lduba_ASI_PNFL_index

#define __vis_ld_s16_nf           __vis_ldsha_ASI_PNF
#define __vis_ld_s16_nf_i         __vis_ldsha_ASI_PNF_index
#define __vis_ld_s16_nf_le        __vis_ldsha_ASI_PNFL
#define __vis_ld_s16_nf_le_i      __vis_ldsha_ASI_PNFL_index

#define __vis_ld_u16_nf           __vis_lduha_ASI_PNF
#define __vis_ld_u16_nf_i         __vis_lduha_ASI_PNF_index
#define __vis_ld_u16_nf_le        __vis_lduha_ASI_PNFL
#define __vis_ld_u16_nf_le_i      __vis_lduha_ASI_PNFL_index

#define __vis_ld_s32_nf           __vis_ldswa_ASI_PNF
#define __vis_ld_s32_nf_i         __vis_ldswa_ASI_PNF_index
#define __vis_ld_s32_nf_le        __vis_ldswa_ASI_PNFL
#define __vis_ld_s32_nf_le_i      __vis_ldswa_ASI_PNFL_index

#define __vis_ld_u32_nf           __vis_lduwa_ASI_PNF
#define __vis_ld_u32_nf_i         __vis_lduwa_ASI_PNF_index
#define __vis_ld_u32_nf_le        __vis_lduwa_ASI_PNFL
#define __vis_ld_u32_nf_le_i      __vis_lduwa_ASI_PNFL_index

#ifdef __ptr64__

#define __vis_ld_s64_nf           __vis_ldxa_ASI_PNF
#define __vis_ld_s64_nf_i         __vis_ldxa_ASI_PNF_index
#define __vis_ld_s64_nf_le        __vis_ldxa_ASI_PNFL
#define __vis_ld_s64_nf_le_i      __vis_ldxa_ASI_PNFL_index

#define __vis_ld_u64_nf           __vis_ldxa_ASI_PNF
#define __vis_ld_u64_nf_i         __vis_ldxa_ASI_PNF_index
#define __vis_ld_u64_nf_le        __vis_ldxa_ASI_PNFL
#define __vis_ld_u64_nf_le_i      __vis_ldxa_ASI_PNFL_index

#elif !defined(_NO_LONGLONG)

#define __vis_ld_s64_nf           __vis_ldda_ASI_PNF
#define __vis_ld_s64_nf_i         __vis_ldda_ASI_PNF_index
#define __vis_ld_s64_nf_le        __vis_ldda_ASI_PNFL
#define __vis_ld_s64_nf_le_i      __vis_ldda_ASI_PNFL_index

#define __vis_ld_u64_nf           __vis_ldda_ASI_PNF
#define __vis_ld_u64_nf_i         __vis_ldda_ASI_PNF_index
#define __vis_ld_u64_nf_le        __vis_ldda_ASI_PNFL
#define __vis_ld_u64_nf_le_i      __vis_ldda_ASI_PNFL_index

#endif  /* __ptr64__ */

#define __vis_ld_f32_nf           __vis_ldfa_ASI_PNF
#define __vis_ld_f32_nf_i         __vis_ldfa_ASI_PNF_index
#define __vis_ld_f32_nf_le        __vis_ldfa_ASI_PNFL
#define __vis_ld_f32_nf_le_i      __vis_ldfa_ASI_PNFL_index

#define __vis_ld_d64_nf           __vis_lddfa_ASI_PNF
#define __vis_ld_d64_nf_i         __vis_lddfa_ASI_PNF_index
#define __vis_ld_d64_nf_le        __vis_lddfa_ASI_PNFL
#define __vis_ld_d64_nf_le_i      __vis_lddfa_ASI_PNFL_index

/* Instructions implemented through builtins */

/* Partial stores. */
#define __vis_stdfa_ASI_PST8P(val, addr, mask)         \
    __builtin_pstoreasi_64f (val, addr, mask, 0xc0)
#define __vis_stdfa_ASI_PST16P(val, addr, mask)        \
    __builtin_pstoreasi_64f (val, addr, mask, 0xc2)
#define __vis_stdfa_ASI_PST32P(val, addr, mask)        \
    __builtin_pstoreasi_64f (val, addr, mask, 0xc4)

#define __vis_stdfa_ASI_PST8PL(val, addr, mask)        \
    __builtin_pstoreasi_64f (val, addr, mask, 0xc8)
#define __vis_stdfa_ASI_PST16PL(val, addr, mask)       \
    __builtin_pstoreasi_64f (val, addr, mask, 0xca)
#define __vis_stdfa_ASI_PST32PL(val, addr, mask)       \
    __builtin_pstoreasi_64f (val, addr, mask, 0xcc)

/* Byte & short stores. */
#define __vis_stdfa_ASI_FL8P(val, addr)                \
    __builtin_storeasi_64f (val, addr, 0, 0xd0)
#define __vis_stdfa_ASI_FL8P_index(val, addr, index)   \
    __builtin_storeasi_64f (val, addr, index, 0xd0)

#define __vis_stdfa_ASI_FL16P(val, addr)               \
    __builtin_storeasi_64f (val, addr, 0, 0xd2)
#define __vis_stdfa_ASI_FL16P_index(val, addr, index)  \
    __builtin_storeasi_64f (val, addr, index, 0xd2)

#define __vis_stdfa_ASI_FL8PL(val, addr)               \
    __builtin_storeasi_64f (val, addr, 0, 0xd8)
#define __vis_stdfa_ASI_FL8PL_index(val, addr, index)  \
    __builtin_storeasi_64f (val, addr, index, 0xd8)

#define __vis_stdfa_ASI_FL16PL(val, addr)              \
    __builtin_storeasi_64f (val, addr, 0, 0xda)
#define __vis_stdfa_ASI_FL16PL_index(val, addr, index) \
    __builtin_storeasi_64f (val, addr, index, 0xda)

/* Byte & short loads. */
#define __vis_lddfa_ASI_FL8P(addr)                     \
    __builtin_loadasi_64f (addr, 0, 0xd0)
#define __vis_lddfa_ASI_FL8P_index(addr, index)        \
    __builtin_loadasi_64f (addr, index, 0xd0)

#define __vis_lddfa_ASI_FL16P(addr)                    \
    __builtin_loadasi_64f (addr, 0, 0xd2)
#define __vis_lddfa_ASI_FL16P_index(addr, index)       \
    __builtin_loadasi_64f (addr, index, 0xd2)

#define __vis_lddfa_ASI_FL8PL(addr)                    \
    __builtin_loadasi_64f (addr, 0, 0xd8)
#define __vis_lddfa_ASI_FL8PL_index(addr, index)       \
    __builtin_loadasi_64f (addr, index, 0xd8)

#define __vis_lddfa_ASI_FL16PL(addr)                   \
    __builtin_loadasi_64f (addr, 0, 0xda)
#define __vis_lddfa_ASI_FL16PL_index(addr, index)      \
    __builtin_loadasi_64f (addr, index, 0xda)

/* Big/little endian loads. */
#define __vis_ldfa_ASI_PL(addr)                        \
    __builtin_loadasi_32f (addr, 0, 0x88)
#define __vis_ldfa_ASI_PL_index(addr, index)           \
    __builtin_loadasi_32f (addr, index, 0x88)

#define __vis_lddfa_ASI_PL(addr)                       \
    __builtin_loadasi_64f (addr, 0, 0x88)
#define __vis_lddfa_ASI_PL_index(addr, index)          \
    __builtin_loadasi_64f (addr, index, 0x88)

/* Nonfaulting load */
#define __vis_lduba_ASI_PNF(addr)                      \
    __builtin_loadasi_8u (addr, 0, 0x82)
#define __vis_lduba_ASI_PNF_index(addr, index)         \
    __builtin_loadasi_8u (addr, index, 0x82)
#define __vis_lduba_ASI_PNFL(addr)                     \
    __builtin_loadasi_8u (addr, 0, 0x8a)
#define __vis_lduba_ASI_PNFL_index(addr, index)        \
    __builtin_loadasi_8u (addr, index, 0x8a)

#define __vis_lduha_ASI_PNF(addr)                      \
    __builtin_loadasi_16u (addr, 0, 0x82)
#define __vis_lduha_ASI_PNF_index(addr, index)         \
    __builtin_loadasi_16u (addr, index, 0x82)
#define __vis_lduha_ASI_PNFL(addr)                     \
    __builtin_loadasi_16u (addr, 0, 0x8a)
#define __vis_lduha_ASI_PNFL_index(addr, index)        \
    __builtin_loadasi_16u (addr, index, 0x8a)

#define __vis_lduwa_ASI_PNF(addr)                      \
    __builtin_loadasi_32u (addr, 0, 0x82)
#define __vis_lduwa_ASI_PNF_index(addr, index)         \
    __builtin_loadasi_32u (addr, index, 0x82)
#define __vis_lduwa_ASI_PNFL(addr)                     \
    __builtin_loadasi_32u (addr, 0, 0x8a)
#define __vis_lduwa_ASI_PNFL_index(addr, index)        \
    __builtin_loadasi_32u (addr, index, 0x8a)

#define __vis_ldfa_ASI_PNF(addr)                       \
    __builtin_loadasi_32f (addr, 0, 0x82)
#define __vis_ldfa_ASI_PNF_index(addr, index)          \
    __builtin_loadasi_32f (addr, index, 0x82)
#define __vis_ldfa_ASI_PNFL(addr)                      \
    __builtin_loadasi_32f (addr, 0, 0x8a)
#define __vis_ldfa_ASI_PNFL_index(addr, index)         \
    __builtin_loadasi_32f (addr, index, 0x8a)

#define __vis_lddfa_ASI_PNF(addr)                      \
    __builtin_loadasi_64f (addr, 0, 0x82)
#define __vis_lddfa_ASI_PNF_index(addr, index)         \
    __builtin_loadasi_64f (addr, index, 0x82)
#define __vis_lddfa_ASI_PNFL(addr)                     \
    __builtin_loadasi_64f (addr, 0, 0x8a)
#define __vis_lddfa_ASI_PNFL_index(addr, index)        \
    __builtin_loadasi_64f (addr, index, 0x8a)

#if __VIS >= 0x200

/* Edge handling instructions which do not set the integer condition codes */
int __vis_edge8n(void * /*rs1*/, void * /*rs2*/);
int __vis_edge8ln(void * /*rs1*/, void * /*rs2*/);
int __vis_edge16n(void * /*rs1*/, void * /*rs2*/);
int __vis_edge16ln(void * /*rs1*/, void * /*rs2*/);
int __vis_edge32n(void * /*rs1*/, void * /*rs2*/);
int __vis_edge32ln(void * /*rs1*/, void * /*rs2*/);

#define __vis_edge8       __vis_edge8n
#define __vis_edge8l      __vis_edge8ln
#define __vis_edge16      __vis_edge16n
#define __vis_edge16l     __vis_edge16ln
#define __vis_edge32      __vis_edge32n
#define __vis_edge32l     __vis_edge32ln

/* Byte mask and shuffle instructions */
void __vis_write_bmask(unsigned int /*rs1*/, unsigned int /*rs2*/);
double __vis_bshuffle(double /*frs1*/, double /*frs2*/);

/* Graphics status register */
unsigned int __vis_read_bmask(void);

#ifdef __ptr64__
unsigned long __vis_read_gsr64(void);
void __vis_write_gsr64(unsigned long /* GSR */);
#elif !defined(_NO_LONGLONG)
unsigned long long __vis_read_gsr64(void);
void __vis_write_gsr64(unsigned long long /* GSR */);
#endif  /* __ptr64__ */

#endif  /* __VIS >= 0x200 */

#if __VIS >= 0x300

/* Single precision floating point multiply-add instructions */
float __vis_fmadds_r1000(float /*frs1*/, float /*frs2*/, float /*frs3*/);
float __vis_fmsubs_r1000(float /*frs1*/, float /*frs2*/, float /*frs3*/);
float __vis_fnmadds_r1000(float /*frs1*/, float /*frs2*/, float /*frs3*/);
float __vis_fnmsubs_r1000(float /*frs1*/, float /*frs2*/, float /*frs3*/);

/* Double precision floating point multiply-add instructions */
double __vis_fmaddd_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_fmsubd_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_fnmaddd_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_fnmsubd_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);

/* Single precision floating point partitioned multiply-add instructions */
double __vis_pfmadds_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_pfmsubs_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_pfnmadds_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_pfnmsubs_r1000(double /*frs1*/, double /*frs2*/, double /*frs3*/);

/* Single precision floating point partitioned arithmetic */
double __vis_pfabss_r1000(double /*frs2*/);
double __vis_pfnegs_r1000(double /*frs2*/);
double __vis_pfadds_r1000(double /*frs1*/, double /*frs2*/);
double __vis_pfsubs_r1000(double /*frs1*/, double /*frs2*/);
double __vis_pfmuls_r1000(double /*frs1*/, double /*frs2*/);

#if defined (__r2000__) || defined (__r2000plus__)

/* Partitioned signed comparison instructions. */
int __vis_fpcmpeq8_r2000(double /*frs1*/, double /*frs2*/);
int __vis_fpcmpne8_r2000(double /*frs1*/, double /*frs2*/);

/* Partitioned unsigned comparison instructions. */
int __vis_fpcmpule8_r2000(double /*frs1*/, double /*frs2*/);
int __vis_fpcmpugt8_r2000(double /*frs1*/, double /*frs2*/);

/* Partitioned addition & subtraction with saturation. */
double __vis_fpadds16_r2000(double /*frs1*/, double /*frs2*/);
float __vis_fpadds16s_r2000(float /*frs1*/, float /*frs2*/);
double __vis_fpadds32_r2000(double /*frs1*/, double /*frs2*/);
float __vis_fpadds32s_r2000(float /*frs1*/, float /*frs2*/);
double __vis_fpsubs16_r2000(double /*frs1*/, double /*frs2*/);
float __vis_fpsubs16s_r2000(float /*frs1*/, float /*frs2*/);
double __vis_fpsubs32_r2000(double /*frs1*/, double /*frs2*/);
float __vis_fpsubs32s_r2000(float /*frs1*/, float /*frs2*/);

/* Partitioned shift instructions. */
double __vis_fsll16_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fsll32_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fsrl16_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fsrl32_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fslas16_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fslas32_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fsra16_r2000(double /*frs1*/, double /*frs2*/);
double __vis_fsra32_r2000(double /*frs1*/, double /*frs2*/);

/* Leading zero count instruction. */
#ifdef __ptr64__
unsigned long __vis_lzcnt_r2000(unsigned long /*value*/);
#elif !defined(_NO_LONGLONG)
unsigned long long __vis_lzcnt_r2000(unsigned long long /*value*/);
#endif  /* __ptr64__ */

/* Combining two single fp-registers into double one. */
double __vis_fmerge32_r2000(float /*frs1*/, float /*frs2*/);

/* Copy 32-bit (single-precision) floating-point register to
   integer register (with sign extension) */
int __vis_movstosw_r2000(float /* frs1 */);

/* Copy 32-bit (single-precision) floating-point register to
   integer register (no sign extension) */
unsigned int __vis_movstouw_r2000(float /* frs1 */);

/* Copy 64-bit (double-precision) floating-point register to
   64-bit integer register */
#ifdef __ptr64__
unsigned long __vis_movdtox_r2000(double /* frs1 */);
#elif !defined(_NO_LONGLONG)
unsigned long long __vis_movdtox_r2000(double /* frs1 */);
#endif  /* __ptr64__ */

/* Copy 32-bit integer register to 32-bit (single-precision)
   floating-point register */
float __vis_movwtos_r2000(int /* rs1 */);

/* Copy 64-bit integer register to 64-bit (double-precision)
   floating-point register */
#ifdef __ptr64__
double __vis_movxtod_r2000(unsigned long /* rs1 */);
#elif !defined(_NO_LONGLONG)
double __vis_movxtod_r2000(unsigned long long /* rs1 */);
#endif  /* __ptr64__ */

#ifdef __r2000plus__

/* 16-bit partitioned checksum instruction */
double __vis_fchksm16_r2000plus(double /*frs1*/, double /*frs2*/);

/* 16-bit partitioned average instruction */
double __vis_fmean16_r2000plus(double /*frs1*/, double /*frs2*/);

/* Distance between eight 8-bit components (with no accumulation) instruction */
long __vis_pdistn_r2000plus(double /*frs1*/, double /*frs2*/);

/* Bitwise (XOR) multiply instructions */
#ifdef __ptr64__
unsigned long __vis_xmulx_r2000plus(unsigned long /*rs1*/, unsigned long /*rs2*/);
unsigned long __vis_xmulxhi_r2000plus(unsigned long /*rs1*/, unsigned long /*rs2*/);
#elif !defined(_NO_LONGLONG)
unsigned long long __vis_xmulx_r2000plus(unsigned long long /*rs1*/, unsigned long long /*rs2*/);
unsigned long long __vis_xmulxhi_r2000plus(unsigned long long /*rs1*/, unsigned long long /*rs2*/);
#endif  /* __ptr64__ */

/* 64-bit integer addition & subtraction instructions */
double __vis_fpadd64_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpsub64_r2000plus(double /*frs1*/, double /*frs2*/);

#if __VIS >= 0x400

/* Partioned integer addition & subtraction of eight 8-bit values instructions */
double __vis_fpadd8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpsub8_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partioned integer addition & subtraction with saturation of
   eight 8-bit signed values instructions */
double __vis_fpadds8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpsubs8_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partioned integer addition & subtraction with saturation
   of eight 8-bit unsigned values instructions */
double __vis_fpaddus8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpsubus8_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partioned integer addition & subtraction with saturation of
   four 16-bit unsigned values instructions */
double __vis_fpaddus16_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpsubus16_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partitioned 8-bit signed comparison instructions */
int __vis_fpcmple8_r2000plus(double /*frs1*/, double /*frs2*/);
int __vis_fpcmpgt8_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partitioned 16-bit unsigned comparison instructions */
int __vis_fpcmpule16_r2000plus(double /*frs1*/, double /*frs2*/);
int __vis_fpcmpugt16_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partitioned 32-bit unsigned comparison instructions */
int __vis_fpcmpule32_r2000plus(double /*frs1*/, double /*frs2*/);
int __vis_fpcmpugt32_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partitioned signed integer maximum/minimum instructions */
double __vis_fpmax8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmin8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmax16_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmin16_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmax32_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmin32_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partitioned unsigned integer maximum/minimum instructions */
double __vis_fpmaxu8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpminu8_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmaxu16_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpminu16_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpmaxu32_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpminu32_r2000plus(double /*frs1*/, double /*frs2*/);

#endif  /* VIS >= 0x400 */

/* Partitioned cyclic left shift instructions */
double __vis_fpcsl32_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpcsl64_r2000plus(double /*frs1*/, double /*frs2*/);

/* Partitioned cyclic right shift instructions */
double __vis_fpcsr32_r2000plus(double /*frs1*/, double /*frs2*/);
double __vis_fpcsr64_r2000plus(double /*frs1*/, double /*frs2*/);

#endif /* __r2000plus__ */

#endif /* defined (__r2000__) || defined (__r2000plus__) */

#else  /* VIS >= 0x300 */

/* Single precision floating point multiply-add instructions */
float __vis_fmadds_ultrasparc(float /*frs1*/, float /*frs2*/, float /*frs3*/);
float __vis_fmsubs_ultrasparc(float /*frs1*/, float /*frs2*/, float /*frs3*/);
float __vis_fnmadds_ultrasparc(float /*frs1*/, float /*frs2*/, float /*frs3*/);
float __vis_fnmsubs_ultrasparc(float /*frs1*/, float /*frs2*/, float /*frs3*/);

/* Double precision floating point multiply-add instructions */
double __vis_fmaddd_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_fmsubd_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_fnmaddd_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_fnmsubd_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);

/* Single precision floating point partitioned multiply-add instructions */
double __vis_pfmadds_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_pfmsubs_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_pfnmadds_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);
double __vis_pfnmsubs_ultrasparc(double /*frs1*/, double /*frs2*/, double /*frs3*/);

/* Single precision floating point partitioned arithmetic */
double __vis_pfabss_ultrasparc(double /*frs2*/);
double __vis_pfnegs_ultrasparc(double /*frs2*/);
double __vis_pfadds_ultrasparc(double /*frs1*/, double /*frs2*/);
double __vis_pfsubs_ultrasparc(double /*frs1*/, double /*frs2*/);
double __vis_pfmuls_ultrasparc(double /*frs1*/, double /*frs2*/);

#endif  /* VIS >= 0x300 */

#ifdef __cplusplus
} // End of extern "C"
#endif /* __cplusplus */

#endif /* VIS_H */
