![]() |
[URL]https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf[/URL]
[quote]We did not include special instruction set support for overflow checks on integer arithmetic operations in the base instruction set, as many overflow checks can be cheaply implemented using RISC-V branches. Overflow checking for unsigned addition requires only a single additional branch instruction after the addition: add t0, t1, t2; bltu t0, t1, overflow. For signed addition, if one operand’s sign is known, overflow checking requires only a single branch after the addition: addi t0, t1, +imm; blt t0, t1, overflow. This covers the common case of addition with an immediate operand. For general signed addition, three additional instructions after the addition are required, leveraging the observation that the sum should be less than one of the operands if and only if the other operand is negative. add t0, t1, t2 slti t3, t2, 0 slt t4, t0, t1 bne t3, t4, overflow[/quote]Oh dear. I wonder how many designers have contemplated an extension that adds an a=a+b instruction that uses the spare register as a carry flag (if arbitrary operand modification is even possible) (if limiting to three operands is as desirable as it appears to be). |
2 Attachment(s)
Attached is a "src" zip for the Longan Nano.
I plan to combine the assembly code into one big function. Anyone willing to look a the assembly code and make recommendations for improvement will be praised. Here is main.cpp: [CODE] /* Performs the test (x+2)^(n+1)==5 mod(n,x^2+1) for n==3 mod 4. 32 bit numbers only using 2x array of 32 bits. */ #include <Arduino.h> typedef unsigned int num[2]; extern "C" { #include "lcd/lcd.h" extern void from32to16(num *r, unsigned int *a); extern void from16to32(unsigned int *r, num *a); extern void getPartial(unsigned int *r, unsigned int *a); extern void getBigNum(num *r, unsigned int *a); extern void setMask(unsigned int *r, unsigned int *a); extern void mulit(num *r, num *a, num *b, num *npar); extern void addit(num *r, num *a, num *b, num *nbig); extern void negit(num *r, num *a, num *nbig, num *npar); extern void cpy(num *r, num *a); extern void shr(unsigned int *a); extern int prp(unsigned int *n); } void setup() { Lcd_Init(); LCD_Clear(BLACK); } unsigned int n=7; unsigned int np1, mask, nbigInt, nparInt, S, T; num s, t, tmp1, tmp2, tmp3, ndw, npar, nbig; char buf[80]; void loop() { getBigNum(&nbig, &n); getPartial(&nparInt, &n); from32to16(&npar, &nparInt); s[1]=0;s[0]=1; t[1]=0;t[0]=2; np1=n+1; setMask(&mask, &np1); while (mask) { mulit(&tmp2, &s, &t, &npar); addit(&tmp1, &tmp2, &tmp2, &npar); negit(&tmp3, &s, &nbig, &npar); addit(&tmp2, &tmp3, &t, &npar); addit(&tmp3, &s, &t, &npar); mulit(&t, &tmp2, &tmp3, &npar); cpy(&s, &tmp1); if(np1&mask){ addit(&tmp2, &s, &s, &npar); addit(&tmp1, &tmp2, &t, &npar); addit(&tmp3, &t, &t, &npar); negit(&tmp2, &s, &nbig, &npar); addit(&t, &tmp3, &tmp2, &npar); cpy(&s, &tmp1); } mask=(mask>>1); //shr(&mask); } from16to32(&S, &s); from16to32(&T, &t); S%=n; T%=n; if(S==0&&T==5) { sprintf(buf, "%u Is prime!", n); LCD_ShowString(10, 20, (u8 const *) buf, GREEN); } else { sprintf(buf, "%u composite", n); LCD_ShowString(10, 20, (u8 const *) buf, RED); } if (n==4294967291) return; n+=4; delay(1000); } [/CODE] |
There is now [URL="https://mangopi.org/mangopi_mqpro"]Mango Pi MQ Pro[/URL] which is a single 64-bit RISC-V SoC (system on a chip) board with mini hdmi and usb-c outputs, wifi and bluetooth. Early doors, yet will just about run a light weight desktop environment.
Cheap on AliExpress but at rip off price on eBay. |
| All times are UTC. The time now is 16:10. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.