xref: /openbmc/qemu/target/arm/op_addsub.h (revision d1e8e8ecc3d2a1a72504912d671f1cbbac1b06e5)
1*fcf5ef2aSThomas Huth /*
2*fcf5ef2aSThomas Huth  * ARMv6 integer SIMD operations.
3*fcf5ef2aSThomas Huth  *
4*fcf5ef2aSThomas Huth  * Copyright (c) 2007 CodeSourcery.
5*fcf5ef2aSThomas Huth  * Written by Paul Brook
6*fcf5ef2aSThomas Huth  *
7*fcf5ef2aSThomas Huth  * This code is licensed under the GPL.
8*fcf5ef2aSThomas Huth  */
9*fcf5ef2aSThomas Huth 
10*fcf5ef2aSThomas Huth #ifdef ARITH_GE
11*fcf5ef2aSThomas Huth #define GE_ARG , void *gep
12*fcf5ef2aSThomas Huth #define DECLARE_GE uint32_t ge = 0
13*fcf5ef2aSThomas Huth #define SET_GE *(uint32_t *)gep = ge
14*fcf5ef2aSThomas Huth #else
15*fcf5ef2aSThomas Huth #define GE_ARG
16*fcf5ef2aSThomas Huth #define DECLARE_GE do{}while(0)
17*fcf5ef2aSThomas Huth #define SET_GE do{}while(0)
18*fcf5ef2aSThomas Huth #endif
19*fcf5ef2aSThomas Huth 
20*fcf5ef2aSThomas Huth #define RESULT(val, n, width) \
21*fcf5ef2aSThomas Huth     res |= ((uint32_t)(glue(glue(uint,width),_t))(val)) << (n * width)
22*fcf5ef2aSThomas Huth 
HELPER(glue (PFX,add16))23*fcf5ef2aSThomas Huth uint32_t HELPER(glue(PFX,add16))(uint32_t a, uint32_t b GE_ARG)
24*fcf5ef2aSThomas Huth {
25*fcf5ef2aSThomas Huth     uint32_t res = 0;
26*fcf5ef2aSThomas Huth     DECLARE_GE;
27*fcf5ef2aSThomas Huth 
28*fcf5ef2aSThomas Huth     ADD16(a, b, 0);
29*fcf5ef2aSThomas Huth     ADD16(a >> 16, b >> 16, 1);
30*fcf5ef2aSThomas Huth     SET_GE;
31*fcf5ef2aSThomas Huth     return res;
32*fcf5ef2aSThomas Huth }
33*fcf5ef2aSThomas Huth 
HELPER(glue (PFX,add8))34*fcf5ef2aSThomas Huth uint32_t HELPER(glue(PFX,add8))(uint32_t a, uint32_t b GE_ARG)
35*fcf5ef2aSThomas Huth {
36*fcf5ef2aSThomas Huth     uint32_t res = 0;
37*fcf5ef2aSThomas Huth     DECLARE_GE;
38*fcf5ef2aSThomas Huth 
39*fcf5ef2aSThomas Huth     ADD8(a, b, 0);
40*fcf5ef2aSThomas Huth     ADD8(a >> 8, b >> 8, 1);
41*fcf5ef2aSThomas Huth     ADD8(a >> 16, b >> 16, 2);
42*fcf5ef2aSThomas Huth     ADD8(a >> 24, b >> 24, 3);
43*fcf5ef2aSThomas Huth     SET_GE;
44*fcf5ef2aSThomas Huth     return res;
45*fcf5ef2aSThomas Huth }
46*fcf5ef2aSThomas Huth 
HELPER(glue (PFX,sub16))47*fcf5ef2aSThomas Huth uint32_t HELPER(glue(PFX,sub16))(uint32_t a, uint32_t b GE_ARG)
48*fcf5ef2aSThomas Huth {
49*fcf5ef2aSThomas Huth     uint32_t res = 0;
50*fcf5ef2aSThomas Huth     DECLARE_GE;
51*fcf5ef2aSThomas Huth 
52*fcf5ef2aSThomas Huth     SUB16(a, b, 0);
53*fcf5ef2aSThomas Huth     SUB16(a >> 16, b >> 16, 1);
54*fcf5ef2aSThomas Huth     SET_GE;
55*fcf5ef2aSThomas Huth     return res;
56*fcf5ef2aSThomas Huth }
57*fcf5ef2aSThomas Huth 
HELPER(glue (PFX,sub8))58*fcf5ef2aSThomas Huth uint32_t HELPER(glue(PFX,sub8))(uint32_t a, uint32_t b GE_ARG)
59*fcf5ef2aSThomas Huth {
60*fcf5ef2aSThomas Huth     uint32_t res = 0;
61*fcf5ef2aSThomas Huth     DECLARE_GE;
62*fcf5ef2aSThomas Huth 
63*fcf5ef2aSThomas Huth     SUB8(a, b, 0);
64*fcf5ef2aSThomas Huth     SUB8(a >> 8, b >> 8, 1);
65*fcf5ef2aSThomas Huth     SUB8(a >> 16, b >> 16, 2);
66*fcf5ef2aSThomas Huth     SUB8(a >> 24, b >> 24, 3);
67*fcf5ef2aSThomas Huth     SET_GE;
68*fcf5ef2aSThomas Huth     return res;
69*fcf5ef2aSThomas Huth }
70*fcf5ef2aSThomas Huth 
HELPER(glue (PFX,subaddx))71*fcf5ef2aSThomas Huth uint32_t HELPER(glue(PFX,subaddx))(uint32_t a, uint32_t b GE_ARG)
72*fcf5ef2aSThomas Huth {
73*fcf5ef2aSThomas Huth     uint32_t res = 0;
74*fcf5ef2aSThomas Huth     DECLARE_GE;
75*fcf5ef2aSThomas Huth 
76*fcf5ef2aSThomas Huth     ADD16(a, b >> 16, 0);
77*fcf5ef2aSThomas Huth     SUB16(a >> 16, b, 1);
78*fcf5ef2aSThomas Huth     SET_GE;
79*fcf5ef2aSThomas Huth     return res;
80*fcf5ef2aSThomas Huth }
81*fcf5ef2aSThomas Huth 
HELPER(glue (PFX,addsubx))82*fcf5ef2aSThomas Huth uint32_t HELPER(glue(PFX,addsubx))(uint32_t a, uint32_t b GE_ARG)
83*fcf5ef2aSThomas Huth {
84*fcf5ef2aSThomas Huth     uint32_t res = 0;
85*fcf5ef2aSThomas Huth     DECLARE_GE;
86*fcf5ef2aSThomas Huth 
87*fcf5ef2aSThomas Huth     SUB16(a, b >> 16, 0);
88*fcf5ef2aSThomas Huth     ADD16(a >> 16, b, 1);
89*fcf5ef2aSThomas Huth     SET_GE;
90*fcf5ef2aSThomas Huth     return res;
91*fcf5ef2aSThomas Huth }
92*fcf5ef2aSThomas Huth 
93*fcf5ef2aSThomas Huth #undef GE_ARG
94*fcf5ef2aSThomas Huth #undef DECLARE_GE
95*fcf5ef2aSThomas Huth #undef SET_GE
96*fcf5ef2aSThomas Huth #undef RESULT
97*fcf5ef2aSThomas Huth 
98*fcf5ef2aSThomas Huth #undef ARITH_GE
99*fcf5ef2aSThomas Huth #undef PFX
100*fcf5ef2aSThomas Huth #undef ADD16
101*fcf5ef2aSThomas Huth #undef SUB16
102*fcf5ef2aSThomas Huth #undef ADD8
103*fcf5ef2aSThomas Huth #undef SUB8
104