From: Gabe Black Date: Fri, 23 Oct 2020 03:00:54 +0000 (-0700) Subject: util: Add the "sum" method to the java and lua m5 util wrappers. X-Git-Tag: develop-gem5-snapshot~388 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bd7ac98819150edf565da3003928886911395345;p=gem5.git util: Add the "sum" method to the java and lua m5 util wrappers. Change-Id: Id55dec87af3e0fc89da6c5471a2aa02443063108 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28175 Tested-by: kokoro Reviewed-by: Gabe Black Reviewed-by: Pouya Fotouhi Maintainer: Gabe Black --- diff --git a/util/m5/src/jni/gem5Op.java b/util/m5/src/jni/gem5Op.java index 11403bfbb..968c4a24a 100644 --- a/util/m5/src/jni/gem5Op.java +++ b/util/m5/src/jni/gem5Op.java @@ -52,6 +52,7 @@ public class gem5Op { public native void exit(long ns_delay); public native void fail(long ns_delay, long code); + public native long sum(long a, long b, long c, long d, long e, long f); public native long init_param(long key_str1, long key_str2); public native void checkpoint(long ns_delay, long ns_period); public native void reset_stats(long ns_delay, long ns_period); diff --git a/util/m5/src/jni_gem5Op.c b/util/m5/src/jni_gem5Op.c index 83a9512e2..fe8d41d9b 100644 --- a/util/m5/src/jni_gem5Op.c +++ b/util/m5/src/jni_gem5Op.c @@ -104,6 +104,16 @@ Java_jni_gem5Op_fail(JNIEnv *env, jobject obj, jlong j_ns_delay, jlong j_code) m5_fail(j_ns_delay, j_code); } +JNIEXPORT jlong JNICALL +Java_jni_gem5Op_sum(JNIEnv *env, jobject obj, jlong a, jlong b, jlong c, + jlong d, jlong e, jlong f) +{ + uint64_t result = m5_sum(a, b, c, d, e, f); + if (result & 0x8000000000000000ULL) + printf("Truncated return value from sum() to 63 bits\n"); + return (result & 0x7FFFFFFFFFFFFFFFULL); +} + JNIEXPORT jlong JNICALL Java_jni_gem5Op_init_1param(JNIEnv *env, jobject obj, jlong j_key_str1, jlong j_key_str2) diff --git a/util/m5/src/lua_gem5Op.cc b/util/m5/src/lua_gem5Op.cc index 3c8b20454..e4d1d76f8 100644 --- a/util/m5/src/lua_gem5Op.cc +++ b/util/m5/src/lua_gem5Op.cc @@ -100,6 +100,20 @@ do_exit(lua_State *L) return 0; } +static int +do_sum(lua_State *L) +{ + uint64_t a = lua_tointeger(L, 1); + uint64_t b = lua_tointeger(L, 2); + uint64_t c = lua_tointeger(L, 3); + uint64_t d = lua_tointeger(L, 4); + uint64_t e = lua_tointeger(L, 5); + uint64_t f = lua_tointeger(L, 6); + uint64_t sum = m5_sum(a, b, c, d, e, f); + lua_pushinteger(L, sum); + return 1; +} + static int do_fail(lua_State *L) {