Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vxrm intrinsics #36

Closed
HanKuanChen opened this issue Aug 25, 2020 · 7 comments
Closed

Support vxrm intrinsics #36

HanKuanChen opened this issue Aug 25, 2020 · 7 comments

Comments

@HanKuanChen
Copy link
Contributor

May we have intrinsics to set vxrm?
Follow fenv

#define VE_TONEARESTUP   /*implementation defined*/
#define VE_TONEARESTEVEN /*implementation defined*/
#define VE_DOWNWARD      /*implementation defined*/
#define VE_TOODD         /*implementation defined*/

int vegetxround();
int vesetxround(int round);
return 0 on success, non-zero otherwise.
@zakk0610
Copy link
Collaborator

We had purposed vread_csr and vwrite_csr interface here, but it is not included in intrinsic RFC and function list yet

enum RVV_CSR {
  RVV_VSTART = 0,
  RVV_VXSAT,
  RVV_VXRM,
  RVV_VCSR,
};

unsigned long vread_csr(enum RVV_CSR csr);
void vwrite_csr(enum RVV_CSR csr, unsigned long value);

Any comments or suggestions will be appreciated.

@arcbbb
Copy link

arcbbb commented Aug 27, 2020

I prefer HK's idea having specific API to read/set vector rounding mode.
In that way user doesn't need to know the format of CSR in order to read the content.

@kito-cheng
Copy link
Collaborator

I prefer high-level API for that too, the only concern to me is it's not intrinsic.

@HanKuanChen
Copy link
Contributor Author

@kito-cheng do you think this is a semantic intrinsic?
If so, I think we should add this.

@HanKuanChen
Copy link
Contributor Author

I propose a new pull request #46 and a simple implementation here.

#define VE_TONEARESTUP 0
#define VE_TONEARESTEVEN 1
#define VE_DOWNWARD 2
#define VE_TOODD 3
// Each of these macro constants expands to a nonnegative integer constant expression.

// return 0 on success, non-zero otherwise.
int vesetxround(int round)
{
	switch(round)
	{
	case VE_TONEARESTUP:
	case VE_TONEARESTEVEN:
	case VE_DOWNWARD:
	case VE_TOODD:
		asm volatile("csrw vxrm,%z0"::"rJ"(round));
		return 0;
	default:
		return -1;
	}
}

// return the current rounding macro, negative value if the rounding mode cannot be determined.
int vegetxround(void)
{
	int vxrm;
	asm volatile("csrr %0,vxrm":"=r"(vxrm));
	switch(vxrm)
	{
	case VE_TONEARESTUP:
	case VE_TONEARESTEVEN:
	case VE_DOWNWARD:
	case VE_TOODD:
		return vxrm;
	default:
		return -1;
	}
}

// clear vxsat
inline void veclearxsat(void)
{
	asm volatile("csrw vxsat,x0");
}

// return 1 if vxsat is set, 0 otherwise.
inline int vetestxsat(void)
{
	int vxsat;
	asm volatile("csrr %0,vxsat":"=r"(vxsat));
	return vxsat;
}

@ebahapo
Copy link

ebahapo commented Nov 9, 2020

Rather, shouldn't a library that supported RVV set vxrm as part of supporting fenv.h instead?

@kito-cheng
Copy link
Collaborator

We define vxrm and vxsat as call clobber in psABI, so this proposal become impossible to implement now.

[1] riscv-non-isa/riscv-elf-psabi-doc#294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants