Skip to content

Commit db01efa

Browse files
wuxyintellijinxia
authored andcommitted
HV:treewide:Update return type for function fls64 and clz64
Change the return type of function fls64 and clz64 as uint16_t; When the input is zero, INVALID_ID_INDEX is returned; Update temporary variable type and return value check of caller when it call fls64 or clz64; When input value is zero, clz64 returns 64 directly. V1-->V2: INVALID_BIT_INDEX instead of INVALID_NUMBER; Partly revert apicv_pending_intr udpates; Add type conversion as needed; Coding style fixing. V2-->V3: Correct type conversion; fls64 return INVALID_BIT_INDEX directly when the input value is zero. V3-->V4: No updates for this part in PATCH V4. Note: For instruction "bsrq", destination register value is undefined when source register value is zero. Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 13d354e commit db01efa

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ apicv_pending_intr(struct vlapic *vlapic, __unused uint32_t *vecptr)
21042104
for (i = 3; i >= 0; i--) {
21052105
pirval = pir_desc->pir[i];
21062106
if (pirval != 0) {
2107-
vpr = (i * 64 + fls64(pirval)) & 0xF0U;
2107+
vpr = (((uint32_t)(i * 64) + (uint32_t)fls64(pirval)) & 0xF0U);
21082108
return (vpr > ppr);
21092109
}
21102110
}
@@ -2188,7 +2188,7 @@ apicv_inject_pir(struct vlapic *vlapic)
21882188
struct pir_desc *pir_desc;
21892189
struct lapic_regs *lapic;
21902190
uint64_t val, pirval;
2191-
int rvi, pirbase = -1, i;
2191+
uint16_t rvi, pirbase = 0U, i;
21922192
uint16_t intr_status_old, intr_status_new;
21932193
struct lapic_reg *irr = NULL;
21942194

@@ -2197,17 +2197,16 @@ apicv_inject_pir(struct vlapic *vlapic)
21972197
return;
21982198

21992199
pirval = 0;
2200-
pirbase = -1;
22012200
lapic = vlapic->apic_page;
22022201
irr = &lapic->irr[0];
22032202

2204-
for (i = 0; i < 4; i++) {
2203+
for (i = 0U; i < 4U; i++) {
22052204
val = atomic_readandclear64((long *)&pir_desc->pir[i]);
22062205
if (val != 0) {
2207-
irr[i * 2].val |= val;
2208-
irr[(i * 2) + 1].val |= val >> 32;
2206+
irr[i * 2U].val |= val;
2207+
irr[(i * 2U) + 1U].val |= val >> 32;
22092208

2210-
pirbase = 64*i;
2209+
pirbase = 64U*i;
22112210
pirval = val;
22122211
}
22132212
}

hypervisor/include/lib/bits.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ static inline uint16_t fls(uint32_t value)
7474
return (uint16_t)ret;
7575
}
7676

77-
static inline int fls64(unsigned long value)
77+
static inline uint16_t fls64(uint64_t value)
7878
{
79-
int ret;
80-
81-
asm volatile("bsrq %1,%q0"
79+
uint64_t ret = 0UL;
80+
if (value == 0UL)
81+
return (INVALID_BIT_INDEX);
82+
asm volatile("bsrq %1,%0"
8283
: "=r" (ret)
83-
: "rm" (value), "0" (-1));
84-
return ret;
84+
: "rm" (value));
85+
return (uint16_t)ret;
8586
}
8687

8788
/**
@@ -152,9 +153,13 @@ static inline uint16_t clz(uint32_t value)
152153
*
153154
* @return The number of leading zeros in 'value'.
154155
*/
155-
static inline int clz64(unsigned long value)
156+
static inline uint16_t clz64(uint64_t value)
156157
{
157-
return (63 - fls64(value));
158+
if (value == 0UL)
159+
return 64U;
160+
else{
161+
return (63U - fls64(value));
162+
}
158163
}
159164

160165
/*

hypervisor/lib/div.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res)
9494
*/
9595

9696
/* align divisor and dividend. */
97-
bits = clz64(divisor) - clz64(dividend);
97+
bits = (uint64_t)(clz64(divisor) - clz64(dividend));
9898
divisor <<= bits;
9999
mask = 1UL << bits;
100100
/* division loop */

0 commit comments

Comments
 (0)