Revision 1497c961 target-arm/op_helper.c

b/target-arm/op_helper.c
18 18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 19
 */
20 20
#include "exec.h"
21
#include "helpers.h"
21 22

  
22 23
void raise_exception(int tt)
23 24
{
......
303 304
    env = saved_env;
304 305
}
305 306
#endif
307

  
308
#define SIGNBIT (uint32_t)0x80000000
309
uint32_t HELPER(add_setq)(uint32_t a, uint32_t b)
310
{
311
    uint32_t res = a + b;
312
    if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT))
313
        env->QF = 1;
314
    return res;
315
}
316

  
317
uint32_t HELPER(add_saturate)(uint32_t a, uint32_t b)
318
{
319
    uint32_t res = a + b;
320
    if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT)) {
321
        env->QF = 1;
322
        res = ~(((int32_t)a >> 31) ^ SIGNBIT);
323
    }
324
    return res;
325
}
326

  
327
uint32_t HELPER(sub_saturate)(uint32_t a, uint32_t b)
328
{
329
    uint32_t res = a - b;
330
    if (((res ^ a) & SIGNBIT) && ((a ^ b) & SIGNBIT)) {
331
        env->QF = 1;
332
        res = ~(((int32_t)a >> 31) ^ SIGNBIT);
333
    }
334
    return res;
335
}
336

  
337
uint32_t HELPER(double_saturate)(int32_t val)
338
{
339
    uint32_t res;
340
    if (val >= 0x40000000) {
341
        res = ~SIGNBIT;
342
        env->QF = 1;
343
    } else if (val <= (int32_t)0xc0000000) {
344
        res = SIGNBIT;
345
        env->QF = 1;
346
    } else {
347
        res = val << 1;
348
    }
349
    return res;
350
}
351

  
352
uint32_t HELPER(add_usaturate)(uint32_t a, uint32_t b)
353
{
354
    uint32_t res = a + b;
355
    if (res < a) {
356
        env->QF = 1;
357
        res = ~0;
358
    }
359
    return res;
360
}
361

  
362
uint32_t HELPER(sub_usaturate)(uint32_t a, uint32_t b)
363
{
364
    uint32_t res = a - b;
365
    if (res > a) {
366
        env->QF = 1;
367
        res = 0;
368
    }
369
    return res;
370
}
371

  

Also available in: Unified diff