#include "hwacha.h"
+#include "mulhi.h"
#include "decode_hwacha_ut.h"
#include "softfloat.h"
#include "platform.h" // softfloat isNaNF32UI, etc.
#include <cstring>
#include <string>
#include <map>
-#include <stdint.h>
+#include <cstdint>
class lfsr_t
{
# error spike requires a two''s-complement c++ implementation
#endif
-#define __STDC_LIMIT_MACROS
-#include <stdint.h>
+#include <cstdint>
#include <string.h>
#include "encoding.h"
#include "config.h"
#include "common.h"
#include <cinttypes>
-typedef int int128_t __attribute__((mode(TI)));
-typedef unsigned int uint128_t __attribute__((mode(TI)));
-
typedef int64_t sreg_t;
typedef uint64_t reg_t;
typedef uint64_t freg_t;
#include <assert.h>
#include <stdio.h>
-#include <stdint.h>
+#include <cstdint>
int main() {
uint64_t x = 123, y = 456, z = 0;
#include "mmu.h"
+#include "mulhi.h"
#include "softfloat.h"
#include "platform.h" // softfloat isNaNF32UI, etc.
#include "internals.h" // ditto
-if(xpr64)
-{
- int64_t a = RS1;
- int64_t b = RS2;
- WRITE_RD((int128_t(a) * int128_t(b)) >> 64);
-}
+if (xpr64)
+ WRITE_RD(mulh(RS1, RS2));
else
WRITE_RD(sext32((sext32(RS1) * sext32(RS2)) >> 32));
-if(xpr64)
-{
- int64_t a = RS1;
- uint64_t b = RS2;
- WRITE_RD((int128_t(a) * uint128_t(b)) >> 64);
-}
+if (xpr64)
+ WRITE_RD(mulhsu(RS1, RS2));
else
WRITE_RD(sext32((sext32(RS1) * reg_t((uint32_t)RS2)) >> 32));
-if(xpr64)
- WRITE_RD((uint128_t(RS1) * uint128_t(RS2)) >> 64);
+if (xpr64)
+ WRITE_RD(mulhu(RS1, RS2));
else
WRITE_RD(sext32(((uint64_t)(uint32_t)RS1 * (uint64_t)(uint32_t)RS2) >> 32));
#ifndef _MEMTRACER_H
#define _MEMTRACER_H
-#include <stdint.h>
+#include <cstdint>
#include <string.h>
#include <vector>
--- /dev/null
+#ifndef _RISCV_MULHI_H
+#define _RISCV_MULHI_H
+
+#include <cstdint>
+
+inline uint64_t mulhu(uint64_t a, uint64_t b)
+{
+ uint64_t t;
+ uint32_t y1, y2, y3;
+ uint64_t a0 = (uint32_t)a, a1 = a >> 32;
+ uint64_t b0 = (uint32_t)b, b1 = b >> 32;
+
+ t = a1*b0 + ((a0*b0) >> 32);
+ y1 = t;
+ y2 = t >> 32;
+
+ t = a0*b1 + y1;
+ y1 = t;
+
+ t = a1*b1 + y2 + (t >> 32);
+ y2 = t;
+ y3 = t >> 32;
+
+ return ((uint64_t)y3 << 32) | y2;
+}
+
+inline int64_t mulh(int64_t a, int64_t b)
+{
+ int negate = (a < 0) != (b < 0);
+ uint64_t res = mulhu(a < 0 ? -a : a, b < 0 ? -b : b);
+ return negate ? ~res + (a * b == 0) : res;
+}
+
+inline int64_t mulhsu(int64_t a, uint64_t b)
+{
+ int negate = a < 0;
+ uint64_t res = mulhu(a < 0 ? -a : a, b);
+ return negate ? ~res + (a * b == 0) : res;
+}
+
+#endif
rocc.h \
dummy-rocc.h \
insn_template.h \
+ mulhi.h \
riscv_precompiled_hdrs = \
insn_template.h \