forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xtensa] Implement CTLZ/CTTZ with NSAU
Close #77
- Loading branch information
Showing
5 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=xtensa -mcpu=esp32 -verify-machineinstrs < %s \ | ||
; RUN: | FileCheck -check-prefix=XTENSA %s | ||
|
||
declare i32 @llvm.ctlz.i32(i32, i1) | ||
|
||
define i32 @test1_ctlz(i32 %v) { | ||
; XTENSA-LABEL: test1_ctlz: | ||
; XTENSA: # %bb.0: | ||
; XTENSA-NEXT: entry a1, 32 | ||
; XTENSA-NEXT: .cfi_def_cfa_offset 32 | ||
; XTENSA-NEXT: nsau a2, a2 | ||
; XTENSA-NEXT: retw.n | ||
%1 = tail call i32 @llvm.ctlz.i32(i32 %v, i1 false) | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @test2_ctlz(i32 %v) { | ||
; XTENSA-LABEL: test2_ctlz: | ||
; XTENSA: # %bb.0: | ||
; XTENSA-NEXT: entry a1, 32 | ||
; XTENSA-NEXT: .cfi_def_cfa_offset 32 | ||
; XTENSA-NEXT: nsau a2, a2 | ||
; XTENSA-NEXT: retw.n | ||
%cnt = tail call i32 @llvm.ctlz.i32(i32 %v, i1 true) | ||
%tobool = icmp eq i32 %v, 0 | ||
%cond = select i1 %tobool, i32 32, i32 %cnt | ||
ret i32 %cond | ||
} | ||
|
||
declare i32 @llvm.cttz.i32(i32, i1) | ||
|
||
define i32 @test1_cttz(i32 %v) { | ||
; XTENSA-LABEL: test1_cttz: | ||
; XTENSA: # %bb.0: | ||
; XTENSA-NEXT: entry a1, 32 | ||
; XTENSA-NEXT: .cfi_def_cfa_offset 32 | ||
; XTENSA-NEXT: movi.n a8, -1 | ||
; XTENSA-NEXT: xor a8, a2, a8 | ||
; XTENSA-NEXT: addi.n a9, a2, -1 | ||
; XTENSA-NEXT: and a8, a8, a9 | ||
; XTENSA-NEXT: nsau a8, a8 | ||
; XTENSA-NEXT: movi.n a9, 32 | ||
; XTENSA-NEXT: sub a2, a9, a8 | ||
; XTENSA-NEXT: retw.n | ||
%1 = tail call i32 @llvm.cttz.i32(i32 %v, i1 false) | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @test2_cttz(i32 %v) { | ||
; XTENSA-LABEL: test2_cttz: | ||
; XTENSA: # %bb.0: | ||
; XTENSA-NEXT: entry a1, 32 | ||
; XTENSA-NEXT: .cfi_def_cfa_offset 32 | ||
; XTENSA-NEXT: movi.n a8, -1 | ||
; XTENSA-NEXT: xor a8, a2, a8 | ||
; XTENSA-NEXT: addi.n a9, a2, -1 | ||
; XTENSA-NEXT: and a8, a8, a9 | ||
; XTENSA-NEXT: nsau a8, a8 | ||
; XTENSA-NEXT: movi.n a9, 32 | ||
; XTENSA-NEXT: sub a2, a9, a8 | ||
; XTENSA-NEXT: retw.n | ||
%cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true) | ||
%tobool = icmp eq i32 %v, 0 | ||
%cond = select i1 %tobool, i32 32, i32 %cnt | ||
ret i32 %cond | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# RUN: llvm-mc %s -triple=xtensa -mattr=+nsa -show-encoding \ | ||
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s | ||
|
||
# Instruction format RRR | ||
# CHECK-INST: nsa a3, a2 | ||
# CHECK: encoding: [0x30,0xe2,0x40] | ||
nsa a3, a2 | ||
|
||
# Instruction format RRR | ||
# CHECK-INST: nsau a3, a2 | ||
# CHECK: encoding: [0x30,0xf2,0x40] | ||
nsau a3, a2 |