# US 9,436,469 B2 · Methods to optimize a program loop via vector instructions using a shuffle table and a mask store table

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 9,436,469 B2
- Document ID: US9436469B2
- Status: Granted
- Kind: B2
- Application number: 13/976,162
- Filed: 2011-12-15
- Published: 2013-12-19
- Granted: 2016-09-06
- Earliest claimed: 2011-12-15
- Assignees: Intel Corporation
- Applicants: Tal Uliel; Elmoustapha Ould-Ahmedvall; Bret T. Toll
- Inventors: Tal Uliel; Elmoustapha Ould-Ahmedvall; Bret T. Toll
- Web page: https://patentgrep.com/patent/US9436469B2

## CPC

- G06F 9/30032: {Movement instructions, e.g. MOVE, SHIFT, ROTATE, SHUFFLE}
- G06F 9/30: Arrangements for executing machine instructions, e.g. instruction decode (for executing microinstructions G06F9/22)
- G06F 9/30036: {Instructions to perform operations on packed data, e.g. vector, tile or matrix operations}
- G06F 9/30038: {using a mask}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

According to one embodiment, a code optimizer is configured to receive first code having a program loop implemented with scalar instructions to store values of a first array to a second array based on values of a third array. The code optimizer is configured to generate second code representing the program loop with vector instructions including a shuffle instruction and a store instruction, the store instruction to shuffle using a shuffle table elements of the first array based on the second array in a vector manner, the store instruction to store using a mask store table the shuffled elements in the third array in a vector manner.

## Claims

### Claim 1

A computer-implemented method, comprising:
receiving first code having a program loop implemented with scalar instructions to store values of a first array to a second array based on values of a third array; and
generating second code representing the program loop with vector instructions, the second code including
a shuffle instruction to shuffle elements of the first array based on the third array using a shuffle table in a vector manner, and
a store instruction to store the shuffled elements of the first array in the second array using a mask store table in a vector manner.

### Claim 2 (depends on 1)

The method of claim 1, wherein the second code further comprises instructions to
compare elements of the third array with a predetermined threshold, generating a comparison result, and
generate a mask based on the comparison result, the elements of the first array to be shuffled based on the mask.

### Claim 3 (depends on 2)

The method of claim 2, wherein the second code further comprises an instruction to load elements of the shuffle table selected based on the mask, the elements of the first array to be shuffled via the shuffle instruction based on the selected elements of the shuffle table.

### Claim 4 (depends on 2)

The method of claim 2, wherein the second code further comprises an instruction to load elements of the mask store table selected based on the mask, the shuffled elements of the first array to be stored via the mask store instruction based on the selected elements of the mask store table.

### Claim 5 (depends on 4)

The method of claim 4, wherein the selected elements of the mask store table are determined based on a number of bits of the mask that have a predetermined logical value.

### Claim 6 (depends on 2)

The method of claim 2, wherein the second code further comprises an instruction to store the predetermined threshold in a vector register, the elements of the first array to be compared with values stored in the vector register using a vector compare instruction.

### Claim 7 (depends on 2)

The method of claim 2, wherein the mask is generated based on sign bits of the comparison result stored in a vector register.

### Claim 8

A non-transitory computer-readable storage medium having instructions stored therein, which when executed by a computer, cause the computer to perform a method, the method comprising:
receiving first code having a program loop implemented with scalar instructions to store values of a first array to a second array based on values of a third array; and
generating second code representing the program loop with vector instructions, the second code including
a shuffle instruction to shuffle elements of the first array based on the third array using a shuffle table in a vector manner, and
a store instruction to store the shuffled elements of the first array in the second array using a mask store table in a vector manner.

### Claim 9 (depends on 8)

The non-transitory computer-readable storage medium of claim 8, wherein the second code further comprises instructions to
compare elements of the third array with a predetermined threshold, generating a comparison result, and
generate a mask based on the comparison result, the elements of the first array to be shuffled based on the mask.

### Claim 10 (depends on 9)

The non-transitory computer-readable storage medium of claim 9, wherein the second code further comprises an instruction to load elements of the shuffle table selected based on the mask, the elements of the first array to be shuffled via the shuffle instruction based on the selected elements of the shuffle table.

### Claim 11 (depends on 9)

The non-transitory computer-readable storage medium of claim 9, wherein the second code further comprises an instruction to load elements of the mask store table selected based on the mask, the shuffled elements of the first array to be stored via the mask store instruction based on the selected elements of the mask store table.

### Claim 12 (depends on 11)

The non-transitory computer-readable storage medium of claim 11, wherein the selected elements of the mask store table are determined based on a number of bits of the mask that have a predetermined logical value.

### Claim 13 (depends on 9)

The non-transitory computer-readable storage medium of claim 9, wherein the second code further comprises an instruction to store the predetermined threshold in a vector register, the elements of the first array to be compared with values stored in the vector register using a vector compare instruction.

### Claim 14 (depends on 9)

The non-transitory computer-readable storage medium of claim 9, wherein the mask is generated based on sign bits of the comparison result stored in a vector register.

### Claim 15

An apparatus, comprising:
a memory to store a shuffle table and a mask store table; and
a code optimizer to receive first code having a program loop implemented with scalar instructions to store values of a first array to a second array based on values of a third array and to generate second code representing the program loop with vector instructions, the second code including
a shuffle instruction to shuffle elements of the first array based on the third array using the shuffle table in a vector manner, and
a store instruction to store the shuffled elements of the first array in the second array using the mask store table in a vector manner.

### Claim 16 (depends on 15)

The apparatus of claim 15, wherein the second code further comprises instructions to
compare elements of the third array with a predetermined threshold, generating a comparison result, and
generate a mask based on the comparison result, the elements of the first array to be shuffled based on the mask.

### Claim 17 (depends on 16)

The apparatus of claim 16, wherein the second code further comprises an instruction to load elements of the shuffle table selected based on the mask, the elements of the first array to be shuffled via the shuffle instruction based on the selected elements of the shuffle table.

### Claim 18 (depends on 16)

The apparatus of claim 16, wherein the second code further comprises an instruction to load elements of the mask store table selected based on the mask, the shuffled elements of the first array to be stored via the mask store instruction based on the selected elements of the mask store table.

### Claim 19 (depends on 18)

The apparatus of claim 18, wherein the selected elements of the mask store table are determined based on a number of bits of the mask that have a predetermined logical value and a mask bit is a most significant bit in each element of the mask.

### Claim 20 (depends on 16)

The apparatus of claim 16, wherein the second code further comprises an instruction to store the predetermined threshold in a vector register, the elements of the first array to be compared with values stored in the vector register using a vector compare instruction.
