Skip to content

Commit 1b9337f

Browse files
author
Mandeep Singh Grang
committed
[COFF, ARM64] Add __byteswap intrinsics
Reviewers: rnk, efriedma, ssijaric, TomTan, haripul Reviewed By: efriedma Subscribers: javed.absar, cfe-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D56685 llvm-svn: 351147
1 parent fe5e5dc commit 1b9337f

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

clang/lib/Headers/intrin.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,16 @@ unsigned __int64 __getReg(int);
566566
long _InterlockedAdd(long volatile *Addend, long Value);
567567
int _ReadStatusReg(int);
568568
void _WriteStatusReg(int, int);
569+
570+
static inline unsigned short _byteswap_ushort (unsigned short val) {
571+
return __builtin_bswap16(val);
572+
}
573+
static inline unsigned long _byteswap_ulong (unsigned long val) {
574+
return __builtin_bswap32(val);
575+
}
576+
static inline unsigned __int64 _byteswap_uint64 (unsigned __int64 val) {
577+
return __builtin_bswap64(val);
578+
}
569579
#endif
570580

571581
/*----------------------------------------------------------------------------*\
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
1-
// RUN: %clang_cc1 -triple arm64-windows \
1+
// REQUIRES: aarch64-registered-target
2+
3+
// RUN: %clang_cc1 -triple arm64-windows -O1 \
24
// RUN: -fms-compatibility -fms-compatibility-version=17.00 \
35
// RUN: -ffreestanding -fsyntax-only -Werror \
4-
// RUN: -isystem %S/Inputs/include %s -S -o - 2>&1 | FileCheck %s
5-
6-
// REQUIRES: aarch64-registered-target
6+
// RUN: -isystem %S/Inputs/include %s -S -o - -emit-llvm 2>&1 \
7+
// RUN: | FileCheck %s
78

89
#include <intrin.h>
910

10-
void f() {
11-
// CHECK: nop
11+
void check_nop() {
12+
// CHECK: "nop"
1213
__nop();
1314
}
15+
16+
unsigned short check_byteswap_ushort(unsigned short val) {
17+
// CHECK: call i16 @llvm.bswap.i16(i16 %val)
18+
return _byteswap_ushort(val);
19+
}
20+
21+
unsigned long check_byteswap_ulong(unsigned long val) {
22+
// CHECK: call i32 @llvm.bswap.i32(i32 %val)
23+
return _byteswap_ulong(val);
24+
}
25+
26+
unsigned __int64 check_byteswap_uint64(unsigned __int64 val) {
27+
// CHECK: call i64 @llvm.bswap.i64(i64 %val)
28+
return _byteswap_uint64(val);
29+
}

0 commit comments

Comments
 (0)