-
Notifications
You must be signed in to change notification settings - Fork 434
Introduce SIMD hint annotations and propagate them through the bytecode translator #4718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
liannacasper
wants to merge
24
commits into
master
from
codex/add-auto-vectorization-for-array-access
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d652298
Refine SIMD docs with real loop example and anti-pattern FAQ
liannacasper f94afc9
Add SIMD hint readiness diagnostics for verbose translator runs
liannacasper 2b12085
Validate SIMD width hints before storing translator metadata
liannacasper cdb33b7
Emit SIMD width hint in generated C and test it
liannacasper b589082
Enforce SIMD annotation validity in translator
liannacasper 27777a7
Emit NEON target pragmas for SIMD-eligible methods
liannacasper e53638f
Revert NEON pragma emission to fix benchmark crash
liannacasper 44a33ba
Reintroduce SIMD pragmas behind opt-in guard
liannacasper cde14f2
Add weak SIMD hook dispatch for eligible translated methods
liannacasper 7b2e32f
Add explicit SIMD Java API with scalar fallback
liannacasper 50489dc
Expand explicit SIMD API and wire Base64 SIMD path
liannacasper 521529e
Always enable SIMD API path and fold isSupported in translator
liannacasper d94c9c0
Simplify SIMD support probe and annotate translated SIMD API invokes
liannacasper 976d86d
Remove SIMD hint annotation pipeline and hook emission
liannacasper 9873e22
Fix Base64 SIMD dead store and reduce lane-call overhead
liannacasper 6477697
Print translated Base64 symbols in integration benchmark
liannacasper 816511c
Persist translated Base64 dump as test artifact file
liannacasper 237e6e3
Add dedicated Base64 translation dump workflow
liannacasper 2941646
Fix Base64 dump workflow dependency resolution
liannacasper 321c9c2
Run Base64 dump workflow on hosted runner JDK 8
liannacasper 5d86ccb
Allow reactor modules without matching test filter
liannacasper 1c6f4fd
Use local core artifacts for Base64 translation dump
liannacasper 4859c50
Inline SIMD.isSupported in CustomInvoke paths
liannacasper 669b2a7
Force translated SIMD.isSupported method to return true
liannacasper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,57 @@ | ||
| name: Base64 Translation Dump | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - 'vm/ByteCodeTranslator/**' | ||
| - 'vm/tests/**' | ||
| - '.github/workflows/base64-translation-dump.yml' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| base64-translation-dump: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Java 8 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '8' | ||
|
|
||
| - name: Cache Maven dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.m2 | ||
| key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-m2 | ||
|
|
||
| - name: Build ByteCodeTranslator | ||
| run: mvn -B -f vm/pom.xml -pl ByteCodeTranslator -am -DskipTests=true install | ||
|
|
||
| - name: Build Codename One core artifact | ||
| run: mvn -B -f maven/pom.xml -pl core -am -DunitTests=true -DskipTests=true -Dspotbugs.skip=true -Dmaven.javadoc.skip=true install | ||
|
|
||
| - name: Generate Base64 translation dump | ||
| run: mvn -B -f vm/pom.xml -pl tests -am -Dcodenameone.core.version=8.0-SNAPSHOT -Dtest=Base64PerformanceIntegrationTest -Dsurefire.failIfNoSpecifiedTests=false test | ||
|
|
||
| - name: Upload Base64 translation dump artifacts | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: base64-translation-dump | ||
| path: | | ||
| vm/tests/target/base64-translated-snippets.txt | ||
| vm/tests/target/surefire-reports/** | ||
| if-no-files-found: warn | ||
This file contains hidden or 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,216 @@ | ||
| /* | ||
| * Copyright (c) 2012, Codename One and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. Codename One designates this | ||
| * particular file as subject to the "Classpath" exception as provided | ||
| * by Oracle in the LICENSE file that accompanied this code. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Codename One through http://www.codenameone.com/ if you | ||
| * need additional information or have any questions. | ||
| */ | ||
| package com.codename1.simd; | ||
|
|
||
| /** | ||
| * Explicit SIMD helper API. | ||
| * <p> | ||
| * This API is intentionally tiny and designed to be bytecode-recognition friendly for | ||
| * platform translators that can lower these calls into native SIMD instructions. | ||
| * </p> | ||
| * <p> | ||
| * The default Java implementation is scalar and fully functional so code remains portable. | ||
| * </p> | ||
| */ | ||
| public final class SIMD { | ||
|
|
||
| private SIMD() { | ||
| throw new AssertionError("SIMD should not be instantiated"); | ||
| } | ||
|
|
||
| /** | ||
| * Returns true when the current runtime+translator combo can map this API to a native SIMD backend. | ||
| * The default implementation returns false. | ||
| * | ||
| * @return true if SIMD backend support is available. | ||
| */ | ||
| public static boolean isSupported() { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * 4-lane float vector value type. | ||
| */ | ||
| public static final class Float4 { | ||
| public final float x; | ||
| public final float y; | ||
| public final float z; | ||
| public final float w; | ||
|
|
||
| public Float4(float x, float y, float z, float w) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| this.w = w; | ||
| } | ||
| } | ||
|
|
||
| public static Float4 makeFloat4(float x, float y, float z, float w) { | ||
| return new Float4(x, y, z, w); | ||
| } | ||
|
|
||
| public static Float4 load(float[] values, int offset) { | ||
| return new Float4( | ||
| values[offset], | ||
| values[offset + 1], | ||
| values[offset + 2], | ||
| values[offset + 3] | ||
| ); | ||
| } | ||
|
|
||
| public static void store(float[] values, int offset, Float4 value) { | ||
| values[offset] = value.x; | ||
| values[offset + 1] = value.y; | ||
| values[offset + 2] = value.z; | ||
| values[offset + 3] = value.w; | ||
| } | ||
|
|
||
| public static Float4 add(Float4 a, Float4 b) { | ||
| return new Float4( | ||
| a.x + b.x, | ||
| a.y + b.y, | ||
| a.z + b.z, | ||
| a.w + b.w | ||
| ); | ||
| } | ||
|
|
||
| public static Float4 mul(Float4 a, Float4 b) { | ||
| return new Float4( | ||
| a.x * b.x, | ||
| a.y * b.y, | ||
| a.z * b.z, | ||
| a.w * b.w | ||
| ); | ||
| } | ||
|
|
||
| public static Float4 fma(Float4 a, Float4 b, Float4 c) { | ||
| return add(mul(a, b), c); | ||
| } | ||
|
|
||
| /** | ||
| * 4-lane integer vector. | ||
| */ | ||
| public static final class Int4 { | ||
| public final int x; | ||
| public final int y; | ||
| public final int z; | ||
| public final int w; | ||
|
|
||
| public Int4(int x, int y, int z, int w) { | ||
| this.x = x; | ||
| this.y = y; | ||
| this.z = z; | ||
| this.w = w; | ||
| } | ||
| } | ||
|
|
||
| public static Int4 makeInt4(int x, int y, int z, int w) { | ||
| return new Int4(x, y, z, w); | ||
| } | ||
|
|
||
| public static Int4 add(Int4 a, Int4 b) { | ||
| return new Int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); | ||
| } | ||
|
|
||
| public static Int4 sub(Int4 a, Int4 b) { | ||
| return new Int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); | ||
| } | ||
|
|
||
| public static Int4 and(Int4 a, Int4 b) { | ||
| return new Int4(a.x & b.x, a.y & b.y, a.z & b.z, a.w & b.w); | ||
| } | ||
|
|
||
| public static Int4 or(Int4 a, Int4 b) { | ||
| return new Int4(a.x | b.x, a.y | b.y, a.z | b.z, a.w | b.w); | ||
| } | ||
|
|
||
| public static Int4 shl(Int4 a, int bits) { | ||
| return new Int4(a.x << bits, a.y << bits, a.z << bits, a.w << bits); | ||
| } | ||
|
|
||
| public static Int4 ushr(Int4 a, int bits) { | ||
| return new Int4(a.x >>> bits, a.y >>> bits, a.z >>> bits, a.w >>> bits); | ||
| } | ||
|
|
||
| /** | ||
| * Unsigned byte 16-lane vector. | ||
| */ | ||
| public static final class U8x16 { | ||
| private final int[] lanes = new int[16]; | ||
|
|
||
| private U8x16() { | ||
| } | ||
| } | ||
|
|
||
| public static U8x16 loadU8(byte[] values, int offset) { | ||
| U8x16 out = new U8x16(); | ||
| for (int i = 0; i < 16; i++) { | ||
| out.lanes[i] = values[offset + i] & 0xff; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| public static int laneU8(U8x16 value, int lane) { | ||
| return value.lanes[lane] & 0xff; | ||
| } | ||
|
|
||
| public static U8x16 and(U8x16 a, U8x16 b) { | ||
| U8x16 out = new U8x16(); | ||
| for (int i = 0; i < 16; i++) { | ||
| out.lanes[i] = (a.lanes[i] & b.lanes[i]) & 0xff; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| public static U8x16 or(U8x16 a, U8x16 b) { | ||
| U8x16 out = new U8x16(); | ||
| for (int i = 0; i < 16; i++) { | ||
| out.lanes[i] = (a.lanes[i] | b.lanes[i]) & 0xff; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| public static U8x16 xor(U8x16 a, U8x16 b) { | ||
| U8x16 out = new U8x16(); | ||
| for (int i = 0; i < 16; i++) { | ||
| out.lanes[i] = (a.lanes[i] ^ b.lanes[i]) & 0xff; | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| public static U8x16 shl(U8x16 a, int bits) { | ||
| U8x16 out = new U8x16(); | ||
| for (int i = 0; i < 16; i++) { | ||
| out.lanes[i] = ((a.lanes[i] << bits) & 0xff); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| public static U8x16 ushr(U8x16 a, int bits) { | ||
| U8x16 out = new U8x16(); | ||
| for (int i = 0; i < 16; i++) { | ||
| out.lanes[i] = (a.lanes[i] >>> bits) & 0xff; | ||
| } | ||
| return out; | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.