Hello Maintainers:<br><br>Please help review this patch when you have 
time.<br><br>Thanks.<br><br>On 06/13/2015 09:19 PM, Chen Gang wrote:<br>&gt; 
The related instructions are exception, cntlz, cnttz, shufflebytes, and<br>&gt; 
add_saturate.<br>&gt;<br>&gt; Signed-off-by: Chen Gang 
&lt;gang.chen.5...@gmail.com&gt;<br>&gt; ---<br>&gt;  target-tilegx/helper.c | 
83 ++++++++++++++++++++++++++++++++++++++++++++++++++<br>&gt;  
target-tilegx/helper.h |  5 +++<br>&gt;  2 files changed, 88 
insertions(+)<br>&gt;  create mode 100644 target-tilegx/helper.c<br>&gt;  
create mode 100644 target-tilegx/helper.h<br>&gt;<br>&gt; diff --git 
a/target-tilegx/helper.c b/target-tilegx/helper.c<br>&gt; new file mode 
100644<br>&gt; index 0000000..5ab41cd<br>&gt; --- /dev/null<br>&gt; +++ 
b/target-tilegx/helper.c<br>&gt; @@ -0,0 +1,83 @@<br>&gt; +/*<br>&gt; + * QEMU 
TILE-Gx helpers<br>&gt; + *<br>&gt; + *  Copyright (c) 2015 Chen Gang<br>&gt; + 
*<br>&gt; + * This library is free software; you can redistribute it 
and/or<br>&gt; + * modify it under the terms of the GNU Lesser General 
Public<br>&gt; + * License as published by the Free Software Foundation; 
either<br>&gt; + * version 2.1 of the License, or (at your option) any later 
version.<br>&gt; + *<br>&gt; + * This library is distributed in the hope that 
it will be useful,<br>&gt; + * but WITHOUT ANY WARRANTY; without even the 
implied warranty of<br>&gt; + * MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.  See the GNU<br>&gt; + * Lesser General Public License for more 
details.<br>&gt; + *<br>&gt; + * You should have received a copy of the GNU 
Lesser General Public<br>&gt; + * License along with this library; if not, 
see<br>&gt; + * &lt;http://www.gnu.org/licenses/lgpl-2.1.html&gt;<br>&gt; + 
*/<br>&gt; +<br>&gt; +#include "cpu.h"<br>&gt; +#include 
"qemu-common.h"<br>&gt; +#include "exec/helper-proto.h"<br>&gt; +<br>&gt; 
+#define SIGNBIT32 0x80000000<br>&gt; +<br>&gt; +int64_t 
helper_add_saturate(CPUTLGState *env, uint64_t rsrc, uint64_t rsrcb)<br>&gt; 
+{<br>&gt; +    uint32_t rdst = rsrc + rsrcb;<br>&gt; +<br>&gt; +    if (((rdst 
^ rsrc) &amp; SIGNBIT32) &amp;&amp; !((rsrc ^ rsrcb) &amp; SIGNBIT32)) 
{<br>&gt; +        rdst = ~(((int32_t)rsrc &gt;&gt; 31) ^ SIGNBIT32);<br>&gt; + 
   }<br>&gt; +<br>&gt; +    return (int64_t)rdst;<br>&gt; +}<br>&gt; +<br>&gt; 
+void helper_exception(CPUTLGState *env, uint32_t excp)<br>&gt; +{<br>&gt; +    
CPUState *cs = CPU(tilegx_env_get_cpu(env));<br>&gt; +<br>&gt; +    
cs-&gt;exception_index = excp;<br>&gt; +    cpu_loop_exit(cs);<br>&gt; 
+}<br>&gt; +<br>&gt; +uint64_t helper_cntlz(uint64_t arg)<br>&gt; +{<br>&gt; +  
  return clz64(arg);<br>&gt; +}<br>&gt; +<br>&gt; +uint64_t 
helper_cnttz(uint64_t arg)<br>&gt; +{<br>&gt; +    return ctz64(arg);<br>&gt; 
+}<br>&gt; +<br>&gt; +/*<br>&gt; + * Functional Description<br>&gt; + *     
uint64_t a = rf[SrcA];<br>&gt; + *     uint64_t b = rf[SrcB];<br>&gt; + *     
uint64_t d = rf[Dest];<br>&gt; + *     uint64_t output = 0;<br>&gt; + *     
unsigned int counter;<br>&gt; + *     for (counter = 0; counter &lt; (WORD_SIZE 
/ BYTE_SIZE); counter++)<br>&gt; + *     {<br>&gt; + *         int sel = 
getByte (b, counter) &amp; 0xf;<br>&gt; + *         uint8_t byte = (sel &lt; 8) 
? getByte (d, sel) : getByte (a, (sel - 8));<br>&gt; + *         output = 
setByte (output, counter, byte);<br>&gt; + *     }<br>&gt; + *     rf[Dest] = 
output;<br>&gt; + */<br>&gt; +uint64_t helper_shufflebytes(uint64_t rdst, 
uint64_t rsrc, uint64_t rsrcb)<br>&gt; +{<br>&gt; +    uint64_t vdst = 
0;<br>&gt; +    int count;<br>&gt; +<br>&gt; +    for (count = 0; count &lt; 
64; count += 8) {<br>&gt; +        uint64_t sel = rsrcb &gt;&gt; count;<br>&gt; 
+        uint64_t src = (sel &amp; 8) ? rsrc : rdst;<br>&gt; +        vdst |= 
((src &gt;&gt; ((sel &amp; 7) * 8)) &amp; 0xff) &lt;&lt; count;<br>&gt; +    
}<br>&gt; +<br>&gt; +    return vdst;<br>&gt; +}<br>&gt; diff --git 
a/target-tilegx/helper.h b/target-tilegx/helper.h<br>&gt; new file mode 
100644<br>&gt; index 0000000..1411c19<br>&gt; --- /dev/null<br>&gt; +++ 
b/target-tilegx/helper.h<br>&gt; @@ -0,0 +1,5 @@<br>&gt; 
+DEF_HELPER_2(exception, noreturn, env, i32)<br>&gt; +DEF_HELPER_FLAGS_1(cntlz, 
TCG_CALL_NO_RWG_SE, i64, i64)<br>&gt; +DEF_HELPER_FLAGS_1(cnttz, 
TCG_CALL_NO_RWG_SE, i64, i64)<br>&gt; +DEF_HELPER_FLAGS_3(shufflebytes, 
TCG_CALL_NO_RWG_SE, i64, i64, i64, i64)<br>&gt; +DEF_HELPER_3(add_saturate, 
s64, env, i64, i64)<br>&gt;<br><br>--<br>Chen Gang<br><br>Open, share, and 
attitude like air, water, and life which God blessed<br>                        
            

Reply via email to